@Test public void testCopyUrl() throws ExecutionException { // Given String url = "https://github.com/cchabanois/mesfavoris"; Bookmark bookmark = new Bookmark(new BookmarkId(), ImmutableMap.of(UrlBookmarkProperties.PROP_URL, url)); IEvaluationContext context = new EvaluationContext(null, new Object()); context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, new StructuredSelection(bookmark)); ExecutionEvent event = new ExecutionEvent(null, new HashMap<>(), null, context); // When CopyBookmarkUrlHandler handler = new CopyBookmarkUrlHandler(); executeHandler(handler, event); // Then assertEquals(url, getClipboardContents()); }
public void refreshState(CommandStack stack) { remaining = stack.hasRemaining(); if (remaining) { armed = stack.getActiveCommand().getStackedState() == StackedState.ARMED; } else { armed = false; } empty = stack.isEmpty(); executionStarted = false; for (StackedCommand cmd : stack.getCommands()) { if (cmd.getStackedState() != StackedState.DISARMED) { executionStarted = true; break; } } Map newState = getCurrentState(); log.info(String.format("Fire new stack state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }
@Override public void setEnabled(Object evalContext) { if (null == evalContext) { isEnabled = false; return; } IEvaluationContext context = (IEvaluationContext) evalContext; Object editor = context.getVariable(ISources.ACTIVE_EDITOR_NAME); if (editor instanceof ViewEditor) { isEnabled = true; return; } isEnabled = false; return; }
private ConsoleStreamFlusher getFlusher(Object context) { if (context instanceof IEvaluationContext) { IEvaluationContext evaluationContext = (IEvaluationContext) context; Object o = evaluationContext.getVariable(ISources.ACTIVE_PART_NAME); if (!(o instanceof IWorkbenchPart)) { return null; } IWorkbenchPart part = (IWorkbenchPart) o; if (part instanceof IConsoleView && ((IConsoleView) part).getConsole() instanceof IConsole) { IConsole activeConsole = (IConsole) ((IConsoleView) part).getConsole(); IProcess process = activeConsole.getProcess(); return (ConsoleStreamFlusher) process.getAdapter(ConsoleStreamFlusher.class); } } return null; }
/** * Change the UI state based on the state of the simulation (none, stopped, * running or notready) */ @Override public void updateStateTo(final String state) { fireSourceChanged(ISources.WORKBENCH, SIMULATION_RUNNING_STATE, state); final IExperimentPlan exp = GAMA.getExperiment(); final String type = exp == null ? "NONE" : exp.isBatch() ? "BATCH" : exp.isMemorize() ? "MEMORIZE" : "REGULAR"; fireSourceChanged(ISources.WORKBENCH, SIMULATION_TYPE, type); String canStepBack = "CANNOT_STEP_BACK"; if (exp != null) { if (exp.getAgent() != null) { canStepBack = exp.getAgent().canStepBack() ? "CAN_STEP_BACK" : "CANNOT_STEP_BACK"; } } fireSourceChanged(ISources.WORKBENCH, SIMULATION_STEPBACK, canStepBack); }
@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); } }
/** * Default constructor. */ public ESLocalProjectPropertySourceProvider() { currentSaveStates = new LinkedHashMap<String, Boolean>(); // check if workspace can init, exit otherwise try { ESWorkspaceProviderImpl.init(); // BEGIN SUPRESS CATCH EXCEPTION } catch (final RuntimeException exception) { // END SUPRESS CATCH EXCEPTION ModelUtil.logException( "ProjectSpacePropertySourceProvider init failed because workspace init failed with exception.", exception); return; } saveStateChangedObserver = new ESSaveStateChangedObserver() { public void saveStateChanged(ESLocalProject localProject, boolean hasUnsavedChangesNow) { final Boolean newValue = new Boolean(hasUnsavedChangesNow); currentSaveStates.put(localProject.getLastUpdated().toString(), newValue); fireSourceChanged(ISources.WORKBENCH, CURRENT_SAVE_STATE_PROPERTY, newValue); } }; ESWorkspaceProviderImpl.getObserverBus().register(saveStateChangedObserver); }
protected Object getFirstSelectVariable( ) { IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object selectVariable = UIUtil.getVariableFromContext( context, ISources.ACTIVE_CURRENT_SELECTION_NAME ); Object selectList = selectVariable; if ( selectVariable instanceof StructuredSelection ) { selectList = ( (StructuredSelection) selectVariable ).toList( ); } if ( selectList instanceof List && ( (List) selectList ).size( ) > 0 ) { selectVariable = getFirstElement( (List) selectList ); } return selectVariable; }
/** * Returns a <code>List</code> containing the currently selected objects. * * @return A List containing the currently selected objects. */ protected IStructuredSelection getSelection( ) { IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object selectVariable = UIUtil.getVariableFromContext( context, ISources.ACTIVE_CURRENT_SELECTION_NAME ); if ( selectVariable != null ) { if ( selectVariable instanceof IStructuredSelection ) { return (IStructuredSelection) selectVariable; } else { return new StructuredSelection( selectVariable ); } } return null; }
public static Object startSimulator(final ExecutionEvent event, final String engineTypeId) { try { final SimulationUIService simulationUiService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getBundleContext()).get(SimulationUIService.class), "unable to get simulation UI service"); if(simulationUiService.getCurrentState().getSimulationEngine() != null) { final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setMessage("A simulation is already active. Do you want to stop the current simulation?"); messageBox.setText("Stop Current Simulation"); if(messageBox.open() == SWT.NO) { return null; } } if(event.getApplicationContext() instanceof IEvaluationContext) { final IEvaluationContext appContext = (IEvaluationContext)event.getApplicationContext(); final ISelection selection = (ISelection)appContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); final SimulationLaunchShortcut launchShortcut = new SimulationLaunchShortcut(); launchShortcut.launch(selection, engineTypeId, ILaunchManager.RUN_MODE); } } catch(final Exception ex) { final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getSymbolicName(), "Error", ex); StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG); } return null; }
private void setGluonFound(boolean gluonFound) { if (this.gluonFound == gluonFound) return; this.gluonFound = gluonFound; String currentState = gluonFound ? GLUON_FOUND : GLUON_NOT_FOUND; fireSourceChanged(ISources.WORKBENCH, SHOW_MENU, currentState); }
private void setGluonFunctionFound(boolean gluonFunctionFound) { if (this.gluonFunctionFound == gluonFunctionFound) return; this.gluonFunctionFound = gluonFunctionFound; String currentState = gluonFunctionFound ? GLUON_FUNCTION_FOUND : GLUON_FUNCTION_NOT_FOUND; fireSourceChanged(ISources.WORKBENCH, SHOW_FUNCTION_MENU, currentState); }
@Override public void defaultKeyChanged ( final KeyInformation key, final Date validUntil ) { logger.debug ( "Default key changed: {} -> {}", key, validUntil ); fireSourceChanged ( ISources.WORKBENCH, getCurrentState () ); }
private IProject getSelectedProject(Object ctx) { if (ctx instanceof IEvaluationContext) { Object sel = ((IEvaluationContext) ctx).getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (sel instanceof IStructuredSelection) { Object el = ((IStructuredSelection) sel).getFirstElement(); if (el instanceof IAdaptable) { return ((IAdaptable) el).getAdapter(IProject.class); } } } return null; }
private static IEditorPart getActivePart(IEvaluationContext context) { if (context == null) return null; Object activePart = context.getVariable(ISources.ACTIVE_PART_NAME); if ((activePart instanceof IEditorPart)) return (IEditorPart) activePart; return null; }
public void updateState(ProcessorInfo processorInfo) { if (processorInfo == null) { replay = false; processing = ""; speed = 1; } else { replay = processorInfo.hasReplayRequest(); processing = replay ? processorInfo.getReplayState().toString() : ""; speed = replay ? processorInfo.getReplayRequest().getSpeed().getParam() : 1; } Map newState = getCurrentState(); log.fine(String.format("Fire new processing state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }
@Override public void onStudioConnect() { Display.getDefault().asyncExec(() -> { Map newState = getCurrentState(); log.fine(String.format("Fire new authz state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }); }
@Override public void onStudioDisconnect() { Display.getDefault().asyncExec(() -> { Map newState = getCurrentState(); log.fine(String.format("Fire new authz state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }); }
@Override public void onStudioConnect() { Display.getDefault().asyncExec(() -> { connected = true; Map newState = getCurrentState(); log.fine(String.format("Fire new connection state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }); }
@Override public void onStudioDisconnect() { Display.getDefault().asyncExec(() -> { connected = false; Map newState = getCurrentState(); log.fine(String.format("Fire new connection state %s", newState)); fireSourceChanged(ISources.WORKBENCH, newState); }); }
/** * Fire a status change event for the model associated with the given model. * <p> * Remark that this method has no clue if an effective status change occurred or not. That decision should already have been made by the component invoking * this method. * </p> * * @param modelCode */ public void fireStatusChanged(String modelCode) { LOGGER.trace("fireStatusChanged() - entry : {}", modelCode); ProcessHandle handle = getWorkflowExecutionHandle(modelCode); LOGGER.debug("fireStatusChanged() - {} -> {}", modelCode, handle); String statusValue = getExecutionStatusForHandle(handle).name(); fireSourceChanged(ISources.WORKBENCH, MY_STATE, statusValue); LOGGER.debug("fireStatusChanged() - setting status : {}", statusValue); LOGGER.trace("fireStatusChanged() - exit : {}", modelCode); }
@Override public void setEnabled(Object evaluationContext) { boolean contentAssistAvailable = false; if (evaluationContext instanceof IEvaluationContext) { Object var = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_EDITOR_NAME); if (var instanceof XtextEditor) { contentAssistAvailable = ((XtextEditor) var).isContentAssistAvailable(); } } super.setBaseEnabled(isEnabled() & contentAssistAvailable); }
private static IStructuredSelection getSelection( IEvaluationContext evaluationContext ) { IStructuredSelection result = StructuredSelection.EMPTY; Object variable = evaluationContext.getVariable( ISources.ACTIVE_CURRENT_SELECTION_NAME ); if( variable instanceof IStructuredSelection ) { result = ( IStructuredSelection )variable; } return result; }
private static boolean isEnabled( IEvaluationContext evaluationContext ) { Object variable = evaluationContext.getVariable( ISources.ACTIVE_EDITOR_INPUT_NAME ); boolean result = false; if( variable instanceof IEditorInput ) { IEditorInput editorInput = ( IEditorInput )variable; result = ResourceUtil.getFile( editorInput ) != null || getFile( editorInput ) != null; } return result; }
private IEvaluationContext createEvaluationContext( ISelection selection ) { IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IEvaluationContext result = new EvaluationContext( null, new Object() ); result.addVariable( ISources.ACTIVE_WORKBENCH_WINDOW_NAME, activeWorkbenchWindow ); result.addVariable( ISources.ACTIVE_CURRENT_SELECTION_NAME, selection ); return result; }
private IEvaluationContext createEvaluationContext( Object editorInput ) { IWorkbenchWindow activeWorkbenchWindow = workbenchPage.getWorkbenchWindow(); IEvaluationContext result = new EvaluationContext( null, new Object() ); result.addVariable( ISources.ACTIVE_WORKBENCH_WINDOW_NAME, activeWorkbenchWindow ); if( editorInput != null ) { result.addVariable( ISources.ACTIVE_EDITOR_INPUT_NAME, editorInput ); } return result; }
private IEvaluationContext createEvaluationContext( IWorkbenchPart activePart ) { IWorkbenchWindow activeWorkbenchWindow = workbenchPage.getWorkbenchWindow(); IEvaluationContext result = new EvaluationContext( null, new Object() ); result.addVariable( ISources.ACTIVE_WORKBENCH_WINDOW_NAME, activeWorkbenchWindow ); if( activePart != null ) { result.addVariable( ISources.ACTIVE_PART_NAME, activePart ); } return result; }
@Override public void setEnabled(Object evaluationContext) { // clear cached selection this.clearFileStores(); if (evaluationContext instanceof IEvaluationContext) { IEvaluationContext context = (IEvaluationContext) evaluationContext; Object value = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (value instanceof ISelection) { ISelection selection = (ISelection) value; if (selection instanceof IStructuredSelection && selection.isEmpty() == false) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Object object : structuredSelection.toArray()) { if (object instanceof IProject || object instanceof IFolder || object instanceof IFile) { IResource resource = (IResource) object; IFileStore fileStore = EFSUtils.getFileStore(resource); if (this.isValid(fileStore)) { this.addFileStore(fileStore); } } } } } } }
public static IResource getSelectedResource(IEvaluationContext evaluationContext) { if (evaluationContext == null) { return null; } Object variable = evaluationContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (variable instanceof IStructuredSelection) { Object selectedObject = ((IStructuredSelection) variable).getFirstElement(); if (selectedObject instanceof IAdaptable) { IResource resource = (IResource) ((IAdaptable) selectedObject).getAdapter(IResource.class); if (resource != null) { return resource; } } } else { // checks the active editor variable = evaluationContext.getVariable(ISources.ACTIVE_EDITOR_NAME); if (variable instanceof IEditorPart) { IEditorInput editorInput = ((IEditorPart) variable).getEditorInput(); if (editorInput instanceof IFileEditorInput) { return ((IFileEditorInput) editorInput).getFile(); } } } return null; }
private List<TextHoverDescriptor> getEnabledTextHoverDescriptors(ITextViewer textViewer, int offset) { List<TextHoverDescriptor> result = new ArrayList<TextHoverDescriptor>(); if (fTextEditor == null) { return result; } try { QualifiedContentType contentType = CommonEditorPlugin.getDefault().getDocumentScopeManager() .getContentType(textViewer.getDocument(), offset); IEvaluationContext context = new EvaluationContext(null, textViewer); IWorkbenchPartSite site = fTextEditor.getSite(); if (site != null) { context.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, site.getId()); } for (TextHoverDescriptor descriptor : TextHoverDescriptor.getContributedHovers()) { if (descriptor.isEnabledFor(contentType, context)) { result.add(descriptor); } } } catch (BadLocationException e) { } return result; }
@Override public void setEnabled(Object evaluationContext) { Object activeSite = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_SITE_NAME); Object activeEditor = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_EDITOR_NAME); if (activeSite instanceof IWorkbenchSite && activeEditor instanceof AbstractThemeableEditor) { ICommandService commandService = (ICommandService) ((IWorkbenchSite) activeSite) .getService(ICommandService.class); Command command = commandService.getCommand(COMMAND_ID); State state = command.getState(RegistryToggleState.STATE_ID); state.setValue(((AbstractThemeableEditor) activeEditor).getWordWrapEnabled()); } }
private boolean isEnabled(Object evaluationContext) { Object activeEditor = HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_EDITOR_NAME); if (activeEditor instanceof MultiPagePlanEditor) { MultiPagePlanEditor multiPagePlanEditor = (MultiPagePlanEditor)activeEditor; boolean editorAreaVisible = multiPagePlanEditor.getCurrentEditor().getEditorSite().getPage().isEditorAreaVisible(); if(editorAreaVisible) { return true; } } return false; }
private boolean isEnabled(Object evaluationContext) { Object activeEditor = HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_EDITOR_NAME); // The following line fixes SPF-5785, but there's a better way, as Andrew discovered: // TODO: As of 3.5, the IPartListener2 can also implement IPageChangedListener to be notified about any parts that implement IPageChangeProvider and post PageChangedEvents. // That would be a better way, now, of telling when the Table or Timeline tab ("page") is selected. if (activeEditor==null) activeEditor=getActiveEditor(); return getMergeEditor(activeEditor) != null; }
protected static final IStructuredSelection getStructuredSelection(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection instanceof IStructuredSelection) { return (IStructuredSelection) selection; } throw new ExecutionException("Incorrect type for " //$NON-NLS-1$ + ISources.ACTIVE_CURRENT_SELECTION_NAME + " found while executing " //$NON-NLS-1$ + event.getCommand().getId() + ", expected " + IStructuredSelection.class.getName() //$NON-NLS-1$ + " found " + selection.getClass().getName()); //$NON-NLS-1$ }
public void setState(boolean state){ String value = FALSE; if (state == true) { value = TRUE; } else { value = FALSE; } fireSourceChanged(ISources.WORKBENCH, PATIENTACTIVE, value); }
public void setLoginSession ( final LoginSession session ) { this.session = session; fireSourceChanged ( ISources.WORKBENCH, getCurrentState () ); }