Package org.eclipse.core.commands

Examples of org.eclipse.core.commands.Command


   * @param parameterMap
   */
  private void createCommand(ICommandService commandService,
      String commandId, Map parameterMap) {
    try {
      Command cmd = commandService.getCommand(commandId);
      if (!cmd.isDefined()) {
        WorkbenchPlugin.log("Command " + commandId + " is undefined"); //$NON-NLS-1$//$NON-NLS-2$
        return;
      }

      if (parameterMap == null) {
        parameterizedCommand = new ParameterizedCommand(cmd, null);
        return;
      }

      ArrayList parameters = new ArrayList();
      Iterator i = parameterMap.keySet().iterator();
      while (i.hasNext()) {
        String parmName = (String) i.next();
        IParameter parm = cmd.getParameter(parmName);
        if (parm == null) {
          WorkbenchPlugin.log("Invalid parameter \'" + parmName //$NON-NLS-1$
              + "\' for command " + commandId); //$NON-NLS-1$
          return;
        }
View Full Code Here


   * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
   */
  protected ParameterizedCommand getBackwardCommand() {
    // TODO Auto-generated method stub
    final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
    final Command command = commandService.getCommand("org.eclipse.ui.window.previousView"); //$NON-NLS-1$
    ParameterizedCommand commandBack = new ParameterizedCommand(command, null);
    return commandBack;
  }
View Full Code Here

   * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand()
   */
  protected ParameterizedCommand getForwardCommand() {
    // TODO Auto-generated method stub
    final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
    final Command command = commandService.getCommand("org.eclipse.ui.window.nextView"); //$NON-NLS-1$
    ParameterizedCommand commandF = new ParameterizedCommand(command, null);
    return commandF;
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
   */
  protected ParameterizedCommand getBackwardCommand() {
    final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
    final Command command = commandService.getCommand("org.eclipse.ui.window.previousPerspective"); //$NON-NLS-1$
    ParameterizedCommand commandBack = new ParameterizedCommand(command, null);
    return commandBack;
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand()
   */
  protected ParameterizedCommand getForwardCommand() {
    final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
    final Command command = commandService.getCommand("org.eclipse.ui.window.nextPerspective"); //$NON-NLS-1$
    ParameterizedCommand commandF = new ParameterizedCommand(command, null);
    return commandF;
  }
View Full Code Here

          .getWorkbench().getService(ICommandService.class);
      final Collection commandIds = commandService.getDefinedCommandIds();
      final Iterator commandIdItr = commandIds.iterator();
      while (commandIdItr.hasNext()) {
        final String currentCommandId = (String) commandIdItr.next();
        final Command command = commandService
            .getCommand(currentCommandId);
        if (command != null && command.isHandled()
            && command.isEnabled()) {
          try {
            Collection combinations = ParameterizedCommand
                .generateCombinations(command);
            for (Iterator it = combinations.iterator(); it
                .hasNext();) {
View Full Code Here

    return null;
  }

  public String getLabel() {
    try {
      Command nestedCommand = command.getCommand();
      if (nestedCommand != null && nestedCommand.getDescription() != null
          && nestedCommand.getDescription().length() != 0) {
        return command.getName() + separator
            + nestedCommand.getDescription();
      }
      return command.getName();
    } catch (NotDefinedException e) {
      return command.toString();
    }
View Full Code Here

          public void run() {
            IHandlerService handlerService =
              (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService =
              (ICommandService) getSite().getService(ICommandService.class);
            Command cmd = commandService.getCommand("net.sf.logsaw.ui.commands.AddLogResourceCommand"); //$NON-NLS-1$
            try {
              Parameterization param = new Parameterization(
                  cmd.getParameter("net.sf.logsaw.ui.commands.AddLogResourceCommand.filename"), ((String[]) target)[0]); //$NON-NLS-1$
              ParameterizedCommand paraCmd = new ParameterizedCommand(cmd, new Parameterization[] {param});
              handlerService.executeCommand(paraCmd, null);
            } catch (CommandException e) {
              // log and show error
              UIPlugin.logAndShowError(new CoreException(new Status(
View Full Code Here

    gridLayout.marginWidth = 0;
    root.setLayout(gridLayout);
   
    ICommandService service =
      (ICommandService) getWorkbenchWindow().getService(ICommandService.class);
    final Command cmd = service.getCommand("net.sf.logsaw.ui.commands.GoToPageCommand"); //$NON-NLS-1$
   
    text = new Text(root, SWT.BORDER | SWT.RIGHT);
    text.addKeyListener(new KeyAdapter() {

      /* (non-Javadoc)
       * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
       */
      @Override
      public void keyReleased(KeyEvent e) {
        if (e.keyCode == SWT.CR) {
          try {
            int pageNumber = Integer.valueOf(text.getText().trim());
            IHandlerService service =
              (IHandlerService) getWorkbenchWindow().getService(IHandlerService.class);
            Parameterization param = new Parameterization(
                cmd.getParameter("net.sf.logsaw.ui.commands.GoToPageCommand.pageNumber"), Integer.toString(pageNumber)); //$NON-NLS-1$
            ParameterizedCommand paraCmd = new ParameterizedCommand(cmd, new Parameterization[] {param});
            service.executeCommand(paraCmd, null);
          } catch (NumberFormatException e1) {
            // nadda
          } catch (CommandException e1) {
            // Log and show error
            UIPlugin.logAndShowError(new CoreException(
                new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID,
                NLS.bind(Messages.GoToPageContribution_error_failedToExecuteCommand,
                    new Object[] {e1.getLocalizedMessage()}), e1)), false);
          }
        }
      }
    });
   
    label = new Label(root, SWT.NONE);
    // This number format is used for label and text field
    nf = new DecimalFormat();
    nf.setGroupingUsed(false);
    nf.setParseIntegerOnly(true);
   
    if (cmd != null) {
      updateState(cmd.isEnabled());
      cmd.addCommandListener(new ICommandListener() {

        /* (non-Javadoc)
         * @see org.eclipse.core.commands.ICommandListener#commandChanged(org.eclipse.core.commands.CommandEvent)
         */
        @Override
 
View Full Code Here

  }
 
  private IContributionItem createContributionItem(IServiceLocator serviceLocator, Action item) {
    ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
   
    Command command = commandService.getCommand("io.emmet.eclipse.commands." + item.getId());
    if (!command.isDefined()) {
      command.define(item.getName(), "", commandService.getCategory("io.emmet.eclipse.commands.category"));
    }
   
    IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class);
    handlerService.activateHandler(command.getId(), handlerFactory(item.getId()));
   
    CommandContributionItemParameter p = new CommandContributionItemParameter(
        serviceLocator, "", command.getId(), CommandContributionItem.STYLE_PUSH);
   
    p.label = item.getName();
   
    CommandContributionItem contribItem = new CommandContributionItem(p);
    contribItem.setVisible(true);
View Full Code Here

TOP

Related Classes of org.eclipse.core.commands.Command

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.