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

项目:neoscada    文件:ConfigurationHelper.java   
private static AlarmNotifierConfiguration convertAlarmNotifier ( final IConfigurationElement ele )
{
    try
    {
        final String connectionId = ele.getAttribute ( "connectionId" ); //$NON-NLS-1$
        final String prefix = ele.getAttribute ( "prefix" ) == null ? "ae.server.info" : ele.getAttribute ( "prefix" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ $NON-NLS-2$
        final URL soundFile = Platform.getBundle ( ele.getContributor ().getName () ).getEntry ( ele.getAttribute ( "soundFile" ) ); //$NON-NLS-1$
        final ParameterizedCommand ackAlarmsAvailableCommand = convertCommand ( ele.getChildren ( "ackAlarmsAvailableCommand" )[0] ); //$NON-NLS-1$
        final ParameterizedCommand alarmsAvailableCommand = convertCommand ( ele.getChildren ( "alarmsAvailableCommand" )[0] ); //$NON-NLS-1$
        return new AlarmNotifierConfiguration ( connectionId, prefix, soundFile, ackAlarmsAvailableCommand, alarmsAvailableCommand );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to convert alarm notifier configuration: {}", ele ); //$NON-NLS-1$
        return null;
    }
}
项目:termsuite-ui    文件:ProgressAnimationItem.java   
/**
 * @param ji
 * @param job
 * @return <code>true</code> if Action or Command is executed
 */
private boolean 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);
        return true;
    }

    prop = job.getProperty(IProgressConstants.COMMAND_PROPERTY);
    if (prop instanceof ParameterizedCommand) {
        ParameterizedCommand command = (ParameterizedCommand) prop;
        getEHandlerService().executeHandler(command);
        removeTopElement(ji);
        return true;
    }
    return false;
}
项目:termsuite-ui    文件:ProgressInfoItem.java   
public void executeTrigger() {

        Object data = link.getData(TRIGGER_KEY);
        if (data instanceof IAction) {
            IAction action = (IAction) data;
            if (action.isEnabled())
                action.run();
            updateTrigger(action, link);
        } else if (data instanceof ParameterizedCommand) {
            getEHandlerService().executeHandler((ParameterizedCommand) data);
        }

        if (link.isDisposed()) {
            return;
        }

        Object text = link.getData(TEXT_KEY);
        if (text == null)
            return;

        // Refresh the text as enablement might have changed
        updateText((String) text, link);
    }
项目: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;
}
项目:termsuite-ui    文件:RunPipelineHandler.java   
@Execute
public void execute(ParameterizedCommand command, 
        @Optional @Named(IServiceConstants.ACTIVE_SELECTION) EPipeline selectedPipeline,
        @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        NLPService extractorService,
        ResourceService resourceService) {
    Map<String, Object> parameterMap = command.getParameterMap();
    boolean useCache = parameterMap.containsKey(TermSuiteUI.COMMAND_RUN_PIPELINE_PARAMETER_USE_CACHE)
            && Boolean.parseBoolean((String) parameterMap.get(TermSuiteUI.COMMAND_RUN_PIPELINE_PARAMETER_USE_CACHE));
    if(!parameterMap.containsKey(TermSuiteUI.COMMAND_RUN_PIPELINE_PARAMETER_PIPELINE_ID)
            && selectedPipeline != null) {
        // run handler from selected pipeline
        runPipeline(shell, extractorService, resourceService, selectedPipeline, useCache);
    } else {
        // run handler from parameterized command
        String pipelineName = parameterMap.get(TermSuiteUI.COMMAND_RUN_PIPELINE_PARAMETER_PIPELINE_ID).toString();
        java.util.Optional<EPipeline> pipeline = resourceService.getPipeline(pipelineName);
        if(pipeline.isPresent()) 
            runPipeline(shell, extractorService, resourceService, pipeline.get(), useCache);
    }
}
项目:termsuite-ui    文件:RunPipelineHandler.java   
@CanExecute
public boolean canExecute(
        @Optional ParameterizedCommand command, 
        @Optional @Named(IServiceConstants.ACTIVE_SELECTION) EPipeline selectedPipeline,
        ResourceService resourceService,
        NLPService extractorService) {
    if(command == null || command.getParameterMap().isEmpty()) {
        // try to run handler from selected EPipeline
        if(selectedPipeline != null)
            return extractorService.isPipelineValid(selectedPipeline);
        else 
            return false;
    } else {
        // try to run handler from parameterized command
        Map<String, Object> parameterMap = command.getParameterMap();
        Object pipelineName = parameterMap.get(TermSuiteUI.COMMAND_RUN_PIPELINE_PARAMETER_PIPELINE_ID);
        return pipelineName != null
                    && resourceService.getPipeline(pipelineName.toString()).isPresent()
                    && extractorService.isPipelineValid(resourceService.getPipeline(pipelineName.toString()).get())
                    ;
    }
}
项目: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;
  }
项目:bts    文件:PerspectiveSwitcherSwtTrim.java   
private void addSaveAsMenuItem(Menu menu) {
    final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
    menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_SAVE_AS$_NAME);

    // TODO: Integrate into help system

    menuItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            ParameterizedCommand command = commandService.createCommand(
                    E4WorkbenchCommandConstants.PERSPECTIVES_SAVE_AS,
                    Collections.EMPTY_MAP);
            handlerService.executeHandler(command);
        }
    });
}
项目:bts    文件:PerspectiveSwitcherSwtTrim.java   
private void addResetMenuItem(Menu menu) {
    final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
    menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_RESET$_NAME);

    // TODO: Integrate into help system

    menuItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            ParameterizedCommand command = commandService.createCommand(
                    E4WorkbenchCommandConstants.PERSPECTIVES_RESET,
                    Collections.EMPTY_MAP);
            handlerService.executeHandler(command);
        }
    });
}
项目:bts    文件:PerspectiveSwitcherSwtTrim.java   
private void addCloseMenuItem(Menu menu) {
    final MenuItem menuItem = new MenuItem(menu, SWT.Activate);
    menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_CLOSE$_NAME);

    // TODO: Integrate into help system

    menuItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            ParameterizedCommand command = commandService.createCommand(
                    E4WorkbenchCommandConstants.PERSPECTIVES_CLOSE,
                    Collections.EMPTY_MAP);
            handlerService.executeHandler(command);
        }
    });
}
项目:bts    文件:PerspectiveSwitcherSwtTrim.java   
private void addShowTextMenuItem(Menu menu) {
    final MenuItem menuItem = new MenuItem(menu, SWT.Activate | SWT.CHECK);
    menuItem.setText(E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_TEXT$_NAME);
    menuItem.setSelection(showShortcutText);

    // TODO: Integrate into help system

    menuItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            Map<String, Object> parameters = new HashMap<String, Object>(3);
            ParameterizedCommand command = commandService.createCommand(
                    E4WorkbenchCommandConstants.PERSPECTIVES_SHOW_TEXT,
                    parameters);
            handlerService.executeHandler(command);
        }
    });
}
项目: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;
}
项目: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);
  }
项目:Eclipse-Postfix-Code-Completion    文件:CodeAssistAdvancedConfigurationBlock.java   
private static String getKeyboardShortcut(ParameterizedCommand command) {
    IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    fgLocalBindingManager.setBindings(bindingService.getBindings());
    try {
        Scheme activeScheme= bindingService.getActiveScheme();
        if (activeScheme != null)
            fgLocalBindingManager.setActiveScheme(activeScheme);
    } catch (NotDefinedException e) {
        JavaPlugin.log(e);
    }

    TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
    if (bindings.length > 0)
        return bindings[0].format();
    return null;
}
项目: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    文件:KeyAssistHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service = (BindingService) bindingService;
    ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
    List<String> lstRemove = Constants.lstRemove;
    Iterator<Binding> it = lstBinding.iterator();
    while (it.hasNext()) {
        Binding binding = it.next();
        ParameterizedCommand pCommand = binding.getParameterizedCommand();
        if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
            it.remove();
        }
    }
    service.getKeyboard().openKeyAssistShell(lstBinding);
    return null;
}
项目:translationstudio8    文件:KeyController2.java   
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
    // Fix the scheme in the local changes.
    final String defaultSchemeId = bindingService.getDefaultSchemeId();
    final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
    try {
        fBindingManager.setActiveScheme(defaultScheme);
    } catch (final NotDefinedException e) {
        // At least we tried....
    }

    // Restore any User defined bindings
    Binding[] bindings = fBindingManager.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
        String commandId = null;
        if (pCommand != null) {
            commandId = pCommand.getCommand().getId();
        }
        if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
            fBindingManager.removeBinding(bindings[i]);
        }
    }
    bindingModel.refresh(contextModel, lstRemove);
    saveBindings(bindingService);
}
项目:gef-gwt    文件:BindingManager.java   
/**
 * A variation on {@link BindingManager#getActiveBindingsFor(String)} that
 * returns an array of bindings, rather than trigger sequences. This method
 * is needed for doing "best" calculations on the active bindings.
 * 
 * @param commandId
 *            The identifier of the command for which the active bindings
 *            should be retrieved; must not be <code>null</code>.
 * @return The active bindings for the given command; this value may be
 *         <code>null</code> if there are no active bindings.
 * @since 3.2
 */
private final Binding[] getActiveBindingsFor1(
        final ParameterizedCommand command) {
    final TriggerSequence[] triggers = getActiveBindingsFor(command);
    if (triggers.length == 0) {
        return null;
    }

    final Map activeBindings = getActiveBindings();
    if (activeBindings != null) {
        final Binding[] bindings = new Binding[triggers.length];
        for (int i = 0; i < triggers.length; i++) {
            final TriggerSequence triggerSequence = triggers[i];
            final Object object = activeBindings.get(triggerSequence);
            final Binding binding = (Binding) object;
            bindings[i] = binding;
        }
        return bindings;
    }

    return null;
}
项目:gef-gwt    文件:BindingManagerEvent.java   
/**
 * Computes whether the active bindings have changed for a given command
 * identifier.
 * 
 * @param parameterizedCommand
 *            The fully-parameterized command whose bindings might have
 *            changed; must not be <code>null</code>.
 * @return <code>true</code> if the active bindings have changed for the
 *         given command identifier; <code>false</code> otherwise.
 */
public final boolean isActiveBindingsChangedFor(
        final ParameterizedCommand parameterizedCommand) {
    final TriggerSequence[] currentBindings = manager
            .getActiveBindingsFor(parameterizedCommand);
    final TriggerSequence[] previousBindings;
    if (previousTriggersByParameterizedCommand != null) {
        final Collection previousBindingCollection = (Collection) previousTriggersByParameterizedCommand
                .get(parameterizedCommand);
        if (previousBindingCollection == null) {
            previousBindings = null;
        } else {
            previousBindings = (TriggerSequence[]) previousBindingCollection
                    .toArray(new TriggerSequence[previousBindingCollection
                            .size()]);
        }
    } else {
        previousBindings = null;
    }

    return !Util.equals(currentBindings, previousBindings);
}
项目: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);
  }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeAssistAdvancedConfigurationBlock.java   
private static String getKeyboardShortcut(ParameterizedCommand command) {
    IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    fgLocalBindingManager.setBindings(bindingService.getBindings());
    try {
        Scheme activeScheme= bindingService.getActiveScheme();
        if (activeScheme != null)
            fgLocalBindingManager.setActiveScheme(activeScheme);
    } catch (NotDefinedException e) {
        JavaPlugin.log(e);
    }

    TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
    if (bindings.length > 0)
        return bindings[0].format();
    return null;
}
项目: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;
}
项目:eclipsensis    文件:NSISInformationControlCreator.java   
public NSISInformationControlCreator(String[] commandIds, int style)
{
    super(style);
    List<ParameterizedCommand> list = new ArrayList<ParameterizedCommand>();
    if (!Common.isEmptyArray(commandIds))
    {
        for (int i = 0; i < commandIds.length; i++)
        {
            ParameterizedCommand command = NSISInformationUtility.getCommand(commandIds[i]);
            if (command != null)
            {
                if (!list.contains(command))
                {
                    list.add(command);
                }
            }
        }
    }
    mCommands = list.toArray(new ParameterizedCommand[list.size()]);
}
项目:tmxeditor8    文件:KeyController2.java   
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
    // Fix the scheme in the local changes.
    final String defaultSchemeId = bindingService.getDefaultSchemeId();
    final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
    try {
        fBindingManager.setActiveScheme(defaultScheme);
    } catch (final NotDefinedException e) {
        // At least we tried....
    }

    // Restore any User defined bindings
    Binding[] bindings = fBindingManager.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
        String commandId = null;
        if (pCommand != null) {
            commandId = pCommand.getCommand().getId();
        }
        if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
            fBindingManager.removeBinding(bindings[i]);
        }
    }
    bindingModel.refresh(contextModel, lstRemove);
    saveBindings(bindingService);
}
项目:tmxeditor8    文件:KeyAssistHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service = (BindingService) bindingService;
    ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
    List<String> lstRemove = Constants.lstRemove;
    Iterator<Binding> it = lstBinding.iterator();
    while (it.hasNext()) {
        Binding binding = it.next();
        ParameterizedCommand pCommand = binding.getParameterizedCommand();
        if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
            it.remove();
        }
    }
    service.getKeyboard().openKeyAssistShell(lstBinding);
    return null;
}
项目:tmxeditor8    文件:KeyController2.java   
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
    // Fix the scheme in the local changes.
    final String defaultSchemeId = bindingService.getDefaultSchemeId();
    final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
    try {
        fBindingManager.setActiveScheme(defaultScheme);
    } catch (final NotDefinedException e) {
        // At least we tried....
    }

    // Restore any User defined bindings
    Binding[] bindings = fBindingManager.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
        String commandId = null;
        if (pCommand != null) {
            commandId = pCommand.getCommand().getId();
        }
        if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
            fBindingManager.removeBinding(bindings[i]);
        }
    }
    bindingModel.refresh(contextModel, lstRemove);
    saveBindings(bindingService);
}
项目: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   
/**
 * Print the details about a parameterized command on the Emacs+ console
 * 
 * @param cmd
 * @param console
 */
void printCmdDetails(ParameterizedCommand cmd, EmacsPlusConsole console) {
    String[] bindings = CommandHelp.getKeyBindingStrings(cmd, false);
    String[] abindings = CommandHelp.getKeyBindingStrings(cmd, true);

    console.print(SWT.TAB + DESC_ID);
    console.printContext(cmd.getId() + CR);

    @SuppressWarnings("unchecked")
    Map<String,?> parameterMap = cmd.getParameterMap();
    if (!parameterMap.isEmpty()) {
        console.printBold(' ' + CMD_PARAM_HEADING + CR);
        try {
            Set<String> keySet = parameterMap.keySet();
            for (String key : keySet) {
                console.print(SWT.TAB + key + '=' + parameterMap.get(key) + CR);
            }
        } catch (Exception e) {}
    }

    console.printBold(' ' + CMD_KEY_HEADING + CR);
    printDetails(cmd.getCommand(), bindings, abindings, console);
}
项目: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    文件: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]);
}
项目:e4macs    文件:CommandHelp.java   
/**
 * Get the displayable key-binding information for the parameterized 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(ParameterizedCommand com, boolean activep) {
    TriggerSequence trigger;
    // Get platform bindings for the ParameterizedCommand's Command 
    Binding[] bindings = getBindings(com.getCommand(),activep);

    List<String> bindingInfo = new ArrayList<String>();
    ParameterizedCommand c;
    for (Binding bind : bindings) {
        c = bind.getParameterizedCommand();
        if (c != null && c.equals(com)) {
            trigger = bind.getTriggerSequence();
            bindingInfo.add(trigger.toString());
            bindingInfo.add(bind.getContextId());
        }
    }
    return bindingInfo.toArray(new String[0]);
}
项目: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();
    }
}
项目:relations    文件:KeyControllerTest.java   
@Test
public void testUpdateTrigger() throws ParseException {
    final BindingElement bindingEl = new BindingElement(keyController);
    final KeySequence oldKeys = KeySequence.getInstance(KeyStroke.getInstance("M1+A"));
    final KeySequence newKeys = KeySequence.getInstance(KeyStroke.getInstance("M1+B"));
    final Command command = commandManager.getCommand("aa");
    final ParameterizedCommand parametrized = new ParameterizedCommand(command, null);
    final KeyBinding model = new KeyBinding(oldKeys, parametrized, SCHEME_ID, "default", null, null, null, 0);
    bindingEl.setModelObject(model);
    keyController.init();
    keyController.setNotifying(false);
    final BindingModel bindingModel = keyController.getBindingModel();
    final SchemeElement scheme = new SchemeElement(keyController);
    scheme.setId("myScheme");
    keyController.getSchemeModel().setSelectedElement(scheme);
    assertTrue(bindingModel.getBindingToElement().isEmpty());
    keyController.updateTrigger(bindingEl, oldKeys, newKeys);
    final Map<Binding, BindingElement> map = bindingModel.getBindingToElement();
    assertEquals(1, map.size());
    final Binding binding = map.keySet().iterator().next();
    final BindingElement updatedEl = map.get(binding);
    assertEquals(bindingEl, updatedEl);
    assertEquals(newKeys, updatedEl.getTrigger());
}
项目:relations    文件:BindingElementTest.java   
@Test
public void testInit1() throws Exception {
    final BindingElement binding = new BindingElement(controller);
    command = commandManager.getCommand("aa");
    final ParameterizedCommand parametrized1 = new ParameterizedCommand(command, null);
    binding.init(parametrized1);
    assertEquals("aa", binding.getId());
    assertEquals("Undefined Command", binding.getName());
    assertEquals("", binding.getDescription());
    assertEquals("Unavailable Category", binding.getCategory());
    verify(controller).firePropertyChange(binding, BindingElement.PROP_MODEL_OBJECT, null, parametrized1);

    command.define("cmd name", "Command for testing purpose", commandManager.getCategory("test_catgory"));
    final ParameterizedCommand parametrized2 = new ParameterizedCommand(command, null);
    binding.init(parametrized2);
    assertEquals("aa", binding.getId());
    assertEquals("cmd name", binding.getName());
    assertEquals("Command for testing purpose", binding.getDescription());
    verify(controller).firePropertyChange(binding, BindingElement.PROP_MODEL_OBJECT, parametrized1, parametrized2);
}