public void testCreateMenu() {
    final MWindow window = createWindowWithOneViewAndMenu();
    wb = new E4Workbench(window, appContext);

    Widget topWidget = (Widget) window.getWidget();
    assertTrue(topWidget instanceof Shell);
    Shell shell = (Shell) topWidget;
    final Menu menuBar = shell.getMenuBar();
    assertNotNull(menuBar);
    assertEquals(1, menuBar.getItemCount());
    final MenuItem fileItem = menuBar.getItem(0);
    assertEquals("File", fileItem.getText());
    final Menu fileMenu = fileItem.getMenu();
    fileMenu.notifyListeners(SWT.Show, null);
    assertEquals(2, fileMenu.getItemCount());
    fileMenu.notifyListeners(SWT.Hide, null);

    MMenu mainMenu = window.getMainMenu();
    MMenu modelFileMenu = (MMenu) mainMenu.getChildren().get(0);
    final MMenuItem item2Model = (MMenuItem) modelFileMenu.getChildren().get(0);
    item2Model.setToBeRendered(false);
    fileMenu.notifyListeners(SWT.Show, null);
    assertEquals(1, fileMenu.getItemCount());
    fileMenu.notifyListeners(SWT.Hide, null);

    item2Model.setToBeRendered(true);
    fileMenu.notifyListeners(SWT.Show, null);
    assertEquals(2, fileMenu.getItemCount());
    fileMenu.notifyListeners(SWT.Hide, null);
  }
示例#2
0
  @Test
  public void testModelMenuTextSetAfterViewerSetContentsEqualsMenuStructure() {

    createWazaabiMenu(false);

    org.eclipse.swt.widgets.Menu swtMenu =
        (org.eclipse.swt.widgets.Menu) SWTUtils.getWidget(viewer, menuComponent);
    Assert.assertEquals(swtMenu.getItemCount(), menuComponent.getChildren().size());
  }
示例#3
0
  @Test
  public void testModelMenuTextSetBeforeViewerSetContentsEqualsSubMenuStructure() {

    createWazaabiMenu(true);

    org.eclipse.swt.widgets.Menu swtMenu2 =
        (org.eclipse.swt.widgets.Menu) SWTUtils.getWidget(viewer, menuBar);
    Assert.assertEquals(swtMenu2.getItemCount(), menuBar.getChildren().size());
  }
示例#4
0
  protected void doDropDown() {
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    createDropDownMenu(menu);
    if (menu.getItemCount() == 0) return;

    Point loc = UIUtils.calcPopupMenuLocation(this);
    menu.setLocation(loc);
    menu.setVisible(true);
  }
示例#5
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());
  }
  /** Populate the dynamic menu */
  protected void fillMenu(Menu parent, List<Concern> concerns) {
    assert parent != null;
    assert !parent.isDisposed();

    //	if (!selectedJavaElements.isEmpty())
    // {
    parent.setEnabled(true);

    fillMenuRecursive(parent, concerns, selectedJavaElements, concernModelProvider.getLinkType());

    String linkAllLabel = getNewConcernMenuItemText();

    for (MenuItem menuItem : parent.getItems()) {
      String text = menuItem.getText();

      if (text.isEmpty()) {
        menuItem.dispose();
      } else if (text.equals(linkAllLabel)) {
        menuItem.dispose();
        break;
      }
    }

    // If there were concerns in the model, add a separator before
    // the New Concern item

    boolean hasItemsToLink = parent.getItemCount() > 0;

    /*if (hasItemsToLink)
    {
    	new MenuItem(parent, SWT.SEPARATOR);
    }*/

    // Add the "New concern..." item
    /*MenuItem lNewConcernItem = new MenuItem(parent, SWT.PUSH);
    lNewConcernItem.addSelectionListener(clickListener);
    lNewConcernItem.setText(linkAllLabel);*/
    /*	}
    else
    {
    	parent.setEnabled(false);
    }*/
  }
 /**
  * Updates the menu item for this sub menu. The menu item is disabled if this sub menu is empty.
  * Does nothing if this menu is not a submenu.
  */
 private void updateMenuItem() {
   /*
   * Commented out until proper solution to enablement of
   * menu item for a sub-menu is found. See bug 30833 for
   * more details.
   *
   if (menuItem != null && !menuItem.isDisposed() && menuExist()) {
   IContributionItem items[] = getItems();
   boolean enabled = false;
   for (int i = 0; i < items.length; i++) {
   IContributionItem item = items[i];
   enabled = item.isEnabled();
   if(enabled) break;
   }
   // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw
   if (menuItem.getEnabled() != enabled)
   menuItem.setEnabled(enabled);
   }
   */
   // Partial fix for bug #34969 - diable the menu item if no
   // items in sub-menu (for context menus).
   if (menuItem != null && !menuItem.isDisposed() && menuExist()) {
     boolean enabled = removeAllWhenShown || menu.getItemCount() > 0;
     // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw
     if (menuItem.getEnabled() != enabled) {
       // We only do this for context menus (for bug #34969)
       Menu topMenu = menu;
       while (topMenu.getParentMenu() != null) {
         topMenu = topMenu.getParentMenu();
       }
       if ((topMenu.getStyle() & SWT.BAR) == 0) {
         menuItem.setEnabled(enabled);
       }
     }
   }
 }
 /**
  * Get the menu item count for the implementation's widget.
  *
  * @return the number of items
  * @since 3.4
  */
 protected int getMenuItemCount() {
   if (menu != null) {
     return menu.getItemCount();
   }
   return 0;
 }
 /**
  * Constructs a new instance of this class given its parent (which must be a <code>Menu</code>)
  * and a style value describing its behavior and appearance. The item is added to the end of the
  * items maintained by its parent.
  *
  * <p>The style value is either one of the style constants defined in class <code>SWT</code> which
  * is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style
  * constants. The class description lists the style constants that are applicable to the class.
  * Style bits are also inherited from superclasses.
  *
  * @param parent a menu control which will be the parent of the new instance (cannot be null)
  * @param style the style of control to construct
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the parent is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  *       <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
  *     </ul>
  *
  * @see SWT#CHECK
  * @see SWT#CASCADE
  * @see SWT#PUSH
  * @see SWT#RADIO
  * @see SWT#SEPARATOR
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
 public MenuItem(Menu parent, int style) {
   super(parent, checkStyle(style));
   this.parent = parent;
   parent.createItem(this, (index = parent.getItemCount()));
 }
  @Override
  public void fill(Menu menu, int index) {

    // this is a hack to prevent this menu from being created twice
    if (menu.getItemCount() > MIDContextMenu.INVALID_MENU_ITEM_LIMIT) {
      return;
    }

    // check selection
    ISelection selection =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
    if (selection == null || selection.isEmpty() || !(selection instanceof StructuredSelection)) {
      return;
    }
    Object[] objects = ((StructuredSelection) selection).toArray();
    boolean doDerivation = true;
    if (objects.length > 1) {
      doDerivation = false;
    }

    // get selection
    ModelElementReference modelElemRef = null;
    for (Object object : objects) {
      if (object instanceof ModelElementReferenceEditPart
          || object instanceof ModelElementReference2EditPart) {
        GraphicalEditPart editPart = (GraphicalEditPart) object;
        modelElemRef = (ModelElementReference) ((View) editPart.getModel()).getElement();
        // TODO MMINT[KLEISLI] replace with KleisliModelElement
        EMFInfo eInfo = modelElemRef.getObject().getEInfo();
        if (!(((ModelEndpointReference) modelElemRef.eContainer()).getObject()
                instanceof KleisliModelEndpoint)
            || MultiModelConstraintChecker.isInstancesLevel(modelElemRef)
            || ( // only types
            !eInfo.getClassName().startsWith("_")
                && ( // only derived classes
                eInfo.getFeatureName() == null || !eInfo.getFeatureName().startsWith("_")))
            || (eInfo.getClassName().startsWith("_")
                && // only derived features
                eInfo.getFeatureName() != null
                && !eInfo.getFeatureName().startsWith("_"))) {
          doDerivation = false;
        }
      }
      if (!doDerivation) {
        return;
      }
    }
    if (modelElemRef == null) { // no relevant edit parts selected
      return;
    }

    // create dynamic menus
    MenuItem mmintItem = new MenuItem(menu, SWT.CASCADE, index);
    mmintItem.setText(MIDContextMenu.MMINT_MENU_LABEL);
    Menu mmintMenu = new Menu(menu);
    mmintItem.setMenu(mmintMenu);
    // derivation
    if (doDerivation) {
      MenuItem derivationItem = new MenuItem(mmintMenu, SWT.NONE);
      derivationItem.setText(MMINT_MENU_KLEISLI_LABEL);
      derivationItem.addSelectionListener(
          new KleisliAddModifyQueryListener(MMINT_MENU_KLEISLI_LABEL, modelElemRef.getObject()));
    }
  }
  public static Menu getContextMenu(
      ISelection selection,
      TreeViewer treeViewer,
      EngineMaintenanceMultiPageEditViewModelHandlerImpl modelHandler) {
    Menu result = new Menu(treeViewer.getTree());
    TreeSelection treeSelection = (TreeSelection) selection;
    Object firstElement = treeSelection.getFirstElement();
    if (firstElement instanceof MasterDetailTreeNode) {
      MasterDetailTreeNode treeNode = (MasterDetailTreeNode) firstElement;
      Datatype datatype = treeNode.getDatatype();

      // Menu 'new'
      Menu newElementMenu =
          createMenu(
              result,
              EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + NEW_ELEMENT,
              "icons/add.png");
      if (datatype instanceof TestEngineConfiguration) {
        Class<? extends Datatype>[] possibleChildrenTypes =
            getPossibleChildrenTypes((TestEngineConfiguration) datatype);

        addMenuItemsNew(newElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler);

        // Menu 'clone'
        Menu cloneElementMenu =
            createMenu(
                result,
                EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + CLONE_ELEMENT,
                "icons/copy.png");

        addMenuItemsClone(
            cloneElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler);

      } else if (datatype instanceof ProxyConfiguration) {
        Class<? extends Datatype>[] possibleChildrenTypes =
            getPossibleChildrenTypes((ProxyConfiguration) datatype);
        addMenuItemsNew(newElementMenu, possibleChildrenTypes, treeNode, treeViewer, modelHandler);
      } else if (datatype instanceof ConfigurationProperty) {
      } else {
        Activator.getDefault()
            .logError(
                "Error. No children-mapping for type '"
                    + datatype.getClass()
                    + "' in "
                    + EngineDataModelManager.class.getCanonicalName()
                    + " found.");
      }
      if (newElementMenu.getItemCount() == 0) {
        newElementMenu.getParentItem().setEnabled(false);
      }
      // If not root case
      if (treeNode.getParent() != null) {
        // Separator
        new MenuItem(result, SWT.SEPARATOR);

        // Remove
        Image image = ImageProvider.createImage("icons/delete.png");
        new RemoveDatatypeMenuItem(
            result,
            treeNode,
            modelHandler,
            treeViewer,
            EngineMaintenanceMultiPageEditViewModelHandlerImpl.ID + REMOVE,
            null,
            image);
      }
    }
    return result;
  }