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);
  }
Ejemplo n.º 2
0
  @Test
  public void testModelMenuTextSetAfterViewerSetContentsEqualsText() {

    createWazaabiMenu(false);

    org.eclipse.swt.widgets.MenuItem swtItem =
        (org.eclipse.swt.widgets.MenuItem) SWTUtils.getWidget(viewer, subMenu);
    Assert.assertEquals(SUB_TEXT, swtItem.getText());
  }
  /** 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);
    }*/
  }