Package org.eclipse.ui.handlers

Examples of org.eclipse.ui.handlers.IHandlerService


    /**
     * @param fActivateEditorBinding
     */
    public static void executeCommand(String commandId) {
        IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
        try {
            handlerService.executeCommand(commandId, null);
        } catch (Exception e) {
            Log.log(e);
        }

    }
View Full Code Here


    CommandContributionItemParameter itemParam = new CommandContributionItemParameter(
        workbench, null, itemAction, STYLE_PUSH);

    IWorkbenchWindow activeWorkbenchWindow = workbench
        .getActiveWorkbenchWindow();
    IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
    IEvaluationContext ctx = hsr.getCurrentState();
    ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, getContext().getSelection());

    return new CommandContributionItem(itemParam);
  }
View Full Code Here

      private IHandlerActivation redoHandlerActivation;
      private IHandlerActivation quickFixHandlerActivation;
      private IHandlerActivation contentAssistHandlerActivation;

      public void focusGained(FocusEvent e) {
        IHandlerService service = getHandlerService();
        if (service == null)
          return;

        if (cutAction != null) {
          cutAction.update();
          cutHandlerActivation = service.activateHandler(
              IWorkbenchCommandConstants.EDIT_CUT,
              new ActionHandler(cutAction),
              new ActiveShellExpression(getParent().getShell()));
        }
        copyAction.update();

        copyHandlerActivation = service.activateHandler(
            IWorkbenchCommandConstants.EDIT_COPY,
            new ActionHandler(copyAction),
            new ActiveShellExpression(getParent().getShell()));
        if (pasteAction != null)
          this.pasteHandlerActivation = service.activateHandler(
              IWorkbenchCommandConstants.EDIT_PASTE,
              new ActionHandler(pasteAction),
              new ActiveShellExpression(getParent().getShell()));
        selectAllHandlerActivation = service.activateHandler(
            IWorkbenchCommandConstants.EDIT_SELECT_ALL,
            new ActionHandler(selectAllAction),
            new ActiveShellExpression(getParent().getShell()));
        if (undoAction != null)
          undoHandlerActivation = service.activateHandler(
              IWorkbenchCommandConstants.EDIT_UNDO,
              new ActionHandler(undoAction),
              new ActiveShellExpression(getParent().getShell()));
        if (redoAction != null)
          redoHandlerActivation = service.activateHandler(
              IWorkbenchCommandConstants.EDIT_REDO,
              new ActionHandler(redoAction),
              new ActiveShellExpression(getParent().getShell()));
        if (quickFixActionHandler != null)
          quickFixHandlerActivation = getHandlerService().activateHandler(
              quickFixActionHandler.getAction().getActionDefinitionId(),
              quickFixActionHandler,
              new ActiveShellExpression(getParent().getShell()));
        if (contentAssistActionHandler != null)
          contentAssistHandlerActivation = getHandlerService().activateHandler(
              contentAssistActionHandler.getAction().getActionDefinitionId(),
              contentAssistActionHandler,
              new ActiveShellExpression(getParent().getShell()));
      }

      public void focusLost(FocusEvent e) {
        IHandlerService service = getHandlerService();
        if (service == null)
          return;

        if (cutHandlerActivation != null)
          service.deactivateHandler(cutHandlerActivation);

        if (copyHandlerActivation != null)
          service.deactivateHandler(copyHandlerActivation);

        if (pasteHandlerActivation != null)
          service.deactivateHandler(pasteHandlerActivation);

        if (selectAllHandlerActivation != null)
          service.deactivateHandler(selectAllHandlerActivation);

        if (undoHandlerActivation != null)
          service.deactivateHandler(undoHandlerActivation);

        if (redoHandlerActivation != null)
          service.deactivateHandler(redoHandlerActivation);

        if (quickFixHandlerActivation != null)
          service.deactivateHandler(quickFixHandlerActivation);

        if (contentAssistHandlerActivation != null)
          service.deactivateHandler(contentAssistHandlerActivation);
      }

    });

        sourceViewer.addSelectionChangedListener(new ISelectionChangedListener() {
View Full Code Here

   * @return {@link ExecutionEvent} with current selection
   */
  protected ExecutionEvent createExecutionEvent() {
    IServiceLocator locator = getServiceLocator();
    ICommandService srv = CommonUtils.getService(locator, ICommandService.class);
    IHandlerService hsrv = CommonUtils.getService(locator, IHandlerService.class);
    Command command = srv.getCommand(commandId);

    ExecutionEvent event = hsrv.createExecutionEvent(command, null);
    if (event.getApplicationContext() instanceof IEvaluationContext)
      ((IEvaluationContext) event.getApplicationContext()).addVariable(
          ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
    return event;
  }
View Full Code Here

    Hyperlink addLink = toolkit.createHyperlink(optionsArea,
        UIText.RepositoriesView_linkAdd, SWT.WRAP);
    addLink.setForeground(linkColor);
    addLink.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
        UIUtils.executeCommand(service,
            "org.eclipse.egit.ui.RepositoriesViewAddRepository"); //$NON-NLS-1$
      }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
        .grab(true, false).applyTo(addLink);

    Label cloneLabel = new Label(optionsArea, SWT.NONE);
    Image cloneImage = UIIcons.CLONEGIT.createImage();
    UIUtils.hookDisposal(cloneLabel, cloneImage);
    cloneLabel.setImage(cloneImage);
    Hyperlink cloneLink = toolkit.createHyperlink(optionsArea,
        UIText.RepositoriesView_linkClone, SWT.WRAP);
    cloneLink.setForeground(linkColor);
    cloneLink.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
        UIUtils.executeCommand(service,
            "org.eclipse.egit.ui.RepositoriesViewClone"); //$NON-NLS-1$
      }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
        .grab(true, false).applyTo(cloneLink);

    Label createLabel = new Label(optionsArea, SWT.NONE);
    Image createImage = UIIcons.CREATE_REPOSITORY.createImage();
    UIUtils.hookDisposal(createLabel, createImage);
    createLabel.setImage(createImage);
    Hyperlink createLink = toolkit.createHyperlink(optionsArea,
        UIText.RepositoriesView_linkCreate, SWT.WRAP);
    createLink.setForeground(linkColor);
    createLink.setText(UIText.RepositoriesView_linkCreate);
    createLink.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
        UIUtils.executeCommand(service,
            "org.eclipse.egit.ui.RepositoriesViewCreateRepository"); //$NON-NLS-1$
      }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
View Full Code Here

    }
    executeOpenCommand();
  }

  private void executeOpenCommand() {
    IHandlerService srv = CommonUtils.getService(getViewSite(), IHandlerService.class);

    try {
      srv.executeCommand("org.eclipse.egit.ui.RepositoriesViewOpen", null); //$NON-NLS-1$
    } catch (Exception e) {
      Activator.handleError(e.getMessage(), e, false);
    }
  }
View Full Code Here

  private Repository getRepository() {
    if (serviceLocator == null)
      return null;

    IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
    if (handlerService == null)
      return null;

    IEvaluationContext evaluationContext = handlerService.getCurrentState();
    return SelectionUtils.getRepository(evaluationContext);
  }
View Full Code Here

      public void open(OpenEvent event) {
        if (input == null || !input.isSingleFile())
          return;

        ICommandService srv = CommonUtils.getService(site, ICommandService.class);
        IHandlerService hsrv = CommonUtils.getService(site, IHandlerService.class);
        Command cmd = srv.getCommand(HistoryViewCommands.SHOWVERSIONS);
        Parameterization[] parms;
        if (Activator.getDefault().getPreferenceStore().getBoolean(
            UIPreferences.RESOURCEHISTORY_COMPARE_MODE))
          try {
            IParameter parm = cmd
                .getParameter(HistoryViewCommands.COMPARE_MODE_PARAM);
            parms = new Parameterization[] { new Parameterization(
                parm, Boolean.TRUE.toString()) };
          } catch (NotDefinedException e) {
            Activator.handleError(e.getMessage(), e, true);
            parms = null;
          }
        else
          parms = null;
        ParameterizedCommand pcmd = new ParameterizedCommand(cmd, parms);
        try {
          hsrv.executeCommandInContext(pcmd, null, hsrv
              .getCurrentState());
        } catch (Exception e) {
          Activator.handleError(e.getMessage(), e, true);
        }
      }
View Full Code Here

    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench()
        .getActiveWorkbenchWindow();
    // no active window during Eclipse shutdown
    if (activeWorkbenchWindow == null)
      return null;
    IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
    ctx = hsr.getCurrentState();
    return ctx;
  }
View Full Code Here

        .getWorkbench(), ICommandService.class);
    Command cmd = commandService.getCommand(commandId);
    if (!cmd.isDefined())
      return false;

    IHandlerService handlerService = CommonUtils.getService(PlatformUI
        .getWorkbench(), IHandlerService.class);
    EvaluationContext c = null;
    if (selection != null) {
      c = new EvaluationContext(
          handlerService.createContextSnapshot(false),
          selection.toList());
      c.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
      c.removeVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    }
    try {
      if (c != null)
        handlerService.executeCommandInContext(
            new ParameterizedCommand(cmd, null), null, c);
      else
        handlerService.executeCommand(commandId, null);

      return true;
    } catch (CommandException ignored) {
      // Ignored
    }
View Full Code Here

TOP

Related Classes of org.eclipse.ui.handlers.IHandlerService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.