Java 类org.eclipse.ui.commands.ICommandService 实例源码

项目:gama    文件:EditorToolbar.java   
private void hookToCommands(final ToolItem lastEdit, final ToolItem nextEdit) {
    final UIJob job = new UIJob("Hooking to commands") {

        @Override
        public IStatus runInUIThread(final IProgressMonitor monitor) {
            final ICommandService service = WorkbenchHelper.getService(ICommandService.class);
            final Command nextCommand = service.getCommand(IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY);
            nextEdit.setEnabled(nextCommand.isEnabled());
            final ICommandListener nextListener = e -> nextEdit.setEnabled(nextCommand.isEnabled());

            nextCommand.addCommandListener(nextListener);
            final Command lastCommand = service.getCommand(IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY);
            final ICommandListener lastListener = e -> lastEdit.setEnabled(lastCommand.isEnabled());
            lastEdit.setEnabled(lastCommand.isEnabled());
            lastCommand.addCommandListener(lastListener);
            // Attaching dispose listeners to the toolItems so that they remove the
            // command listeners properly
            lastEdit.addDisposeListener(e -> lastCommand.removeCommandListener(lastListener));
            nextEdit.addDisposeListener(e -> nextCommand.removeCommandListener(nextListener));
            return Status.OK_STATUS;
        }
    };
    job.schedule();

}
项目:Tarski    文件:MarkerVisibilityHandler.java   
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
  this.decoratorManager = Activator.getDefault().getWorkbench().getDecoratorManager();

  if (!this.isHidden) {
    this.isHidden = true;
    this.setStore(false);
    this.setDecorator(false);
  } else {
    this.isHidden = false;
    this.setStore(true);
    this.setDecorator(true);
  }
  this.store.needsSaving();

  final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  final ICommandService commandService = window.getService(ICommandService.class);
  if (commandService != null) {
    commandService.refreshElements(COMMAND_ID, null);
  }
  return null;
}
项目:eclemma    文件:ImportSessionHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {

    final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
    final ICommandService cs = (ICommandService) site
        .getService(ICommandService.class);
    final IHandlerService hs = (IHandlerService) site
        .getService(IHandlerService.class);
    final Command command = cs
        .getCommand(IWorkbenchCommandConstants.FILE_IMPORT);

    try {
      hs.executeCommand(ParameterizedCommand.generateCommand(command,
          Collections.singletonMap(
              IWorkbenchCommandConstants.FILE_IMPORT_PARM_WIZARDID,
              SessionImportWizard.ID)),
          null);
    } catch (CommandException e) {
      EclEmmaUIPlugin.log(e);
    }

    return null;
  }
项目:eclemma    文件:ExportSessionHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {

    final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
    final ICommandService cs = (ICommandService) site
        .getService(ICommandService.class);
    final IHandlerService hs = (IHandlerService) site
        .getService(IHandlerService.class);
    final Command command = cs
        .getCommand(IWorkbenchCommandConstants.FILE_EXPORT);

    try {
      hs.executeCommand(ParameterizedCommand.generateCommand(command,
          Collections.singletonMap(
              IWorkbenchCommandConstants.FILE_EXPORT_PARM_WIZARDID,
              SessionExportWizard.ID)),
          null);
    } catch (CommandException e) {
      EclEmmaUIPlugin.log(e);
    }

    return null;
  }
项目:hssd    文件:DropEntryHandler.java   
@Override
public boolean performDrop(Object data) {
    IServiceLocator locator = Helper.getWB();
    ICommandService svc = (ICommandService)locator.getService(
            ICommandService.class);
    Command cmd = svc.getCommand(CMD_ID_MOVE_ENTRY);

    Map<String, String> params = new HashMap<>();

    params.put("source", data.toString());

    TreeNode en = (TreeNode)getCurrentTarget();
    EntryData ed = EntryData.of(en);
    params.put("target", String.valueOf(ed.entryID()));

    try {
        cmd.executeWithChecks(
                new ExecutionEvent(cmd, params, getCurrentEvent(), null));
    } catch (ExecutionException | NotDefinedException | NotEnabledException
            | NotHandledException e) {
        throw new RuntimeException(e);
    }
    return true;
}
项目:org.csstudio.display.builder    文件:SendToElogAction.java   
public static boolean isElogAvailable() {
    try {
        if (LogbookClientManager.getLogbookClientFactory() == null)
            return false;

        // Check if logbook dialog is available
        ICommandService commandService = PlatformUI
                .getWorkbench().getActiveWorkbenchWindow()
                .getService(ICommandService.class);
        Command command = commandService
                .getCommand(OPEN_LOGENTRY_BUILDER_DIALOG_ID);
        if (command == null) {
            return false;
        }

        return true;
    } catch (Exception e) {
        return false;
    }
}
项目:EasyShell    文件:Utils.java   
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
    if (workbench == null) {
        workbench = PlatformUI.getWorkbench();
    }
    // get command
    ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
    Command command = commandService != null ? commandService.getCommand(commandName) : null;
    // get handler service
    //IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
    //TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
    IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
    if (command != null && handlerService != null) {
        ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
        try {
            handlerService.executeCommand(paramCommand, null);
        } catch (Exception e) {
            Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
        }
    }
}
项目:IDRT-Import-and-Mapping-Tool    文件:ActionCommand.java   
public ParameterizedCommand getCommand() {
    IWorkbenchWindow activeWorkbenchWindow = Activator.getDefault()
            .getWorkbench().getActiveWorkbenchWindow();


    if (activeWorkbenchWindow != null) {

        ICommandService commandService = (ICommandService) activeWorkbenchWindow
                .getService(ICommandService.class);


        if (commandService != null) {


            // commandService.
            ParameterizedCommand parameterizedCommand = ParameterizedCommand
                    .generateCommand(commandService.getCommand(_commandID),
                            _params);
            return parameterizedCommand;
        }
    }
    return null;
}
项目:IDRT-Import-and-Mapping-Tool    文件:ActionCommand.java   
public ParameterizedCommand getParameterizedCommand() {
    IWorkbenchWindow activeWorkbenchWindow = Activator.getDefault()
            .getWorkbench().getActiveWorkbenchWindow();

    if (activeWorkbenchWindow != null) {
        ICommandService commandService = (ICommandService) activeWorkbenchWindow
                .getService(ICommandService.class);
        if (commandService != null) {
            ParameterizedCommand parameterizedCommand = ParameterizedCommand
                    .generateCommand(commandService.getCommand(_commandID),
                            _params);
            return parameterizedCommand;
        }
    }
    return null;
}
项目:gama    文件:DelegateForAllElements.java   
@Override
public void run(final IAction action) {

    // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench():
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    // or a site from within a editor or view:
    // IServiceLocator serviceLocator = getSite();

    ICommandService commandService = serviceLocator.getService(ICommandService.class);

    try {
        // Lookup commmand with its ID
        Command command = commandService.getCommand("org.eclipse.xtext.ui.shared.OpenXtextElementCommand");

        // Optionally pass a ExecutionEvent instance, default no-param arg creates blank event
        command.executeWithChecks(new ExecutionEvent());

    } catch (Exception e) {

        // Replace with real-world exception handling
        e.printStackTrace();
    }

}
项目:eip-designer    文件:CompareWithRouteAction.java   
@Override
public void run(IAction action) {
   System.err.println("In run(IACtion)");
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 

   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }

   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
项目:eip-designer    文件:PersistToRouteModelAction.java   
@Override
public void run(IAction action) {
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 

   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }

   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
项目:eip-designer    文件:CompareWithRouteAction.java   
@Override
public void run(IAction action) {
   System.err.println("In run(IACtion)");
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 

   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }

   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
项目:eip-designer    文件:PersistToRouteModelAction.java   
@Override
public void run(IAction action) {
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 

   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }

   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
项目:APICloud-Studio    文件:ExecutionListenerRegistrant.java   
/**
 * setup
 */
private void setup()
{
    try
    {
        // listen for execution events
        Object service = PlatformUI.getWorkbench().getService(ICommandService.class);

        if (service instanceof ICommandService)
        {
            ICommandService commandService = (ICommandService) service;

            commandService.addExecutionListener(this);
        }
    }
    catch (IllegalStateException e)
    {
        // workbench not yet started, or may be running headless (like in core unit tests)
    }
    // listen for element visibility events
    BundleManager manager = BundleManager.getInstance();

    manager.addElementVisibilityListener(this);
}
项目:APICloud-Studio    文件:ExecutionListenerRegistrant.java   
/**
 * tearDown
 */
private void tearDown()
{
    // stop listening for visibility events
    BundleManager manager = BundleManager.getInstance();

    manager.removeElementVisibilityListener(this);

    // stop listening for execution events
    Object service = PlatformUI.getWorkbench().getService(ICommandService.class);

    if (service instanceof ICommandService)
    {
        ICommandService commandService = (ICommandService) service;

        commandService.removeExecutionListener(this);
    }

    // drop all references
    this._commandToIdsMap.clear();
    this._idToCommandsMap.clear();
    this._nonlimitedCommands.clear();
}
项目:APICloud-Studio    文件:UIUtils.java   
public static void setCoolBarVisibility(boolean visible)
{
    IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
    if (activeWorkbenchWindow instanceof WorkbenchWindow)
    {
        WorkbenchWindow workbenchWindow = (WorkbenchWindow) activeWorkbenchWindow;
        workbenchWindow.setCoolBarVisible(visible);
        workbenchWindow.setPerspectiveBarVisible(visible);

        // Try to force a refresh of the text on the action
        IWorkbenchPart activePart = getActivePart();
        if (activePart != null)
        {
            ICommandService cmdService = (ICommandService) activePart.getSite().getService(ICommandService.class);
            cmdService.refreshElements("org.eclipse.ui.ToggleCoolbarAction", null); //$NON-NLS-1$
        }
    }
}
项目:mytourbook    文件:ActionHandlerPhotoFilter.java   
@Override
public void setEnabled(final Object evaluationContext) {

    super.setEnabled(evaluationContext);

    if (_isAppPhotoFilterInitialized == false) {

        _isAppPhotoFilterInitialized = true;

        /*
         * initialize app photo filter, this is a hack because the whole app startup should be
         * sometimes be streamlined, it's more and more confusing
         */
        final Command command = ((ICommandService) PlatformUI//
                .getWorkbench()
                .getService(ICommandService.class))//
                .getCommand(ActionHandlerPhotoFilter.COMMAND_ID);

        final State state = command.getState(RegistryToggleState.STATE_ID);
        final Boolean isPhotoFilterActive = (Boolean) state.getValue();

        TourbookPlugin.setActivePhotoFilter(isPhotoFilterActive);
    }
}
项目:OpenSPIFe    文件:PlanModifierHandler.java   
/**
 * @throws ExecutionException  
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    IEditorInput editorInput = editor.getEditorInput();
    PlanEditorModel model = PlanEditorModelRegistry.getPlanEditorModel(editorInput);
    EPlan plan = model.getEPlan();
    PlanModifierMember planModifierMember = PlanModifierMember.get(plan);
    String factoryName = event.getParameter("name");
    PlanModifierFactory factory = (factoryName != null ? getNamedFactory(factoryName) : getNextFactory(planModifierMember));
    if (factory != null) {
        IPlanModifier modifier = factory.instantiateModifier();
        modifier.initialize(plan);
        planModifierMember.setModifier(modifier);
        ICommandService commandService = (ICommandService)editor.getSite().getService(ICommandService.class);
        commandService.refreshElements(event.getCommand().getId(), null);
    }
    return null;
}
项目:OpenSPIFe    文件:EnsembleWorkbenchAdvisor.java   
@Override
public void preStartup() {
    // log system startup and record feature names/versions
    if (logUsage) {
        EnsembleUsageLogger.logUsage("RcpPlugin.start()");
    }
    LogUtil.warn("Starting a new " + Platform.getProduct().getName() + " session");

    PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP, true);
    IDE.registerAdapters();

    // Set up exception listeners so that they can be properly logged
    // rather than falling off the stack silently
    Thread.setDefaultUncaughtExceptionHandler(EnsembleUnhandledExceptionHandler.getInstance());
    Platform.addLogListener(EnsembleUnhandledExceptionHandler.getInstance());
    if (shouldLogCommandExecutions()) {
        ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
        service.addExecutionListener(new CommandExecutionMonitor());
    }
    super.preStartup();
}
项目:OpenSPIFe    文件:AbstractTimelineCommandHandler.java   
/**
 * Get the current command for this handler. The command instance can change
 * based on the command service, which changes based on the active workbench
 * window.
 * 
 * @return the current command for this handler.
 */
protected org.eclipse.core.commands.Command getCommand() {
    org.eclipse.core.commands.Command command = null;

    IWorkbench workbench = PlatformUI.getWorkbench();
    if(workbench != null) {
        IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
        if(activeWorkbenchWindow != null) {
            Object service = activeWorkbenchWindow.getService(ICommandService.class);

            if(service != null && service instanceof ICommandService) {
                ICommandService commandService = (ICommandService)service;
                command = commandService.getCommand(getCommandId());
            }
        }
    }

    return command;     
}
项目:Eclipse-Postfix-Code-Completion    文件:CorrectionCommandInstaller.java   
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<IHandlerActivation>();

    Collection<String> definedCommandIds= commandService.getDefinedCommandIds();
    for (Iterator<String> iter= definedCommandIds.iterator(); iter.hasNext();) {
        String id= iter.next();
        if (id.startsWith(ICommandAccess.COMMAND_ID_PREFIX)) {
            boolean isAssist= id.endsWith(ICommandAccess.ASSIST_SUFFIX);
            CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist);
            IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
            fCorrectionHandlerActivations.add(activation);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeAssistAdvancedConfigurationBlock.java   
private void createDefaultLabel(Composite composite, int h_span) {
   final ICommandService commandSvc= (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class);
final Command command= commandSvc.getCommand(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
ParameterizedCommand pCmd= new ParameterizedCommand(command, null);
String key= getKeyboardShortcut(pCmd);
if (key == null)
    key= PreferencesMessages.CodeAssistAdvancedConfigurationBlock_no_shortcut;

PixelConverter pixelConverter= new PixelConverter(composite);
int width= pixelConverter.convertWidthInCharsToPixels(40);

Label label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(Messages.format(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_page_description, new Object[] { key }));
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);

createFiller(composite, h_span);

label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_default_table_description);
gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);
  }
项目:mondo-collab-framework    文件:MACLIncQueryGenerator.java   
private boolean callRuleGenerationCommand(EPackage ePack, PatternInstance pattern, IPath iPath) {
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    ICommandService commandService = serviceLocator.getService(ICommandService.class);
    IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
    Command command = commandService.getCommand("org.mondo.collaboration.security.macl.tao.generation.rule");
    try {
        IParameter parameter = command.getParameter(MACLCommandContext.ID);
        String contextId = UUID.randomUUID().toString();
        Activator.put(contextId, context);
        Parameterization parameterization = new Parameterization(parameter, contextId);
        ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, new Parameterization[] { parameterization });
        return (Boolean) handlerService.executeCommand(parameterizedCommand, null);

    } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
        return false;
    }
}
项目:mondo-collab-framework    文件:MACLPatternImplementation.java   
@Override
public boolean execute(EPackage ePack, PatternInstance pattern, IPath iPath) {
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    ICommandService commandService = serviceLocator.getService(ICommandService.class);
    IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
    Command command = commandService.getCommand("org.mondo.collaboration.security.macl.tao.generation");
    try {
        IParameter parameter = command.getParameter(MACLCommandContext.ID);
        MACLCommandContext context = new MACLCommandContext(ePack, pattern, iPath);
        String contextId = UUID.randomUUID().toString();
        Activator.put(contextId, context);
        Parameterization parameterization = new Parameterization(parameter, contextId);
        ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, new Parameterization[] { parameterization });
        return (Boolean) handlerService.executeCommand(parameterizedCommand, null);

    } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
        return false;
    }
}
项目:translationstudio8    文件:CommandsPropertyTester.java   
public boolean test(final Object receiver, final String property,
        final Object[] args, final Object expectedValue) {
    if (receiver instanceof IServiceLocator && args.length == 1
            && args[0] instanceof String) {
        final IServiceLocator locator = (IServiceLocator) receiver;
        if (TOGGLE_PROPERTY_NAME.equals(property)) {
            final String commandId = args[0].toString();
            final ICommandService commandService = (ICommandService) locator
                    .getService(ICommandService.class);
            final Command command = commandService.getCommand(commandId);
            final State state = command
                    .getState(RegistryToggleState.STATE_ID);
            if (state != null) {
                return state.getValue().equals(expectedValue);
            }
        }
    }
    return false;
}
项目:WP3    文件:MarkerVisibilityHandler.java   
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
  this.decoratorManager = Activator.getDefault().getWorkbench().getDecoratorManager();

  if (!this.isHidden) {
    this.isHidden = true;
    this.setStore(false);
    this.setDecorator(false);
  } else {
    this.isHidden = false;
    this.setStore(true);
    this.setDecorator(true);
  }
  this.store.needsSaving();

  final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  final ICommandService commandService = window.getService(ICommandService.class);
  if (commandService != null) {
    commandService.refreshElements(COMMAND_ID, null);
  }
  return null;
}
项目:gef-gwt    文件:CommandAction.java   
/**
 * Build a command from the executable extension information.
 * 
 * @param commandService
 *            to get the Command object
 * @param commandId
 *            the command id for this action
 * @param parameterMap
 */
private void createCommand(ICommandService commandService,
        String commandId, Map parameterMap) {
    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;
    }

    parameterizedCommand = ParameterizedCommand.generateCommand(cmd,
            parameterMap);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CorrectionCommandInstaller.java   
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<IHandlerActivation>();

    Collection<String> definedCommandIds= commandService.getDefinedCommandIds();
    for (Iterator<String> iter= definedCommandIds.iterator(); iter.hasNext();) {
        String id= iter.next();
        if (id.startsWith(ICommandAccess.COMMAND_ID_PREFIX)) {
            boolean isAssist= id.endsWith(ICommandAccess.ASSIST_SUFFIX);
            CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist);
            IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
            fCorrectionHandlerActivations.add(activation);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeAssistAdvancedConfigurationBlock.java   
private void createDefaultLabel(Composite composite, int h_span) {
   final ICommandService commandSvc= (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class);
final Command command= commandSvc.getCommand(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
ParameterizedCommand pCmd= new ParameterizedCommand(command, null);
String key= getKeyboardShortcut(pCmd);
if (key == null)
    key= PreferencesMessages.CodeAssistAdvancedConfigurationBlock_no_shortcut;

PixelConverter pixelConverter= new PixelConverter(composite);
int width= pixelConverter.convertWidthInCharsToPixels(40);

Label label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(Messages.format(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_page_description, new Object[] { key }));
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);

createFiller(composite, h_span);

label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_default_table_description);
gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);
  }
项目:show-shortcuts    文件:Activator.java   
@Override
public void start(final BundleContext context) throws Exception {
    super.start(context);
    plugin = this;

    // need to do this later if all debug options are initialized properly
    Job job = new Job("Registering trace listener") { //$NON-NLS-1$
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            Dictionary<String, String> props = new Hashtable<String, String>(1, 1);
            props.put(DebugOptions.LISTENER_SYMBOLICNAME, PLUGIN_ID);
            context.registerService(DebugOptionsListener.class.getName(), Activator.this, props);
            return Status.OK_STATUS;
        }
    };
    job.setSystem(true);
    job.schedule();

    getPreferenceStore().addPropertyChangeListener(plugin);

    if (isEnabled()) {
        ICommandService cmdService = (ICommandService) getWorkbench().getService(ICommandService.class);
        cmdService.addExecutionListener(plugin);
    }
}
项目:show-shortcuts    文件:Activator.java   
@Override
public void stop(BundleContext context) throws Exception {
    getPreferenceStore().removePropertyChangeListener(plugin);

    ICommandService cmdService = (ICommandService) getWorkbench().getService(ICommandService.class);
    if (cmdService != null) {
        cmdService.removeExecutionListener(plugin);
    }

    closePopup();

    debugTrace = null;
    debug = false;
    plugin = null;

    super.stop(context);
}
项目:tmxeditor8    文件:CommandsPropertyTester.java   
public boolean test(final Object receiver, final String property,
        final Object[] args, final Object expectedValue) {
    if (receiver instanceof IServiceLocator && args.length == 1
            && args[0] instanceof String) {
        final IServiceLocator locator = (IServiceLocator) receiver;
        if (TOGGLE_PROPERTY_NAME.equals(property)) {
            final String commandId = args[0].toString();
            final ICommandService commandService = (ICommandService) locator
                    .getService(ICommandService.class);
            final Command command = commandService.getCommand(commandId);
            final State state = command
                    .getState(RegistryToggleState.STATE_ID);
            if (state != null) {
                return state.getValue().equals(expectedValue);
            }
        }
    }
    return false;
}
项目:e4macs    文件:MarkUtils.java   
private static void removeExecutionListeners(ITextEditor editor) {
    ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
    if (ics != null) {
        if (execExecListener != null) {
            ics.removeExecutionListener(execExecListener);
        }
        if (copyCmdExecListener != null) {
            Command com = ics.getCommand(EMP_COPY);
            if (com != null) {
                com.removeExecutionListener(copyCmdExecListener);
            }
        }
    }
    copyCmdExecListener = null;
    execExecListener = null;
}
项目:e4macs    文件:RepeatHandler.java   
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) throws BadLocationException {
    RepeatCommandSupport repeat = RepeatCommandSupport.getInstance();
    String id = repeat.getId();

    try {
        Integer count = repeat.getCount();
        Command c = ((ICommandService)editor.getSite().getService(ICommandService.class)).getCommand(id);
        showMessage(editor, (count != 1) ? String.format(UREPEAT, count, c.getName()) : String.format(REPEAT, c.getName()), false);
    } catch (NotDefinedException e) {
        // won't happen
    }       
    Object result = NO_OFFSET;
    result = repeatLast(editor, id, repeat.getParams());
    return (result instanceof Integer ? (Integer)result : NO_OFFSET);
}
项目:e4macs    文件:KbdMacroLoadHandler.java   
/**
 * Verify statically that this macro will execute properly
 * - Ensure the current Eclipse defines the commands used by the macro 
 * 
 * @param editor
 * @param kbdMacro
 * @return true if validates, else false
 */
private String checkMacro(ITextEditor editor, KbdMacro kbdMacro) {
    String result = null;
    ICommandService ics = (editor != null ) ? (ICommandService) editor.getSite().getService(ICommandService.class) : 
        (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);      
    @SuppressWarnings("unchecked")  // Eclipse documents the type 
    Collection<String> cmdIds = (Collection<String>)ics.getDefinedCommandIds();
    for (KbdEvent e : kbdMacro.getKbdMacro()) {
        String cmdId;
        if ((cmdId = e.getCmd()) != null) {
            if (!cmdIds.contains(cmdId)) {
                result = cmdId;
                break;
            }
        }
    }
    return result;
}
项目:e4macs    文件:KbdMacroDefineHandler.java   
/**
 * Define the Command to be used when executing the named kbd macro
 * 
 * @param editor
 * @param id - the full command id
 * @param name - the short name
 * @param category - the category to use in the definition
 * @return the Command
 */
Command defineKbdMacro(ITextEditor editor, String id, String name, String category) {
    Command command = null;
    if (id != null) {
        // Now create the executable command 
        ICommandService ics = (editor != null ) ? (ICommandService) editor.getSite().getService(ICommandService.class) : 
            (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);      
        command = ics.getCommand(id);
        IParameter[] parameters = null;
        try {
            // kludge: Eclipse has no way to dynamically define a parameter, so grab it from a known command
            IParameter p = ics.getCommand(PARAMETER_CMD).getParameter(PARAMETER);
            parameters = new IParameter[] { p };
        } catch (Exception e) { 
        }
        command.define(name, String.format(KBD_DESCRIPTION,name), ics.getCategory(category), parameters);
        command.setHandler(new KbdMacroNameExecuteHandler(name));
    }
    return command;
}
项目:e4macs    文件:EmacsPlusCmdHandler.java   
/**
 * Execute the command id (with universal-argument, if appropriate)
 * 
 * @param id
 * @param event
 * @return execution result
 */
private Object dispatchId(ITextEditor editor, String id, Map<String,Object> params) {
    Object result = null;
    if (id != null) {
        ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
        if (ics != null) {
            Command command = ics.getCommand(id);
            if (command != null) {
                try {
                    result = executeCommand(id, (Map<String,?>)params, null, getThisEditor());
                } catch (CommandException e) {}
            }
        }
    }
    return result;
}
项目:e4macs    文件:EmacsPlusUtils.java   
private static Object executeCommand(String commandId, Map<String,?> parameters, Event event, ICommandService ics, IHandlerService ihs)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
    Object result = null;
    if (ics != null && ihs != null) {
        Command command = ics.getCommand(commandId);
        if (command != null) {
            try {
                MarkUtils.setIgnoreDispatchId(true);
                ParameterizedCommand pcommand = ParameterizedCommand.generateCommand(command, parameters);
                if (pcommand != null) {
                    result = ihs.executeCommand(pcommand, event);
                }
            } finally {
                MarkUtils.setIgnoreDispatchId(false);
            }       
        }
    }
    return result;
}
项目:e4macs    文件:KbdMacroSupport.java   
/**
 * Start the definition of a keyboard macro
 * 
 * @param editor
 * @param append - if true, append to the current definition
 */
public void startKbdMacro(ITextEditor editor, boolean append) {

    if (!isExecuting()) {
        setEditor(editor);
        isdefining = true;
        ics = (ICommandService) editor.getSite().getService(ICommandService.class);
        // listen for command executions
        ics.addExecutionListener(this);
        addDocumentListener(editor);
        if (!append || kbdMacro == null) {
            kbdMacro = new KbdMacro();
        }
        setViewer(findSourceViewer(editor));
        if (viewer instanceof ITextViewerExtension) {
            ((ITextViewerExtension) viewer).prependVerifyKeyListener(whileDefining);
        } else {
            viewer = null;
        }
        // add a listener for ^G
        Beeper.addBeepListener(KbdMacroBeeper.beeper);
        currentCommand = null;
    }
}