Search in sources :

Example 1 with MenuEntry

use of org.phoebus.ui.spi.MenuEntry in project phoebus by ControlSystemStudio.

the class MenuEntryService method populateMenuTree.

/**
 * @param root
 * @param menuEntries
 */
synchronized void populateMenuTree(MenuTreeNode root, List<MenuEntry> menuEntries) {
    // Sort hidden menu entries to allow binary search
    Arrays.sort(Preferences.hide_spi_menu);
    for (MenuEntry menuEntry : menuEntries) {
        // Skip hidden menu entries
        final String clazz = menuEntry.getClass().getName();
        if (Arrays.binarySearch(Preferences.hide_spi_menu, clazz) >= 0)
            continue;
        MenuTreeNode parent = root;
        List<String> path = Arrays.asList(menuEntry.getMenuPath().split("\\."));
        for (String p : path) {
            Optional<MenuTreeNode> child = parent.getChild(p);
            if (child.isPresent()) {
                parent = child.get();
            } else {
                MenuTreeNode node = new MenuTreeNode(p);
                parent.addChildren(node);
                parent = node;
            }
        }
        parent.addMenuEntries(menuEntry);
    }
}
Also used : MenuEntry(org.phoebus.ui.spi.MenuEntry)

Example 2 with MenuEntry

use of org.phoebus.ui.spi.MenuEntry in project phoebus by ControlSystemStudio.

the class PhoebusApplication method addMenuNode.

private void addMenuNode(Menu parent, MenuTreeNode node) {
    for (MenuEntry entry : node.getMenuItems()) {
        MenuItem m = createMenuItem(entry);
        parent.getItems().add(m);
    }
    for (MenuTreeNode child : node.getChildren()) {
        Menu childMenu = new Menu(child.getName());
        addMenuNode(childMenu, child);
        parent.getItems().add(childMenu);
    }
}
Also used : MenuEntry(org.phoebus.ui.spi.MenuEntry) CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) Menu(javafx.scene.control.Menu)

Example 3 with MenuEntry

use of org.phoebus.ui.spi.MenuEntry in project phoebus by ControlSystemStudio.

the class MenuEntryServiceTest method test.

@Test
public void test() {
    List<MenuEntry> menuEntries = Arrays.asList(new testMenuEntry("applications.display", "greetings"), new testMenuEntry("applications.display", "hello"));
    MenuTreeNode root = new MenuTreeNode("Applications");
    MenuEntryService.getInstance().populateMenuTree(root, menuEntries);
    assertTrue("Parsing MenuEntries: ", root.getChildren().size() == 1);
    assertTrue("Parsing MenuEntries: ", root.getMenuItems().size() == 0);
    MenuTreeNode applicationsNode = root.getChildren().get(0);
    assertTrue("Parsing MenuEntries: ", applicationsNode.getChildren().size() == 1);
    assertTrue("Parsing MenuEntries: ", applicationsNode.getMenuItems().size() == 0);
    MenuTreeNode displayNode = applicationsNode.getChildren().get(0);
    assertTrue("Parsing MenuEntries: ", displayNode.getChildren().size() == 0);
    assertTrue("Parsing MenuEntries: ", displayNode.getMenuItems().size() == 2);
}
Also used : MenuEntry(org.phoebus.ui.spi.MenuEntry) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) Test(org.junit.Test)

Aggregations

MenuEntry (org.phoebus.ui.spi.MenuEntry)3 MenuTreeNode (org.phoebus.ui.application.MenuEntryService.MenuTreeNode)2 CheckMenuItem (javafx.scene.control.CheckMenuItem)1 Menu (javafx.scene.control.Menu)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 Test (org.junit.Test)1