コード例 #1
0
    /* (non-Javadoc)
     * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
     */
    @Override
    protected IContributionItem[] getContributionItems() {
      final List<IContributionItem> res = new ArrayList<IContributionItem>();
      IRepository repository = RepositoryManager.getInstance().getCurrentRepository();
      diagramSotre =
          (DiagramRepositoryStore) repository.getRepositoryStore(DiagramRepositoryStore.class);
      try {
        for (AbstractProcess process : diagramSotre.getAllProcesses()) {
          if (process.getName().equals(subprocessName)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put(OpenSpecificProcessCommand.PARAMETER_PROCESS_NAME, process.getName());
            params.put(OpenSpecificProcessCommand.PARAMETER_PROCESS_VERSION, process.getVersion());
            CommandContributionItemParameter param =
                new CommandContributionItemParameter(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
                    null,
                    OpenSpecificProcessCommand.ID,
                    CommandContributionItem.STYLE_PUSH);
            param.parameters = params;
            param.label = process.getVersion();
            param.visibleEnabled = true;
            param.commandId = OpenSpecificProcessCommand.ID;
            CommandContributionItem commandContributionItem = new CommandContributionItem(param);
            commandContributionItem.setVisible(true);
            res.add(commandContributionItem);
          }
        }

      } catch (Exception ex) {
        BonitaStudioLog.error(ex);
      }
      return res.toArray(new IContributionItem[res.size()]);
    }
コード例 #2
0
  public void testVisibilityTracksEnablement() throws Exception {
    final MenuManager manager = new MenuManager();
    final CommandContributionItemParameter parm =
        new CommandContributionItemParameter(
            window,
            null,
            COMMAND_ID,
            Collections.EMPTY_MAP,
            null,
            null,
            null,
            null,
            null,
            null,
            CommandContributionItem.STYLE_PUSH,
            null,
            true);
    final CommandContributionItem item = new CommandContributionItem(parm);

    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(item, null);
          }
        };

    menuService.addContributionFactory(factory);
    menuService.populateContributionManager(manager, LOCATION);

    assertFalse(item.isEnabled());
    assertFalse("starting state", item.isVisible());

    IHandlerService handlers = window.getService(IHandlerService.class);
    TestEnabled handler = new TestEnabled();
    IHandlerActivation activateHandler = handlers.activateHandler(COMMAND_ID, handler);

    assertTrue(handler.isEnabled());
    assertTrue(item.isEnabled());
    assertTrue("activated handler", item.isVisible());

    handler.setEnabled(false);

    assertFalse("set enabled == false", item.isVisible());

    handler.setEnabled(true);

    assertTrue("set enabled == true", item.isVisible());

    handlers.deactivateHandler(activateHandler);

    assertFalse("deactivate handler", item.isVisible());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }