private ModernActionKeyBindingSupport( final IAdaptable serviceLocator, final Expression expression, final int sourcePriorities) { Check.notNull(serviceLocator, "serviceLocator"); //$NON-NLS-1$ Check.notNull(expression, "expression"); //$NON-NLS-1$ bindingService = (IBindingService) serviceLocator.getAdapter(IBindingService.class); handlerService = (IHandlerService) serviceLocator.getAdapter(IHandlerService.class); if (bindingService == null || handlerService == null) { throw new IllegalArgumentException( "specified IAdapable could not provide IBindingService or IHandlerService"); //$NON-NLS-1$ } this.expression = expression; this.sourcePriorities = sourcePriorities; }
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; }
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; }
private void hookDoubleClickAction() { bookmarksTreeViewer.addDoubleClickListener(event -> { ISelection selection = bookmarksTreeViewer.getSelection(); Object firstElement = ((IStructuredSelection) selection).getFirstElement(); Bookmark bookmark = Adapters.adapt(firstElement, Bookmark.class); if (bookmark instanceof BookmarkFolder) { bookmarksTreeViewer.setExpandedState(firstElement, !bookmarksTreeViewer.getExpandedState(firstElement)); } else { // sometimes, selection and part in the command handler are not set to the boomarks view when we double-click on a bookmark getSite().getWorkbenchWindow().getActivePage().activate(this); IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); try { handlerService.executeCommand(COMMAND_ID_GOTO_FAVORI, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { StatusHelper.logError("Could not go to bookmark", e); } } }); }
public boolean close() { this.filterJob.cancel(); this.refreshCacheJob.cancel(); this.refreshProgressMessageJob.cancel(); if (showViewHandler != null) { IHandlerService service = PlatformUI .getWorkbench().getService(IHandlerService.class); service.deactivateHandler(showViewHandler); showViewHandler.getHandler().dispose(); showViewHandler = null; } if (menuManager != null) menuManager.dispose(); if (contextMenuManager != null) contextMenuManager.dispose(); storeDialog(getDialogSettings()); return super.close(); }
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); } } }
/** * Hook double click command. */ private void hookDoubleClickCommand() { this.getCommonViewer().addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); try { if ((event.getSelection() != null) && (event.getSelection() instanceof IStructuredSelection)) { IStructuredSelection structSel = (IStructuredSelection) event.getSelection(); Object element = structSel.iterator().next(); if (element instanceof CollectionNode) { handlerService.executeCommand("synergyviewcore.collections.openMediaCollection", null); } if (element instanceof AnnotationSetNode) { handlerService.executeCommand("synergyviewcore.subtitle.openannotationseteditor", null); } } } catch (Exception ex) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex); logger.log(status); } } }); }
@Override public void run(IAction action) { System.err.println("In run(IACtion)"); if (serviceLocator == null) { serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } // Create an ExecutionEvent using Eclipse machinery. ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class); IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class); ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null); // Fill it my current active selection. if (event.getApplicationContext() instanceof IEvaluationContext) { ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection); } try { handler.execute(event); } catch (ExecutionException e) { Activator.handleError(e.getMessage(), e, true); } }
@Override public void run(IAction action) { if (serviceLocator == null) { serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } // Create an ExecutionEvent using Eclipse machinery. ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class); IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class); ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null); // Fill it my current active selection. if (event.getApplicationContext() instanceof IEvaluationContext) { ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection); } try { handler.execute(event); } catch (ExecutionException e) { Activator.handleError(e.getMessage(), e, true); } }
/** * Fills the actions bars. * <p> * Subclasses may extend. * * @param actionBars the action bars */ protected void fillActionBars(IActionBars actionBars) { IToolBarManager toolBar= actionBars.getToolBarManager(); fillToolBar(toolBar); IAction action; action= getCopyToClipboardAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action); action= getSelectAllAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class); handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction)); }
private void setGlobalActionHandlers(IActionBars actionBars) { // Navigate Go Into and Go To actions. actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO, fZoomInAction); actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), fBackAction); actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), fForwardAction); actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP, fUpAction); actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_TO_RESOURCE, fGotoResourceAction); actionBars.setGlobalActionHandler(JdtActionConstants.GOTO_TYPE, fGotoTypeAction); actionBars.setGlobalActionHandler(JdtActionConstants.GOTO_PACKAGE, fGotoPackageAction); actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), fSelectAllAction); fRefactorActionGroup.retargetFileMenuActions(actionBars); IHandlerService handlerService= (IHandlerService) fPart.getViewSite().getService(IHandlerService.class); handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkingAction)); handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(fCollapseAllAction)); }
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<IHandlerActivation>(); Collection<String> definedCommandIds= commandService.getDefinedCommandIds(); for (Iterator<String> iter= definedCommandIds.iterator(); iter.hasNext();) { String id= iter.next(); if (id.startsWith(ICommandAccess.COMMAND_ID_PREFIX)) { boolean isAssist= id.endsWith(ICommandAccess.ASSIST_SUFFIX); CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist); IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite())); fCorrectionHandlerActivations.add(activation); } } }
/** * Creates page 0 of the multi-page editor, * which contains a text editor. */ void createPage0() { try { editor = new TextEditor(); int index = addPage(editor, getEditorInput()); setPageText(index, editor.getTitle()); IHandlerService serv = (IHandlerService) getSite().getService(IHandlerService.class); MyCopyHandler cp = new MyCopyHandler(); serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_PASTE, cp); //serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_, cp); } catch (PartInitException e) { ErrorDialog.openError( getSite().getShell(), "Error creating nested text editor", null, e.getStatus()); } }
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; } }
@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; } }
@Override protected void fillActionBars(final IActionBars actionBars) { super.fillActionBars(actionBars); actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), fBackAction); actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), fForthAction); fInputSelectionProvider.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_ATTACHED_JAVA_DOC, fOpenBrowserAction); } }); IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class); handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction)); }
@Override protected void configureToolBar(final IToolBarManager manager) { super.configureToolBar(manager); final IDiagramOutputActionFactory factory = JiveUIPlugin.getDefault() .getDiagramOutputActionFactory(); final ScalableRootEditPart root = (ScalableRootEditPart) viewer.getRootEditPart(); final IAction zoomIn = new ZoomInAction(root.getZoomManager()); final IAction zoomOut = new ZoomOutAction(root.getZoomManager()); final IUpdatableAction saveAs = factory.createDiagramExportAction(viewer); final IUpdatableAction print = factory.createPrintAction(viewer); addUpdatableAction(saveAs); addUpdatableAction(print); // reference: http://dev.eclipse.org/newslists/news.eclipse.platform/msg60866.html // register action handlers for zoom in and zoom out: final IHandlerService handlerService = (IHandlerService) getSite().getService( IHandlerService.class); handlerService.activateHandler(zoomIn.getActionDefinitionId(), new ActionHandler(zoomIn)); handlerService.activateHandler(zoomOut.getActionDefinitionId(), new ActionHandler(zoomOut)); manager.insertBefore(AbstractJiveView.GROUP_STEP_CONTROLS, new Separator( AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP)); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, saveAs); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, print); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, zoomIn); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, zoomOut); }
/** * In the console context, use paste as * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText * will not simulate keyboard input * * @param event the ExecutionEvent * @param widget The consoles StyledText widget */ protected void paste(ExecutionEvent event, StyledText widget) { IWorkbenchPart apart = HandlerUtil.getActivePart(event); if (apart != null) { try { IWorkbenchPartSite site = apart.getSite(); if (site != null) { IHandlerService service = (IHandlerService) site.getService(IHandlerService.class); if (service != null) { service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null); KillRing.getInstance().setYanked(true); } } } catch (CommandException e) { } } }
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; }
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(); } }
private void activateTerminateHandler(final IProgressMonitor monitor, final WorkspaceJob job) { final IHandlerService handlerService = (IHandlerService) window .getService(IHandlerService.class); window.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { final IHandlerActivation activation = handlerService.activateHandler(TERMINATE_ID, new TerminateHandler(monitor)); job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { window.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { handlerService.deactivateHandler(activation); } }); } }); } }); }
public static void executeWithParams(PersistentObject parameter){ try { // get the command IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ICommandService cmdService = (ICommandService) window.getService(ICommandService.class); Command cmd = cmdService.getCommand(EditEigenleistungUi.COMMANDID); // create the parameter HashMap<String, Object> param = new HashMap<String, Object>(); param.put(EditEigenleistungUi.PARAMETERID, parameter); // build the parameterized command ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param); // execute the command IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getService(IHandlerService.class); handlerService.executeCommand(pc, null); } catch (Exception ex) { throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex); } }
public static void executeWithParams(PersistentObject parameter){ try { // get the command IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ICommandService cmdService = (ICommandService) window.getService(ICommandService.class); Command cmd = cmdService.getCommand(EditEigenartikelUi.COMMANDID); // create the parameter HashMap<String, Object> param = new HashMap<String, Object>(); param.put(EditEigenartikelUi.PARAMETERID, parameter); // build the parameterized command ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param); // execute the command IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getService(IHandlerService.class); handlerService.executeCommand(pc, null); } catch (Exception ex) { throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex); } }
public static Object ExecuteWithParams(IViewSite origin, Tree<?> tSelection){ IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class); ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class); try { Command command = cmdService.getCommand(ID); Parameterization px = new Parameterization(command.getParameter("ch.elexis.RechnungErstellen.parameter"), //$NON-NLS-1$ new TreeToStringConverter().convertToString(tSelection)); ParameterizedCommand parmCommand = new ParameterizedCommand(command, new Parameterization[] { px }); return handlerService.executeCommand(parmCommand, null); } catch (Exception ex) { throw new RuntimeException("add.command not found"); //$NON-NLS-1$ } }
private static Object execute(IViewSite origin, String commandID, Map<String, Object> params){ if (origin == null) { log.error("origin is null"); return null; } IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class); ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class); try { Command command = cmdService.getCommand(commandID); String name = StringTool.unique("CommandHandler"); //$NON-NLS-1$ paramMap.put(name, params); Parameterization px = new Parameterization(new DefaultParameter(), name); ParameterizedCommand parmCommand = new ParameterizedCommand(command, new Parameterization[] { px }); return handlerService.executeCommand(parmCommand, null); } catch (Exception ex) { throw new RuntimeException("add.command not found"); //$NON-NLS-1$ } }
public static void executeWithParams(PersistentObject parameter){ try { // get the command IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ICommandService cmdService = (ICommandService) window.getService(ICommandService.class); Command cmd = cmdService.getCommand(COMMANDID); // create the parameter HashMap<String, Object> param = new HashMap<String, Object>(); param.put(PARAMETERID, parameter); // build the parameterized command ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param); // execute the command IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getService(IHandlerService.class); handlerService.executeCommand(pc, null); } catch (Exception ex) { throw new RuntimeException(COMMANDID, ex); } }
public static Object ExecuteWithParams(IViewSite origin, String bereich, String from, String until){ IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class); ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class); try { Command command = cmdService.getCommand(ID); Parameterization px1 = new Parameterization( command.getParameter("ch.elexis.agenda.param.resource"), bereich); //$NON-NLS-1$ Parameterization px2 = new Parameterization(command.getParameter("ch.elexis.agenda.param.from"), from); //$NON-NLS-1$ Parameterization px3 = new Parameterization(command.getParameter("ch.elexis.agenda.param.until"), until); //$NON-NLS-1$ ParameterizedCommand parmCommand = new ParameterizedCommand(command, new Parameterization[] { px1, px2, px3 }); return handlerService.executeCommand(parmCommand, null); } catch (Exception ex) { throw new RuntimeException(" export command not found"); //$NON-NLS-1$ } }
private boolean openSendMailDlg(Patient patient, List<?> iOutboxElements, ICommandService commandService, String attachmentsString) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException{ Command sendMailCommand = commandService.getCommand("ch.elexis.core.mail.ui.sendMail"); HashMap<String, String> params = new HashMap<String, String>(); params.put("ch.elexis.core.mail.ui.sendMail.attachments", attachmentsString); if (patient != null) { params.put("ch.elexis.core.mail.ui.sendMail.subject", "Patient: " + patient.getLabel()); } ParameterizedCommand parametrizedCommmand = ParameterizedCommand.generateCommand(sendMailCommand, params); Object obj = PlatformUI.getWorkbench().getService(IHandlerService.class) .executeCommand(parametrizedCommmand, null); return Boolean.TRUE.equals(obj); }
/** * Optionally returns with the current state of the workbench only and if only the * {@link PlatformUI#isWorkbenchRunning() workbench is running}. * * @return the current state of the running workbench. Returns with an {@link Optional#absent() absent} if the * workbench is not running or the {@link IHandlerService} is not available. */ public static Optional<IEvaluationContext> getCurrentWorkbenchState() { if (!isWorkbenchRunning()) { return absent(); } final Object service = getWorkbench().getService(IHandlerService.class); return service instanceof IHandlerService ? fromNullable(((IHandlerService) service).getCurrentState()) : absent(); }
private void executeCommand ( final ParameterizedCommand command ) throws PartInitException { final IHandlerService handlerService = (IHandlerService)getWorkbenchWindow ().getService ( IHandlerService.class ); if ( command.getCommand ().isDefined () ) { try { handlerService.executeCommand ( command, null ); } catch ( final Exception e ) { throw new RuntimeException ( e ); } } }
protected void startHdView () { try { final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class ); final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class ); final Command command = commandService.getCommand ( "org.eclipse.scada.ui.chart.view.commands.OpenParametersChartView" ); //$NON-NLS-1$ final Parameterization[] parameterizations = new Parameterization[4]; parameterizations[0] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.connectionId" ), this.connectionId ); //$NON-NLS-1$ parameterizations[1] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemId" ), this.itemId ); //$NON-NLS-1$ if ( this.queryString == null || this.queryString.isEmpty () ) { parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), "2400000:600000" ); //$NON-NLS-1$ //$NON-NLS-2$ } else { parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), this.queryString ); //$NON-NLS-1$ } parameterizations[3] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemType" ), "hd" ); //$NON-NLS-1$ //$NON-NLS-2$ final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations ); handlerService.executeCommand ( parameterCommand, null ); } catch ( final Exception e ) { logger.debug ( "Failed to open view", e ); StatusManager.getManager ().handle ( new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.TrendControlImage_TrendError, e ), StatusManager.BLOCK ); } }
/** * Execute an Eclipse command * * @param commandId * the command to execute * @param eventData * the parameter event data (depends on the command) */ public void executeCommand ( final String commandId, final Map<String, String> eventData ) { try { final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class ); final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class ); final Command command = commandService.getCommand ( commandId ); final Parameterization[] parameterizations = new Parameterization[eventData.size ()]; int i = 0; for ( final Map.Entry<String, String> entry : eventData.entrySet () ) { parameterizations[i] = new Parameterization ( command.getParameter ( entry.getKey () ), entry.getValue () ); i++; } final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations ); handlerService.executeCommand ( parameterCommand, null ); } catch ( final Exception e ) { logger.warn ( "Failed to execute command", e ); StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK ); } }
@Override public void doubleClick ( final DoubleClickEvent event ) { try { final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class ); handlerService.executeCommand ( COMMAND_ID, null ); } catch ( final Exception e ) { logger.warn ( "Failed to execute command", e ); StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK ); } }
public CommandProvider(IEvaluationContext evaluationContext) { this.evaluationContext = evaluationContext; IEclipseContext context = ((ExpressionContext) evaluationContext).eclipseContext; ehandlerService = context.get(EHandlerService.class); handlerService = context.get(IHandlerService.class); commandService = context.get(ICommandService.class); commandById = new HashMap<>(); }
private void callEgitCommitCommand(){ if (!isCommitCommandAvailable || !mainPrefs.getBoolean(PREF.CALL_COMMIT_COMMAND_AFTER_UPDATE)){ return; } try { getSite().getSelectionProvider().setSelection(new StructuredSelection(proj.getProject())); getSite().getService(IHandlerService.class).executeCommand(COMMAND.COMMIT_COMMAND_ID, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { Log.log(Log.LOG_WARNING, "Could not execute command " + COMMAND.COMMIT_COMMAND_ID, e); //$NON-NLS-1$ ExceptionNotifier.notifyDefault(Messages.ProjectEditorDiffer_failed_egit_commit, e); } }