Java 类org.eclipse.core.commands.Command 实例源码

项目: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();

}
项目:eclipse-plugin-commander    文件:CommandElement.java   
@Override
public String getLabel() {
    final StringBuilder label = new StringBuilder();

    try {
        Command command = parameterizedCommand.getCommand();
        label.append(parameterizedCommand.getName());
        if (command.getDescription() != null && command.getDescription().length() != 0) {
            label.append(separator).append(command.getDescription());
        }
    } catch (NotDefinedException e) {
        label.append(parameterizedCommand.getId());
    }

    return label.toString();
}
项目:termsuite-ui    文件:WorskpaceSizeControl.java   
@PostConstruct
public Control createContents(Composite parent, NLPService nlpService, ECommandService commandService, EHandlerService handlerService) {
    l = new Label(parent, SWT.None);
    int size = 0;
    updateSize(nlpService);
    Button b = new Button(parent, SWT.PUSH);
    b.setImage(TermSuiteUI.getImg(TermSuiteUI.IMG_CLEAR_CO).createImage());
    b.setSize(50, -1);
    b.setToolTipText("Clear all preprocessed corpus save in cache");
    b.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Command command = commandService.getCommand(TermSuiteUI.COMMAND_CLEAR_CACHE_ID);
            ParameterizedCommand pCmd = new ParameterizedCommand(command, null);
            if (handlerService.canExecute(pCmd)) 
                handlerService.executeHandler(pCmd);
        }
    });
    return parent;
}
项目: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;
}
项目:depan    文件:StatsShapeOptionHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.SHAPE_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
项目:depan    文件:StatsRootOptionHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.COLOR_ROOT_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
项目:depan    文件:StatsRatioOptionHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.RATIO_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
项目:depan    文件:StatsSizeOptionHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.SIZE_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
项目: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);
        }
    }
}
项目: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    文件:PinHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Command command = event.getCommand();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Set<? extends EPlanElement> elements = PlanEditorUtil.emfFromSelection(selection);
    final IUndoableOperation op;
    boolean state = getCommandState(command);
    if (state) {
        op = new UnpinOperation(elements);
    } else {
        op = new PinOperation(elements);
    }
    CommonUtils.execute(op, getUndoContext());
    setCommandState(command, !state);
    return null;
}
项目:OpenSPIFe    文件:ChainHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Command command = event.getCommand();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Set<EPlanElement> allElements = PlanEditorUtil.emfFromSelection(selection);
    List<EPlanElement> elements = EPlanUtils.getConsolidatedPlanElements(allElements);
    boolean state = getCommandState(command);
    IEditorPart editor = getActiveEditor();
    final IUndoableOperation op;
    if (state) {
        op = new UnchainOperation(elements);
    } else {
        PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
        List<EPlanChild> children = CommonUtils.castList(EPlanChild.class, elements);
        op = new ChainOperation(modifier, children, true);
    }
    WidgetUtils.execute(op, getUndoContext(), null, editor.getSite());
    setCommandState(command, !state);
    return null;
}
项目: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;
}
项目: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    文件: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);
  }
项目:Environment    文件:CommandExecutor.java   
public boolean execute(String id){
    Command command = commandService.getCommand(id);

    if(command == null){
        logger.warning("execute("+ id +"): Command with specified ID was not found!");
        return false;
    }

    ParameterizedCommand pc = new ParameterizedCommand(command, null);

    if(handlerService.canExecute(pc, CloudscaleContext.getActiveContext())){
        handlerService.executeHandler(pc, CloudscaleContext.getActiveContext());
        return true;
    }

    return false;
}
项目:Environment    文件:CommandExecutor.java   
public boolean execute(String id, IEclipseContext staticContext){
    Command command = commandService.getCommand(id);

    if(command == null){
        logger.warning("execute("+ id +"): Command with specified ID was not found!");
        return false;
    }

    ParameterizedCommand pc = new ParameterizedCommand(command, null);

    if(handlerService.canExecute(pc, staticContext)){
        handlerService.executeHandler(pc, staticContext);
        return true;
    }

    return false;
}
项目: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;
}
项目:birt    文件:CommandUtils.java   
public static Parameterization createParameter( Command command,
        String parameterId, Object value ) throws NotDefinedException,
        ExecutionException, ParameterValueConversionException
{
    ParameterType parameterType = command.getParameterType( parameterId );
    if ( parameterType == null )
    {
        throw new ExecutionException( "Command does not have a parameter type for the given parameter" ); //$NON-NLS-1$
    }

    IParameter param = command.getParameter( parameterId );
    AbstractParameterValueConverter valueConverter = parameterType.getValueConverter( );
    if ( valueConverter == null )
    {
        throw new ExecutionException( "Command does not have a value converter" ); //$NON-NLS-1$
    }

    String valueString = valueConverter.convertToString( value );
    Parameterization parm = new Parameterization( param, valueString );
    return parm;
}
项目:DynamicSpotter    文件:ExpertViewHandler.java   
/**
 * Retrieves the toggle state of the command.
 * 
 * @param expertViewCommand
 *            the command or <code>null</code> to manually try to lookup the
 *            command
 * 
 * @return the toggle state of the command
 */
private State getCommandState(Command expertViewCommand) {
    Command command = expertViewCommand;

    if (command == null && commandService != null) {
        command = commandService.getCommand(EXPERT_VIEW_COMMAND_ID);
    }

    if (command == null) {
        throw new RuntimeException("Unable to retrieve command " + EXPERT_VIEW_COMMAND_ID);
    }

    State state = command.getState(TOGGLE_STATE_ID);

    if (state == null) {
        throw new RuntimeException("Unable to retrieve state " + TOGGLE_STATE_ID + " from command "
                + EXPERT_VIEW_COMMAND_ID);
    }

    return state;
}
项目: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    文件:CommandAproposHandler.java   
private void printCommand(String name, Command command, EmacsPlusConsole console) {
    console.printBold(name + SWT.TAB);
    String bindingStrings = CommandHelp.getKeyBindingString(command, true);
    if (bindingStrings != null) {
        console.printContext(A_MSG + bindingStrings + Z_MSG);
    }
    try {
        String desc = command.getDescription();
        if (desc != null) {
            desc = desc.replaceAll(CR, CR + blanks + SWT.TAB);
            console.print(desc + CR);
        } else {
            console.print(CR);
        }
    } catch (NotDefinedException e) {
    }
}
项目:e4macs    文件:CommandBriefKeyHandler.java   
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean executeResult(ITextEditor editor, Object minibufferResult) {

    String summary = EMPTY_STR;
    if (minibufferResult != null) {

        IBindingResult bindingR = (IBindingResult) minibufferResult;
        String name = bindingR.getKeyString();
        if (bindingR == null || bindingR.getKeyBinding() == null) {
            summary = String.format(CMD_NO_RESULT, name) + CMD_NO_BINDING;
        } else {
            summary = String.format(CMD_KEY_RESULT,name); 
            Binding binding = bindingR.getKeyBinding();
            try {
                Command com = getCommand(binding);
                if (com != null) {
                    summary += normalizeCommandName(com.getName());
                }
            } catch (NotDefinedException e) {
                // can't happen as the Command will be null or valid
            }
        }
    }
    showResultMessage(editor, summary, false);
    return true;
}
项目: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   
/**
 * Bind the loaded macro to its previous key binding, removing any conflicts
 * 
 * @param editor
 * @param command - the new kbd macro command
 * @param sequence - key sequence for binding
 * @param previous - conflicting binding
 */
private void bindMacro(ITextEditor editor, Command command, KeySequence sequence, Binding previous) {
    if (command != null && sequence != null) {

        IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) :
            (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
        if (service instanceof  BindingService) {
            BindingService bindingMgr = (BindingService) service;
            if (previous != null) {
                bindingMgr.removeBinding(previous);
            }
            ParameterizedCommand p = new ParameterizedCommand(command, null);
            Binding binding = new KeyBinding(sequence, p,
                    KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER);
            bindingMgr.addBinding(binding);
            // check for conflicts independent of the current Eclipse context
            checkConflicts(bindingMgr,sequence,binding);
        }
    }               
}
项目:e4macs    文件:CommandDescribeHandler.java   
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(ITextEditor, java.lang.Object)
 */
public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {

    if (minibufferResult != null) {
        EmacsPlusConsole console = EmacsPlusConsole.getInstance();
        console.clear();
        console.activate();

        ICommandResult commandR = (ICommandResult) minibufferResult;
        String name = commandR.getName();
        Command cmd = commandR.getCommand();
        console.printBold(name + CR);
        printCmdDetails(cmd, console);
    }
    return true;
}
项目: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    文件:CommandSupport.java   
/**
 * Determine the longest common command name substring that starts with the current substring
 *  
 * @param subTree
 * @param subString
 * @return the longest common name
 */
public String getCommonString(SortedMap<String, Command> subTree, String subString) {
    String result = (isWildCarded(subString) ? "" : subString); //$NON-NLS-1$
    Set<String> keySet = subTree.keySet();
    Iterator<String> it = keySet.iterator();

    String key;
    String possible;

    key = it.next();
    do {
        if (key.length() > result.length()) {
            possible = key.substring(0, result.length()+1);
            while (it.hasNext()) {
                key = it.next();
                if (!key.startsWith(possible)) {
                    return result;
                }
            }
            result = possible;
            it = keySet.iterator();
            key = it.next();
        }
    } while (result.length() < key.length());
    return result;
}
项目:e4macs    文件:CommandHelp.java   
/**
 * Get the displayable key-binding information for the command
 * 
 * @param com - the command
 * @param activep - if true, return only active bindings
 * 
 * @return a String array of binding sequence binding context information
 */
public static String[] getKeyBindingStrings(Command com, boolean activep) {
    String id = com.getId();

    TriggerSequence trigger;
    // Get platform bindings for Command 
    Binding[] bindings = getBindings(com,activep);

    List<String> bindingInfo = new ArrayList<String>();
    ParameterizedCommand c;
    for (Binding bind : bindings) {
        c = bind.getParameterizedCommand();
        if (c != null && c.getId().equals(id)) {
            trigger = bind.getTriggerSequence();
            bindingInfo.add(trigger.toString());
            bindingInfo.add(bind.getContextId());
        }
    }
    return bindingInfo.toArray(new String[0]);
}
项目:egitblit    文件:CloneAction.java   
@Override
public void doRun(){
    GitBlitViewModel model = getSelectedModel();
    if(model instanceof ProjectViewModel){

      // Copy url to clipboard
        CopyAction cca = new CopyAction(getViewer());
        cca.setPrefModel(getPrefModel());
        cca.run();

        Command cmd = getEGitCommand();
        if(cmd == null){
            Activator.logError("Can't call EGit. Eclipse command service not avail or EGit not installed.");
            return;
        }
        try{
            cmd.executeWithChecks(new ExecutionEvent());
        }catch(Exception e){
            Activator.logError("Error pasting repository url to EGit", e);
        }
    }
}
项目:redmine.rap    文件:CommandUtils.java   
public static void executeCommand(String commandId, Map<String, Object> parameters) {
    // Locals
    ParameterizedCommand customizeCommand = null;
    Command command = null;

    try {
        // 
        command = ((ICommandService) PlatformUI.getWorkbench()
                                               .getService(ICommandService.class))
                                               .getCommand(commandId);
        // Generate customize command
        customizeCommand = ParameterizedCommand.generateCommand(command, parameters);

        // Execute the customize command
        ((IHandlerService) PlatformUI.getWorkbench()
                                     .getService(IHandlerService.class))
                                     .executeCommand(customizeCommand, null);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
项目:LinGUIne    文件:SelectCommandWizard.java   
@Override
public boolean performFinish() {
    String selectedOption = wizardPage.getSelectedOption();
    String commandId = commandOptions.get(selectedOption);
    Command selectedCommand = commandService.getCommand(commandId);

    try{
        selectedCommand.executeWithChecks(new ExecutionEvent());
    }
    catch(ExecutionException | NotDefinedException
            | NotEnabledException | NotHandledException e){
        MessageDialog.openError(getShell(), "Error", "The selected Command"
                + " could not be executed successfully.");

        return false;
    }

    return true;
}