Search in sources :

Example 31 with ICommandService

use of org.eclipse.ui.commands.ICommandService in project xtext-xtend by eclipse.

the class ShowHierarchyTest method invokeTestingHandler.

@SuppressWarnings("cast")
private TestingTypeHierarchyHandler invokeTestingHandler(XtextEditor xtextEditor, String commandID) throws Exception {
    IHandlerService handlerService = (IHandlerService) xtextEditor.getSite().getService(IHandlerService.class);
    final ICommandService commandService = (ICommandService) xtextEditor.getSite().getService(ICommandService.class);
    Command command = commandService.getCommand("org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchy");
    TestingTypeHierarchyHandler testingHandler = new TestingTypeHierarchyHandler();
    getInjector().injectMembers(testingHandler);
    IHandler originalHandler = command.getHandler();
    command.setHandler(testingHandler);
    final ExecutionEvent event = new ExecutionEvent(command, Collections.EMPTY_MAP, null, handlerService.getCurrentState());
    command.executeWithChecks(event);
    command.setHandler(originalHandler);
    return testingHandler;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IHandler(org.eclipse.core.commands.IHandler) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 32 with ICommandService

use of org.eclipse.ui.commands.ICommandService in project linuxtools by eclipse.

the class DockerContainersView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createForm(parent);
    form.setText(DVMessages.getString(NoConnectionSelected));
    final Composite container = form.getBody();
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
    createTableViewer(container);
    getSite().registerContextMenu(new MenuManager(), null);
    // track selection changes in the Docker Explorer view (only)
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(DockerExplorerView.VIEW_ID, this);
    hookContextMenu();
    hookToolBarItems();
    // Look at stored preference to determine if all containers should be
    // shown or just running/paused containers. By default, only show
    // running/paused containers
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    boolean showAll = preferences.getBoolean(SHOW_ALL_CONTAINERS_PREFERENCE, true);
    showAllContainers(showAll);
    final ICommandService service = getViewSite().getWorkbenchWindow().getService(ICommandService.class);
    service.getCommand(SHOW_ALL_CONTAINERS_COMMAND_ID).getState(TOGGLE_STATE).setValue(showAll);
    service.refreshElements(SHOW_ALL_CONTAINERS_COMMAND_ID, null);
    boolean filterByLabels = preferences.getBoolean(FILTER_WITH_LABELS_PREFERENCE, false);
    showContainersWithLabels(filterByLabels);
    service.getCommand(FILTER_CONTAINERS_COMMAND_ID).getState(TOGGLE_STATE).setValue(filterByLabels);
    service.refreshElements(FILTER_CONTAINERS_COMMAND_ID, null);
    DockerConnectionManager.getInstance().addConnectionManagerListener(this);
    // On startup, this view might get set up after the Docker Explorer View
    // and so we won't get the notification when it chooses the connection.
    // Find out if it has a selection and set our connection appropriately.
    ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection(DockerExplorerView.VIEW_ID);
    if (selection != null) {
        selectionChanged(null, selection);
        // also notify DockerConnectionWatcher
        DockerConnectionWatcher.getInstance().selectionChanged(null, selection);
    }
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) MenuManager(org.eclipse.jface.action.MenuManager) ISelection(org.eclipse.jface.viewers.ISelection) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 33 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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 34 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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 35 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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)

Aggregations

ICommandService (org.eclipse.ui.commands.ICommandService)38 Command (org.eclipse.core.commands.Command)24 IHandlerService (org.eclipse.ui.handlers.IHandlerService)8 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)7 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)6 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)6 ExecutionException (org.eclipse.core.commands.ExecutionException)4 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)4 IEvaluationService (org.eclipse.ui.services.IEvaluationService)4 HashMap (java.util.HashMap)3 NotEnabledException (org.eclipse.core.commands.NotEnabledException)3 NotHandledException (org.eclipse.core.commands.NotHandledException)3 State (org.eclipse.core.commands.State)3 ISelection (org.eclipse.jface.viewers.ISelection)3 StyledText (org.eclipse.swt.custom.StyledText)3 Composite (org.eclipse.swt.widgets.Composite)3 Test (org.junit.Test)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)2 IHandler (org.eclipse.core.commands.IHandler)2