Search in sources :

Example 6 with MenuItem

use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.

the class DefaultWorkbenchFeaturesMenusHelper method buildMenusFromNavTree.

public TopLevelMenusBuilder<MenuBuilder> buildMenusFromNavTree(NavTree navTree) {
    if (navTree == null) {
        return null;
    }
    MenuBuilder<TopLevelMenusBuilder<MenuBuilder>> builder = null;
    for (NavItem navItem : navTree.getRootItems()) {
        // Skip dividers
        if (navItem instanceof NavDivider) {
            continue;
        }
        // AF-953: Ignore empty groups
        if (navItem instanceof NavGroup && ((NavGroup) navItem).getChildren().isEmpty()) {
            continue;
        }
        // Build a top level menu entry
        if (builder == null) {
            builder = MenuFactory.newTopLevelMenu(navItem.getName());
        } else {
            builder = builder.endMenu().newTopLevelMenu(navItem.getName());
        }
        // Append its children
        if (navItem instanceof NavGroup) {
            List<MenuItem> childItems = buildMenuItemsFromNavGroup((NavGroup) navItem);
            builder.withItems(childItems);
        }
        // Append the place request
        NavWorkbenchCtx navCtx = NavWorkbenchCtx.get(navItem);
        if (navCtx.getResourceId() != null && ActivityResourceType.PERSPECTIVE.equals(navCtx.getResourceType())) {
            PlaceRequest placeRequest = resolvePlaceRequest(navCtx.getResourceId());
            builder = builder.place(placeRequest);
        }
    }
    return builder != null ? builder.endMenu() : null;
}
Also used : DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) TopLevelMenusBuilder(org.uberfire.workbench.model.menu.MenuFactory.TopLevelMenusBuilder) MenuItem(org.uberfire.workbench.model.menu.MenuItem) NavWorkbenchCtx(org.dashbuilder.navigation.workbench.NavWorkbenchCtx) NavItem(org.dashbuilder.navigation.NavItem) NavDivider(org.dashbuilder.navigation.NavDivider) NavGroup(org.dashbuilder.navigation.NavGroup)

Example 7 with MenuItem

use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.

the class RegisteredDocumentsMenuBuilderTest method testDisable.

@Test
public void testDisable() {
    final MenuItem mi = builder.build();
    mi.setEnabled(false);
    verify(view, times(1)).setEnabled(eq(false));
}
Also used : DocumentMenuItem(org.kie.workbench.common.widgets.metadata.client.menu.RegisteredDocumentsMenuView.DocumentMenuItem) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 8 with MenuItem

use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.

the class KieEditorTest method testAddDownloadMenuItem.

@Test
public void testAddDownloadMenuItem() {
    final MenuItem menuItem = mock(MenuItem.class);
    doReturn(menuItem).when(presenter).downloadMenuItem();
    presenter.addDownloadMenuItem(fileMenuBuilder);
    verify(fileMenuBuilder).addNewTopLevelMenu(menuItem);
}
Also used : MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 9 with MenuItem

use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.

the class KieEditorTest method testAddSave.

@Test
public void testAddSave() {
    final MenuItem menuItem = mock(MenuItem.class);
    when(versionRecordManager.newSaveMenuItem(any(ParameterizedCommand.class))).thenReturn(menuItem);
    presenter.addSave(fileMenuBuilder);
    verify(fileMenuBuilder).addSave(menuItem);
}
Also used : MenuItem(org.uberfire.workbench.model.menu.MenuItem) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Test(org.junit.Test)

Example 10 with MenuItem

use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.

the class DefaultWorkbenchFeaturesMenusHelperTest method buildMenusFromNavTreeTest.

@Test
public void buildMenusFromNavTreeTest() {
    NavTree navTree = new NavTreeBuilder().group("g1", "g1", "g1", true).item("i1", "i1", "i1", true).endGroup().group("g2", "g2", "g2", true).item("i2", "i2", "i2", true).endGroup().group("g3", "g3", "g3", true).endGroup().build();
    Menus menus = menusHelper.buildMenusFromNavTree(navTree).build();
    List<MenuItem> menuItems = menus.getItems();
    assertEquals(menuItems.size(), 2);
    MenuGroup group1 = (MenuGroup) menuItems.get(0);
    assertEquals(group1.getCaption(), "g1");
    assertEquals(group1.getItems().size(), 1);
    MenuItem item1 = group1.getItems().get(0);
    assertEquals(item1.getCaption(), "i1");
    MenuGroup group2 = (MenuGroup) menuItems.get(1);
    assertEquals(group2.getCaption(), "g2");
    assertEquals(group2.getItems().size(), 1);
    MenuItem item2 = group2.getItems().get(0);
    assertEquals(item2.getCaption(), "i2");
}
Also used : NavTree(org.dashbuilder.navigation.NavTree) NavTreeBuilder(org.dashbuilder.navigation.impl.NavTreeBuilder) Menus(org.uberfire.workbench.model.menu.Menus) MenuItem(org.uberfire.workbench.model.menu.MenuItem) MenuGroup(org.uberfire.workbench.model.menu.MenuGroup) Test(org.junit.Test)

Aggregations

MenuItem (org.uberfire.workbench.model.menu.MenuItem)34 Test (org.junit.Test)18 Button (org.gwtbootstrap3.client.ui.Button)6 IsWidget (com.google.gwt.user.client.ui.IsWidget)5 ButtonGroup (org.gwtbootstrap3.client.ui.ButtonGroup)5 DropDownMenu (org.gwtbootstrap3.client.ui.DropDownMenu)5 Command (org.uberfire.mvp.Command)5 AnchorListItem (org.gwtbootstrap3.client.ui.AnchorListItem)4 ButtonSize (org.gwtbootstrap3.client.ui.constants.ButtonSize)4 IconType (org.gwtbootstrap3.client.ui.constants.IconType)4 Toggle (org.gwtbootstrap3.client.ui.constants.Toggle)4 MenuUtils (org.kie.workbench.common.stunner.client.widgets.menu.MenuUtils)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Inject (javax.inject.Inject)3 IconPosition (org.gwtbootstrap3.client.ui.constants.IconPosition)3 Pull (org.gwtbootstrap3.client.ui.constants.Pull)3 PlaceRequest (org.uberfire.mvp.PlaceRequest)3 Menus (org.uberfire.workbench.model.menu.Menus)3 BaseMenuCustom (org.uberfire.workbench.model.menu.impl.BaseMenuCustom)3