private void gatherContributions(final IMenuManager mgr) {
   final IContributionItem[] items = mgr.getItems();
   for (int i = 0; i < items.length; i++) {
     if (items[i] instanceof PluginActionContributionItem) {
       actionContributionCache.add((PluginActionContributionItem) items[i]);
     } else if (items[i] instanceof IMenuManager) {
       gatherContributions(((IMenuManager) items[i]));
     }
   }
 }
 public void init(IActionBars bars) {
   super.init(bars);
   IMenuManager menuMgr = bars.getMenuManager();
   IMenuManager editMenu = menuMgr.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
   if (editMenu != null) {
     IContributionItem[] items = editMenu.getItems();
     undoAction = ((ActionContributionItem) items[0]).getAction();
     redoAction = ((ActionContributionItem) items[1]).getAction();
     undoAction.addPropertyChangeListener(this);
     redoAction.addPropertyChangeListener(this);
   }
 }
 /**
  * @param menu
  * @return
  */
 private MenuManager getOpenShiftMenuManager(IMenuManager menu) {
   for (IContributionItem item : menu.getItems()) {
     // make this call in this way, since item id can be null
     if (OPENSHIFT_SERVER_ADAPTER_MENU.equals(item.getId())) {
       return (MenuManager) item;
     }
   }
   MenuManager openshiftMenu = new MenuManager("OpenShift", OPENSHIFT_SERVER_ADAPTER_MENU);
   menu.add(openshiftMenu);
   menu.insertBefore(ServerActionProvider.TOP_SECTION_END_SEPARATOR, openshiftMenu);
   return openshiftMenu;
 }
示例#4
0
  private void fillContextMenu(IMenuManager menuManager) {
    addActionsForSelection(menuManager);

    menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

    if (menuManager.getItems().length > 1) {
      menuManager.add(new Separator());
    }

    if (!getViewer().getSelection().isEmpty()) {
      menuManager.add(goToMarkerAction);
      menuManager.add(copyAction);
    }
  }
示例#5
0
 @Override
 protected void editorContextMenuAboutToShow(IMenuManager menu) {
   super.editorContextMenuAboutToShow(menu);
   // remove editor actions that don't work in Photon
   menu.remove(ITextEditorActionConstants.CONTEXT_PREFERENCES);
   for (IContributionItem item : menu.getItems()) {
     if (item instanceof MenuManager) {
       MenuManager subMenu = (MenuManager) item;
       // Warning: this is a best effort since the menu doesn't have an
       // id
       if (subMenu.getMenuText().startsWith("Sho&w In")) { // $NON-NLS-1$
         menu.remove(subMenu);
       }
     }
   }
 }
 public void menuAboutToShow(IMenuManager manager) {
   IContributionItem[] items = manager.getItems();
   // add configuration's menu items
   IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
   if (listener != null) {
     listener.menuAboutToShow(manager);
     manager.add(new Separator());
   }
   if (items.length > 0 && items[items.length - 1].getId() != null) {
     manager.insertAfter(
         items[items.length - 1].getId(),
         new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
   } else {
     manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
   }
 }
  private void cleanMenuBar() {
    String contribID = null;

    for (IContributionItem contribItem : myMenuBar.getItems()) {
      contribID = contribItem.getId();

      if ((contribID.startsWith("org.eclipse."))
          || (contribID.startsWith(IWorkbenchActionConstants.MB_ADDITIONS))
          || (contribID.startsWith(IWorkbenchActionConstants.M_NAVIGATE))) {
        myMenuBar.remove(contribItem);
      }
    }

    //
    //	myMenuBar.getgetParent().getParent().getParent().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));

    myMenuBar.update(true); // refresh the display of the menu bar
  }
示例#8
0
  private void fillNewWizardActions(IMenuManager menu) {
    // Fill the menu from the commonWizard contributions.
    newWizardActionGroup.setContext(getContext());
    newWizardActionGroup.fillContextMenu(menu);

    IContributionItem newResourceFolderItem = null;
    IContributionItem newModelResourceItem = null;
    IContributionItem newBinaryFileItem = null;
    IContributionItem newTextFileItem = null;

    String firstID = null;
    IContributionItem[] newWizardItems = menu.getItems();
    for (IContributionItem newWizardItem : newWizardItems) {
      if (newWizardItem instanceof ActionContributionItem) {
        IAction action = ((ActionContributionItem) newWizardItem).getAction();
        if (action instanceof IPluginContribution) {
          IPluginContribution pluginContribution = (IPluginContribution) action;
          String id = pluginContribution.getLocalId();
          if (NewFolderWizard.ID.equals(id)) {
            newResourceFolderItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewResourceWizard.ID.equals(id)) {
            newModelResourceItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewBinaryResourceWizard.ID.equals(id)) {
            newBinaryFileItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewTextResourceWizard.ID.equals(id)) {
            newTextFileItem = menu.remove(newWizardItem);
            continue;
          }
        }

        // Filter out the dubious "Ecore Diagram" action that appears everywhere.
        if ("Ecore Diagram".equals(action.getText())) {
          menu.remove(newWizardItem);
          continue;
        }
      }

      if (firstID == null) {
        firstID = newWizardItem.getId();
      }
    }

    if (firstID == null) {
      Separator group = new Separator("cdo-new-wizards");
      menu.add(group);
      firstID = group.getId();
    }

    if (newResourceFolderItem != null) {
      menu.insertBefore(firstID, newResourceFolderItem);
    }

    if (newModelResourceItem != null) {
      menu.insertBefore(firstID, newModelResourceItem);
    }

    if (newBinaryFileItem != null) {
      menu.insertBefore(firstID, newBinaryFileItem);
    }

    if (newTextFileItem != null) {
      menu.insertBefore(firstID, newTextFileItem);
    }
  }
  /**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports from an
   * existing diagram, the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromNavigation() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Set the focus to the desired package
    assertTrue(
        "We should have a DiagramDocumentEditor", editorPart instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editorPart;

    // Get the package named "SubPackage"
    PackageableElement element = model.getPackagedElement("SubPackage");
    assertTrue("Corrupted input data", element instanceof Package);
    final Package packageSubPackage = (Package) element;

    IMenuManager popupMenu = new MenuManager();
    popupMenu.add(
        new MenuManager(
            IWorkbenchActionConstants.MB_ADDITIONS,
            IWorkbenchActionConstants.MB_ADDITIONS)); // $NON-NLS-1$ //$NON-NLS-2$
    popupMenu.add(new MenuManager("popup.new", "popup.new")); // $NON-NLS-1$

    // Set the focus to package SubPackage
    IGraphicalEditPart elementEditPart =
        getEditPart(getFirstDiagramElement(diagram, packageSubPackage));
    diagramEditor.getDiagramGraphicalViewer().setFocus(elementEditPart);

    DNode focusedElement =
        (DNode)
            ((GraphicalEditPart) diagramEditor.getDiagramGraphicalViewer().getFocusEditPart())
                .resolveSemanticElement();
    assertTrue(
        "This is not the good focused element", focusedElement.getTarget() instanceof Package);
    assertEquals(
        "This is not the good focused element",
        "SubPackage",
        ((Package) focusedElement.getTarget()).getName());

    ContributionItemService.getInstance().contributeToPopupMenu(popupMenu, diagramEditor);

    // Check the popup menu.
    IMenuManager newRepresentationMenu = (IMenuManager) popupMenu.find("popup.new");
    IContributionItem[] items = newRepresentationMenu.getItems();

    boolean inNewRepresentationToGroup = false;

    ActionContributionItem actionContribution = null;

    for (int i = 0; i < items.length; i++) {
      if (items[i] instanceof Separator) {
        Separator sep = (Separator) items[i];
        if ("createRepresentationGroup".equals(sep.getId())) {
          inNewRepresentationToGroup = true;
        } else {
          inNewRepresentationToGroup = false;
        }
      }
      if (inNewRepresentationToGroup && items[i] instanceof ActionContributionItem) {
        assertNull("There should be only one ActionContributionItem", actionContribution);
        actionContribution = (ActionContributionItem) items[i];
      }
    }

    assertNotNull("There should be one ActionContributionItem", actionContribution);
    final IAction action = actionContribution.getAction();

    assertEquals("Action has not the correct text", "New diagram", action.getText());

    // Disabling ui callback of diagram command factory
    final Object adapter = diagramEditor.getAdapter(IDiagramCommandFactoryProvider.class);
    final IDiagramCommandFactoryProvider diagramCmdFactoryProvider =
        (IDiagramCommandFactoryProvider) adapter;
    final IDiagramCommandFactory diagramCommandFactory =
        diagramCmdFactoryProvider.getCommandFactory(session.getTransactionalEditingDomain());
    diagramCommandFactory.setUserInterfaceCallBack(new NoUICallback());

    action.run();

    IEditorPart editor2 =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("We should have a DiagramDocumentEditor", editor2 instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor2 = (DiagramDocumentEditor) editor2;
    GraphicalEditPart diagramPart = (GraphicalEditPart) diagramEditor2.getDiagramEditPart();
    final DSemanticDiagram diagram2 = (DSemanticDiagram) diagramPart.resolveSemanticElement();

    assertEquals(
        "The opened diagram is not valid", diagram2.getTarget(), focusedElement.getTarget());

    // Get the class named "SubClass1"
    element = packageSubPackage.getPackagedElement("SubClass1");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class subClass1 = (Class) element;

    final Property firstProperty = subClass1.getOwnedAttribute("Prop1", subClass1);
    final Property secondProperty = subClass1.getOwnedAttribute("Prop2", subClass1);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram2, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram2, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    DialectUIManager.INSTANCE.closeEditor(editor2, false);
    TestsUtil.synchronizationWithUIThread();
  }