示例#1
0
  protected void initActions(
      final IServiceLocator serviceLocator, final HandlerCollection handlers) {
    final IHandlerService handlerService =
        (IHandlerService) serviceLocator.getService(IHandlerService.class);

    {
      final IHandler2 handler = new RefreshHandler(fTable);
      handlers.add(IWorkbenchCommandConstants.FILE_REFRESH, handler);
      handlerService.activateHandler(IWorkbenchCommandConstants.FILE_REFRESH, handler);
    }
    {
      final IHandler2 handler = new SelectAllHandler(fTable);
      handlers.add(IWorkbenchCommandConstants.EDIT_SELECT_ALL, handler);
      handlerService.activateHandler(IWorkbenchCommandConstants.EDIT_SELECT_ALL, handler);
    }
    //		{	final IHandler2 handler = new CopyDataHandler(fTable);
    //			handlers.add(IWorkbenchCommandConstants.EDIT_COPY, handler);
    //			handlerService.activateHandler(IWorkbenchCommandConstants.EDIT_COPY, handler);
    //		}
    {
      final IHandler2 handler = new FindDialogHandler(this);
      handlers.add(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, handler);
      handlerService.activateHandler(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, handler);
    }
  }
 public void registerAction(IAction action, String commandId) {
   IHandlerService handlerService = getHandlerService();
   if (handlerService == null) return;
   action.setActionDefinitionId(commandId);
   IHandlerActivation activation;
   if (fExpression == null) {
     activation = handlerService.activateHandler(commandId, new ActionHandler(action));
   } else {
     activation =
         handlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
   }
   if (activation != null) {
     fActivations.add(activation);
   }
 }
示例#3
0
  /**
   * Install a copy popup menu on the specified control and activate the copy handler for the
   * control when the control has focus. The handler will be deactivated when the control is
   * disposed.
   *
   * @param copyable the copyable that will perform the copy
   * @param control the control on which to install the menu and handler
   */
  public static void activateCopy(ICopyable copyable, final Control control) {
    IFocusService fs = PlatformUI.getWorkbench().getService(IFocusService.class);
    final IHandlerService hs = PlatformUI.getWorkbench().getService(IHandlerService.class);
    new CopyPopup(copyable, control);
    if (fs != null && hs != null) {
      fs.addFocusTracker(control, CONTROL_ID);
      final IHandlerActivation handlerActivation =
          hs.activateHandler(
              CopyHandler.ID,
              new CopyHandler(copyable),
              new Expression() {
                public EvaluationResult evaluate(IEvaluationContext context) {
                  return context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_NAME) == control
                      ? EvaluationResult.TRUE
                      : EvaluationResult.FALSE;
                }

                public void collectExpressionInfo(final ExpressionInfo info) {
                  info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_NAME);
                }
              });
      control.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              hs.deactivateHandler(handlerActivation);
            }
          });
    }
  }
  public void registerCommands(CompilationUnitEditor editor) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    ICommandService commandService = (ICommandService) workbench.getAdapter(ICommandService.class);
    IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class);
    if (commandService == null || handlerService == null) {
      return;
    }

    if (fCorrectionHandlerActivations != null) {
      JavaPlugin.logErrorMessage("correction handler activations not released"); // $NON-NLS-1$
    }
    fCorrectionHandlerActivations = new ArrayList();

    Collection definedCommandIds = commandService.getDefinedCommandIds();
    for (Iterator iter = definedCommandIds.iterator(); iter.hasNext(); ) {
      String id = (String) iter.next();
      if (id.startsWith(COMMAND_PREFIX)) {
        boolean isAssist = id.endsWith(ASSIST_SUFFIX);
        CorrectionCommandHandler handler = new CorrectionCommandHandler(editor, id, isAssist);
        IHandlerActivation activation =
            handlerService.activateHandler(
                id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
        fCorrectionHandlerActivations.add(activation);
      }
    }
  }
  public void testVisibilityTracksEnablement() throws Exception {
    final MenuManager manager = new MenuManager();
    final CommandContributionItemParameter parm =
        new CommandContributionItemParameter(
            window,
            null,
            COMMAND_ID,
            Collections.EMPTY_MAP,
            null,
            null,
            null,
            null,
            null,
            null,
            CommandContributionItem.STYLE_PUSH,
            null,
            true);
    final CommandContributionItem item = new CommandContributionItem(parm);

    AbstractContributionFactory factory =
        new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) {
          @Override
          public void createContributionItems(
              IServiceLocator menuService, IContributionRoot additions) {
            additions.addContributionItem(item, null);
          }
        };

    menuService.addContributionFactory(factory);
    menuService.populateContributionManager(manager, LOCATION);

    assertFalse(item.isEnabled());
    assertFalse("starting state", item.isVisible());

    IHandlerService handlers = window.getService(IHandlerService.class);
    TestEnabled handler = new TestEnabled();
    IHandlerActivation activateHandler = handlers.activateHandler(COMMAND_ID, handler);

    assertTrue(handler.isEnabled());
    assertTrue(item.isEnabled());
    assertTrue("activated handler", item.isVisible());

    handler.setEnabled(false);

    assertFalse("set enabled == false", item.isVisible());

    handler.setEnabled(true);

    assertTrue("set enabled == true", item.isVisible());

    handlers.deactivateHandler(activateHandler);

    assertFalse("deactivate handler", item.isVisible());

    menuService.releaseContributions(manager);
    menuService.removeContributionFactory(factory);
    manager.dispose();
  }
 private void installQuickAccessAction() {
   fHandlerService = (IHandlerService) fSite.getService(IHandlerService.class);
   if (fHandlerService != null) {
     fQuickAccessAction = new SourceQuickAccessAction(fEditor);
     fQuickAccessHandlerActivation =
         fHandlerService.activateHandler(
             fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction));
   }
 }
 /**
  * Registers the given action with the workbench command support.
  *
  * @param action the action to register.
  */
 private void registerKeybindings(IAction action) {
   final IHandler handler = new ActionHandler(action);
   final IHandlerService handlerService =
       (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
   final IHandlerActivation activation =
       handlerService.activateHandler(
           action.getActionDefinitionId(), handler, new ActiveShellExpression(dialog.getShell()));
   activations.add(activation);
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.console.IConsolePageParticipant#activated()
  */
 public void activated() {
   // add EOF submissions
   IPageSite site = fPage.getSite();
   IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
   IContextService contextService = (IContextService) site.getService(IContextService.class);
   fActivatedContext = contextService.activateContext(fContextId);
   fActivatedHandler =
       handlerService.activateHandler(
           "org.eclipse.debug.ui.commands.eof", fEOFHandler); // $NON-NLS-1$
   ErlideUIPlugin.getDefault().setConsolePage((ErlangConsolePage) fPage);
 }
示例#9
0
 @Nullable
 public static IHandlerActivation registerKeyBinding(
     IServiceLocator serviceLocator, IAction action) {
   IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
   if (handlerService != null) {
     return handlerService.activateHandler(
         action.getActionDefinitionId(), new ActionHandler(action));
   } else {
     return null;
   }
 }
示例#10
0
  /**
   * @param currentHandler
   * @param expression1
   */
  private void makeHandler(String handler, String context, ActiveContextExpression expression) {
    IHandler currentHandler = null;
    if (!testHandlers.containsKey(handler)) {
      currentHandler = new ActTestHandler(context);
      testHandlers.put(handler, currentHandler);
    } else {
      currentHandler = (IHandler) testHandlers.get(handler);
    }

    testHandlerActivations.put(
        handler, handlerService.activateHandler(CMD_ID, currentHandler, expression));
  }
  /** Is triggered when a spec has been parsed not intended to be called by clients */
  public void specParsed(Spec spec) {
    /*
     * This controls graying and activating of the menu
     * item Parse Errors which raises the parse errors
     * view. It activates a handler programmatically
     * when appropriate because declaring the handler as a
     * plug in extension did not activate the handler quickly
     * enough. For example, when a parse error is introduced,
     * the Parse Errors menu item would not be active until
     * the user did something such as highlight text. However,
     * by activating it programmatically here, the menu item
     * will become active as soon as there is a parse error
     * and will become inactive as soon as there is no parse
     * error.
     */
    if (parseErrorsHandlerActivation != null) {
      IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      /*
       *  It is necessary to deactivate the currently active handler if there
       *  was one because a command can have at most one
       *  active handler at a time.
       * It seems unnecessary to deactivate and reactivate a handler
       * when the parse status goes from error to error, but I cannot
       * find a way to determine if there is currently
       * an active handler for the parse error view command, so the
       * currently active handler is always deactivated, and then reactivated
       * if there is still an error.
       */
      handlerService.deactivateHandler(parseErrorsHandlerActivation);
      parseErrorsHandlerActivation = null;
    }
    if (AdapterFactory.isProblemStatus(spec.getStatus())) {
      IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      parseErrorsHandlerActivation =
          handlerService.activateHandler(
              "toolbox.command.openParseErrorView", new OpenParseErrorViewHandler());
    }

    // inform the participants
    this.lifecycleManager.sendEvent(new SpecEvent(spec, SpecEvent.TYPE_PARSE));
  }
 public void setGlobalActionHandler(String actionId, IAction actionHandler) {
   IActionBars bars = getActionBars();
   if (bars != null) {
     bars.setGlobalActionHandler(actionId, actionHandler);
     return;
   } else if (fExpression != null
       && actionHandler != null
       && actionHandler.getActionDefinitionId() != null) {
     IHandlerService service = getHandlerService();
     if (service != null) {
       IHandlerActivation activation =
           service.activateHandler(
               actionHandler.getActionDefinitionId(),
               new ActionHandler(actionHandler),
               fExpression);
       fPaneActivations.add(activation);
       return;
     }
   }
   // Remove the action definition id since we won't get key bindings
   if (actionHandler != null) actionHandler.setActionDefinitionId(null);
 }
  public void activateHandlers() {
    ICommandService commandSupport = getSite().getService(ICommandService.class);
    IHandlerService handlerService = getSite().getService(IHandlerService.class);
    IContextService contextSupport = getSite().getService(IContextService.class);

    if (commandSupport != null && handlerService != null && contextSupport != null) {
      contextSupport.activateContext(ID_MEMORY_VIEW_CONTEXT);

      fAddHandler =
          new AbstractHandler() {
            @Override
            public Object execute(ExecutionEvent event) throws ExecutionException {
              IAdaptable context = DebugUITools.getPartDebugContext(getSite());
              if (context != null
                  && MemoryViewUtil.isValidSelection(new StructuredSelection(context))) {
                RetargetAddMemoryBlockAction action =
                    new RetargetAddMemoryBlockAction(MemoryView.this);
                action.run();
                action.dispose();
              }
              return null;
            }
          };
      handlerService.activateHandler(ID_ADD_MEMORY_BLOCK_COMMAND, fAddHandler);

      fToggleMonitorsHandler =
          new AbstractHandler() {
            @Override
            public Object execute(ExecutionEvent event) throws ExecutionException {
              ToggleMemoryMonitorsAction action = new ToggleMemoryMonitorsAction();
              action.init(MemoryView.this);
              action.run();
              action.dispose();
              return null;
            }
          };

      handlerService.activateHandler(
          ID_TOGGLE_MEMORY_MONITORS_PANE_COMMAND, fToggleMonitorsHandler);

      fNextMemoryBlockHandler =
          new AbstractHandler() {

            @Override
            public Object execute(ExecutionEvent event) throws ExecutionException {
              SwitchMemoryBlockAction action = new SwitchMemoryBlockAction();
              action.init(MemoryView.this);
              action.run();
              action.dispose();
              return null;
            }
          };
      handlerService.activateHandler(ID_NEXT_MEMORY_BLOCK_COMMAND, fNextMemoryBlockHandler);

      fCloseRenderingHandler =
          new AbstractHandler() {

            @Override
            public Object execute(ExecutionEvent event) throws ExecutionException {

              IMemoryRenderingContainer container = getContainer(fActivePaneId);
              if (container != null) {
                if (container instanceof RenderingViewPane) {
                  if (!((RenderingViewPane) container).canRemoveRendering()) return null;
                }
                IMemoryRendering activeRendering = container.getActiveRendering();
                if (activeRendering != null) {
                  container.removeMemoryRendering(activeRendering);
                }
              }

              return null;
            }
          };
      handlerService.activateHandler(ID_CLOSE_RENDERING_COMMAND, fCloseRenderingHandler);

      fNewRenderingHandler =
          new AbstractHandler() {

            @Override
            public Object execute(ExecutionEvent event) throws ExecutionException {

              IMemoryRenderingContainer container = getContainer(fActivePaneId);

              if (container != null && container instanceof RenderingViewPane) {
                RenderingViewPane pane = (RenderingViewPane) container;
                if (pane.canAddRendering()) pane.showCreateRenderingTab();
              }
              return null;
            }
          };
      handlerService.activateHandler(ID_NEW_RENDERING_COMMAND, fNewRenderingHandler);
    }
  }
示例#14
0
 protected void activateHandlers(IHandlerService handlerService) {
   handlerService.activateHandler(
       IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR,
       new ActionHandler(fToggleLinkingAction));
 }
  /**
   * Get the toolbar for the container
   *
   * @return Control
   */
  Control getContainerToolBar(Composite composite) {

    final ToolBarManager historyManager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
    historyManager.createControl(composite);

    history.createHistoryControls(historyManager.getControl(), historyManager);

    Action popupMenuAction =
        new Action() {
          @Override
          public ImageDescriptor getImageDescriptor() {
            return WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
          }

          @Override
          public void run() {
            MenuManager manager = new MenuManager();
            manager.add(
                new Action() {
                  @Override
                  public void run() {

                    sash.addFocusListener(
                        new FocusAdapter() {
                          @Override
                          public void focusGained(FocusEvent e) {
                            sash.setBackground(
                                sash.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
                          }

                          @Override
                          public void focusLost(FocusEvent e) {
                            sash.setBackground(
                                sash.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                          }
                        });
                    sash.setFocus();
                  }

                  @Override
                  public String getText() {
                    return WorkbenchMessages.FilteredPreferenceDialog_Resize;
                  }
                });
            manager.add(
                new Action() {
                  @Override
                  public void run() {
                    activeKeyScrolling();
                  }

                  @Override
                  public String getText() {
                    return WorkbenchMessages.FilteredPreferenceDialog_Key_Scrolling;
                  }
                });
            Menu menu = manager.createContextMenu(getShell());
            Rectangle bounds = historyManager.getControl().getBounds();
            Point topLeft = new Point(bounds.x + bounds.width, bounds.y + bounds.height);
            topLeft = historyManager.getControl().toDisplay(topLeft);
            menu.setLocation(topLeft.x, topLeft.y);
            menu.setVisible(true);
          }
        };
    popupMenuAction.setToolTipText(WorkbenchMessages.FilteredPreferenceDialog_FilterToolTip);
    historyManager.add(popupMenuAction);
    IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class);
    showViewHandler =
        service.activateHandler(
            IWorkbenchCommandConstants.WINDOW_SHOW_VIEW_MENU,
            new ActionHandler(popupMenuAction),
            new ActiveShellExpression(getShell()));

    historyManager.update(false);

    return historyManager.getControl();
  }
  /** This method creates the items to show on the {@link Frame} , and adds actions */
  protected void initWindow() {
    drawArea = new JPanel();
    window.add(drawArea, BorderLayout.CENTER);
    drawArea.setSize(windowSize.width, windowSize.height);
    drawArea.setPreferredSize(new Dimension(windowSize.width, windowSize.height));

    menuBar = new JMenuBar();
    window.add(menuBar, BorderLayout.NORTH);

    JMenu mnFile = new JMenu("File");

    ActionListener saveGraph =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String path = "";
            try {
              path =
                  project.getPersistentProperty(
                      new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
              errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                        dialog.setText("Save Pajek file");
                        dialog.setFilterPath(oldPath);
                        dialog.setFilterExtensions(new String[] {"*.net", "*.dot"});
                        String graphFilePath = dialog.open();
                        if (graphFilePath == null) {
                          return;
                        }
                        String newPath =
                            graphFilePath.substring(
                                0, graphFilePath.lastIndexOf(File.separator) + 1);
                        try {
                          QualifiedName name =
                              new QualifiedName(
                                  ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                          project.setPersistentProperty(name, newPath);

                          if ("dot"
                              .equals(
                                  graphFilePath.substring(
                                      graphFilePath.lastIndexOf('.') + 1,
                                      graphFilePath.length()))) {
                            GraphHandler.saveGraphToDot(graph, graphFilePath, project.getName());
                          } else {
                            GraphHandler.saveGraphToPajek(graph, graphFilePath);
                          }

                        } catch (BadLayoutException be) {
                          ErrorReporter.logExceptionStackTrace(
                              "Error while saving image to " + newPath, be);
                          errorHandler.reportErrorMessage("Bad layout\n\n" + be.getMessage());
                        } catch (Exception ce) {
                          ErrorReporter.logExceptionStackTrace(
                              "Error while saving image to " + newPath, ce);
                          errorHandler.reportException(
                              "Error while setting persistent property", ce);
                        }
                      }
                    });
          }
        };

    final JMenuItem mntmSave = new JMenuItem("Save (Ctrl+S)");
    mntmSave.addActionListener(saveGraph);
    mnFile.add(mntmSave);

    ActionListener exportImage =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String path = "";
            try {
              path =
                  project.getPersistentProperty(
                      new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
              errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        ExportPreferencesDialog prefDialog =
                            new ExportPreferencesDialog(editorComposite.getShell());
                        ImageExportType mode = prefDialog.open();

                        FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                        dialog.setText("Export image");
                        dialog.setFilterPath(oldPath);
                        dialog.setFilterExtensions(new String[] {"*.png"});
                        String graphFilePath = dialog.open();
                        if (graphFilePath == null) {
                          return;
                        }
                        String newPath =
                            graphFilePath.substring(
                                0, graphFilePath.lastIndexOf(File.separator) + 1);
                        try {
                          QualifiedName name =
                              new QualifiedName(
                                  ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                          project.setPersistentProperty(name, newPath);
                          handler.saveToImage(graphFilePath, mode);
                        } catch (BadLayoutException be) {
                          errorHandler.reportException("Error while saving image", be);
                          errorHandler.reportErrorMessage(be.getMessage());
                        } catch (CoreException ce) {
                          errorHandler.reportException(
                              "Error while setting persistent property", ce);
                        }
                      }
                    });
          }
        };

    final JMenuItem mntmExportToImage = new JMenuItem("Export to image file (Ctrl+E)");
    mntmExportToImage.addActionListener(exportImage);
    mnFile.add(mntmExportToImage);

    layoutMenu = new JMenu("Layout");
    layoutGroup = new ButtonGroup();

    layoutListener =
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final IProgressMonitor monitor = Job.getJobManager().createProgressGroup();
            monitor.beginTask("Change layout", 100);
            if (!(e.getSource() instanceof LayoutEntry)) {
              errorHandler.reportErrorMessage(
                  "Unexpected error\n\nAn unusual error has been logged" + LOGENTRYNOTE);
              ErrorReporter.logError(
                  "The layout changing event's source is not of type \"LayoutEntry\"!");
              return;
            }
            final LayoutEntry layout = (LayoutEntry) e.getSource();
            if (handler.getVisualizator() != null) {
              drawArea.remove(handler.getVisualizator());
            }
            try {
              handler.changeLayout(layout, windowSize);
              drawArea.add(handler.getVisualizator());
              if (satView != null) {
                satView.add(handler.getSatelliteViewer());
              }
              window.pack();
            } catch (BadLayoutException exc) {
              layout.setSelected(false);
              chosenLayout.setSelected(true);
              if (exc.getType() == ErrorType.EMPTY_GRAPH || exc.getType() == ErrorType.NO_OBJECT) {
                return;
              }
              try {
                handler.changeLayout(chosenLayout, windowSize);
                drawArea.add(handler.getVisualizator());
                if (satView != null) {
                  satView.add(handler.getSatelliteViewer());
                }
                window.pack();
                monitor.done();
              } catch (BadLayoutException exc2) {
                monitor.done();
                if (exc2.getType() != ErrorType.CYCLIC_GRAPH
                    && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                  errorHandler.reportException("Error while creating layout", exc2);
                } else {
                  errorHandler.reportErrorMessage(exc2.getMessage());
                }
              } catch (IllegalStateException exc3) {
                monitor.done();
                errorHandler.reportException("Error while creating layout", exc3);
              }
              if (exc.getType() != ErrorType.CYCLIC_GRAPH
                  && exc.getType() != ErrorType.EMPTY_GRAPH) {
                errorHandler.reportException("Error while creating layout", exc);
              } else {
                errorHandler.reportErrorMessage(exc.getMessage());
              }
            } catch (IllegalStateException exc) {
              layout.setSelected(false);
              chosenLayout.setSelected(true);
              try {
                handler.changeLayout(chosenLayout, windowSize);
                drawArea.add(handler.getVisualizator());
                if (satView != null) {
                  satView.add(handler.getSatelliteViewer());
                }
                window.pack();
                monitor.done();
              } catch (BadLayoutException exc2) {
                monitor.done();
                if (exc2.getType() != ErrorType.CYCLIC_GRAPH
                    && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                  errorHandler.reportException("Error while creating layout", exc2);
                } else {
                  errorHandler.reportErrorMessage(exc2.getMessage());
                }
              } catch (IllegalStateException exc3) {
                monitor.done();
                errorHandler.reportException("Error while creating layout", exc3);
              }
              errorHandler.reportException("Error while creating layout", exc);
            }
            chosenLayout = layout.clone();
            monitor.done();
          }
        };

    JMenu findMenu = new JMenu("Find");
    final JMenuItem nodeByName = new JMenuItem("Node by name (Ctrl+F)");

    final GraphEditor thisEditor = this;
    nodeByName.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (wndFind != null) {
                          wndFind.close();
                        }
                        try {
                          wndFind =
                              new FindWindow<NodeDescriptor>(
                                  editorComposite.getShell(), thisEditor, graph.getVertices());
                          wndFind.open();
                        } catch (IllegalArgumentException e) {
                          errorHandler.reportException("", e);
                        }
                      }
                    });
          }
        });

    findMenu.add(nodeByName);

    JMenu tools = new JMenu("Tools");
    final JMenuItem findCircles = new JMenuItem("Show circles");
    final JMenuItem findPaths = new JMenuItem("Show parallel paths");
    final JMenuItem clearResults = new JMenuItem("Clear Results");

    findCircles.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ev) {
            Job circlesJob =
                new Job("Searching for circles") {
                  @Override
                  protected IStatus run(IProgressMonitor monitor) {
                    if (graph == null) {
                      return null;
                    }
                    CircleCheck<NodeDescriptor, EdgeDescriptor> checker =
                        new CircleCheck<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.isCyclic()) {
                      for (EdgeDescriptor e : graph.getEdges()) {
                        e.setColour(Color.lightGray);
                      }
                      for (Deque<EdgeDescriptor> st : checker.getCircles()) {
                        for (EdgeDescriptor e : st) {
                          e.setColour(NodeColours.DARK_RED);
                        }
                      }
                      refresh();
                    } else {
                      errorHandler.reportInformation("Result:\n\nThis graph is not cyclic!");
                    }

                    return Status.OK_STATUS;
                  } // end run
                }; // end job
            circlesJob.schedule();
          } // end actionPerformed
        });

    findPaths.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ev) {
            Job pathsJob =
                new Job("Searching for parallel paths") {
                  @Override
                  protected IStatus run(IProgressMonitor monitor) {
                    if (graph == null) {
                      return null;
                    }
                    CheckParallelPaths<NodeDescriptor, EdgeDescriptor> checker = null;
                    checker = new CheckParallelPaths<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.hasParallelPaths()) {
                      for (EdgeDescriptor e : graph.getEdges()) {
                        e.setColour(Color.lightGray);
                      }
                      for (Deque<EdgeDescriptor> list : checker.getPaths()) {
                        for (EdgeDescriptor e : list) {
                          e.setColour(NodeColours.DARK_RED);
                        }
                      }
                      refresh();
                    } else {
                      errorHandler.reportInformation(
                          "Result:\n\nThere are no parallel paths in this graph!");
                    }

                    return Status.OK_STATUS;
                  } // end run
                }; // end job
            pathsJob.schedule();
          } // end actionPerformed
        });

    clearResults.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ev) {
            for (EdgeDescriptor e : graph.getEdges()) {
              e.setColour(Color.black);
            }
            refresh();
          }
        });

    tools.add(findCircles);
    tools.add(findPaths);
    tools.add(clearResults);

    menuBar.add(mnFile);
    menuBar.add(findMenu);
    menuBar.add(tools);
    menuBar.add(layoutMenu);

    // TODO implement refresh action
    /*
     * JMenuItem RefreshMenu=new JMenuItem("Refresh"); ActionListener
     * RefreshAction=new ActionListener() { public void
     * actionPerformed(ActionEvent ev) { GraphGenerator.schedule(); } };
     * RefreshMenu.addActionListener(RefreshAction);
     *
     * menuBar.add(RefreshMenu);
     */

    handlerService.activateHandler(
        GRAPH_SEARCHCMD_ID,
        new AbstractHandler() {
          @Override
          public Object execute(ExecutionEvent event) throws ExecutionException {
            nodeByName.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
          }
        });

    handlerService.activateHandler(
        GRAPH_SAVECMD_ID,
        new AbstractHandler() {
          @Override
          public Object execute(ExecutionEvent event) throws ExecutionException {
            mntmSave.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
          }
        });

    handlerService.activateHandler(
        GRAPH_EXPORTCMD_ID,
        new AbstractHandler() {
          @Override
          public Object execute(ExecutionEvent event) throws ExecutionException {
            mntmExportToImage.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
          }
        });

    try {
      generator.generateGraph();
      setLabeller(generator.getLabeler());
      setGraph(generator.getGraph());
    } catch (InterruptedException ex) {
      errorHandler.reportException("Error while creating the graph", ex);
    }
  }
 /*
  * @see edu.berkeley.eduride.isa.ui.browsing.JavaBrowsingPart#activateHandlers(org.eclipse.ui.handlers.IHandlerService)
  * @since 3.4
  */
 protected void activateHandlers(IHandlerService handlerService) {
   super.activateHandlers(handlerService);
   handlerService.activateHandler(
       CollapseAllHandler.COMMAND_ID, new ActionHandler(fCollapseAllAction));
 }