@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext()); final IWorkbenchPart activePart = WorkbenchUIUtil.getActivePart(event.getApplicationContext()); if (selection == null || activePart == null) { return null; } final ISourceUnit su = LTKSelectionUtil.getSingleSourceUnit(activePart); if (!(su instanceof IRSourceUnit)) { return null; } ExtractFunctionRefactoring refactoring = null; if (selection instanceof ITextSelection) { final ITextSelection textSelection = (ITextSelection) selection; refactoring = new ExtractFunctionRefactoring( (IRSourceUnit) su, new Region(textSelection.getOffset(), textSelection.getLength())); } if (refactoring != null) { final RefactoringWizardExecutionHelper executionHelper = new RefactoringWizardExecutionHelper( new ExtractFunctionWizard(refactoring), RefactoringSaveHelper.SAVE_NOTHING); executionHelper.perform(activePart.getSite().getShell()); } // } // catch (final CoreException e) { // StatusManager.getManager().handle(new Status( // IStatus.ERROR, RUI.PLUGIN_ID, -1, // Messages.InlineTemp_Wizard_title, e), // StatusManager.LOG | StatusManager.SHOW); // } return null; }
/** * Extract the variable. * * @param event The execution event that contains the application context * @param name The variable name to extract. * @return The object from the application context, or <code>null</code> if it could not be found. */ public static Object getVariable(ExecutionEvent event, String name) { if (event.getApplicationContext() instanceof IEvaluationContext) { Object var = ((IEvaluationContext) event.getApplicationContext()).getVariable(name); return var == IEvaluationContext.UNDEFINED_VARIABLE ? null : var; } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { // Get the currently selected item final ISelection sel = HandlerUtil.getActiveMenuSelection(event); // Get the filter parameter for the command final String var = event.getParameter(PlayUsesPortHandler.FILTER_PARAM); // Check if we should send each play command individually or as a group final boolean sendList = Boolean.parseBoolean(event.getParameter(PlayUsesPortHandler.LIST_PARAM)); // Get the ports variable for the command - this is only used via programmatic command execution final Object ports = HandlerUtil.getVariable(event, PlayUsesPortHandler.PORTS_VAR); String message = null; final List<ScaUsesPort> portList = new ArrayList<ScaUsesPort>(); // First, check if we're called from a menu if ((sel != null) && (sel instanceof IStructuredSelection)) { final IStructuredSelection ss = (IStructuredSelection) sel; for (final Object element : ss.toList()) { if (element instanceof ScaUsesPort) { final ScaUsesPort port = (ScaUsesPort) element; portList.add(port); } else { final Object obj = Platform.getAdapterManager().getAdapter(element, ScaUsesPort.class); if (obj instanceof ScaUsesPort) { portList.add((ScaUsesPort) obj); } } } // If it's called programmatically, ports should be a list of ScaPort objects } else if ((ports != null) && (ports instanceof List)) { for (final Object element : (List<?>) ports) { if (element instanceof ScaUsesPort) { final ScaUsesPort port = ((ScaUsesPort) element); portList.add(port); } else { final Object obj = Platform.getAdapterManager().getAdapter(element, ScaUsesPort.class); if (obj instanceof ScaUsesPort) { portList.add((ScaUsesPort) obj); } } } } else { message = "Unable to determine what to play"; } // Check if we found any ports to play if (portList.size() > 0) { message = playPort(var, portList, sendList); } // Any errors will be put into message if (message != null) { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Unable to Play", message); } return null; }
/** {@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; }
/** * the command has been executed, so extract extract the needed information from the application * context. */ public Object doExecute(ExecutionEvent event, IExecutionSavedContext savedContext) throws ExtendedHandlerExecutionException { IWorkbenchPage workbenchPage = HandlerUtil.getActivePart(event).getSite().getPage(); String filePath = event.getParameter(FILE_PATH_PARAMETER); Integer lineNumber = null; try { lineNumber = new Integer(event.getParameter(LINE_NUMBER_PARAMETER)); } catch (Exception e) { // do something very clever here... } if (lineNumber == null) lineNumber = 1; launchJob(workbenchPage, lineNumber, filePath); return null; }
/** * @see * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { toSelect = new ArrayList<EObject>(); IEditorPart editor = RequirementUtils.getCurrentEditor(); IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor); CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage(); if (services != null && ((EvaluationContext) event.getApplicationContext()).getDefaultVariable() instanceof List<?>) { EditingDomain editingDomain = services.getEditingDomain(editor); // Get the current selection List<?> elements = ((List<?>) ((EvaluationContext) event.getApplicationContext()).getDefaultVariable()); CompoundCommand compoundCmd = new CompoundCommand(Messages.getString("AddAttributeHandler.1")); // $NON-NLS-1$ for (Object currObject : elements) { EObject parent = null; if (currObject instanceof Attribute) { parent = ((Attribute) currObject).eContainer(); int newIndex = calculateIndex(parent, (EObject) currObject); Attribute toDuplicate = null; if (currObject instanceof AttributeLink) { toDuplicate = RequirementHelper.INSTANCE.duplicateAttributeLink((AttributeLink) currObject); } else if (currObject instanceof ObjectAttribute) { toDuplicate = RequirementHelper.INSTANCE.duplicateObjectAttribute((ObjectAttribute) currObject); } if (parent != null && toDuplicate != null) { toSelect.add(toDuplicate); compoundCmd.appendIfCanExecute( AddCommand.create( editingDomain, parent, RequirementPackage.eINSTANCE.getRequirement_Attribute(), toDuplicate, newIndex)); } } } if (!compoundCmd.isEmpty() && compoundCmd.canExecute()) { editingDomain.getCommandStack().execute(compoundCmd); page.setSelection(new StructuredSelection(toSelect)); } } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { String viewName = event.getParameter(VIEW_NAME_PARAM); PlotWindow.getManager().openView(null, viewName); return null; }
private static void noVariableFound(ExecutionEvent event, String name) throws ExecutionException { throw new ExecutionException( "No " + name //$NON-NLS-1$ + " found while executing " + event.getCommand().getId()); // $NON-NLS-1$ }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Command command = event.getCommand(); ISelection selection = HandlerUtil.getCurrentSelection(event); EList<EPlanElement> elements = getSelectedTemporalElements(selection); boolean isChecked = getCommandState(command); IUndoContext undoContext = getUndoContext(); CompositeOperation op = new CompositeOperation(getEarliestOrLatestName()); if (isChecked) { for (EPlanElement element : elements) { ConstraintsMember member = element.getMember(ConstraintsMember.class, true); Set<PeriodicTemporalConstraint> constraints = getRelevantConstraints(member); for (PeriodicTemporalConstraint constraint : constraints) { op.add(new DeleteTemporalBoundOperation(constraint)); } } } else { Object data = showDialog(); if (data instanceof Amount) { Amount<Duration> offset = (Amount<Duration>) data; if (!elements.isEmpty()) { ECollections.sort(elements, TemporalChainUtils.CHAIN_ORDER); for (EPlanElement planElement : elements) { op.add(createPeriodicTemporalConstraintOperation(planElement, offset, undoContext)); } } } } CommonUtils.execute(op, undoContext); setCommandState(command, !isChecked); return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // in regular PasteHandler we do follwing: //// copy contents from clipboard - in case there was something else in the clipboard, e.g. // copied from the system buffer. //// Plugin.getInstance().getContents().getFromClipboard(); // but here it would break the order of elements, rendering this command unusable, // so we are ok to possibly lose the clipboard content.. String paramValue = event.getParameter("MoreClipboard.commands.morePasteIndexParameter"); if (paramValue == null) { throw new ExecutionException( "Failed to perform paste with index command - parameter is null"); } int index = Integer.parseInt(paramValue); Plugin.getInstance().getContents().setToClipboard(index); try { // run regular paste command final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); handlerService.executeCommand("org.eclipse.ui.edit.paste", null); // result is ignored.. } catch (NotDefinedException e) { throw new ExecutionException("Failed to perform paste with index command", e); } catch (NotEnabledException e) { throw new ExecutionException("Failed to perform paste with index command", e); } catch (NotHandledException e) { throw new ExecutionException("Failed to perform paste with index command", e); } return null; }
/* (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; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); if (activeWorkbenchWindow != null) { WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage(); if (page != null) { Map parameters = event.getParameters(); String value = (String) parameters.get(IWorkbenchCommandConstants.WINDOW_CLOSE_PERSPECTIVE_PARM_ID); if (value == null) { page.closePerspective(page.getPerspective(), true, true); } else { IPerspectiveDescriptor perspective = activeWorkbenchWindow .getWorkbench() .getPerspectiveRegistry() .findPerspectiveWithId(value); if (perspective != null) { page.closePerspective(perspective, true, true); } } } } return null; }
/** * Checks whether the radio state of the command is same as the radio state parameter's value * * @param event The execution event that contains the application context * @return <code>true</code> whe the values are same, <code>false</code> otherwise * @throws ExecutionException When the command doesn't have the radio state or the event doesn't * have the radio state parameter * @since 3.5 */ public static boolean matchesRadioState(ExecutionEvent event) throws ExecutionException { String parameter = event.getParameter(RadioState.PARAMETER_ID); if (parameter == null) throw new ExecutionException( "The event does not have the radio state parameter"); //$NON-NLS-1$ Command command = event.getCommand(); State state = command.getState(RadioState.STATE_ID); if (state == null) throw new ExecutionException("The command does not have a radio state"); // $NON-NLS-1$ if (!(state.getValue() instanceof String)) throw new ExecutionException( "The command's radio state doesn't contain a String value"); //$NON-NLS-1$ return parameter.equals(state.getValue()); }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext()); final List<IProject> projects; if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; projects = new ArrayList<>(structuredSelection.size()); for (final Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) { final Object obj = iter.next(); if (obj instanceof IAdaptable) { final IProject project = (IProject) ((IAdaptable) obj).getAdapter(IProject.class); if (project != null) { projects.add(project); } } } } else { return null; } final WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { final SubMonitor m = SubMonitor.convert(monitor, TexUIMessages.TexProject_ConvertTask_label, 100); try { final SubMonitor mProjects = m.newChild(100).setWorkRemaining(projects.size()); for (final IProject project : projects) { if (m.isCanceled()) { throw new InterruptedException(); } TexProjects.setupTexProject(project, mProjects.newChild(1)); } } finally { m.done(); } } }; try { UIAccess.getActiveWorkbenchWindow(true).run(true, true, op); } catch (final InvocationTargetException e) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, TexUI.PLUGIN_ID, TexUIMessages.TexProject_ConvertTask_error_message, e.getTargetException())); } catch (final InterruptedException e) { // cancelled } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IWorkbenchPart activePart = HandlerUtil.getActivePart(event); final boolean checked = !HandlerUtil.toggleCommandState(event.getCommand()); if (activePart instanceof DockerContainersView) { final DockerContainersView containersView = (DockerContainersView) activePart; containersView.showContainersWithLabels(checked); } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { HandlerUtil.toggleCommandState(event.getCommand()); IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); if (part instanceof RepositoriesView) { CommonViewer viewer = ((RepositoriesView) part).getCommonViewer(); viewer.refresh(); } return null; }
public Object execute(ExecutionEvent event) throws ExecutionException { IJavaScriptElement javaElement = (IJavaScriptElement) event.getObjectParameterForExecution(PARAM_ID_ELEMENT_REF); PackageExplorerPart view = PackageExplorerPart.openInActivePerspective(); view.tryToReveal(javaElement); return null; }
public Object execute(final ExecutionEvent event) throws ExecutionException { final boolean isPhotoFilterActive = !HandlerUtil.toggleCommandState(event.getCommand()); TourbookPlugin.setActivePhotoFilter(isPhotoFilterActive); // fire event that photo filter has changed _prefStore.setValue(ITourbookPreferences.APP_DATA_FILTER_IS_MODIFIED, Math.random()); return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Command command = event.getCommand(); boolean oldValue = HandlerUtil.toggleCommandState(command); // use the old value and perform the operation for (PlanStripsEditor editor : PlanStripsEditorRegistry.instance().all()) { PlanNameToggleAdapter toggler = (PlanNameToggleAdapter) editor.getAdapter(PlanNameToggleAdapter.class); toggler.setShowPlanNames(!oldValue); } return null; }
/* * (non-Javadoc) * * @see * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands. * ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { String perspectiveId = event.getParameter(PERSP_ID); if (perspectiveId == null) { MessageDialog.openInformation( HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), "Open", "Please choose a perspective"); } else { System.out.println("Set perspective: " + perspectiveId); } return null; }
public final Object execute(final ExecutionEvent event) { final IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); final String href = event.getParameter(PARAM_ID_HREF); if (href == null) { helpSystem.displayHelp(); } else { helpSystem.displayHelpResource(href); } return null; }
/** * Invokes 'Configure Git Repository' dialog to share given project. * * @see * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { final String projectName = event.getParameter(PROJECT_NAME_PARAMETER); final IProject projectToShare = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); IWorkbench workbench = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench(); final SharingWizard wizard = new SharingWizard(); wizard.init(workbench, projectToShare); final Shell shell = HandlerUtil.getActiveShell(event); WizardDialog wizardDialog = new WizardDialog(shell, wizard); wizardDialog.open(); return null; }
private static void incorrectTypeFound( ExecutionEvent event, String name, Class expectedType, Class wrongType) throws ExecutionException { throw new ExecutionException( "Incorrect type for " //$NON-NLS-1$ + name + " found while executing " //$NON-NLS-1$ + event.getCommand().getId() + ", expected " + expectedType.getName() // $NON-NLS-1$ + " found " + wrongType.getName()); // $NON-NLS-1$ }
public Object execute(ExecutionEvent event) throws ExecutionException { try { String name = event.getCommand().getName(); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); if (!MessageDialog.openConfirm( shell, Messages.JavaBeansGeneratorAction_MSG_DIALOG_MESSAGE, name + Messages.JavaBeansGeneratorAction_MSG_DIALOG_DESC)) { return null; } /* 実行中のダイアログ表示 */ ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.setCancelable(true); IWorkbenchPartSite site = HandlerUtil.getActivePartChecked(event).getSite(); ISelection selection = HandlerUtil.getCurrentSelection(event); IStructuredSelection ss = null; if (selection instanceof IStructuredSelection) { ss = (IStructuredSelection) selection; } try { logger.debug("execute"); // $NON-NLS-1$ String id = event.getCommand().getId(); JavaBeansCreatorWithProgress progress = new JavaBeansCreatorWithProgress(ss, site, id); dialog.run(true, true, progress); } catch (InvocationTargetException e) { Activator.logException(e); } catch (InterruptedException e) { Activator.logException(e, false); } } catch (NotDefinedException e) { Activator.logException(e); } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { String viewID = event.getParameter("uk.ac.diamond.scisoft.analysis.command.sourceView"); if (viewID != null) { final AbstractPlotView apv = (AbstractPlotView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(viewID); DataSetPlotter plotter = apv.getPlotter(); if (plotter != null) { plotter.setYAxisScaling(ScaleType.LN); } return Boolean.TRUE; } return Boolean.FALSE; }
@Override public Object execute(ExecutionEvent event) { // Determine whether the execution event carries an // SWT event with it and whether its loaded wth a // ITeiidServer reference. Object object = event.getTrigger(); if (object instanceof Event) { Event swtEvent = (Event) object; Object data = swtEvent.data; if (data instanceof ITeiidServer) serverBeingEdited = (ITeiidServer) data; } run(); return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { /* * Retrieve data */ String procId = event.getParameter(ARG_PROCID); /* * Retrieve the procedure */ IProcedureManager mgr = (IProcedureManager) ServiceManager.get(IProcedureManager.class); IProcedure proc = mgr.getProcedure(procId); proc.getController().recover(); return CommandResult.SUCCESS; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { String genId = event.getParameter("com.opcoach.gendoc.generateDocument.generatorID"); ISelection sel = HandlerUtil.getCurrentSelection(event); if (sel instanceof IStructuredSelection) { Object selected = ((IStructuredSelection) sel).getFirstElement(); if (selected instanceof EObject) { // Can get the path of current object and initialize the gendoc // generator. GeneratorDesc gd = OPCGendocActivator.getDocumentGeneratorRegistry().get(genId); generateDocument((EObject) selected, gd); } } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IEvaluationContext context = (IEvaluationContext) event.getApplicationContext(); /* Get the map */ final IWorkbenchWindow window = (IWorkbenchWindow) context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); final IWorkbenchPage activePage = window.getActivePage(); /* set input to gtt tables */ final IScenarioDataProvider dataProvider = KalypsoAFGUIFrameworkPlugin.getDataProvider(); final IFolder scenarioFolder = (IFolder) dataProvider.getScenarioFolder(); KalypsoCorePlugin.getDefault().getSelectionManager().clear(); WorkflowHandlerUtils.setGttInput( activePage, "NaNodes", "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:NaNodes:gtt", Messages.getString("ResultOutputManagementTaskHandler_0"), scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ WorkflowHandlerUtils.setGttInput( activePage, "Catchments", "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:Catchments:gtt", Messages.getString("ResultOutputManagementTaskHandler_1"), scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ WorkflowHandlerUtils.setGttInput( activePage, "StorageChannels", "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:StorageChannels:gtt", Messages.getString("ResultOutputManagementTaskHandler_2"), scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ WorkflowHandlerUtils.setGftInput( activePage, "Outputs", "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:Outputs:gft", Messages.getString("ResultOutputManagementTaskHandler_3"), scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return null; }
@Override public final Object execute(final ExecutionEvent event) throws ExecutionException { if ((action.getStyle() == IAction.AS_CHECK_BOX) || (action.getStyle() == IAction.AS_RADIO_BUTTON)) { action.setChecked(!action.isChecked()); } final Object trigger = event.getTrigger(); try { if (trigger instanceof Event) { action.runWithEvent((Event) trigger); } else { action.runWithEvent(new Event()); } } catch (Exception e) { throw new ExecutionException( "While executing the action, an exception occurred", e); // $NON-NLS-1$ } return null; }