Esempio n. 1
0
 @Override
 public void dispose() {
   disposeScheduleAction();
   if (headerImage != null) {
     headerImage.dispose();
   }
   if (editorBusyIndicator != null) {
     editorBusyIndicator.stop();
   }
   if (activateAction != null) {
     activateAction.dispose();
   }
   if (menuService != null) {
     if (leftToolBarManager != null) {
       menuService.releaseContributions(leftToolBarManager);
     }
     if (toolBarManager instanceof ContributionManager) {
       menuService.releaseContributions((ContributionManager) toolBarManager);
     }
   }
   if (textSupport != null) {
     textSupport.dispose();
   }
   if (messageHyperLinkListener instanceof IDisposable) {
     ((IDisposable) messageHyperLinkListener).dispose();
   }
   super.dispose();
 }
Esempio n. 2
0
  public void fill(Menu menu, int index) {
    if (getParent() instanceof MenuManager) {
      ((MenuManager) getParent()).addMenuListener(menuListener);
    }

    if (!dirty) {
      return;
    }

    if (currentManager != null && currentManager.getSize() > 0) {
      IMenuService service = (IMenuService) locator.getService(IMenuService.class);
      service.releaseContributions(currentManager);
      currentManager.removeAll();
    }

    currentManager = new MenuManager();
    fillMenu(currentManager);
    IContributionItem[] items = currentManager.getItems();
    if (items.length == 0) {
      MenuItem item = new MenuItem(menu, SWT.NONE, index++);
      item.setText(NO_TARGETS_MSG);
      item.setEnabled(false);
    } else {
      for (int i = 0; i < items.length; i++) {
        if (items[i].isVisible()) {
          items[i].fill(menu, index++);
        }
      }
    }
    dirty = false;
  }
  public void testExtensionContributionExpression() throws Exception {
    IAction a =
        new Action() {
          @Override
          public void run() {
            System.out.println("Hello action");
          }
        };
    final MenuManager manager = new MenuManager();
    final ActionContributionItem aci = new ActionContributionItem(a);

    IExtensionRegistry reg = Platform.getExtensionRegistry();
    IExtensionPoint menusExtension = reg.getExtensionPoint("org.eclipse.ui.menus");
    IExtension extension = menusExtension.getExtension(EXTENSION_ID);

    IConfigurationElement[] mas = extension.getConfigurationElements();
    final Expression activeContextExpr[] = new Expression[1];
    for (IConfigurationElement ma : mas) {
      IConfigurationElement[] items = ma.getChildren();
      for (IConfigurationElement item : items) {
        String id = item.getAttribute("id");
        if (id != null && id.equals("org.eclipse.ui.tests.menus.itemX1")) {
          IConfigurationElement visibleWhenElement = item.getChildren("visibleWhen")[0];
          activeContextExpr[0] =
              ExpressionConverter.getDefault().perform(visibleWhenElement.getChildren()[0]);
        }
      }
    }
    assertNotNull("Failed to find expression", activeContextExpr[0]);
    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(aci, activeContextExpr[0]);
          }
        };

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

    assertFalse("starting state", aci.isVisible());

    activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID);
    final Menu menu = manager.createContextMenu(window.getShell());
    menu.notifyListeners(SWT.Show, new Event());
    assertTrue("active context", aci.isVisible());
    menu.notifyListeners(SWT.Hide, new Event());

    contextService.deactivateContext(activeContext);
    activeContext = null;

    menu.notifyListeners(SWT.Show, new Event());
    assertFalse("after deactivation", aci.isVisible());
    menu.notifyListeners(SWT.Hide, new Event());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
  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();
  }
Esempio n. 5
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.ContributionItem#dispose()
  */
 public void dispose() {
   if (currentManager != null && currentManager.getSize() > 0) {
     IMenuService service = (IMenuService) locator.getService(IMenuService.class);
     if (service != null) {
       service.releaseContributions(currentManager);
     }
     currentManager.removeAll();
   }
 }
  public void testBasicContribution() throws Exception {

    IAction a =
        new Action() {
          @Override
          public void run() {
            System.out.println("Hello action");
          }
        };
    final MenuManager manager = new MenuManager();
    final ActionContributionItem item = new ActionContributionItem(a);
    final Expression activeContextExpr =
        new ActiveContextExpression(
            MenuContributionHarness.CONTEXT_TEST1_ID, new String[] {ISources.ACTIVE_CONTEXT_NAME});
    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(item, activeContextExpr);
          }
        };

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

    Shell shell = window.getShell();

    // Test the initial menu creation
    final Menu menuBar = manager.createContextMenu(shell);
    Event e = new Event();
    e.type = SWT.Show;
    e.widget = menuBar;
    menuBar.notifyListeners(SWT.Show, e);

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

    activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID);
    menuBar.notifyListeners(SWT.Show, e);

    assertTrue("active context", item.isVisible());

    contextService.deactivateContext(activeContext);
    activeContext = null;
    menuBar.notifyListeners(SWT.Show, e);

    assertFalse("after deactivation", item.isVisible());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
  /** Dispose of the menu extender. Should only be called when the part is disposed. */
  public void dispose() {
    clearStaticActions();
    final IMenuService menuService = (IMenuService) part.getSite().getService(IMenuService.class);
    if (menuService != null) {
      menuService.releaseContributions(menu);
    }
    Platform.getExtensionRegistry().removeRegistryChangeListener(this);
    menu.removeMenuListener(this);

    if (menuModel != null) {
      // unlink ourselves from the renderer
      IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
      AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
      if (obj instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
        unlink(renderer, menuModel);
        renderer.clearModelToManager(menuModel, menu);
      }

      modelPart.getMenus().remove(menuModel);
    }
  }