Example #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);
    }
  }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // in regular PasteHandler we do follwing:
    //// copy contents from clipboard - in case there was something else in the clipboard, e.g.
    // copied from the system buffer.
    //// Plugin.getInstance().getContents().getFromClipboard();
    // but here it would break the order of elements, rendering this command unusable,
    // so we are ok to possibly lose the clipboard content..
    String paramValue = event.getParameter("MoreClipboard.commands.morePasteIndexParameter");
    if (paramValue == null) {
      throw new ExecutionException(
          "Failed to perform paste with index command - parameter is null");
    }

    int index = Integer.parseInt(paramValue);
    Plugin.getInstance().getContents().setToClipboard(index);

    try {
      // run regular paste command
      final IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      handlerService.executeCommand("org.eclipse.ui.edit.paste", null); // result is ignored..
    } catch (NotDefinedException e) {
      throw new ExecutionException("Failed to perform paste with index command", e);
    } catch (NotEnabledException e) {
      throw new ExecutionException("Failed to perform paste with index command", e);
    } catch (NotHandledException e) {
      throw new ExecutionException("Failed to perform paste with index command", e);
    }

    return null;
  }
 protected void executeCommand(String commandId)
     throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
   // Grab the handler service to execute our command
   IHandlerService service =
       (IHandlerService) getActiveEditor().getSite().getService(IHandlerService.class);
   service.executeCommand(commandId, null);
 }
  /**
   * the command has been executed, so extract extract the needed information from the application
   * context.
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!ITextEditor.class.isAssignableFrom(activeEditor.getClass())) {
      return null;
    }
    ITextEditor iTextEditor = (ITextEditor) activeEditor;
    ISelection selection = iTextEditor.getSelectionProvider().getSelection();
    if (!ITextSelection.class.isAssignableFrom(selection.getClass())) {
      return null;
    }
    ITextSelection textSelection = (ITextSelection) selection;

    IHandlerService service =
        (IHandlerService) HandlerUtil.getActiveSite(event).getService(IHandlerService.class);
    try {
      if (textSelection.getLength() == 0) {
        service.executeCommand("org.eclipse.ui.edit.text.cut.line", null);
      } else {
        service.executeCommand("org.eclipse.ui.edit.cut", null);
      }
    } catch (NotDefinedException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    } catch (NotEnabledException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    } catch (NotHandledException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    }

    return null;
  }
  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);
      }
    }
  }
  /**
   * @param ji
   * @param job
   */
  private void execute(JobInfo ji, Job job) {

    Object prop = job.getProperty(IProgressConstants.ACTION_PROPERTY);
    if (prop instanceof IAction && ((IAction) prop).isEnabled()) {
      IAction action = (IAction) prop;
      action.run();
      removeTopElement(ji);
    }

    prop = job.getProperty(IProgressConstants2.COMMAND_PROPERTY);
    if (prop instanceof ParameterizedCommand) {
      ParameterizedCommand command = (ParameterizedCommand) prop;
      IWorkbenchWindow window = getWindow();
      IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
      Exception exception = null;
      try {
        service.executeCommand(command, null);
        removeTopElement(ji);
      } catch (ExecutionException e) {
        exception = e;
      } catch (NotDefinedException e) {
        exception = e;
      } catch (NotEnabledException e) {
        exception = e;
      } catch (NotHandledException e) {
        exception = e;
      }

      if (exception != null) {
        Status status =
            new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, exception.getMessage(), exception);
        StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
      }
    }
  }
Example #7
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);
            }
          });
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated()
  */
 public void deactivated() {
   // remove EOF submissions
   IPageSite site = fPage.getSite();
   IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
   IContextService contextService = (IContextService) site.getService(IContextService.class);
   handlerService.deactivateHandler(fActivatedHandler);
   contextService.deactivateContext(fActivatedContext);
 }
 public void dispose() {
   clearPaneActionHandlers();
   IHandlerService service = getHandlerService();
   if (service == null) return;
   service.deactivateHandlers(fActivations);
   fActivations.clear();
   fDisposed = true;
 }
 public void deregisterCommands() {
   IHandlerService handlerService =
       (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
   if (handlerService != null && fCorrectionHandlerActivations != null) {
     handlerService.deactivateHandlers(fCorrectionHandlerActivations);
     fCorrectionHandlerActivations = null;
   }
 }
 /** may return a single object, or a collection */
 public static Object getNavigationSelectionObject() {
   if (!PlatformUI.getWorkbench().hasService(IHandlerService.class)) return null;
   IHandlerService hs =
       (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
   IEvaluationContext ctx = hs.getCurrentState();
   if (ctx == null) return null;
   return ctx.getDefaultVariable();
 }
  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 clearPaneActionHandlers() {
   if (!fPaneActivations.isEmpty()) {
     IHandlerService service = getHandlerService();
     if (service != null) {
       service.deactivateHandlers(fPaneActivations);
       fPaneActivations.clear();
     }
   }
 }
 /**
  * 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);
 }
 /** Dispose the receiver and clear out the references. */
 public void dispose() {
   final IHandlerService handlerService =
       (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
   final Iterator iterator = activations.iterator();
   while (iterator.hasNext()) {
     handlerService.deactivateHandler((IHandlerActivation) iterator.next());
   }
   activations.clear();
 }
  @Override
  public void execute(String newText) throws CoreException {

    if (newText.isEmpty()) {
      if (getModel().getText() != null) {
        EnquiryTranslationRemoveCommand removeCmd = new EnquiryTranslationRemoveCommand(getModel());
        removeCmd.execute(newText);
      }
      return;
    }
    if (newText.equals(getModel().getText())) {
      // do nothing if text is the same.
      return;
    }

    IEditorPart editorPart = getActiveEditorPart();
    if (editorPart != null) {

      // Extract useful parameters needed for the command
      IWorkbenchPartSite site = editorPart.getSite();

      // Invoke the command
      IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
      ICommandService commandService = (ICommandService) site.getService(ICommandService.class);

      CommandStack commandStack = (CommandStack) editorPart.getAdapter(CommandStack.class);

      try {

        // Get the command and assign values to parameters
        Command command = commandService.getCommand(EDIT_COMMAND_ID);
        Parameterization parameter = new Parameterization(command.getParameter("text"), newText);
        ParameterizedCommand parmCommand =
            new ParameterizedCommand(command, new Parameterization[] {parameter});

        // Prepare the evaluation context
        IEvaluationContext ctx = handlerService.getCurrentState();
        ctx.addVariable("model", getModel());
        ctx.addVariable("commandStack", commandStack);

        // Execute the command
        handlerService.executeCommandInContext(parmCommand, null, ctx);

      } catch (Exception ex) {
        IStatus status =
            new Status(
                IStatus.ERROR,
                Activator.PLUGIN_ID,
                "Error while executing command to update translation",
                ex);
        throw new CoreException(status);
      }
    } else {
      /** @TODO log warn no active editorPart, should never occur */
    }
  }
Example #17
0
 @Override
 public void run() {
   try {
     IHandlerService service =
         (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
     service.executeCommand(ActionFactory.IMPORT.getCommandId(), null);
   } catch (Exception e) {
     log.error("Failed to open import wizard", e);
   }
 }
  /** {@inheritDoc} */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    StructuredSelection selection =
        (StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
    AbstractRootEditor rootEditor = (AbstractRootEditor) HandlerUtil.getActiveEditor(event);
    RepositoryDefinition repositoryDefinition =
        rootEditor.getInputDefinition().getRepositoryDefinition();

    Object selectedObject = selection.getFirstElement();
    ExceptionSensorData dataToNavigateTo = null;
    if (selectedObject instanceof ExceptionSensorData) {
      dataToNavigateTo = (ExceptionSensorData) selectedObject;
    } else if (selectedObject instanceof InvocationSequenceData) {
      List<ExceptionSensorData> exceptions =
          ((InvocationSequenceData) selectedObject).getExceptionSensorDataObjects();
      if ((null != exceptions) && !exceptions.isEmpty()) {
        for (ExceptionSensorData exSensorData : exceptions) {
          if (0 != exSensorData.getMethodIdent()) {
            dataToNavigateTo = exSensorData;
            break;
          }
        }
      }
    }

    if (null != dataToNavigateTo) {
      ExceptionSensorData exceptionSensorData = dataToNavigateTo;

      // exit if the object does not carry the methodIdent
      if (null == exceptionSensorData.getThrowableType()) {
        return null;
      }

      InputDefinition inputDefinition =
          getInputDefinition(repositoryDefinition, exceptionSensorData);

      // open the view via command
      IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      ICommandService commandService =
          (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);

      Command command = commandService.getCommand(OpenViewHandler.COMMAND);
      ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event());
      IEvaluationContext context = (IEvaluationContext) executionEvent.getApplicationContext();
      context.addVariable(OpenViewHandler.INPUT, inputDefinition);

      try {
        command.executeWithChecks(executionEvent);
      } catch (NotDefinedException | NotEnabledException | NotHandledException e) {
        throw new ExecutionException("Error opening the exception type view.", e);
      }
    }
    return null;
  }
Example #19
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;
   }
 }
 /*
  * (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);
 }
 @Override
 public boolean close() {
   if (showViewHandler != null) {
     IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class);
     service.deactivateHandler(showViewHandler);
     showViewHandler.getHandler().dispose();
     showViewHandler = null;
   }
   removeKeyScrolling();
   history.dispose();
   return super.close();
 }
 @Override
 public void run() {
   IHandlerService handlerService =
       (IHandlerService) getSite().getService(IHandlerService.class);
   try {
     setEnabled(false);
     handlerService.executeCommand("org.eclipse.equinox.p2.ui.sdk.update", new Event());
   } catch (Exception e) {
     JBossCentralActivator.log(e);
   } finally {
     setEnabled(true);
   }
 }
 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);
   }
 }
  @Override
  public void execute(String newText) throws CoreException {

    IEditorPart editorPart = getActiveEditorPart();
    if (editorPart != null) {

      // Extract useful parameters needed for the command
      IWorkbenchPartSite site = editorPart.getSite();

      // Invoke the command
      IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
      ICommandService commandService = (ICommandService) site.getService(ICommandService.class);

      if (editorPart instanceof VersionMultiPageEditor) {
        VersionMultiPageEditor vEditor = (VersionMultiPageEditor) editorPart;
        EditingDomain editingDomain = vEditor.getVersionFormEditor().getEditingDomain();
        CommandStack commandStack = editingDomain.getCommandStack();

        try {

          // Get the command and assign values to parameters
          Command command = commandService.getCommand(getCommandId());
          ParameterizedCommand parmCommand =
              new ParameterizedCommand(command, new Parameterization[] {});

          // Prepare the evaluation context
          IEvaluationContext ctx = handlerService.getCurrentState();
          ctx.addVariable("model", getModel());
          ctx.addVariable("commandStack", commandStack);
          ctx.addVariable("editingDomain", editingDomain);

          // Execute the command
          handlerService.executeCommandInContext(parmCommand, null, ctx);

        } catch (Exception ex) {
          IStatus status =
              new Status(
                  IStatus.ERROR,
                  VersionEditorActivator.PLUGIN_ID,
                  "Error while executing command to remove translation",
                  ex);
          throw new CoreException(status);
        }
      }
    } else {
      /** @TODO log warn no active editorPart, should never occur */
    }
  }
Example #25
0
 public static void executeCommand(IViewSite site, String command) {
   ICommandService cmdService = (ICommandService) site.getService(ICommandService.class);
   IHandlerService hdlService = (IHandlerService) site.getService(IHandlerService.class);
   Command cmd = cmdService.getCommand(command);
   try {
     hdlService.executeCommand(cmd.getId(), null);
   } catch (ExecutionException e) {
     e.printStackTrace();
   } catch (NotDefinedException e) {
     e.printStackTrace();
   } catch (NotEnabledException e) {
     e.printStackTrace();
   } catch (NotHandledException e) {
     e.printStackTrace();
   }
 }
Example #26
0
  private void openSample(String file) throws CommandException {
    IHandlerService handlerService =
        (IHandlerService) getIntroSite().getService(IHandlerService.class);
    ICommandService commandService =
        (ICommandService) getIntroSite().getService(ICommandService.class);

    Command command =
        commandService.getCommand(
            "name.abuchen.portfolio.ui.commands.openSampleCommand"); //$NON-NLS-1$

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("name.abuchen.portfolio.ui.param.sample", file); // $NON-NLS-1$
    ParameterizedCommand parameterized = ParameterizedCommand.generateCommand(command, parameters);
    handlerService.executeCommand(parameterized, null);
    PlatformUI.getWorkbench().getIntroManager().closeIntro(this);
  }
Example #27
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
  */
 protected void doTearDown() throws Exception {
   handlerService.deactivateHandlers(testHandlerActivations.values());
   testHandlerActivations.clear();
   contextService.deactivateContexts(testContextActivations.values());
   testContextActivations.clear();
   super.doTearDown();
 }
  /*
   * Called when the window is closed with the top-right corner X or keyboard shortcut
   */
  @Override
  public boolean preWindowShellClose() {
    Boolean result = Boolean.FALSE;
    final IHandlerService handlerService =
        (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);

    try {
      /* event is null, the handler wont call workbench.close() */
      result =
          (Boolean)
              handlerService.executeCommand(
                  "com.netifera.platform.ui.application.closeWorkspace", null);
    } catch (Exception e) {
      // XXX log something here
    }
    return result;
  }
 private void installQuickAccessAction() {
   fHandlerService = (IHandlerService) fSite.getService(IHandlerService.class);
   if (fHandlerService != null) {
     fQuickAccessAction = new SourceQuickAccessAction(fEditor);
     fQuickAccessHandlerActivation =
         fHandlerService.activateHandler(
             fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction));
   }
 }
Example #30
0
 @Override
 public void run() {
   IHandlerService service =
       (IHandlerService)
           PlatformUI.getWorkbench()
               .getActiveWorkbenchWindow()
               .getActivePage()
               .getActivePart()
               .getSite()
               .getService(IHandlerService.class);
   try {
     service.executeCommand(
         "de.fu_berlin.inf.dpp.ui.commands.OpenSarosPreferences", //$NON-NLS-1$
         null);
   } catch (Exception e) {
     log.error("Could not execute command", e); // $NON-NLS-1$
   }
 }