public void registerCommands(CompilationUnitEditor editor) { IWorkbench workbench = PlatformUI.getWorkbench(); ICommandService commandService = (ICommandService) workbench.getAdapter(ICommandService.class); IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class); if (commandService == null || handlerService == null) { return; } if (fCorrectionHandlerActivations != null) { JavaPlugin.logErrorMessage("correction handler activations not released"); // $NON-NLS-1$ } fCorrectionHandlerActivations = new ArrayList(); Collection definedCommandIds = commandService.getDefinedCommandIds(); for (Iterator iter = definedCommandIds.iterator(); iter.hasNext(); ) { String id = (String) iter.next(); if (id.startsWith(COMMAND_PREFIX)) { boolean isAssist = id.endsWith(ASSIST_SUFFIX); CorrectionCommandHandler handler = new CorrectionCommandHandler(editor, id, isAssist); IHandlerActivation activation = handlerService.activateHandler( id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite())); fCorrectionHandlerActivations.add(activation); } } }
// the 'paste' key binding overrides the 'redo' key binding on Windows // platforms public void testPasteAndRedoBindingEmacs() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); final Scheme emacsScheme = bindingService.getScheme(EMACS_SCHEME_ID); assertNotNull(emacsScheme); final Scheme defaultScheme = bindingService.getScheme(IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID); assertNotNull(defaultScheme); final Binding[] originalBindings = bindingService.getBindings(); bindingService.savePreferences(emacsScheme, originalBindings); ParameterizedCommand pasteCmd = new ParameterizedCommand( commandService.getCommand(IWorkbenchCommandConstants.EDIT_PASTE), null); ParameterizedCommand redoCmd = new ParameterizedCommand( commandService.getCommand(IWorkbenchCommandConstants.EDIT_REDO), null); final KeySequence keyCtrlY = KeySequence.getInstance("CTRL+Y"); final Binding pasteBinding = bindingService.getPerfectMatch(keyCtrlY); assertNotNull(pasteBinding); assertEquals(pasteCmd, pasteBinding.getParameterizedCommand()); assertEquals(EMACS_SCHEME_ID, pasteBinding.getSchemeId()); // reset the scheme bindingService.savePreferences(defaultScheme, originalBindings); final Binding redoBinding = bindingService.getPerfectMatch(keyCtrlY); assertNotNull(redoBinding); assertEquals(redoCmd, redoBinding.getParameterizedCommand()); assertEquals(IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID, redoBinding.getSchemeId()); }
@Override public void execute(String newText) throws CoreException { if (newText.isEmpty()) { if (getModel().getText() != null) { EnquiryTranslationRemoveCommand removeCmd = new EnquiryTranslationRemoveCommand(getModel()); removeCmd.execute(newText); } return; } if (newText.equals(getModel().getText())) { // do nothing if text is the same. return; } IEditorPart editorPart = getActiveEditorPart(); if (editorPart != null) { // Extract useful parameters needed for the command IWorkbenchPartSite site = editorPart.getSite(); // Invoke the command IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); ICommandService commandService = (ICommandService) site.getService(ICommandService.class); CommandStack commandStack = (CommandStack) editorPart.getAdapter(CommandStack.class); try { // Get the command and assign values to parameters Command command = commandService.getCommand(EDIT_COMMAND_ID); Parameterization parameter = new Parameterization(command.getParameter("text"), newText); ParameterizedCommand parmCommand = new ParameterizedCommand(command, new Parameterization[] {parameter}); // Prepare the evaluation context IEvaluationContext ctx = handlerService.getCurrentState(); ctx.addVariable("model", getModel()); ctx.addVariable("commandStack", commandStack); // Execute the command handlerService.executeCommandInContext(parmCommand, null, ctx); } catch (Exception ex) { IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, "Error while executing command to update translation", ex); throw new CoreException(status); } } else { /** @TODO log warn no active editorPart, should never occur */ } }
/* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override public void stop(final BundleContext context) throws Exception { Activator.plugin = null; // we remove the listener on the command service final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class); service.removeExecutionListener(this.commandServiceListener); super.stop(context); }
/** {@inheritDoc} */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); AbstractRootEditor rootEditor = (AbstractRootEditor) HandlerUtil.getActiveEditor(event); RepositoryDefinition repositoryDefinition = rootEditor.getInputDefinition().getRepositoryDefinition(); Object selectedObject = selection.getFirstElement(); ExceptionSensorData dataToNavigateTo = null; if (selectedObject instanceof ExceptionSensorData) { dataToNavigateTo = (ExceptionSensorData) selectedObject; } else if (selectedObject instanceof InvocationSequenceData) { List<ExceptionSensorData> exceptions = ((InvocationSequenceData) selectedObject).getExceptionSensorDataObjects(); if ((null != exceptions) && !exceptions.isEmpty()) { for (ExceptionSensorData exSensorData : exceptions) { if (0 != exSensorData.getMethodIdent()) { dataToNavigateTo = exSensorData; break; } } } } if (null != dataToNavigateTo) { ExceptionSensorData exceptionSensorData = dataToNavigateTo; // exit if the object does not carry the methodIdent if (null == exceptionSensorData.getThrowableType()) { return null; } InputDefinition inputDefinition = getInputDefinition(repositoryDefinition, exceptionSensorData); // open the view via command IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand(OpenViewHandler.COMMAND); ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event()); IEvaluationContext context = (IEvaluationContext) executionEvent.getApplicationContext(); context.addVariable(OpenViewHandler.INPUT, inputDefinition); try { command.executeWithChecks(executionEvent); } catch (NotDefinedException | NotEnabledException | NotHandledException e) { throw new ExecutionException("Error opening the exception type view.", e); } } return null; }
/* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override public void start(final BundleContext context) throws Exception { super.start(context); Activator.plugin = this; Activator.log = new LogHelper(this); // we add a listener on the command service this.commandServiceListener = new SaveEMFCompareListener(); final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class); service.addExecutionListener(this.commandServiceListener); }
public static boolean isShowPlanNames() { ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class); Command command = commandService.getCommand("at.ac.tuwien.ieg.asbruedit.show-planname-toggle"); State state = command.getState("org.eclipse.ui.commands.toggleState"); boolean isToggled = (Boolean) state.getValue(); return isToggled; }
/** Alert whoever is listening that a new OPIShell has been created. */ private static void sendUpdateCommand() { IServiceLocator serviceLocator = PlatformUI.getWorkbench(); ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); try { Command command = commandService.getCommand(OPI_SHELLS_CHANGED_ID); command.executeWithChecks(new ExecutionEvent()); } catch (ExecutionException | NotHandledException | NotEnabledException | NotDefinedException e) { log.log(Level.WARNING, "Failed to send OPI shells changed command", e); } }
public final void testBindingTransform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand addWS = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null); KeySequence m18w = KeySequence.getInstance("M1+8 W"); KeySequence m28w = KeySequence.getInstance("M2+8 W"); boolean foundDeleteMarker = false; int numOfMarkers = 0; Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() == Binding.SYSTEM) { String platform = binding.getPlatform(); int idx = (platform == null ? -1 : platform.indexOf(',')); assertEquals(binding.toString(), -1, idx); if (addWS.equals(binding.getParameterizedCommand())) { if (m18w.equals(binding.getTriggerSequence())) { numOfMarkers++; assertNull(m18w.format(), binding.getPlatform()); } else if (m28w.equals(binding.getTriggerSequence())) { numOfMarkers++; assertTrue( platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); } } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) { assertTrue( platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); numOfMarkers++; foundDeleteMarker = true; } } } assertEquals(3, numOfMarkers); assertTrue("Unable to find delete marker", foundDeleteMarker); TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS); assertEquals(1, activeBindingsFor.length); }
/* * (non-Javadoc) * * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() */ protected void doSetUp() throws Exception { for (int i = 0; i < CREATE_CONTEXTS.length; i++) { final String[] contextInfo = CREATE_CONTEXTS[i]; final Context context = contextService.getContext(contextInfo[0]); if (!context.isDefined()) { context.define(contextInfo[1], contextInfo[2], contextInfo[3]); } } Command cmd = commandService.getCommand(CMD_ID); if (!cmd.isDefined()) { Category cat = commandService.getCategory(CATEGORY_ID); cmd.define("Test Handler", "Test handler activation", cat); } }
@Override public void execute(String newText) throws CoreException { IEditorPart editorPart = getActiveEditorPart(); if (editorPart != null) { // Extract useful parameters needed for the command IWorkbenchPartSite site = editorPart.getSite(); // Invoke the command IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); ICommandService commandService = (ICommandService) site.getService(ICommandService.class); if (editorPart instanceof VersionMultiPageEditor) { VersionMultiPageEditor vEditor = (VersionMultiPageEditor) editorPart; EditingDomain editingDomain = vEditor.getVersionFormEditor().getEditingDomain(); CommandStack commandStack = editingDomain.getCommandStack(); try { // Get the command and assign values to parameters Command command = commandService.getCommand(getCommandId()); ParameterizedCommand parmCommand = new ParameterizedCommand(command, new Parameterization[] {}); // Prepare the evaluation context IEvaluationContext ctx = handlerService.getCurrentState(); ctx.addVariable("model", getModel()); ctx.addVariable("commandStack", commandStack); ctx.addVariable("editingDomain", editingDomain); // Execute the command handlerService.executeCommandInContext(parmCommand, null, ctx); } catch (Exception ex) { IStatus status = new Status( IStatus.ERROR, VersionEditorActivator.PLUGIN_ID, "Error while executing command to remove translation", ex); throw new CoreException(status); } } } else { /** @TODO log warn no active editorPart, should never occur */ } }
public static void setCoolBarVisibility(boolean visible) { IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); if (activeWorkbenchWindow instanceof WorkbenchWindow) { WorkbenchWindow workbenchWindow = (WorkbenchWindow) activeWorkbenchWindow; workbenchWindow.setCoolBarVisible(visible); workbenchWindow.setPerspectiveBarVisible(visible); // Try to force a refresh of the text on the action IWorkbenchPart activePart = getActivePart(); if (activePart != null) { ICommandService cmdService = (ICommandService) activePart.getSite().getService(ICommandService.class); cmdService.refreshElements("org.eclipse.ui.ToggleCoolbarAction", null); // $NON-NLS-1$ } } }
private void defineAllCommands() { commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); autogeneratedCategory = commandService.getCategory(CommandManager.AUTOGENERATED_CATEGORY_ID); defineCommand(newContactCommandId, Messages.getString("Label.NewContact"), newContactHandler); defineCommand( deleteContactCommandId, Messages.getString("Label.DeleteContact"), deleteContactHandler); defineCommand( deleteCertificateCommandId, Messages.getString("Label.DeleteCertificate"), deleteCertificateHandler); defineCommand( deleteKeyPairCommandId, Messages.getString("Label.DeleteKeyPair"), deleteKeyPairHandler); defineCommand( deleteSecretKeyCommandId, Messages.getString("Label.DeleteSecretKey"), deleteSecretKeyHandler); defineCommand( exportCertificateCommandId, org.jcryptool.crypto.keystore.ui.actions.ex.Messages.getString("Label.ExportPublicKey"), exportCertificateHandler); defineCommand( exportKeyPairCommandId, org.jcryptool.crypto.keystore.ui.actions.ex.Messages.getString("Label.ExportKeyPair"), exportKeyPairHandler); defineCommand( exportSecretKeyCommandId, org.jcryptool.crypto.keystore.ui.actions.ex.Messages.getString("Label.ExportSecretKey"), exportSecretKeyHandler); }
public void testTwoHandlers() throws Exception { createHandlerActivation(C1_ID, H1, new String[] {ISources.ACTIVE_CONTEXT_NAME}); createHandlerActivation( C2_ID, H2, new String[] {ISources.ACTIVE_CONTEXT_NAME, ISources.ACTIVE_ACTION_SETS_NAME}); Command cmd = commandService.getCommand(CMD_ID); assertTrue("Command should be defined", cmd.isDefined()); assertFalse("Should not be handled yet", cmd.isHandled()); IContextActivation activationC1 = activateContext(C1_ID); assertTrue("Should definitely be handled", cmd.isHandled()); ActTestHandler handler1 = (ActTestHandler) testHandlers.get(H1); int count1 = handler1.executionCount; cmd.executeWithChecks(new ExecutionEvent()); assertEquals("The handler count should be incremented", count1 + 1, handler1.executionCount); activateContext(C2_ID); assertTrue("Should still be handled", cmd.isHandled()); ActTestHandler handler2 = (ActTestHandler) testHandlers.get(H2); int count2 = handler2.executionCount; count1 = handler1.executionCount; cmd.executeWithChecks(new ExecutionEvent()); assertEquals("The handler1 count should not be incremented", count1, handler1.executionCount); assertEquals("The handler2 count should be incremented", count2 + 1, handler2.executionCount); contextService.deactivateContext(activationC1); assertTrue("Will still be handled", cmd.isHandled()); }
/* (non-Javadoc) * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { String param = event.getParameter(ID_PARAMETER_MODE); if (param == null || param.equals(fCurrentValue)) return null; fCurrentValue = param; CDebugCorePlugin.getDefault() .getPluginPreferences() .setValue(ICDebugConstants.PREF_STEP_MODE, fCurrentValue); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ICommandService service = window.getService(ICommandService.class); service.refreshElements(event.getCommand().getId(), null); return null; }
public static void executeCommand(IViewSite site, String command) { ICommandService cmdService = (ICommandService) site.getService(ICommandService.class); IHandlerService hdlService = (IHandlerService) site.getService(IHandlerService.class); Command cmd = cmdService.getCommand(command); try { hdlService.executeCommand(cmd.getId(), null); } catch (ExecutionException e) { e.printStackTrace(); } catch (NotDefinedException e) { e.printStackTrace(); } catch (NotEnabledException e) { e.printStackTrace(); } catch (NotHandledException e) { e.printStackTrace(); } }
private void openSample(String file) throws CommandException { IHandlerService handlerService = (IHandlerService) getIntroSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getIntroSite().getService(ICommandService.class); Command command = commandService.getCommand( "name.abuchen.portfolio.ui.commands.openSampleCommand"); //$NON-NLS-1$ Map<String, String> parameters = new HashMap<String, String>(); parameters.put("name.abuchen.portfolio.ui.param.sample", file); // $NON-NLS-1$ ParameterizedCommand parameterized = ParameterizedCommand.generateCommand(command, parameters); handlerService.executeCommand(parameterized, null); PlatformUI.getWorkbench().getIntroManager().closeIntro(this); }
public void testModifierNotApplied() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand exportCmd = new ParameterizedCommand(commandService.getCommand("org.eclipse.ui.file.export"), null); Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() != Binding.SYSTEM) continue; if (exportCmd.equals(binding.getParameterizedCommand())) { // make sure the modifier is NOT applied assertEquals(KeySequence.getInstance("M1+8 E"), binding.getTriggerSequence()); break; } } }
void createCommand(String commandId, Map parameters) { if (commandId == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", no command id"); //$NON-NLS-1$ return; } Command cmd = commandService.getCommand(commandId); if (!cmd.isDefined()) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", command \"" + commandId + "\" not defined"); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (parameters == null || parameters.size() == 0) { command = new ParameterizedCommand(cmd, null); return; } try { ArrayList parmList = new ArrayList(); Iterator i = parameters.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String parmName = (String) entry.getKey(); IParameter parm; parm = cmd.getParameter(parmName); if (parm == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", parameter \"" + parmName + "\" for command \"" //$NON-NLS-1$ //$NON-NLS-2$ + commandId + "\" is not defined"); //$NON-NLS-1$ return; } parmList.add(new Parameterization(parm, (String) entry.getValue())); } command = new ParameterizedCommand( cmd, (Parameterization[]) parmList.toArray(new Parameterization[parmList.size()])); } catch (NotDefinedException e) { // this shouldn't happen as we checked for !defined, but we // won't take the chance WorkbenchPlugin.log( "Failed to create menu item " //$NON-NLS-1$ + getId(), e); } }
private static void executeAction( final String action, final IHandlerService handlerService, final ICommandService commandService) { try { final ParameterizedCommand command = commandService.deserialize(action); handlerService.executeCommand(command, null); } catch (CommandException e) { VrapperLog.error("Command not handled: " + action, e); } }
public final void testSinglePlatform() throws Exception { // Get the services. ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand about = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.help.aboutAction"), null); KeySequence m18A = KeySequence.getInstance("M1+8 A"); KeySequence m18B = KeySequence.getInstance("M1+8 B"); int numAboutBindings = 0; Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() == Binding.SYSTEM) { String platform = binding.getPlatform(); int idx = (platform == null ? -1 : platform.indexOf(',')); assertEquals(binding.toString(), -1, idx); if (about.equals(binding.getParameterizedCommand())) { if (m18A.equals(binding.getTriggerSequence())) { numAboutBindings++; assertNull("M+8 A", binding.getPlatform()); } else if (m18B.equals(binding.getTriggerSequence())) { numAboutBindings++; // assertEquals(Util.WS_CARBON, binding.getPlatform()); // temp work around for honouring carbon bindings assertTrue( "failure for platform: " + binding.getPlatform(), Util.WS_CARBON.equals(binding.getPlatform()) || Util.WS_COCOA.equals(binding.getPlatform())); } } } } if (Util.WS_CARBON.equals(SWT.getPlatform()) || Util.WS_COCOA.equals(SWT.getPlatform())) { assertEquals(2, numAboutBindings); } else { assertEquals(1, numAboutBindings); } }
private void addSave(IMenuManager menu) { ICommandService commandService = (ICommandService) fContainer.getWorkbenchPart().getSite().getService(ICommandService.class); final Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_SAVE); final IHandler handler = command.getHandler(); if (handler != null) { if (fSaveContributionItem == null) { fSaveContributionItem = new CommandContributionItem( new CommandContributionItemParameter( fContainer.getWorkbenchPart().getSite(), null, command.getId(), CommandContributionItem.STYLE_PUSH)); } // save is an editable dependent action, ie add only when edit // is possible if (handler.isHandled() && getSourceViewer().isEditable()) menu.add(fSaveContributionItem); } }
@Override public void launch(final IEditorPart editor, final String mode) { assert mode.equals("run"); // $NON-NLS-1$ final IWorkbenchPart workbenchPart = UIAccess.getActiveWorkbenchPart(false); final IWorkbenchPartSite site = workbenchPart.getSite(); if (site != null) { final IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); final ICommandService commandService = (ICommandService) site.getService(ICommandService.class); final Map<String, String> parameters = new HashMap<String, String>(); parameters.put(RCodeLaunching.FILE_COMMAND_ID_PARAMTER_ID, fFileCommandId); final Command command = commandService.getCommand( !fGotoConsole ? RCodeLaunching.RUN_FILEVIACOMMAND_COMMAND_ID : RCodeLaunching.RUN_FILEVIACOMMAND_GOTOCONSOLE_COMMAND_ID); final ExecutionEvent executionEvent = new ExecutionEvent(command, parameters, null, handlerService.getCurrentState()); if (!editor.equals(HandlerUtil.getActivePart(executionEvent))) { LaunchShortcutUtil.handleUnsupportedExecution(executionEvent); return; } try { command.executeWithChecks(executionEvent); } catch (final ExecutionException e) { LaunchShortcutUtil.handleRLaunchException( e, RLaunchingMessages.RScriptLaunch_error_message, executionEvent); } catch (final NotDefinedException e) { LaunchShortcutUtil.handleUnsupportedExecution(executionEvent); } catch (final NotEnabledException e) { LaunchShortcutUtil.handleUnsupportedExecution(executionEvent); } catch (final NotHandledException e) { LaunchShortcutUtil.handleUnsupportedExecution(executionEvent); } } }
public void run() { ICommandService commandService = (ICommandService) this.cheatSheetCatalogView.getSite().getService(ICommandService.class); IStructuredSelection structuredSelection = (IStructuredSelection) this.cheatSheetCatalogView.getViewer().getSelection(); CheatSheetReference cheatSheetReference = (CheatSheetReference) structuredSelection.getFirstElement(); if (cheatSheetReference.getUrl().startsWith("platform:/")) { Command command = commandService.getCommand("org.eclipse.ui.cheatsheets.openCheatSheet"); Map<String, String> map = new HashMap<String, String>(); map.put("cheatSheetId", cheatSheetReference.getUrl().substring("platform:/".length())); try { command.executeWithChecks(new ExecutionEvent(command, map, null, null)); } catch (Exception e) { ErrorDialog errorDialog = new ErrorDialog( "Impossible to open Cheat Sheet", "An error occured while trying to open cheat sheet.", e); errorDialog.open(); } } else { Command command = commandService.getCommand("org.eclipse.ui.cheatsheets.openCheatSheetURL"); Map<String, String> map = new HashMap<String, String>(); map.put("cheatSheetId", cheatSheetReference.getId()); map.put("name", cheatSheetReference.getName()); map.put("url", cheatSheetReference.getUrl()); try { command.executeWithChecks(new ExecutionEvent(command, map, null, null)); } catch (Exception e) { ErrorDialog errorDialog = new ErrorDialog( "Impossible to open Cheat Sheet", "An error occured while trying to open cheat sheet.", e); errorDialog.open(); } } }
public void testModifierWithPlatform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand importCmd = new ParameterizedCommand(commandService.getCommand("org.eclipse.ui.file.import"), null); Binding[] bindings = bindingService.getBindings(); int numOfMarkers = 0; for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() != Binding.SYSTEM) continue; if (importCmd.equals(binding.getParameterizedCommand())) { // make sure the modifier is applied assertEquals(KeySequence.getInstance("M2+8 I"), binding.getTriggerSequence()); numOfMarkers++; } } // only one binding, if the platform matches assertEquals(numOfMarkers, 1); }
public void testDifferentPlatform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand backCmd = new ParameterizedCommand(commandService.getCommand("org.eclipse.ui.navigate.back"), null); Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() != Binding.SYSTEM) continue; if (backCmd.equals(binding.getParameterizedCommand())) { // make sure the modifier is NOT applied // this will fail on Photon (but Paul thinks we'll never run the // test suite on that platform :-) assertEquals(KeySequence.getInstance("M1+8 Q"), binding.getTriggerSequence()); // and the platform should be null assertNull(binding.getPlatform()); break; } } }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.ContributionItem#dispose() */ public void dispose() { if (elementRef != null) { commandService.unregisterElement(elementRef); elementRef = null; } if (commandListener != null) { command.getCommand().removeCommandListener(commandListener); commandListener = null; } command = null; commandService = null; disposeOldImages(); super.dispose(); }
public void testForNegativeNumber() throws Exception { String c5_id = C_PREFIX + ISources.ACTIVE_MENU_NAME; String h5 = C_PREFIX + "h5"; createHandlerActivation( c5_id, h5, new String[] {ISources.ACTIVE_CONTEXT_NAME, ISources.ACTIVE_MENU_NAME}); createHandlerActivation(C1_ID, H1, new String[] {ISources.ACTIVE_CONTEXT_NAME}); Command cmd = commandService.getCommand(CMD_ID); activateContext(C1_ID); activateContext(c5_id); assertHandlerIsExecuted(cmd, h5); }
public void testAboutBindingIn3x() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); final Scheme activeScheme = bindingService.getActiveScheme(); ParameterizedCommand aboutCmd = new ParameterizedCommand( commandService.getCommand(IWorkbenchCommandConstants.HELP_ABOUT), null); ParameterizedCommand activateEditorCmd = new ParameterizedCommand( commandService.getCommand(IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR), null); final KeySequence keyF12 = KeySequence.getInstance("F12"); final Binding editorBinding = bindingService.getPerfectMatch(keyF12); assertNotNull(editorBinding); assertEquals(activateEditorCmd, editorBinding.getParameterizedCommand()); EBindingService ebs = (EBindingService) fWorkbench.getService(EBindingService.class); HashMap<String, String> attrs = new HashMap<String, String>(); attrs.put(EBindingService.TYPE_ATTR_TAG, "user"); final Binding localAboutBinding = ebs.createBinding(keyF12, aboutCmd, IContextService.CONTEXT_ID_WINDOW, attrs); assertEquals(Binding.USER, localAboutBinding.getType()); final Binding[] bindings = bindingService.getBindings(); Binding[] added = new Binding[bindings.length + 1]; System.arraycopy(bindings, 0, added, 0, bindings.length); added[bindings.length] = localAboutBinding; bindingService.savePreferences(activeScheme, added); final Binding secondMatch = bindingService.getPerfectMatch(keyF12); // fails assertNotNull(secondMatch); assertEquals(aboutCmd, secondMatch.getParameterizedCommand()); }
/** * @throws ExecutionException * @throws NotDefinedException * @throws NotEnabledException * @throws NotHandledException */ private void doTestForBreak() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { Command cmd = commandService.getCommand(CMD_ID); assertTrue("Command should be defined", cmd.isDefined()); assertFalse("Should not be handled yet", cmd.isHandled()); IContextActivation c1 = activateContext(C1_ID); IContextActivation c2 = activateContext(C2_ID); IContextActivation c3 = activateContext(C3_ID); assertTrue("Should still be handled", cmd.isHandled()); assertHandlerIsExecuted(cmd, H3); contextService.deactivateContext(c3); contextService.deactivateContext(c2); contextService.deactivateContext(c1); }