Java Code Examples for org.eclipse.core.commands.Command#executeWithChecks()

The following examples show how to use org.eclipse.core.commands.Command#executeWithChecks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenStickerPreferencePage.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	ICommandService commandService =
		(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	
	Command cmd = commandService.getCommand("org.eclipse.ui.window.preferences");
	try {
		HashMap<String, String> hm = new HashMap<String, String>();
		hm.put("preferencePageId", "ch.elexis.prefs.sticker");
		ExecutionEvent ev = new ExecutionEvent(cmd, hm, null, null);
		cmd.executeWithChecks(ev);
	} catch (Exception exception) {
		Status status =
			new Status(IStatus.WARNING, Activator.PLUGIN_ID,
				"Error opening sticker preference page");
		StatusManager.getManager().handle(status, StatusManager.SHOW);
	}
	return null;
}
 
Example 2
Source File: FindingsUiUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Execute the UI command found by the commandId, using the {@link ICommandService}.
 * 
 * @param commandId
 * @param selection
 * @return
 */
public static Object executeCommand(String commandId, IFinding selection){
	try {
		ICommandService commandService =
			(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		
		Command cmd = commandService.getCommand(commandId);
		if(selection != null) {
			PlatformUI.getWorkbench().getService(IEclipseContext.class)
				.set(commandId.concat(".selection"), new StructuredSelection(selection));
		}
		ExecutionEvent ee = new ExecutionEvent(cmd, Collections.EMPTY_MAP, null, null);
		return cmd.executeWithChecks(ee);
	} catch (Exception e) {
		LoggerFactory.getLogger(FindingsUiUtil.class)
			.error("cannot execute command with id: " + commandId, e);
	}
	return null;
}
 
Example 3
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example 4
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example 5
Source File: XrefExtension.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
		}
	}
}
 
Example 6
Source File: TestFullScenario.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws ExecutionException
 */
public void editAndSave() throws Exception {
    processEditor = getTheOnlyOneEditor();
    processEditor.getEditingDomain().getCommandStack().execute(
            new SetCommand(processEditor.getEditingDomain(),
                    task,
                    ProcessPackage.Literals.ELEMENT__NAME,
                    TESTNAME));

    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
    final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command saveCommand = commandService.getCommand("org.eclipse.ui.file.save");
    final ExecutionEvent executionEvent = new ExecutionEvent(saveCommand, Collections.EMPTY_MAP, null,
            handlerService.getClass());
    saveCommand.executeWithChecks(executionEvent);
}
 
Example 7
Source File: EditLocalDocumentUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 IDocumentLetter}, and the provided {@link IViewPart} is hidden.
 * 
 * @param view
 * @param document
 * @return returns true if edit local is started and view is hidden
 */
public static boolean startEditLocalDocument(IViewPart view, IDocumentLetter document){
	if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && document != 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(document));
		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;
}
 
Example 8
Source File: ContributionAction.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Object executeCommand(){
	try {
		ICommandService commandService =
			(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		
		Command cmd = commandService.getCommand(commandId);
		if (selection != null) {
			PlatformUI.getWorkbench().getService(IEclipseContext.class)
				.set(commandId.concat(".selection"), new StructuredSelection(selection));
		}
		ExecutionEvent ee = new ExecutionEvent(cmd, Collections.EMPTY_MAP, null, null);
		return cmd.executeWithChecks(ee);
	} catch (Exception e) {
		LoggerFactory.getLogger(getClass())
			.error("cannot execute command with id: " + commandId, e);
	}
	return null;
}
 
Example 9
Source File: EditLocalDocumentUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: FindingsTemplateUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static void executeCommand(String commandId){
	try {
		ICommandService commandService =
			(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		
		Command cmd = commandService.getCommand(commandId);
		ExecutionEvent ee = new ExecutionEvent(cmd, new HashMap<String, Object>(), null, null);
		cmd.executeWithChecks(ee);
	} catch (Exception e) {
		LoggerFactory.getLogger(FindingsTemplateUtil.class)
			.error("cannot execute command with id: " + commandId, e);
	}
}
 
Example 11
Source File: ShowHierarchyTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private TestingTypeHierarchyHandler invokeTestingHandler(XtextEditor xtextEditor, String commandID) throws Exception {
	IHandlerService handlerService = xtextEditor.getSite().getService(IHandlerService.class);
	final ICommandService commandService = 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;
}
 
Example 12
Source File: TestFullScenario.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @throws CoreException
 * @throws ExecutionException
 */
public void renameProcess() throws Exception {
    processEditor = getTheOnlyOneEditor();
    process = (MainProcess) processEditor.getDiagramEditPart().resolveSemanticElement();
    final MainProcess oldProc = EcoreUtil.copy(process);

    processEditor.getEditingDomain().getCommandStack().execute(new SetCommand(
            processEditor.getEditingDomain(),
            process,
            ProcessPackage.Literals.ELEMENT__NAME,
            "Web_Purchase_Diagram"));
    processEditor.getEditingDomain().getCommandStack().execute(new SetCommand(
            processEditor.getEditingDomain(),
            process,
            ProcessPackage.Literals.ABSTRACT_PROCESS__VERSION,
            webPurchaseVersion));

    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
    final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command saveCommand = commandService.getCommand("org.eclipse.ui.file.save");
    final ExecutionEvent executionEvent = new ExecutionEvent(saveCommand, Collections.EMPTY_MAP, null,
            handlerService.getClass());

    saveCommand.executeWithChecks(executionEvent);

    assertFalse("Old input should not exist any more after rename", input.exists());
}
 
Example 13
Source File: MigrationStatusView.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void clearMigrationReport(final boolean save) throws IOException {
    final IEditorPart editorPart = (IEditorPart) tableViewer.getInput();
    if (editorPart != null && editorPart instanceof DiagramEditor) {
        final Resource emfResource = ((DiagramEditor) editorPart).getDiagramEditPart().getNotationView().eResource();
        final Report report = getMigrationReport(emfResource);
        if (report != null) {
            final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(emfResource);
            if (domain != null) {
                domain.getCommandStack().execute(new RecordingCommand(domain) {

                    @Override
                    protected void doExecute() {
                        emfResource.getContents().remove(report);
                    }
                });
                if (save) {
                    final ICommandService service = (ICommandService) getSite().getService(ICommandService.class);
                    final Command cmd = service.getCommand("org.eclipse.ui.file.save");
                    try {
                        cmd.executeWithChecks(new ExecutionEvent());
                    } catch (final Exception e) {
                        BonitaStudioLog.error(e, MigrationPlugin.PLUGIN_ID);
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: RunProcessOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IStatus openConsole() {
    final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command cmd = service.getCommand("org.bonitasoft.studio.application.openConsole");
    try {
        cmd.executeWithChecks(new ExecutionEvent());
    } catch (final Exception ex) {
        status = new Status(IStatus.ERROR, EnginePlugin.PLUGIN_ID, ex.getMessage(), ex);
        BonitaStudioLog.error(ex);
    }
    return Status.OK_STATUS;
}
 
Example 15
Source File: RunProcessContributionItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Listener createSelectionListener(AbstractProcess process) {
    return e -> {
        Command command = iCommandService.getCommand(RUN_COMMAND);
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("process", process);
        ExecutionEvent executionEvent = new ExecutionEvent(command, parameters, this, null);
        try {
            command.executeWithChecks(executionEvent);
        } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
            throw new RuntimeException(String.format("An error occured while executing command %s", RUN_COMMAND),
                    e1);
        }
    };
}
 
Example 16
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static boolean runCommand(final Command c, final ExecutionEvent event) throws ExecutionException {
	if (c.isEnabled()) {
		try {
			c.executeWithChecks(event);
			return true;
		} catch (NotDefinedException | NotEnabledException | NotHandledException e) {
			e.printStackTrace();
		}
	}
	return false;
}
 
Example 17
Source File: ConcordanceSearchHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	if (!isEnabled()) {
		return null;
	}
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof IXliffEditor) {
		String tshelp = System.getProperties().getProperty("TSHelp");
		String tsstate = System.getProperties().getProperty("TSState");
		if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
			LoggerFactory.getLogger(ConcordanceSearchHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
			System.exit(0);
		}
		IXliffEditor xliffEditor = (IXliffEditor) editor;
		String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";

		IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
			// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
			IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
			List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
			if (lstDatabase.size() == 0) {
				MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
						Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
						Messages.getString("handler.ConcordanceSearchHandler.msg"));
				return null;
			}

			String selectText = xliffEditor.getSelectPureText();
			if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
				selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
			} else if (selectText == null) {
				selectText = "";
			}
			ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
					xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), selectText.trim());
			dialog.open();
			if (selectText != null && !selectText.trim().equals("")) {
				dialog.initGroupIdAndSearch();
				IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
				ICommandService commandService = (ICommandService) site.getService(
						ICommandService.class);
				Command command = commandService
						.getCommand(ActionFactory.COPY.getCommandId());
				IEvaluationService evalService = (IEvaluationService) site.getService(
						IEvaluationService.class);
				IEvaluationContext currentState = evalService.getCurrentState();
				ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
				try {
					command.executeWithChecks(executionEvent);
				} catch (Exception e1) {}
			}
		}
	}
	return null;
}
 
Example 18
Source File: ConcordanceSearchHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	if (!isEnabled()) {
		return null;
	}
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (editor instanceof IXliffEditor) {
		IXliffEditor xliffEditor = (IXliffEditor) editor;
		String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";

		IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
			// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
			IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
			ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
			List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
			if (lstDatabase.size() == 0) {
				MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
						Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
						Messages.getString("handler.ConcordanceSearchHandler.msg"));
				return null;
			}

			String selectText = xliffEditor.getSelectPureText();
			if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
				selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
			} else if (selectText == null) {
				selectText = "";
			}
			String srcLang = xliffEditor.getSrcColumnName();
			String tgtLang = xliffEditor.getTgtColumnName();
			ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
					srcLang,tgtLang, selectText.trim());
			Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
			Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
			dialog.open();
			if (srcLangL.isBidi() || tgtLangL.isBidi()) {
				dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
			}
			if (selectText != null && !selectText.trim().equals("")) {
				dialog.initGroupIdAndSearch();
				IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
				ICommandService commandService = (ICommandService) site.getService(
						ICommandService.class);
				Command command = commandService
						.getCommand(ActionFactory.COPY.getCommandId());
				IEvaluationService evalService = (IEvaluationService) site.getService(
						IEvaluationService.class);
				IEvaluationContext currentState = evalService.getCurrentState();
				ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
				try {
					command.executeWithChecks(executionEvent);
				} catch (Exception e1) {}
			}
		}
	}
	return null;
}