-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New public API for building application menu: adds `MenuConfiguration`, `MenuOptions` and `MenuOption` where `MenuConfiguration` is the main entry point to access menu data to build main menu. Fixes: #20063
- Loading branch information
Showing
7 changed files
with
463 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
flow-server/src/main/java/com/vaadin/flow/server/menu/MenuConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.server.menu; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Menu configuration helper class to retrieve available menu options for | ||
* application main menu. | ||
*/ | ||
public class MenuConfiguration implements Serializable { | ||
|
||
/** | ||
* Get the {@link MenuOptions} instance containing all menu options for the | ||
* application. | ||
* | ||
* @return the {@link MenuOptions} instance | ||
*/ | ||
public static MenuOptions getMenuOptions() { | ||
return MenuOptions.getInstance(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
flow-server/src/main/java/com/vaadin/flow/server/menu/MenuOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.server.menu; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.vaadin.flow.component.Component; | ||
|
||
/** | ||
* Menu option for the main menu. | ||
* | ||
* @param path | ||
* the path to navigate to | ||
* @param title | ||
* the title to display | ||
* @param order | ||
* the order in the menu or null for default order | ||
* @param exclude | ||
* whether to exclude the menu option | ||
* @param icon | ||
* Icon to use in the menu or null for no icon. Value can go inside a | ||
* {@code <vaadin-icon>} element's {@code icon} attribute which | ||
* accepts icon group and name like 'vaadin:file'. Or it can go to a | ||
* {@code <vaadin-icon>} element's {@code src} attribute which takes | ||
* path to the icon. E.g. 'line-awesome/svg/lock-open-solid.svg'. | ||
* @param menuClass | ||
* the source class with {@link com.vaadin.flow.router.Menu} | ||
* annotation or null if not available | ||
*/ | ||
public record MenuOption(String path, String title, Double order, | ||
boolean exclude, String icon, Class<? extends Component> menuClass) implements Serializable { | ||
} |
73 changes: 73 additions & 0 deletions
73
flow-server/src/main/java/com/vaadin/flow/server/menu/MenuOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.server.menu; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* {@link MenuOptions} holds a list of menu options. | ||
*/ | ||
public class MenuOptions implements Serializable { | ||
|
||
private final List<MenuOption> menuOptions; | ||
|
||
private MenuOptions(List<MenuOption> menuOptions) { | ||
this.menuOptions = menuOptions; | ||
} | ||
|
||
/** | ||
* Construct a new instance containing all available menu options. | ||
*/ | ||
public static MenuOptions getInstance() { | ||
return new MenuOptions( | ||
MenuRegistry.collectMenuItemsList().stream().map(viewInfo -> { | ||
if (viewInfo.menu() == null) { | ||
return new MenuOption(viewInfo.route(), | ||
viewInfo.title(), null, false, null, null); | ||
} | ||
return new MenuOption(viewInfo.route(), | ||
(viewInfo.menu().title() != null | ||
&& !viewInfo.menu().title().isBlank() | ||
? viewInfo.menu().title() | ||
: viewInfo.title()), | ||
viewInfo.menu().order(), viewInfo.menu().exclude(), | ||
viewInfo.menu().icon(), | ||
viewInfo.menu().menuClass()); | ||
}).toList()); | ||
} | ||
|
||
/** | ||
* Get a stream of the menu options. | ||
* | ||
* @return the menu options stream | ||
*/ | ||
public Stream<MenuOption> stream() { | ||
return menuOptions.stream(); | ||
} | ||
|
||
/** | ||
* Get the list of the menu options. Returned list is mutable and any | ||
* changes to it will also change {@link MenuOptions} state. | ||
* | ||
* @return the menu options list | ||
*/ | ||
public List<MenuOption> get() { | ||
return menuOptions; | ||
} | ||
} |
Oops, something went wrong.