@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 */ } }
@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 */ } }