/**
  * Recursive method to create a menu from the contribute items of a manger
  *
  * @param menu actual menu
  * @param items manager contributor items
  */
 private void createMenu(Menu menu, IContributionItem[] items) {
   for (IContributionItem item : items) {
     if (item instanceof MenuManager) {
       MenuManager manager = (MenuManager) item;
       MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE);
       subMenuItem.setText(manager.getMenuText());
       Menu subMenu = new Menu(Display.getCurrent().getActiveShell(), SWT.DROP_DOWN);
       subMenuItem.setMenu(subMenu);
       createMenu(subMenu, manager.getItems());
     } else if (item instanceof ActionContributionItem) {
       ActionContributionItem actionItem = (ActionContributionItem) item;
       if (actionItem.getAction() instanceof CustomSelectionAction) {
         final CustomSelectionAction action = (CustomSelectionAction) actionItem.getAction();
         MenuItem actionEnrty = new MenuItem(menu, SWT.CHECK);
         action.setSelection(getLastRawSelection());
         actionEnrty.setText(actionItem.getAction().getText());
         actionEnrty.setSelection(action.isChecked());
         actionEnrty.setEnabled(action.canExecute());
         actionEnrty.addSelectionListener(
             new SelectionAdapter() {
               @Override
               public void widgetSelected(SelectionEvent e) {
                 action.run();
               }
             });
       }
     }
   }
 }
예제 #2
0
 private IAction getChartAction(IViewPart view) {
   IAction result = null;
   IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
   for (IContributionItem item : manager.getItems()) {
     if (item instanceof ActionContributionItem) {
       ActionContributionItem actionItem = (ActionContributionItem) item;
       if (actionItem.getAction().getId().equals(MassifViewPart.CHART_ACTION)) {
         result = actionItem.getAction();
       }
     }
   }
   return result;
 }
 private DisplayMode getCurrentMode() {
   String actionText = changeModeAction.getAction().getText();
   for (DisplayMode aMode : DisplayMode.values()) {
     if (aMode.getText().equals(actionText)) return aMode;
   }
   return null;
 }
예제 #4
0
  public void testExecPidMenu() throws Exception {
    ILaunchConfigurationWorkingCopy config =
        createConfiguration(proj.getProject()).getWorkingCopy();
    config.setAttribute(LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD, true);
    config.doSave();
    doLaunch(config, "testExec"); // $NON-NLS-1$

    ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
    MassifViewPart dynamicView = (MassifViewPart) view.getDynamicView();
    MassifOutput output = dynamicView.getOutput();

    MassifPidMenuAction menuAction = null;
    IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
    for (IContributionItem item : manager.getItems()) {
      if (item instanceof ActionContributionItem
          && ((ActionContributionItem) item).getAction() instanceof MassifPidMenuAction) {
        menuAction = (MassifPidMenuAction) ((ActionContributionItem) item).getAction();
      }
    }

    assertNotNull(menuAction);

    Integer[] pids = dynamicView.getOutput().getPids();
    Shell shell = new Shell(Display.getCurrent());
    Menu pidMenu = menuAction.getMenu(shell);

    assertEquals(2, pidMenu.getItemCount());
    ActionContributionItem firstPid = (ActionContributionItem) pidMenu.getItem(0).getData();
    ActionContributionItem secondPid = (ActionContributionItem) pidMenu.getItem(1).getData();

    // check initial state
    assertTrue(firstPid.getAction().isChecked());
    assertFalse(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());

    // select second pid
    selectItem(pidMenu, 1);

    assertFalse(firstPid.getAction().isChecked());
    assertTrue(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());

    // select second pid again
    selectItem(pidMenu, 1);

    assertFalse(firstPid.getAction().isChecked());
    assertTrue(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());

    // select first pid
    selectItem(pidMenu, 0);

    assertTrue(firstPid.getAction().isChecked());
    assertFalse(secondPid.getAction().isChecked());
    assertEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());
  }
예제 #5
0
 private void setAncestorVisibility(boolean visible, boolean enabled) {
   if (fAncestorItem != null) {
     Action action = (Action) fAncestorItem.getAction();
     if (action != null) {
       action.setChecked(visible);
       action.setEnabled(enabled);
     }
   }
   getCompareConfiguration()
       .setProperty(ICompareUIConstants.PROP_ANCESTOR_VISIBLE, new Boolean(visible));
 }
 // TODO: should have better way of doing this
 @Override
 protected void setManualFilteringAndLinkingEnabled(boolean on) {
   IViewPart part = super.getPartForAction();
   if (part instanceof CommonNavigator) {
     for (IContributionItem item :
         ((CommonNavigator) part).getViewSite().getActionBars().getToolBarManager().getItems()) {
       if (item instanceof ActionContributionItem) {
         ActionContributionItem actionItem = (ActionContributionItem) item;
         if (actionItem.getAction() instanceof LinkEditorAction) {
           actionItem.getAction().setEnabled(on);
         }
       }
     }
     for (IContributionItem item :
         ((CommonNavigator) part).getViewSite().getActionBars().getMenuManager().getItems()) {
       if (item instanceof ActionContributionItem) {
         ActionContributionItem actionItem = (ActionContributionItem) item;
         if (actionItem.getAction() instanceof SelectFiltersAction) {
           actionItem.getAction().setEnabled(on);
         }
       }
     }
   }
 }
예제 #7
0
 protected IAction getPyUnitViewAction(ViewPart view, Class<?> class1) {
   IAction action = null;
   IContributionItem[] items = view.getViewSite().getActionBars().getToolBarManager().getItems();
   for (IContributionItem iContributionItem : items) {
     if (iContributionItem instanceof ActionContributionItem) {
       ActionContributionItem item = (ActionContributionItem) iContributionItem;
       IAction lAction = item.getAction();
       if (class1.isInstance(lAction)) {
         action = lAction;
       }
     }
   }
   if (action == null) {
     fail("Could not find action of class: " + class1);
   }
   return action;
 }
예제 #8
0
 /**
  * @see com.aptana.ide.core.ui.widgets.ToolTip#shouldCreateToolTip(org.eclipse.swt.widgets.Event)
  */
 protected boolean shouldCreateToolTip(Event event) {
   boolean shouldCreateToolTip = super.shouldCreateToolTip(event);
   if (shouldCreateToolTip) {
     ToolItem item = tb.getItem(new Point(event.x, event.y));
     if (item == null) {
       return false;
     }
     Object data2 = item.getData();
     ContributionItem citem = (ContributionItem) data2;
     if (citem instanceof ActionContributionItem) {
       ActionContributionItem cm = (ActionContributionItem) citem;
       IAction action = cm.getAction();
       String id = action.getId();
       if (id != null) {
         if (id.equals(this.id)) {
           return true;
         }
       }
     }
   }
   return false;
 }
예제 #9
0
    public final void testAdditionalNonePresent() {
      ShapeWrapper sw =
          new ShapeWrapper(
              "rect",
              new RectangleShape(
                  new WorldLocation(12.1, 12.3, 12), new WorldLocation(1.1, 1.1, 12)),
              Color.red,
              new HiResDate(2222));
      Editable[] editables = new Editable[] {sw};
      MenuManager menu = new MenuManager("Holder");

      RightClickSupport.getDropdownListFor(menu, editables, null, null, null, true);

      boolean foundTransparent = false;

      // note: this next test may return 4 if run from within IDE,
      // some contributions provided by plugins
      assertEquals("Has items", 2, menu.getSize(), 2);

      IContributionItem[] items = menu.getItems();
      for (int i = 0; i < items.length; i++) {
        IContributionItem thisI = items[i];
        if (thisI instanceof MenuManager) {
          MenuManager subMenu = (MenuManager) thisI;
          IContributionItem[] subItems = subMenu.getItems();
          for (int j = 0; j < subItems.length; j++) {
            IContributionItem subI = subItems[j];
            if (subI instanceof ActionContributionItem) {
              ActionContributionItem ac = (ActionContributionItem) subI;
              String theName = ac.getAction().getText();
              if (theName.equals("Semi transparent")) foundTransparent = true;
            }
          }
        }
      }

      assertTrue("The additional bean info got processed!", foundTransparent);
    }
 public void setRemoveEnabled(boolean enabled) {
   removeToolbarContributionItem.getAction().setEnabled(enabled);
   removeMenuContributionItem.getAction().setEnabled(enabled);
 }
 private boolean getSingleValueMode() {
   if (singleValueToggleAction != null) return singleValueToggleAction.getAction().isChecked();
   return false;
 }
 /** Returns the action object held in this descriptor. */
 public IAction getAction() {
   return (item != null ? item.getAction() : null);
 }
  /**
   * 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();
  }