public void dispose() {
    getSite()
        .getWorkbenchWindow()
        .getSelectionService()
        .removePostSelectionListener(getSelectionServiceListener());
    if (fDoubleClickProvider != null) {
      getTreeViewer().removeDoubleClickListener(fDoubleClickProvider);
    }

    // dispose menu controls
    if (fContextMenu != null) {
      fContextMenu.dispose();
    }
    if (fContextMenuManager != null) {
      fContextMenuManager.removeMenuListener(fGroupAdder);
      fContextMenuManager.removeAll();
      fContextMenuManager.dispose();
    }

    fDropTarget.dispose();
    fDragSource.dispose();

    IStatusLineManager statusLineManager = getSite().getActionBars().getStatusLineManager();
    if (statusLineManager != null) {
      statusLineManager.setMessage(null);
    }
    unconfigure();
    super.dispose();
  }
 private void fillOpenWithMenu(IMenuManager menu, Object object) {
   if (object instanceof IAdaptable) {
     MenuManager submenu = new MenuManager("Open With", OPEN_WITH_ID);
     submenu.add(new OpenWithMenu(view.getSite().getPage(), (IAdaptable) object));
     menu.add(submenu);
   }
 }
  private void createFileContentsGroup(Composite parent) {
    Group theGroup =
        WidgetFactory.createGroup(
            parent, getString("fileContentsGroup"), SWT.NONE, 1, 4); // $NON-NLS-1$
    GridData groupGD = new GridData(GridData.FILL_BOTH);
    groupGD.heightHint = GROUP_HEIGHT_190;
    groupGD.widthHint = 400;
    theGroup.setLayoutData(groupGD);

    this.fileContentsViewer = new ListViewer(theGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 4;
    this.fileContentsViewer.getControl().setFont(JFaceResources.getTextFont());
    this.fileContentsViewer.getControl().setLayoutData(data);

    if (this.dataFileInfo != null) {
      for (String row : this.dataFileInfo.getCachedFirstLines()) {
        if (row != null) {
          this.fileContentsViewer.add(row);
        }
      }
    }

    // Add a Context Menu
    final MenuManager columnMenuManager = new MenuManager();
    this.fileContentsViewer.getControl().setMenu(columnMenuManager.createContextMenu(parent));
  }
  public IMenuManager getMenuManager() {
    MenuManager menMgr = new MenuManager("Unlink");
    Menu men = menMgr.createContextMenu(FLATTT.tableView.getViewer().getControl());
    getMenu(menMgr);

    return menMgr;
  }
Example #5
0
  private void hideMenuCheck() {
    try {
      URL pluginUrl = Platform.getBundle(GrassUiPlugin.PLUGIN_ID).getResource("/");
      String pluginPath = FileLocator.toFileURL(pluginUrl).getPath();
      File pluginFile = new File(pluginPath);
      File installFolder = pluginFile.getParentFile().getParentFile().getParentFile();

      File grassFolderFile = new File(installFolder, "grass");
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
        if (!grassFolderFile.exists() || !grassFolderFile.isDirectory()) {
          IWorkbenchWindow[] wwindows = PlatformUI.getWorkbench().getWorkbenchWindows();
          String actionSetID = "eu.hydrologis.jgrass.ui.grassactionset";

          for (IWorkbenchWindow iWorkbenchWindow : wwindows) {
            IWorkbenchPage activePage = iWorkbenchWindow.getActivePage();
            if (activePage != null) {
              activePage.hideActionSet(actionSetID);
              MenuManager mbManager = ((ApplicationWindow) iWorkbenchWindow).getMenuBarManager();
              for (int i = 0; i < mbManager.getItems().length; i++) {
                IContributionItem item = mbManager.getItems()[i];
                if (item.getId().equals(actionSetID)) {
                  item.setVisible(false);
                }
              }
            }
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  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;
  }
 private int extractStyle(final MenuManager manager) {
   int style = SWT.NONE;
   if (manager.getItems() != null && manager.getItems().length > 0) {
     style = SWT.DROP_DOWN;
   }
   return style;
 }
  /*
   * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
   */
  @Override
  public void contributeToMenu(IMenuManager menu) {

    super.contributeToMenu(menu);

    IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
    if (editMenu != null) {

      MenuManager structureSelection =
          new MenuManager(
              JavaEditorMessages.ExpandSelectionMenu_label, "expandSelection"); // $NON-NLS-1$
      editMenu.insertAfter(ITextEditorActionConstants.SELECT_ALL, structureSelection);
      structureSelection.add(fStructureSelectEnclosingAction);
      structureSelection.add(fStructureSelectNextAction);
      structureSelection.add(fStructureSelectPreviousAction);
      structureSelection.add(fStructureSelectHistoryAction);

      editMenu.appendToGroup(
          ITextEditorActionConstants.GROUP_INFORMATION, fRetargetShowInformationAction);
    }

    IMenuManager navigateMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
    if (navigateMenu != null) {
      navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
      navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy);
    }

    IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); // $NON-NLS-1$
    if (gotoMenu != null) {
      gotoMenu.add(new Separator("additions2")); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); // $NON-NLS-1$
    }
  }
  public static void addActionsLibraryToMenu(IMenuManager manager) {
    if (!actionsLoaded) {
      initActions();
    }

    addMenuForAspect(
        manager, MODELING_ASPECT_LABELS.MODEL_PROJECT_MANAGEMENT, ASPECT_MODEL_PROJECT_MANAGEMENT);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.DEFINE_MODELS, ASPECT_DEFINE_MODELS);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.MANAGE_CONNECTIONS, ASPECT_MANAGE_CONNECTIONS);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.MODEL_DATA_SOURCES, ASPECT_MODEL_DATA_SOURCES);
    // addMenuForAspect(manager, MODELING_ASPECT_LABELS.CONSUME_REST_WS, ASPECT_CONSUME_REST_WS);
    //		addMenuForAspect(manager, MODELING_ASPECT_LABELS.CONSUME_SOAP_WS, ASPECT_CONSUME_SOAP_WS);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.MANAGE_VDBS, ASPECT_MANAGE_VDBS);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.TEIID_SERVER, ASPECT_TEIID_SERVER);
    addMenuForAspect(manager, MODELING_ASPECT_LABELS.TEST, ASPECT_TEST);

    if (!cheatSheetActions.isEmpty()) {
      manager.add(new Separator());
      MenuManager subManager = new MenuManager("Cheat Sheets"); // $NON-NLS-1$
      for (IAction action : cheatSheetActions) {
        subManager.add(action);
      }
      manager.add(subManager);
    }
  }
    @Override
    protected void addActions(MenuManager menuManager) {
      IAction action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_2,
              IDiagramModelConnection.LINE_SOLID,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.LINE_SOLID));
      menuManager.add(action);
      action.setChecked(
          (fConnection.getType() & IDiagramModelConnection.LINE_DASHED) == 0
              & (fConnection.getType() & IDiagramModelConnection.LINE_DOTTED) == 0);

      action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_3,
              IDiagramModelConnection.LINE_DASHED,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.LINE_DASHED));
      menuManager.add(action);

      action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_4,
              IDiagramModelConnection.LINE_DOTTED,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.LINE_DOTTED));
      menuManager.add(action);
    }
    @Override
    protected void addActions(MenuManager menuManager) {
      IAction action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_11,
              IDiagramModelConnection.ARROW_NONE,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.LINE_SOLID));
      action.setChecked(
          (fConnection.getType() & IDiagramModelConnection.ARROW_FILL_TARGET) == 0
              & (fConnection.getType() & IDiagramModelConnection.ARROW_HOLLOW_TARGET) == 0
              & (fConnection.getType() & IDiagramModelConnection.ARROW_LINE_TARGET) == 0);
      menuManager.add(action);

      action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_12,
              IDiagramModelConnection.ARROW_FILL_TARGET,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.ARROW_TARGET_FILL));
      menuManager.add(action);

      action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_13,
              IDiagramModelConnection.ARROW_HOLLOW_TARGET,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.ARROW_TARGET_HOLLOW));
      menuManager.add(action);

      action =
          createAction(
              Messages.DiagramConnectionLineStyleSection_14,
              IDiagramModelConnection.ARROW_LINE_TARGET,
              IZentaImages.ImageFactory.getImageDescriptor(IZentaImages.ARROW_TARGET_LINE));
      menuManager.add(action);
    }
  /**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(Event event) {
    Widget item = event.widget;
    if (item != null) {
      int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          Menu menu = menuManager.createContextMenu(ti.getParent());
          menuManager.addMenuListener(
              new IMenuListener() {
                public void menuAboutToShow(IMenuManager manager) {
                  String id = getId();
                  if (dropDownMenuOverride != null) {
                    id = dropDownMenuOverride;
                  }
                  menuService.populateContributionManager(menuManager, "menu:" + id); // $NON-NLS-1$
                }
              });
          // position the menu below the drop down item
          Rectangle b = ti.getBounds();
          Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height));
          menu.setLocation(p.x, p.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
Example #13
0
  private void createViewer(Composite parent) {
    viewer =
        new TableViewer(
            parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(parent, viewer);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(ArrayContentProvider.getInstance());
    WritableList input = new WritableList(ModelProvider.INSTANCE.getTasks(), Task.class);
    ViewerSupport.bind(
        viewer,
        input,
        BeanProperties.values(new String[] {"id", "name", "status", "date", "info"}));

    viewer.setInput(input);
    getSite().setSelectionProvider(viewer);

    MenuManager manager = fillMenu();
    viewer.getControl().setMenu(manager.createContextMenu(viewer.getControl()));

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
  }
Example #14
0
 public MenuManager fillSortMenu() {
   MenuManager subMenu = new MenuManager("Sort by ...");
   subMenu.add(
       new Action("ID") {
         @Override
         public void run() {
           ModelProvider.INSTANCE.sortBy(SortBy.ID);
           refresh();
         }
       });
   subMenu.add(
       new Action("Name") {
         @Override
         public void run() {
           ModelProvider.INSTANCE.sortBy(SortBy.NAME);
           refresh();
         }
       });
   subMenu.add(
       new Action("Status") {
         @Override
         public void run() {
           ModelProvider.INSTANCE.sortBy(SortBy.STATUS);
           refresh();
         }
       });
   return subMenu;
 }
  /** {@inheritDoc} */
  public Menu getMenu(final Control parent) {
    if (manager == null) {
      manager = new MenuManager();
    }
    Menu menu = manager.getMenu();
    if (menu != null) {
      menu.dispose();
      menu = null;
    }
    manager.removeAll();
    menu = manager.createContextMenu(parent);
    IAction removeAction =
        new Action(
            "Remove Section Set",
            Activator.imageDescriptorFromPlugin(Activator.ID, "/icons/delete.gif")) {

          /** {@inheritDoc} */
          @Override
          public void run() {
            // remove this section descriptor set state from its parent
            sectionSetDescriptorStates.remove(getSectionSetDescriptorState());
            metamodelViewer.refresh();
          }
        };
    manager.add(removeAction);
    manager.add(new Separator(ADD_GROUP));

    return menu;
  }
  protected void fillMenuBar(IMenuManager menuBar) {
    MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
    MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);

    menuBar.add(fileMenu);
    // Add a group marker indicating where action set menus will appear.
    menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    menuBar.add(helpMenu);
    helpMenu.add(helpContentsAction);

    // File Menu
    /* fileMenu.add(prefAction);
    fileMenu.add(new Separator());
    fileMenu.add(exitAction); */

    // Ajout sous la forme de ActionContributionItem pour pouvoir rendre les actions ensuite
    // invisibles, car elle sont dŽjˆ prŽsentes dans le menu Pomme du mac.
    ActionContributionItem preferencesActionItem = new ActionContributionItem(prefAction);
    fileMenu.add(preferencesActionItem);
    ActionContributionItem exitActionItem = new ActionContributionItem(exitAction);
    fileMenu.add(exitActionItem);

    if (Util.isMac()) {
      preferencesActionItem.setVisible(false);
      exitActionItem.setVisible(false);
    }
  }
Example #17
0
  private void createContextMenu() {
    final MenuManager contextMenu = new MenuManager();
    showAction =
        new Action() {
          public void run() {
            IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
            showLocation(sel.getFirstElement());
          }
        };

    Messages.initAction(showAction, "action_show"); // $NON-NLS-1$
    contextMenu.setRemoveAllWhenShown(true);
    contextMenu.addMenuListener(
        new IMenuListener() {

          public void menuAboutToShow(IMenuManager mgr) {
            contextMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
            contextMenu.add(new Separator());

            showAction.setImageDescriptor(Images.getDescriptor(Images.SHOW_CO));

            contextMenu.add(showAction);
          }
        });

    // Create menu.
    Menu menu = contextMenu.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);

    // Register menu for extension.
    getSite().registerContextMenu(contextMenu, viewer);
  }
  /**
   * DOC klliu Comment method "buildControls".
   *
   * @param group
   */
  private void buildControls(Group group) {
    table = new Table(group, SWT.FULL_SELECTION);
    GridData data = new GridData(GridData.FILL_BOTH);
    table.setLayoutData(data);
    viewer = buildAndLayoutTable(table);

    attachContentProvider(viewer);
    attachLabelProvider(viewer);
    attachCellEditors(viewer, table);

    MenuManager popupMenu = new MenuManager();
    IAction newRowAction = new NewRowAction();
    popupMenu.add(newRowAction);
    IAction delRowAction = new DelRowAction();
    popupMenu.add(delRowAction);
    Menu menu = popupMenu.createContextMenu(table);
    table.setMenu(menu);
    table.addListener(
        SWT.Modify,
        new Listener() {

          public void handleEvent(Event event) {
            checkFieldsValue();
          }
        });
    viewer.setInput(content);
    // viewer.addSelectionChangedListener(new listener)
    createDefinitionParametersButton(group, viewer);
  }
  /**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(final Event event) {
    final Widget item = event.widget;
    if (item != null) {
      final int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          final ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          final Menu menu = menuManager.createContextMenu(ti.getParent());
          if (this.workbenchHelpSystem != null) {
            this.workbenchHelpSystem.setHelp(menu, this.helpContextId);
          }
          initDropDownMenu(menuManager);

          // position the menu below the drop down item
          final Point point = ti.getParent().toDisplay(new Point(event.x, event.y));
          menu.setLocation(point.x, point.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
 private void createMenu() {
   MenuManager manager = new MenuManager();
   manager.add(new OpenEditorAction());
   manager.add(TreeClipboard.onCopy(tree));
   Menu menu = manager.createContextMenu(tree.getControl());
   tree.getControl().setMenu(menu);
 }
  void fillContextMenu(IMenuManager manager) {
    addFocusActionOrNot(manager);
    manager.add(fResetAction);
    manager.add(fRefreshAction);
    manager.add(new Separator());

    if (!getSite().getSelectionProvider().getSelection().isEmpty()) {
      MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
      IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
      showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(workbenchWindow));
      manager.add(showInSubMenu);
    }
    addElementActionsOrNot(manager);
    manager.add(new Separator());

    manager.add(fCopyAction);
    manager.add(new Separator());

    fDrillDownAdapter.addNavigationActions(manager);
    manager.add(new Separator());
    // Other plug-ins can contribute there actions here
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    manager.add(new Separator());
    addCompareActionOrNot(manager);
    manager.add(fPropertiesAction);
  }
Example #22
0
 public static void fillVmListMenu(IMenuManager manager, List<VMTreeObject> list) {
   List<VMTreeObjectVMinGroup> vmList = new ArrayList<VMTreeObjectVMinGroup>();
   boolean isDefault = true;
   boolean isNotDefault = true;
   for (VMTreeObject o : list) {
     if (o.getParent().getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
       isNotDefault = false;
     } else {
       isDefault = false;
     }
     vmList.add((VMTreeObjectVMinGroup) o);
   }
   if (isDefault) {
     MenuManager addtogroupMenu = new MenuManager("Ìí¼Óµ½...");
     for (VMTreeObject group : vmList.get(0).getParent().getParent().getChildren()) {
       if (!group.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
         addtogroupMenu.add(new AddtoGroupAction(vmList, (VMTreeObjectGroup) group));
       }
     }
     manager.add(addtogroupMenu);
     return;
   }
   if (isNotDefault) {
     manager.add(new ResetGroupAction(vmList));
   }
 }
 /**
  * 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();
               }
             });
       }
     }
   }
 }
Example #24
0
  public static void fillVMMenu(IMenuManager manager, VMTreeObject selection) {

    VMTreeObjectVMinGroup vminGroup = (VMTreeObjectVMinGroup) selection;
    if (selection.getParent().getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
      MenuManager addtogroupMenu = new MenuManager("Ìí¼Óµ½...");
      for (VMTreeObject group : vminGroup.getParent().getParent().getChildren()) {
        if (!group.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
          addtogroupMenu.add(new AddtoGroupAction(vminGroup, (VMTreeObjectGroup) group));
        }
      }
      manager.add(addtogroupMenu);
    } else {
      manager.add(new ResetGroupAction(vminGroup));
    }
    manager.add(new Separator());
    VMTreeObjectVM vm = vminGroup.getVmObject();
    VM.Record record = vm.getRecord();
    Types.VmPowerState state = record.powerState;
    if (state.equals(Types.VmPowerState.RUNNING)) {
      manager.add(new ShutDownAction(vm));
      manager.add(new RebootAction(vm));
    } else {
      manager.add(new StartAction(vm));
    }
  }
 protected MenuManager createMenuManager() {
   MenuManager main_menu = new MenuManager(null);
   MenuManager action_menu = new MenuManager("Menu");
   main_menu.add(action_menu);
   action_menu.add(status_action);
   return main_menu;
 }
Example #26
0
 /**
  * Create the menu manager.
  *
  * @return the menu manager
  */
 @Override
 protected MenuManager createMenuManager() {
   MenuManager menuManager = new MenuManager("menu");
   menuManager.add(MenuAction.aboutAction);
   menuManager.add(MenuAction.exitAction);
   return menuManager;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
   */
  @Override
  public void createPartControl(Composite parent) {
    GridLayout gridLayout = new GridLayout(1, true);
    parent.setLayout(gridLayout);
    createTitle(parent);
    stViewer = createAbstractSTViewer(parent);

    // create the actions before the input is set on the viewer but after
    // the sorter and filter are set so the actions will be enabled correctly.
    createActions();

    final MenuManager mgr = initContextMenu();
    final Menu menu = mgr.createContextMenu(parent);
    stViewer.getViewer().getControl().setMenu(menu);

    getSite().registerContextMenu(mgr, stViewer.getViewer());

    // the selection provider registered
    getSite().setSelectionProvider(stViewer.getViewer());

    IActionBars actionBars = getViewSite().getActionBars();

    initMenu(actionBars.getMenuManager());
    initToolBar(actionBars.getToolBarManager());
  }
  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 MergeSourceViewer(
      SourceViewer sourceViewer, ResourceBundle bundle, ICompareContainer container) {
    Assert.isNotNull(sourceViewer);
    fSourceViewer = sourceViewer;
    fResourceBundle = bundle;
    fContainer = container;

    MenuManager menu = new MenuManager();
    menu.setRemoveAllWhenShown(true);
    menu.addMenuListener(this);
    StyledText te = getSourceViewer().getTextWidget();
    te.setMenu(menu.createContextMenu(te));
    fContainer.registerContextMenu(menu, getSourceViewer());

    // for listening to editor show/hide line number preference value
    fPreferenceChangeListener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            MergeSourceViewer.this.handlePropertyChangeEvent(event);
          }
        };
    EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener);
    fShowLineNumber =
        EditorsUI.getPreferenceStore()
            .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
    if (fShowLineNumber) {
      updateLineNumberRuler();
    }

    IOperationHistory history = getHistory();
    if (history != null) history.addOperationHistoryListener(this);

    // don't add save when in a dialog, IWorkbenchPart is null in dialog containers
    fAddSaveAction = fContainer.getWorkbenchPart() != null;
  }
  /**
   * @see
   *     com.vectrace.MercurialEclipse.views.AbstractRootView#createMenus(org.eclipse.jface.action.IMenuManager)
   */
  @Override
  protected void createMenus(IMenuManager mgr) {
    final Action openMergeEditorAction =
        new Action("Open in Merge Editor") {
          @Override
          public void run() {
            ResolveStatus selection = table.getSelection();
            if (selection != null) {
              openMergeEditor(selection);
            }
          }
        };

    final Action openEditorAction =
        new Action("Open in Default Editor") {
          @Override
          public void run() {
            IFile file = getSelection();
            if (file == null) {
              return;
            }
            ResourceUtils.openEditor(getSite().getPage(), file);
          }
        };

    final Action actionShowHistory =
        new Action("Show History") {
          @Override
          public void run() {
            IFile file = getSelection();
            if (file == null) {
              return;
            }
            TeamUI.getHistoryView().showHistoryFor(file);
          }
        };
    actionShowHistory.setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("history.gif"));

    // Contribute actions to popup menu
    final MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(table);
    menuMgr.addMenuListener(
        new IMenuListener() {
          public void menuAboutToShow(IMenuManager menuMgr1) {
            menuMgr1.add(openMergeEditorAction);
            menuMgr1.add(openEditorAction);
            menuMgr1.add(new Separator());
            menuMgr1.add(actionShowHistory);
            menuMgr1.add(new Separator());
            menuMgr1.add(markResolvedAction);
            menuMgr1.add(markUnresolvedAction);
            menuMgr1.add(new Separator());
            menuMgr1.add(completeAction);
            menuMgr1.add(abortAction);
          }
        });

    menuMgr.setRemoveAllWhenShown(true);
    table.getTableViewer().getControl().setMenu(menu);
  }