private List<? extends MenuItem> getDeploymentViews() {
    final List<MenuItem> result = new ArrayList<MenuItem>(3);

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Deployments())
            .withRoles(kieACL.getGrantedRoles(F_DEPLOYMENTS))
            .place(new DefaultPlaceRequest("Deployments"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.Rule_Deployments())
            .withRoles(kieACL.getGrantedRoles(F_MANAGEMENT))
            .place(new DefaultPlaceRequest("ServerManagementPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.Jobs())
            .withRoles(kieACL.getGrantedRoles(F_JOBS))
            .place(new DefaultPlaceRequest("Jobs"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  private List<? extends MenuItem> getDashboardViews() {
    final List<MenuItem> result = new ArrayList<MenuItem>(1);
    result.add(
        MenuFactory.newSimpleItem(constants.Process_Dashboard())
            .withRoles(kieACL.getGrantedRoles(F_PROCESS_DASHBOARD))
            .place(new DefaultPlaceRequest("DashboardPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    final String dashbuilderURL =
        DashboardURLBuilder.getDashboardURL(
            "/dashbuilder/workspace", "showcase", LocaleInfo.getCurrentLocale().getLocaleName());
    result.add(
        MenuFactory.newSimpleItem(constants.Business_Dashboard())
            .withRoles(kieACL.getGrantedRoles(F_DASHBOARD_BUILDER))
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    Window.open(dashbuilderURL, "_blank", "");
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
 private List<? extends MenuItem> getExtensionsViews() {
   final List<MenuItem> result = new ArrayList<MenuItem>(2);
   result.add(
       MenuFactory.newSimpleItem(constants.plugins())
           .withRoles(kieACL.getGrantedRoles(F_PLUGIN_MANAGEMENT))
           .place(new DefaultPlaceRequest("PlugInAuthoringPerspective"))
           .endMenu()
           .build()
           .getItems()
           .get(0));
   result.add(
       MenuFactory.newSimpleItem(constants.Apps())
           .withRoles(kieACL.getGrantedRoles(F_APPS))
           .place(new DefaultPlaceRequest("AppsPerspective"))
           .endMenu()
           .build()
           .getItems()
           .get(0));
   result.add(
       MenuFactory.newSimpleItem(constants.DataSets())
           .withRoles(kieACL.getGrantedRoles(F_DATASETS))
           .place(new DefaultPlaceRequest("DataSetAuthoringPerspective"))
           .endMenu()
           .build()
           .getItems()
           .get(0));
   return result;
 }
  protected List<? extends MenuItem> getProcessManagementViews() {
    final List<MenuItem> result = new ArrayList<>(3);

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Definitions())
            .perspective("Process Definitions")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Process_Instances())
            .perspective("DataSet Process Instances With Variables")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Process_Instances_Admin())
            .perspective("Process Admin")
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  protected List<? extends MenuItem> getDashboardsViews() {
    final List<MenuItem> result = new ArrayList<>(2);

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Dashboard())
            .perspective("DashboardPerspective")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Business_Dashboard())
            .respondsWith(
                () ->
                    Window.open(
                        DashboardURLBuilder.getDashboardURL(
                            "/dashbuilder/workspace",
                            null,
                            LocaleInfo.getCurrentLocale().getLocaleName()),
                        "_blank",
                        ""))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  protected List<? extends MenuItem> getWorkViews() {
    final List<MenuItem> result = new ArrayList<>(4);

    result.add(
        MenuFactory.newSimpleItem(constants.Tasks_List())
            .perspective("DataSet Tasks")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Tasks_List_Admin())
            .perspective("Tasks Admin")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Data_Sets())
            .perspective("DataSetAuthoringPerspective")
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  protected List<? extends MenuItem> getExperimentalViews() {
    final List<MenuItem> result = new ArrayList<>(3);

    result.add(
        MenuFactory.newSimpleItem(constants.Grid_Base_Test())
            .perspective("Grid Base Test")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Logs())
            .perspective("Logs")
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Documents())
            .perspective("Documents Perspective")
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  private List<? extends MenuItem> getHomeViews(
      final Boolean socialEnabled, final boolean usersSystemActive) {
    final AbstractWorkbenchPerspectiveActivity defaultPerspective = getDefaultPerspectiveActivity();
    final List<MenuItem> result = new ArrayList<MenuItem>(1);

    result.add(
        MenuFactory.newSimpleItem(constants.homePage())
            .place(new DefaultPlaceRequest(defaultPerspective.getIdentifier()))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    // Social menu items.
    if (socialEnabled) {
      result.add(
          MenuFactory.newSimpleItem(constants.timeline())
              .place(new DefaultPlaceRequest("SocialHomePagePerspective"))
              .endMenu()
              .build()
              .getItems()
              .get(0));

      result.add(
          MenuFactory.newSimpleItem(constants.people())
              .place(new DefaultPlaceRequest("UserHomePagePerspective"))
              .endMenu()
              .build()
              .getItems()
              .get(0));
    }

    // User management menu items (only if services are active and constrained to admin roles).
    if (usersSystemActive) {
      result.add(
          MenuFactory.newSimpleItem(constants.userManagement())
              .withRoles(kieACL.getGrantedRoles(F_ADMINISTRATION))
              .place(new DefaultPlaceRequest("UsersManagementPerspective"))
              .endMenu()
              .build()
              .getItems()
              .get(0));
      result.add(
          MenuFactory.newSimpleItem(constants.groupManagement())
              .withRoles(kieACL.getGrantedRoles(F_ADMINISTRATION))
              .place(new DefaultPlaceRequest("GroupsManagementPerspective"))
              .endMenu()
              .build()
              .getItems()
              .get(0));
    }

    return result;
  }
 private List<Menus> getRoles() {
   final List<Menus> result = new ArrayList<Menus>(identity.getRoles().size());
   result.add(
       MenuFactory.newSimpleItem(constants.LogOut())
           .respondsWith(new LogoutCommand())
           .endMenu()
           .build());
   for (final Role role : identity.getRoles()) {
     if (!role.getName().equals("IS_REMEMBER_ME")) {
       result.add(
           MenuFactory.newSimpleItem(constants.Role() + ": " + role.getName()).endMenu().build());
     }
   }
   return result;
 }
  @WorkbenchMenu
  public Menus buildMenu() {
    return MenuFactory.newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {
              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<Button>() {

                  @Override
                  public Button build() {
                    return new Button() {
                      {
                        setIcon(IconType.HOME);
                        setTitle(Constants.INSTANCE.Home());
                        setSize(ButtonSize.SMALL);
                        addClickHandler(
                            new ClickHandler() {
                              @Override
                              public void onClick(ClickEvent event) {
                                refreshCacheAndGeneratesSelectEvent(loggedUser.getIdentifier());
                              }
                            });
                      }
                    };
                  }
                };
              }
            })
        .endMenu()
        .build();
  }
 @WorkbenchMenu
 public Menus getMenus() {
   return MenuFactory.newTopLevelMenu(constants.MenuOrganizationalUnits())
       .withPermission(OrganizationalUnit.RESOURCE_TYPE, OrganizationalUnitAction.READ)
       .menus()
       .menu(constants.MenuManageOrganizationalUnits())
       .respondsWith(
           () ->
               placeManager.goTo(
                   "org.kie.workbench.common.screens.organizationalunit.manager.OrganizationalUnitManager"))
       .endMenu()
       .endMenus()
       .endMenu()
       .newTopLevelMenu(constants.repositories())
       .menus()
       .menu(constants.listRepositories())
       .withPermission(Repository.RESOURCE_TYPE, RepositoryAction.READ)
       .respondsWith(() -> placeManager.goTo("RepositoriesEditor"))
       .endMenu()
       .menu(constants.cloneRepository())
       .withPermission(Repository.RESOURCE_TYPE, RepositoryAction.READ)
       .respondsWith(cloneRepoCommand)
       .endMenu()
       .menu(constants.newRepository())
       .withPermission(Repository.RESOURCE_TYPE, RepositoryAction.CREATE)
       .respondsWith(newRepoCommand)
       .endMenu()
       .endMenus()
       .endMenu()
       .build();
 }
 @WorkbenchMenu
 public Menus buildMenu() {
   return MenuFactory.newTopLevelCustomMenu(serverTemplateSelectorMenuBuilder)
       .endMenu()
       .newTopLevelCustomMenu(new RefreshMenuBuilder(this))
       .endMenu()
       .build();
 }
  private List<MenuItem> getAuthoringViews() {
    final List<MenuItem> result = new ArrayList<MenuItem>(4);

    result.add(
        MenuFactory.newSimpleItem(constants.project_authoring())
            .withRoles(kieACL.getGrantedRoles(F_PROJECT_AUTHORING))
            .place(new DefaultPlaceRequest("AuthoringPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.contributors())
            .withRoles(kieACL.getGrantedRoles(F_CONTRIBUTORS))
            .place(new DefaultPlaceRequest("ContributorsPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.artifactRepository())
            .withRoles(kieACL.getGrantedRoles(F_ARTIFACT_REPO))
            .place(
                new DefaultPlaceRequest(
                    "org.guvnor.m2repo.client.perspectives.GuvnorM2RepoPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.administration())
            .withRoles(kieACL.getGrantedRoles(F_ADMINISTRATION))
            .place(new DefaultPlaceRequest("AdministrationPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  protected List<? extends MenuItem> getDeploymentViews() {
    final List<MenuItem> result = new ArrayList<>(3);

    result.add(
        MenuFactory.newSimpleItem(constants.Execution_Servers())
            .place(new DefaultPlaceRequest("ServerManagementPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));
    result.add(
        MenuFactory.newSimpleItem(constants.Jobs())
            .perspective("Jobs")
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  @WorkbenchMenu
  public Menus getMenus() {
    return MenuFactory.newTopLevelMenu(Constants.INSTANCE.New_Process_Instance())
        .respondsWith(
            new Command() {
              @Override
              public void execute() {
                newProcessInstancePopup.show();
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {
              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {
                  @Override
                  public IsWidget build() {
                    menuRefreshButton.addClickHandler(
                        new ClickHandler() {
                          @Override
                          public void onClick(ClickEvent clickEvent) {
                            refreshGrid();
                          }
                        });
                    return menuRefreshButton;
                  }

                  @Override
                  public boolean isEnabled() {
                    return true;
                  }

                  @Override
                  public void setEnabled(boolean enabled) {}

                  @Override
                  public String getSignatureId() {
                    return "org.jbpm.console.ng.pr.client.editors.instance.list.ProcessInstanceListPresenter#menuRefreshButton";
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(refreshSelectorMenuBuilder)
        .endMenu()
        .newTopLevelCustomMenu(resetFiltersMenuBuilder)
        .endMenu()
        .build();
  }
  protected List<? extends MenuItem> getAuthoringViews() {
    final List<MenuItem> result = new ArrayList<>(1);

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Authoring())
            .perspective(constants.Authoring())
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  protected List<? extends MenuItem> getCaseManagementViews() {
    final List<MenuItem> result = new ArrayList<>(1);

    result.add(
        MenuFactory.newSimpleItem(constants.Cases())
            .perspective("Cases")
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  private List<? extends MenuItem> getProcessMGMTViews() {
    final List<MenuItem> result = new ArrayList<MenuItem>(2);

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Definitions())
            .withRoles(kieACL.getGrantedRoles(F_PROCESS_DEFINITIONS))
            .place(new DefaultPlaceRequest("Process Definitions"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    result.add(
        MenuFactory.newSimpleItem(constants.Process_Instances())
            .withRoles(kieACL.getGrantedRoles(F_PROCESS_INSTANCES))
            .place(new DefaultPlaceRequest("DataSet Process Instances With Variables"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
  private List<MenuItem> getDeploymentViews() {
    final List<MenuItem> result = new ArrayList<MenuItem>(1);

    result.add(
        MenuFactory.newSimpleItem(constants.ruleDeployments())
            .withRoles(kieACL.getGrantedRoles(F_MANAGEMENT))
            .place(new DefaultPlaceRequest("ServerManagementPerspective"))
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return result;
  }
 @WorkbenchMenu
 public Menus getMenus() {
   return MenuFactory.newTopLevelMenu("Open")
       .withItems(ShowcaseEntryPoint.getScreens())
       .endMenu()
       .newTopLevelMenu("Command")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Command!");
             }
           })
       .endMenu()
       .newTopLevelMenu("Create New")
       .menus()
       .menu("Command 1")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Command 1!");
             }
           })
       .endMenu()
       .menu("Command 2")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Command 2!");
             }
           })
       .endMenu()
       .endMenus()
       .endMenu()
       .newTopLevelMenu("Find")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Find!");
             }
           })
       .position(MenuPosition.RIGHT)
       .endMenu()
       .build();
 }
  @Override
  protected void setupMenu() {

    final AbstractWorkbenchPerspectiveActivity defaultPerspective =
        menusHelper.getDefaultPerspectiveActivity();
    final Menus menus =
        MenuFactory.newTopLevelMenu(constants.Home())
            .place(new DefaultPlaceRequest(defaultPerspective.getIdentifier()))
            .endMenu()
            .newTopLevelMenu(constants.Authoring())
            .withItems(getAuthoringViews())
            .endMenu()
            .newTopLevelMenu(constants.Deploy())
            .withItems(getDeploymentViews())
            .endMenu()
            .newTopLevelMenu(constants.Case_Management())
            .withItems(getCaseManagementViews())
            .endMenu()
            .newTopLevelMenu(constants.Process_Management())
            .withItems(getProcessManagementViews())
            .endMenu()
            .newTopLevelMenu(constants.Work())
            .withItems(getWorkViews())
            .endMenu()
            .newTopLevelMenu(constants.Dashboards())
            .withItems(getDashboardsViews())
            .endMenu()
            .newTopLevelMenu(constants.Extensions())
            .withItems(menusHelper.getExtensionsViews())
            .endMenu()
            .newTopLevelMenu(constants.Experimental())
            .withItems(getExperimentalViews())
            .endMenu()
            .newTopLevelCustomMenu(iocManager.lookupBean(SearchMenuBuilder.class).getInstance())
            .endMenu()
            .build();

    menuBar.addMenus(menus);

    menusHelper.addRolesMenuItems();
    menusHelper.addGroupsMenuItems();
    menusHelper.addWorkbenchConfigurationMenuItem();
    menusHelper.addUtilitiesMenuItems();
  }
  @Override
  protected void makeMenuBar() {
    super.makeMenuBar();

    menuBuilder.addNewTopLevelMenu(
        MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Tags())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    AddTag addTag = new AddTag(PerspectiveEditorPresenter.this);
                    addTag.show();
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));
  }
Example #23
0
 @WorkbenchMenu
 public Menus getMenu() {
   return MenuFactory.newTopLevelMenu("Save")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Saved!");
             }
           })
       .endMenu()
       .newTopLevelMenu("Delete")
       .respondsWith(
           new Command() {
             @Override
             public void execute() {
               Window.alert("Deleted!");
             }
           })
       .endMenu()
       .build();
 }
 private void makeMenuBar() {
   menus =
       MenuFactory.newTopLevelMenu(constants.Bulk_Actions())
           .withItems(getBulkActions())
           .endMenu()
           .newTopLevelMenu(constants.Refresh())
           .respondsWith(
               new Command() {
                 @Override
                 public void execute() {
                   view.getShowAllLink().setStyleName("active");
                   view.getShowCompletedLink().setStyleName("");
                   view.getShowAbortedLink().setStyleName("");
                   view.getShowRelatedToMeLink().setStyleName("");
                   refreshActiveProcessList();
                   clearSearchEvent.fire(new ClearSearchEvent());
                   view.setCurrentFilter("");
                   view.displayNotification(constants.Process_Instances_Refreshed());
                 }
               })
           .endMenu()
           .build();
 }
  @WorkbenchMenu
  public Menus buildMenu() {
    return MenuFactory.newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {

              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {

                  @Override
                  public IsWidget build() {
                    return view.getNewInstanceButton();
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {

              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {

                  @Override
                  public IsWidget build() {
                    return view.getOptionsButton();
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {

              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {

                  @Override
                  public IsWidget build() {
                    return view.getRefreshButton();
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {

              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {

                  @Override
                  public IsWidget build() {
                    return view.getCloseButton();
                  }
                };
              }
            })
        .endMenu()
        .build();
  }
  @WorkbenchMenu
  public Menus getMenus() {
    GWT.log("get menus DatasetTasklist presenter " + autoRefreshSeconds);
    setupButtons();

    return MenuFactory.newTopLevelMenu(Constants.INSTANCE.New_Task())
        .respondsWith(
            new Command() {
              @Override
              public void execute() {
                quickNewTaskPopup.show();
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {
              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {
                  @Override
                  public IsWidget build() {
                    menuRefreshButton.addClickHandler(
                        new ClickHandler() {
                          @Override
                          public void onClick(ClickEvent clickEvent) {
                            refreshGrid();
                          }
                        });
                    return menuRefreshButton;
                  }

                  @Override
                  public boolean isEnabled() {
                    return true;
                  }

                  @Override
                  public void setEnabled(boolean enabled) {}

                  @Override
                  public String getSignatureId() {
                    return "org.jbpm.console.ng.ht.client.editors.taskslist.grid.dash.DataSetTaskListGridPresenter#menuRefreshButton";
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {
              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {
                  @Override
                  public IsWidget build() {
                    return menuActionsButton;
                  }

                  @Override
                  public boolean isEnabled() {
                    return true;
                  }

                  @Override
                  public void setEnabled(boolean enabled) {}

                  @Override
                  public String getSignatureId() {
                    return "org.jbpm.console.ng.ht.client.editors.taskslist.grid.dash.DataSetTaskListGridPresenter#menuActionsButton";
                  }
                };
              }
            })
        .endMenu()
        .newTopLevelCustomMenu(
            new MenuFactory.CustomMenuBuilder() {
              @Override
              public void push(MenuFactory.CustomMenuBuilder element) {}

              @Override
              public MenuItem build() {
                return new BaseMenuCustom<IsWidget>() {
                  @Override
                  public IsWidget build() {
                    menuResetTabsButton.addClickHandler(
                        new ClickHandler() {
                          @Override
                          public void onClick(ClickEvent clickEvent) {
                            view.restoreTabs();
                          }
                        });
                    return menuResetTabsButton;
                  }

                  @Override
                  public boolean isEnabled() {
                    return true;
                  }

                  @Override
                  public void setEnabled(boolean enabled) {}

                  @Override
                  public String getSignatureId() {
                    return "org.jbpm.console.ng.ht.client.editors.taskslist.grid.dash.DataSetTaskListGridPresenter#menuResetTabsButton";
                  }
                };
              }
            })
        .endMenu()
        .build();
  }
  @Override
  public Menus build() {
    final Map<Object, MenuItem> menuItems = new LinkedHashMap<Object, MenuItem>();
    if (saveCommand != null) {
      menuItems.put(
          MenuItems.SAVE,
          MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Save())
              .respondsWith(saveCommand)
              .endMenu()
              .build()
              .getItems()
              .get(0));
    } else if (saveMenuItem != null) {
      menuItems.put(MenuItems.SAVE, saveMenuItem);
      menuItemsSyncedWithLockState.add(saveMenuItem);
    }

    if (deleteCommand != null) {
      if (deleteMenuItem == null) {
        deleteMenuItem =
            MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Delete())
                .respondsWith(deleteCommand)
                .endMenu()
                .build()
                .getItems()
                .get(0);
      }
      menuItems.put(MenuItems.DELETE, deleteMenuItem);
      menuItemsSyncedWithLockState.add(deleteMenuItem);
    }

    if (renameCommand != null) {
      if (renameMenuItem == null) {
        renameMenuItem =
            MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Rename())
                .respondsWith(renameCommand)
                .endMenu()
                .build()
                .getItems()
                .get(0);
      }
      menuItems.put(MenuItems.RENAME, renameMenuItem);
      menuItemsSyncedWithLockState.add(renameMenuItem);
    }

    if (copyCommand != null) {
      menuItems.put(
          MenuItems.COPY,
          MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Copy())
              .respondsWith(copyCommand)
              .endMenu()
              .build()
              .getItems()
              .get(0));
    }

    if (validateCommand != null) {
      menuItems.put(
          MenuItems.VALIDATE,
          MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Validate())
              .respondsWith(validateCommand)
              .endMenu()
              .build()
              .getItems()
              .get(0));
    }

    if (restoreCommand != null) {
      if (restoreMenuItem == null) {
        restoreMenuItem =
            MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Restore())
                .respondsWith(restoreCommand)
                .endMenu()
                .build()
                .getItems()
                .get(0);
      }
      menuItemsSyncedWithLockState.add(restoreMenuItem);
    }

    if (!(otherCommands == null || otherCommands.isEmpty())) {
      final List<MenuItem> otherMenuItems = new ArrayList<MenuItem>();
      for (Pair<String, Command> other : otherCommands) {
        otherMenuItems.add(
            newSimpleItem(other.getK1())
                .respondsWith(other.getK2())
                .endMenu()
                .build()
                .getItems()
                .get(0));
      }
      final MenuItem item =
          MenuFactory.newTopLevelMenu(CommonConstants.INSTANCE.Other())
              .withItems(otherMenuItems)
              .endMenu()
              .build()
              .getItems()
              .get(0);
      menuItems.put(item, item);
    }

    for (MenuItem menuItem : topLevelMenus) {
      menuItems.put(menuItem, menuItem);
    }

    return new Menus() {

      @Override
      public List<MenuItem> getItems() {
        return new ArrayList<MenuItem>() {
          {
            for (final MenuItem menuItem : menuItems.values()) {
              add(menuItem);
            }
          }
        };
      }

      @Override
      public Map<Object, MenuItem> getItemsMap() {
        return menuItems;
      }

      @Override
      public void accept(MenuVisitor visitor) {
        if (visitor.visitEnter(this)) {
          for (final MenuItem item : menuItems.values()) {
            item.accept(visitor);
          }
          visitor.visitLeave(this);
        }
      }
    };
  }
  private List<? extends MenuItem> getBulkActions() {
    List<MenuItem> bulkActions = new ArrayList<MenuItem>(2);
    bulkActions.add(
        MenuFactory.newSimpleItem(constants.Bulk_Signal())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    StringBuffer processIdsParam = new StringBuffer();
                    if (view.getSelectedProcessInstances() != null) {

                      for (ProcessInstanceSummary selected : view.getSelectedProcessInstances()) {
                        if (selected.getState() != ProcessInstance.STATE_ACTIVE) {
                          view.displayNotification(
                              constants.Signaling_Process_Instance_Not_Allowed()
                                  + "(id="
                                  + selected.getId()
                                  + ")");
                          continue;
                        }
                        processIdsParam.append(selected.getId() + ",");
                        view.getProcessInstanceListGrid()
                            .getSelectionModel()
                            .setSelected(selected, false);
                      }
                      // remove last ,
                      if (processIdsParam.length() > 0) {
                        processIdsParam.deleteCharAt(processIdsParam.length() - 1);
                      }
                    } else {
                      processIdsParam.append("-1");
                    }
                    PlaceRequest placeRequestImpl = new DefaultPlaceRequest("Signal Process Popup");
                    placeRequestImpl.addParameter("processInstanceId", processIdsParam.toString());

                    placeManager.goTo(placeRequestImpl);
                    view.displayNotification(constants.Signaling_Process_Instance());
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));

    bulkActions.add(
        MenuFactory.newSimpleItem(constants.Bulk_Abort())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    if (view.getSelectedProcessInstances() != null) {
                      List<Long> ids = new ArrayList<Long>();
                      for (ProcessInstanceSummary selected : view.getSelectedProcessInstances()) {
                        if (selected.getState() != ProcessInstance.STATE_ACTIVE) {
                          view.displayNotification(
                              constants.Aborting_Process_Instance_Not_Allowed()
                                  + "(id="
                                  + selected.getId()
                                  + ")");
                          continue;
                        }
                        ids.add(selected.getId());

                        view.getProcessInstanceListGrid()
                            .getSelectionModel()
                            .setSelected(selected, false);
                        view.displayNotification(
                            constants.Aborting_Process_Instance()
                                + "(id="
                                + selected.getId()
                                + ")");
                      }
                      abortProcessInstance(ids);
                    }
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return bulkActions;
  }
  private void setupMenu() {
    final AbstractWorkbenchPerspectiveActivity defaultPerspective = getDefaultPerspectiveActivity();

    final Menus menus =
        MenuFactory.newTopLevelMenu(AppConstants.INSTANCE.Home())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    if (defaultPerspective != null) {
                      placeManager.goTo(
                          new DefaultPlaceRequest(defaultPerspective.getIdentifier()));
                    } else {
                      Window.alert("Default perspective not found.");
                    }
                  }
                })
            .endMenu()
            .newTopLevelMenu(AppConstants.INSTANCE.MenuOrganizationalUnits())
            .menus()
            .menu(AppConstants.INSTANCE.MenuManageOrganizationalUnits())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(
                        "org.kie.workbench.common.screens.organizationalunit.manager.OrganizationalUnitManager");
                  }
                })
            .endMenu()
            .endMenus()
            .endMenu()
            .newTopLevelMenu("Repositories")
            .menus()
            .menu("Repositories List")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo("RepositoriesEditor");
                  }
                })
            .endMenu()
            .menu("Clone repository")
            .respondsWith(cloneRepoCommand)
            .endMenu()
            .menu("New repository")
            .respondsWith(newRepoCommand)
            .endMenu()
            .endMenus()
            .endMenu()
            .newTopLevelMenu("Authoring")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    if (defaultPerspective != null) {
                      placeManager.goTo(new DefaultPlaceRequest("AuthoringPerspective"));
                    } else {
                      Window.alert(" perspective not found.");
                    }
                  }
                })
            .endMenu()
            .newTopLevelMenu("Artifacts")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(
                        new DefaultPlaceRequest(
                            "org.guvnor.m2repo.client.perspectives.GuvnorM2RepoPerspective"));
                  }
                })
            .endMenu()
            .newTopLevelMenu("Wires")
            .menus()
            .menu("Scratch Pad")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("WiresScratchPadPerspective"));
                  }
                })
            .endMenu()
            .menu("Trees")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("WiresTreesPerspective"));
                  }
                })
            .endMenu()
            .menu("Bayesian networks")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("WiresBayesianPerspective"));
                  }
                })
            .endMenu()
            .endMenus()
            .endMenu()
            .newTopLevelMenu("Workbench")
            .menus()
            .menu("Apps")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("AppsPerspective"));
                  }
                })
            .endMenu()
            .menu("Plugins")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("PlugInAuthoringPerspective"));
                  }
                })
            .endMenu()
            .endMenus()
            .endMenu()
            .newTopLevelMenu("Messages")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("MessagesPerspective"));
                  }
                })
            .endMenu()
            .newTopLevelMenu("Inbox")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("InboxPerspective"));
                  }
                })
            .endMenu()
            .newTopLevelMenu("Assets")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("AssetsPerspective"));
                  }
                })
            .endMenu()
            .newTopLevelMenu("Projects")
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    placeManager.goTo(new DefaultPlaceRequest("ProjectsPerspective"));
                  }
                })
            .endMenu()
            .newTopLevelMenu(AppConstants.INSTANCE.Logout())
            .respondsWith(new LogoutCommand())
            .position(MenuPosition.RIGHT)
            .endMenu()
            .build();

    menubar.addMenus(menus);
  }