Search in sources :

Example 26 with Command

use of org.eclipse.core.commands.Command in project linuxtools by eclipse.

the class PerfStatsQuickDiffHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // get default files
    PerfPlugin plugin = PerfPlugin.getDefault();
    IPath curStatData = plugin.getPerfFile(PerfPlugin.PERF_DEFAULT_STAT);
    IPath prevStatData = plugin.getPerfFile(PerfPlugin.PERF_DEAFULT_OLD_STAT);
    IResource curStatFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(curStatData);
    IResource prevStatFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(prevStatData);
    // Inject our own selections into the context
    IEvaluationContext ctx = (IEvaluationContext) event.getApplicationContext();
    ctx.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, new StructuredSelection(new IResource[] { prevStatFile, curStatFile }));
    ICommandService cmdService = PlatformUI.getWorkbench().getService(ICommandService.class);
    // $NON-NLS-1$
    Command cmd = cmdService.getCommand("org.eclipse.linuxtools.perf.CompareAction");
    try {
        cmd.executeWithChecks(event);
    } catch (Exception e) {
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Command(org.eclipse.core.commands.Command) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PerfPlugin(org.eclipse.linuxtools.internal.perf.PerfPlugin) IResource(org.eclipse.core.resources.IResource) ICommandService(org.eclipse.ui.commands.ICommandService) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException)

Example 27 with Command

use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.

the class SwitchProcessorCompoundContributionItem method updateSelection.

private void updateSelection() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    Command command = commandService.getCommand(SWITCH_PROCESSOR_COMMAND);
    try {
        ProcessorInfo currentProcessor = ManagementCatalogue.getInstance().getCurrentProcessorInfo();
        HandlerUtil.updateRadioState(command, currentProcessor.getName());
    } catch (ExecutionException e) {
        log.log(Level.SEVERE, "Could not update radio state", e);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ProcessorInfo(org.yamcs.protobuf.YamcsManagement.ProcessorInfo) Command(org.eclipse.core.commands.Command) ExecutionException(org.eclipse.core.commands.ExecutionException) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 28 with Command

use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.

the class SwitchProcessorHandler method updateElement.

/*
     * Workaround to allow checking radio items in a dynamic contribution
     *
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398647
     */
@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
    ICommandService service = (ICommandService) element.getServiceLocator().getService(ICommandService.class);
    String state = (String) parameters.get(RadioState.PARAMETER_ID);
    Command command = service.getCommand(SwitchProcessorCompoundContributionItem.SWITCH_PROCESSOR_COMMAND);
    State commandState = command.getState(RadioState.STATE_ID);
    if (commandState.getValue().equals(state)) {
        element.setChecked(true);
    }
}
Also used : Command(org.eclipse.core.commands.Command) RadioState(org.eclipse.ui.handlers.RadioState) State(org.eclipse.core.commands.State) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 29 with Command

use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.

the class RCPUtils method runCommand.

public static void runCommand(String commandId) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ICommandService commandService = (ICommandService) window.getService(ICommandService.class);
    IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
    try {
        Command cmd = commandService.getCommand(commandId);
        cmd.executeWithChecks(new ExecutionEvent(cmd, new HashMap<String, String>(), null, evaluationService.getCurrentState()));
    } catch (Exception exception) {
        log.log(Level.SEVERE, "Could not execute command " + commandId, exception);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Command(org.eclipse.core.commands.Command) HashMap(java.util.HashMap) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ICommandService(org.eclipse.ui.commands.ICommandService) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 30 with Command

use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.

the class EventLog method updateState.

private void updateState() {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = service.getCommand(EventLog.CMD_SCROLL_LOCK);
    State state = command.getState(EventLog.STATE_SCROLL_LOCK);
    enableScrollLock((Boolean) state.getValue());
}
Also used : Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) ICommandService(org.eclipse.ui.commands.ICommandService)

Aggregations

Command (org.eclipse.core.commands.Command)31 ICommandService (org.eclipse.ui.commands.ICommandService)24 IHandlerService (org.eclipse.ui.handlers.IHandlerService)8 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)7 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)7 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)7 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 State (org.eclipse.core.commands.State)5 HashMap (java.util.HashMap)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)4 IEvaluationService (org.eclipse.ui.services.IEvaluationService)4 NotEnabledException (org.eclipse.core.commands.NotEnabledException)3 NotHandledException (org.eclipse.core.commands.NotHandledException)3 Test (org.junit.Test)3 Binding (org.eclipse.jface.bindings.Binding)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IWorkbench (org.eclipse.ui.IWorkbench)2 RegistryToggleState (org.eclipse.ui.handlers.RegistryToggleState)2