Search in sources :

Example 21 with Command

use of org.eclipse.core.commands.Command in project gfm_viewer by satyagraha.

the class ViewerSupportDefault method isOnline.

@Override
public boolean isOnline() {
    LOGGER.fine("");
    Command command = commandService.getCommand(GFM_VIEWER_PLUGIN_ONLINE);
    State state = command.getState(RegistryToggleState.STATE_ID);
    return (Boolean) state.getValue();
}
Also used : Command(org.eclipse.core.commands.Command) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) State(org.eclipse.core.commands.State)

Example 22 with Command

use of org.eclipse.core.commands.Command in project azure-tools-for-java by Microsoft.

the class AzureAbstractHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Map<String, String> properties = new HashMap<>();
    try {
        final Command cmd = event.getCommand();
        String handlerName = this.getClass().getSimpleName();
        final Collection<?> callingMenus = HandlerUtil.getActiveMenus(event);
        boolean fromProjectMenu = callingMenus != null && callingMenus.contains("org.eclipse.ui.navigator.ProjectExplorer#PopupMenu");
        properties.put("FromProjectMenu", String.valueOf(fromProjectMenu));
        if (cmd != null) {
            properties.put("CategoryId", cmd.getCategory().getId());
            properties.put("Category", cmd.getCategory().getName());
            properties.put("CommandId", cmd.getId());
            properties.put("Text", cmd.getName());
            if (null == handlerName || handlerName.isEmpty()) {
                handlerName = cmd.getName();
            }
        }
        AppInsightsClient.createByType(AppInsightsClient.EventType.Action, handlerName, null, properties);
    } catch (NotDefinedException ignore) {
    }
    return onExecute(event);
}
Also used : HashMap(java.util.HashMap) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException)

Example 23 with Command

use of org.eclipse.core.commands.Command in project eclipse.platform.text by eclipse.

the class ShowInSystemExplorerHyperlink method open.

@Override
public void open() {
    ECommandService commandService = PlatformUI.getWorkbench().getService(ECommandService.class);
    EHandlerService handlerService = PlatformUI.getWorkbench().getService(EHandlerService.class);
    Command command = commandService.getCommand(ShowInSystemExplorerHandler.ID);
    if (command.isDefined()) {
        ParameterizedCommand parameterizedCommand = commandService.createCommand(ShowInSystemExplorerHandler.ID, Collections.singletonMap(ShowInSystemExplorerHandler.RESOURCE_PATH_PARAMETER, fileLocation));
        if (handlerService.canExecute(parameterizedCommand)) {
            handlerService.executeHandler(parameterizedCommand);
        }
    }
}
Also used : EHandlerService(org.eclipse.e4.core.commands.EHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService)

Example 24 with Command

use of org.eclipse.core.commands.Command in project eclipse.platform.text by eclipse.

the class ToggleHighlight method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Command command = event.getCommand();
    boolean oldValue = HandlerUtil.toggleCommandState(command);
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(GenericEditorPlugin.BUNDLE_ID);
    preferences.putBoolean(TOGGLE_HIGHLIGHT_PREFERENCE, !oldValue);
    return null;
}
Also used : Command(org.eclipse.core.commands.Command) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 25 with Command

use of org.eclipse.core.commands.Command 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)

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