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); } } }); }
@Override public boolean performDrop(Object data) { IServiceLocator locator = Helper.getWB(); ICommandService svc = (ICommandService)locator.getService( ICommandService.class); Command cmd = svc.getCommand(CMD_ID_MOVE_ENTRY); Map<String, String> params = new HashMap<>(); params.put("source", data.toString()); TreeNode en = (TreeNode)getCurrentTarget(); EntryData ed = EntryData.of(en); params.put("target", String.valueOf(ed.entryID())); try { cmd.executeWithChecks( new ExecutionEvent(cmd, params, getCurrentEvent(), null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { throw new RuntimeException(e); } return true; }
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; } }
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; }
@Override public boolean performFinish() { String selectedOption = wizardPage.getSelectedOption(); String commandId = commandOptions.get(selectedOption); Command selectedCommand = commandService.getCommand(commandId); try{ selectedCommand.executeWithChecks(new ExecutionEvent()); } catch(ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e){ MessageDialog.openError(getShell(), "Error", "The selected Command" + " could not be executed successfully."); return false; } return true; }
private void createEvent(Command command, IPersistentObject po){ IStructuredSelection iStructuredSelection = null; if (po != null) { iStructuredSelection = new StructuredSelection(po); } PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), iStructuredSelection); try { command.executeWithChecks( new ExecutionEvent(command, Collections.EMPTY_MAP, this, null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { logger.error("cannot executre local edit event", e); } }
/** * If {@link Preferences#P_TEXT_EDIT_LOCAL} is set, the * <code> ch.elexis.core.ui.command.startEditLocalDocument </code> command is called with the * provided {@link Brief}, and the provided {@link IViewPart} is hidden. * * @param view * @param brief * @return returns true if edit local is started and view is hidden */ public static boolean startEditLocalDocument(IViewPart view, Brief brief){ if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && brief != null) { // open for editing ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$ PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), new StructuredSelection(brief)); try { command.executeWithChecks( new ExecutionEvent(command, Collections.EMPTY_MAP, view, null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { MessageDialog.openError(view.getSite().getShell(), Messages.TextView_errortitle, Messages.TextView_errorlocaleditmessage); } view.getSite().getPage().hideView(view); return true; } return false; }
private void startLocalEdit(Brief brief){ if (brief != null) { ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$ PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), new StructuredSelection(brief)); try { command.executeWithChecks( new ExecutionEvent(command, Collections.EMPTY_MAP, this, null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.BriefAuswahl_errorttile, Messages.BriefAuswahl_erroreditmessage); } } }
private void endLocalEdit(StructuredSelection selection){ ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand("ch.elexis.core.ui.command.endLocalDocument"); //$NON-NLS-1$ PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), selection); try { command .executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null)); tableViewer.setInput(service.getAll()); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle, Messages.LocalDocumentsDialog_errorendmessage); } }
private void abortLocalEdit(StructuredSelection selection){ ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand("ch.elexis.core.ui.command.abortLocalDocument"); //$NON-NLS-1$ PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), selection); try { command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null)); tableViewer.setInput(service.getAll()); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle, Messages.LocalDocumentsDialog_errorabortmessage); } }
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); }
private void setStatus(String statusId){ ICommandService commandService = (ICommandService) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getService(ICommandService.class); Command command = commandService.getCommand("at.medevit.elexis.agenda.ui.command.setStatus"); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("at.medevit.elexis.agenda.ui.command.parameter.statusId", statusId); ExecutionEvent ev = new ExecutionEvent(command, parameters, null, null); try { command.executeWithChecks(ev); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException ex) { LoggerFactory.getLogger(getClass()).error("Error setting status", ex); } }
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); } }
@Override public void run() { IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class); try { handlerService.executeCommand(Constants.GRAPH_PROPERTY_COMMAND_ID, null); } catch ( ExecutionException| NotDefinedException| NotEnabledException| NotHandledException ex) { throw new RuntimeException(Constants.GRAPH_PROPERTY_COMMAND_ID + "not found"); } }
/** * Executes a given command. might do nothing if there isn't an active * handler to handle the event * * @param commandId */ public static void executeCommand(String commandId) { try { if (commandId != null) { getHandlerService().executeCommand(commandId, null); } } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { // just swallowing the exception here } }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final Command c = WorkbenchHelper.getService(ICommandService.class).getCommand("org.eclipse.equinox.p2.ui.sdk.update"); if (c != null) { try { return c.executeWithChecks(event); } catch (NotDefinedException | NotEnabledException | NotHandledException e) {} } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final Command c = WorkbenchHelper.getService(ICommandService.class).getCommand("org.eclipse.ui.file.restartWorkbench"); if (c != null) { try { return c.executeWithChecks(event); } catch (NotDefinedException | NotEnabledException | NotHandledException e) {} } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final Command c = WorkbenchHelper.getService(ICommandService.class) .getCommand("org.eclipse.equinox.p2.ui.sdk.installationDetails"); if (c != null) { try { return c.executeWithChecks(event); } catch (NotDefinedException | NotEnabledException | NotHandledException e) {} } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final Command c = WorkbenchHelper.getService(ICommandService.class).getCommand("org.eclipse.equinox.p2.ui.sdk.install"); if (c != null) { try { return c.executeWithChecks(event); } catch (NotDefinedException | NotEnabledException | NotHandledException e) {} } return null; }
/** * @since 3.4 */ public void notEnabled(IAction action, NotEnabledException exception) { String actionDefinitionId = action.getActionDefinitionId(); if (actionDefinitionId == null || !applicabilityChecker.isApplicable(action)) { return; } commandManager.fireNotEnabled(actionDefinitionId, exception); }
@Override public void run() { commandService = getCommandService(); if (commandService != null) { try { doCommand(); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException exception) { // intentionally empty } } }
@Override public void run(IAction action) { IHandlerService handlerService = window.getService(IHandlerService.class); try { handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); // //$NON-NLS-1$ } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { e.printStackTrace(); } }
public static Object executeCommand( String commandId, Map paramMap ) throws NotDefinedException, ExecutionException, ParameterValueConversionException, NotEnabledException, NotHandledException { Command cmd = CommandUtils.getCommand( commandId ); List paramList = new ArrayList( ); if ( paramMap != null ) { for ( Iterator iter = paramMap.entrySet( ).iterator( ); iter.hasNext( ); ) { Map.Entry entry = (Entry) iter.next( ); String paramId = entry.getKey( ).toString( ); Object value = entry.getValue( ); if ( value != null ) { paramList.add( createParameter( cmd, paramId, value ) ); } } } if ( paramList.size( ) > 0 ) { ParameterizedCommand paramCommand = new ParameterizedCommand( cmd, (Parameterization[]) paramList.toArray( new Parameterization[paramList.size( )] ) ); return getHandlerService( ).executeCommand( paramCommand, null ); } else { return getHandlerService( ).executeCommand( commandId, null ); } }
public static Object executeCommand( String commandId ) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { return getHandlerService( ).executeCommand( commandId, null ); }
private static Object executeCommand(String commandId, Event event, IHandlerService service) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException { Object result = null; if (service != null) { try { MarkUtils.setIgnoreDispatchId(true); result = service.executeCommand(commandId, event); } finally { MarkUtils.setIgnoreDispatchId(false); } } return result; }
public static void run_the_command(final String id) { try { ((IHandlerService) get_the_workbench().getService(IHandlerService.class)).executeCommand(id, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { throw new IllegalStateException("Unable to run the command " + id, e); } }
/** * Attempts to execute the command with the given Id. */ private void executeCommand(String commandId){ Command command = commandService.getCommand(commandId); try { command.executeWithChecks(new ExecutionEvent()); } catch(ExecutionException | NotDefinedException | NotEnabledException | NotHandledException exception) { exception.printStackTrace(); } }
private void makeActions(){ doubleClickAction = new Action() { public void run(){ ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj instanceof IDocument) { IDocument dh = (IDocument) obj; DocumentStoreServiceHolder.getService().getPersistenceObject(dh) .ifPresent(po -> { ICommandService commandService = (ICommandService) PlatformUI .getWorkbench().getService(ICommandService.class); Command command = commandService .getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); PlatformUI.getWorkbench().getService(IEclipseContext.class) .set(command.getId().concat(".selection"), new StructuredSelection(po)); try { command.executeWithChecks( new ExecutionEvent(command, Collections.EMPTY_MAP, null, null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { e.printStackTrace(); } }); viewer.refresh(); } } }; }
private void sendMailWithFiles(Patient patient, List<?> iOutboxElements, ICommandService commandService, String attachmentsString) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException{ if (openSendMailDlg(patient, iOutboxElements, commandService, attachmentsString)) { for (Object iOutboxElement : iOutboxElements) { if (iOutboxElement instanceof OutboxElement) { OutboxServiceComponent.getService().changeOutboxElementState( (OutboxElement) iOutboxElement, State.SENT); } } } }
private void sendMailWithXdm(Patient patient, List<?> iOutboxElements, ICommandService commandService, String retInfo) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException{ String[] retInfos = retInfo.split(":::"); // a retInfo must contain at least one xdm and one attachment if (retInfos.length > 1 && openSendMailDlg(patient, iOutboxElements, commandService, retInfos[0])) { StringBuilder warnings = new StringBuilder(); for (Object iOutboxElement : iOutboxElements) { if (iOutboxElement instanceof OutboxElement) { OutboxElement outboxElement = (OutboxElement) iOutboxElement; String lblOutBoxElement = outboxElement.getLabel(); // check if outbox element is sent boolean outboxElementSent = false; for (String info : retInfos) { if (info.endsWith(lblOutBoxElement)) { outboxElementSent = true; } } if (outboxElementSent) { OutboxServiceComponent.getService() .changeOutboxElementState((OutboxElement) iOutboxElement, State.SENT); } else { warnings.append("\n"); warnings.append(lblOutBoxElement); } } } if (warnings.length() > 0) { MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Warnung", "Folgende Outbox Elemente konnten nicht versendet werden:\n" + warnings); } } }
private Object createXDM(Patient patient, ICommandService commandService, String attachmentsString) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException{ Command xdmCommand = commandService .getCommand("at.medevit.elexis.ehc.ui.vacdoc.CreateXdmHandler"); if (xdmCommand.isDefined()) { HashMap<String, String> params = new HashMap<String, String>(); params.put("at.medevit.elexis.ehc.ui.vacdoc.tmp.dir", attachmentsFolder.getAbsolutePath()); params.put("at.medevit.elexis.ehc.ui.vacdoc.attachments", attachmentsString); if (patient != null) { params.put("at.medevit.elexis.ehc.ui.vacdoc.patient.id", patient.getId()); } ParameterizedCommand parametrizedCommmand = ParameterizedCommand.generateCommand(xdmCommand, params); if (parametrizedCommmand != null) { Object obj = PlatformUI.getWorkbench().getService(IHandlerService.class) .executeCommand(parametrizedCommmand, null); return obj; } } else { MessageDialog.openError(Display.getCurrent().getActiveShell(), "Fehler", "Es wurde kein Plugin zum erstellen von XDM Dateien gefunden."); } return null; }
public void executeCommand(ParameterizedCommand command) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { handlerService.executeCommandInContext(command, null, evaluationContext); }
@Override public boolean updateMarker(final IMarker marker, final IDocument doc, final Position position) { try { this.markerType = marker.getType(); final int start = position.getOffset(); final int end = position.getOffset() + position.getLength(); if (!MarkUtilities.getText(marker).equals(doc.get(start, position.getLength()))) { // text of marker is changed Display.getDefault().syncExec(new Runnable() { @Override public void run() { final IServiceLocator serviceLocator = PlatformUI.getWorkbench(); final ICommandService commandService = serviceLocator.getService(ICommandService.class); try { final Command command = commandService.getCommand("eu.modelwriter.marker.command.updatechangeandimpact"); command.executeWithChecks(new ExecutionEvent()); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { e1.printStackTrace(); } } }); } MarkUtilities.setStart(marker, start); MarkUtilities.setEnd(marker, end); MarkUtilities.setLinenumber(marker, doc.getLineOfOffset(start)); MarkUtilities.setText(marker, doc.get(start, position.getLength())); MarkerUpdater.update(marker); // TODO When the update action completed, you must trigger the Visualization.showViz method // for refreshing the view. return true; } catch (CoreException | BadLocationException e) { return false; } }
/** Execute command. */ abstract protected void doCommand() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException;
@Override protected void doCommand() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { commandService.refreshElements(command, null); }
protected void doCommand() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { commandService.getCommand(command).executeWithChecks( new ExecutionEvent()); }
public static Object executeCommand(String commandId, Integer count, Event event, IWorkbenchPart editor) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException { Map<String, Integer> parameters = new HashMap<String, Integer>(); parameters.put(EmacsPlusUtils.UNIVERSAL_ARG, count); return (editor == null) ? executeCommand(commandId, parameters, event) : executeCommand(commandId, parameters, event, editor); }
public void notEnabled(String commandId, NotEnabledException exception) { }