org.eclipse.core.expressions.IEvaluationContext Java Examples
The following examples show how to use
org.eclipse.core.expressions.IEvaluationContext.
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: CompareWithRouteAction.java From eip-designer with Apache License 2.0 | 6 votes |
@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); } }
Example #2
Source File: EvalExpressionAction.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Object applicationContext = event.getApplicationContext(); if (applicationContext instanceof IEvaluationContext) { IEvaluationContext evalCtx = (IEvaluationContext) applicationContext; Object obj = evalCtx.getDefaultVariable(); if (obj instanceof Set) { Set set = (Set) obj; if (set.size() > 0) { Object sel = set.iterator().next(); if (sel instanceof TextSelection) { String expr = ((TextSelection) sel).getText(); if (expr != null && expr.trim().length() > 0) { eval(expr); } } } } } else { Log.log("Expected IEvaluationContext. Received: " + applicationContext.getClass()); } return null; }
Example #3
Source File: PropertiesHandler.java From tlaplus with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void setEnabled(final Object evaluationContext) { final IEvaluationContext context = (IEvaluationContext)evaluationContext; final Object defaultVariable = context.getDefaultVariable(); Spec spec = null; if (defaultVariable instanceof List) { final List<?> list = (List<?>)defaultVariable; if (list.size() == 1) { final Object o = list.get(0); if (o instanceof Spec) { spec = (Spec)o; } } } m_enabled = (spec != null); }
Example #4
Source File: DeleteModuleHandler.java From tlaplus with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void setEnabled(final Object evaluationContext) { final Module m = getModuleFromContext((IEvaluationContext)evaluationContext); if (m != null) { final WorkspaceSpecManager specManager = Activator.getSpecManager(); final Spec loadedSpec = specManager.getSpecLoaded(); final String specName = loadedSpec.getName(); final String moduleName = m.getModuleName(); m_enabled = !specName.equals(moduleName); return; } m_enabled = false; }
Example #5
Source File: RenameModelHandlerDelegate.java From tlaplus with MIT License | 6 votes |
@SuppressWarnings("unchecked") // generics casting... @Override public void setEnabled(final Object evaluationContext) { final Object selection = ((IEvaluationContext)evaluationContext).getDefaultVariable(); if (selection instanceof List) { final List<Object> list = (List<Object>)selection; boolean modelEncountered = false; // Will always go to true on given current XML definitions; future proofing for (final Object element : list) { if (element instanceof Model) { if (((Model)element).isSnapshot()) { setBaseEnabled(false); return; } modelEncountered = true; } } setBaseEnabled(modelEncountered); } else { setBaseEnabled(false); } }
Example #6
Source File: InsertRowHandler.java From birt with Eclipse Public License 1.0 | 6 votes |
public Object execute( ExecutionEvent event ) throws ExecutionException { super.execute( event ); IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object position = UIUtil.getVariableFromContext( context, ICommandParameterNameContants.INSERT_ROW_POSITION); int intPos = -1; if(position != null && position instanceof Integer) { intPos = ((Integer)position).intValue( ); } if ( Policy.TRACING_ACTIONS ) { System.out.println( "Insert row above action >> Run ..." ); //$NON-NLS-1$ } if ( getTableEditPart( ) != null && !getRowHandles( ).isEmpty( ) ) { // has combined two behavior into one. getTableEditPart( ).insertRows( intPos, getRowNumbers( ) ); } return Boolean.TRUE; }
Example #7
Source File: DeleteModuleHandler.java From tlaplus with MIT License | 6 votes |
private Module getModuleFromContext(final IEvaluationContext context) { final Object defaultVariable = context.getDefaultVariable(); if (defaultVariable instanceof List) { final List<?> list = (List<?>)defaultVariable; if (list.size() == 1) { final Object o = list.get(0); if (o instanceof Module) { return (Module)o; } } } return null; }
Example #8
Source File: SelectionHandler.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example #9
Source File: AbstractViewEditorHandler.java From depan with Apache License 2.0 | 6 votes |
@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; }
Example #10
Source File: SelectionHandler.java From birt with Eclipse Public License 1.0 | 6 votes |
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; }
Example #11
Source File: InsertColumnHandler.java From birt with Eclipse Public License 1.0 | 6 votes |
public Object execute( ExecutionEvent event ) throws ExecutionException { super.execute( event ); IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object position = UIUtil.getVariableFromContext( context, ICommandParameterNameContants.INSERT_COLUMN_POSITION ); int intPos = -1; if ( position instanceof Integer ) { intPos = ( (Integer) position ).intValue( ); } if ( Policy.TRACING_ACTIONS ) { System.out.println( "Insert row above action >> Run ..." ); //$NON-NLS-1$ } if ( getTableEditPart( ) != null && !getColumnHandles( ).isEmpty( ) ) { // has combined two behavior into one. getTableEditPart( ).insertColumns( intPos, getColumnNumbers( ) ); } return Boolean.TRUE; }
Example #12
Source File: PublishToLibraryHandler.java From birt with Eclipse Public License 1.0 | 6 votes |
public Object execute( ExecutionEvent event ) throws ExecutionException { super.execute( event ); // String filePath = SessionHandleAdapter.getInstance( ) // .getReportDesignHandle( ) // .getFileName( ); // String fileName = filePath.substring( filePath.lastIndexOf( File.separator ) + 1 ); IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); String fileName = (String)UIUtil.getVariableFromContext( context, ICommandParameterNameContants.PUBLISH_LIBRARY_FILENAME); LibraryHandle libHandle = (LibraryHandle) UIUtil.getVariableFromContext( context, ICommandParameterNameContants.PUBLISH_LIBRARY_LIBRARY_HANDLE); PublishLibraryWizard publishLibrary = new PublishLibraryWizard( libHandle, fileName, ReportPlugin.getDefault( ).getResourceFolder( ) ); WizardDialog dialog = new BaseWizardDialog( UIUtil.getDefaultShell( ), publishLibrary ); dialog.setPageSize( 500, 250 ); dialog.open( ); return Boolean.TRUE; }
Example #13
Source File: PersistToRouteModelAction.java From eip-designer with Apache License 2.0 | 6 votes |
@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); } }
Example #14
Source File: CompareWithRouteAction.java From eip-designer with Apache License 2.0 | 6 votes |
@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); } }
Example #15
Source File: PersistToRouteModelAction.java From eip-designer with Apache License 2.0 | 6 votes |
@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); } }
Example #16
Source File: HandlerServiceUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static <T> Optional<T> getVariable(final String variableName, final Class<T> expectedClass) { if (isNullOrEmpty(variableName) || null == expectedClass) { return absent(); } final Optional<IEvaluationContext> state = getCurrentWorkbenchState(); if (!state.isPresent()) { return absent(); } final Object variable = state.get().getVariable(variableName); if (null == variable || UNDEFINED_VARIABLE == variable) { return absent(); } if (expectedClass.isAssignableFrom(variable.getClass())) { return fromNullable(expectedClass.cast(variable)); } return absent(); }
Example #17
Source File: BaseInsertHandler.java From birt with Eclipse Public License 1.0 | 5 votes |
protected boolean initializeVariable(ExecutionEvent event) { IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object obj = UIUtil.getVariableFromContext( context, ICommandParameterNameContants.BASE_INSERT_TYPE_NAME ); if(obj == null || (obj instanceof String)) { insertType = (String)obj; } if(insertType == null) { return false; } obj = UIUtil.getVariableFromContext( context, ICommandParameterNameContants.BASE_INSERT_SLOT_HANDLE_NAME ); if(obj == null || (obj instanceof SlotHandle)) { slotHandle = (SlotHandle)obj; } if(slotHandle == null) { return false; } obj = UIUtil.getVariableFromContext( context,ICommandParameterNameContants.BASE_INSERT_MODEL_NAME ); if(obj == null) { return false; } model = obj; return true; }
Example #18
Source File: CppStyleHandler.java From CppStyle with MIT License | 5 votes |
@Override protected EvaluationResult evaluate(IEvaluationContext context) { IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context); // no window? not active if (window == null) return EvaluationResult.FALSE; WorkbenchPage page = (WorkbenchPage) window.getActivePage(); // no page? not active if (page == null) return EvaluationResult.FALSE; // get saveable part ISaveablePart saveablePart = getSaveablePart(context); if (saveablePart == null) return EvaluationResult.FALSE; if (saveablePart instanceof ISaveablesSource) { ISaveablesSource modelSource = (ISaveablesSource) saveablePart; if (SaveableHelper.needsSave(modelSource)) return EvaluationResult.TRUE; return EvaluationResult.FALSE; } if (saveablePart != null && saveablePart.isDirty()) return EvaluationResult.TRUE; return EvaluationResult.FALSE; }
Example #19
Source File: EditGroupHandler.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object execute( ExecutionEvent event ) throws ExecutionException { super.execute( event ); GroupHandle handle = null; IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object obj =UIUtil.getVariableFromContext( context, EditGroupAction.GROUP_HANDLE_NAME ); if ( obj != null && obj instanceof GroupHandle ) { handle = (GroupHandle) obj; } if ( Policy.TRACING_ACTIONS ) { System.out.println( "Edit group action >> Run ..." ); //$NON-NLS-1$ } CommandStack stack = getActiveCommandStack( ); stack.startTrans( STACK_MSG_EDIT_GROUP ); GroupDialog dialog = new GroupDialog( PlatformUI.getWorkbench( ) .getDisplay( ) .getActiveShell( ), GroupDialog.GROUP_DLG_TITLE_EDIT ); dialog.setInput( handle ); if ( dialog.open( ) == Window.OK ) { stack.commit( ); } else { stack.rollbackAll( ); } return Boolean.TRUE; }
Example #20
Source File: UIUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Gets the object from the context through the key.If the value is a Object * return null. * * @param context * @param key * @return */ public static Object getVariableFromContext( IEvaluationContext context, String key ) { Object retValue = context.getVariable( key ); if ( retValue == null ) { return null; } if ( retValue.getClass( ).getName( ).equals( "java.lang.Object" ) )//$NON-NLS-1$ { retValue = null; } return retValue; }
Example #21
Source File: EditStyleHandler.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object execute( ExecutionEvent event ) throws ExecutionException { super.execute( event ); IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( ); Object obj = UIUtil.getVariableFromContext( context, ICommandParameterNameContants.EDIT_STYLE_SHARED_STYLE_HANDLE_NAME ); if ( obj != null && obj instanceof SharedStyleHandle ) { handle = (SharedStyleHandle) obj; } if ( handle == null ) { return Boolean.FALSE; } if ( Policy.TRACING_ACTIONS ) { System.out.println( "Edit style action >> Run ..." ); //$NON-NLS-1$ } StyleBuilder builder = new StyleBuilder( PlatformUI.getWorkbench( ) .getDisplay( ) .getActiveShell( ), handle, StyleBuilder.DLG_TITLE_EDIT ); builder.open( ); return Boolean.TRUE; }
Example #22
Source File: UIUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
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; }
Example #23
Source File: BaseHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@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); } } } } } } }
Example #24
Source File: SarosSourceProvider.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public Map<Object, Object> getCurrentState() { Object session = sessionManager.getSession(); if (session == null) session = IEvaluationContext.UNDEFINED_VARIABLE; Map<Object, Object> map = new HashMap<Object, Object>(2); map.put(SAROS, saros); map.put(SAROS_SESSION, session); return map; }
Example #25
Source File: HandlerServiceUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Optionally returns with the current state of the workbench only and if only the * {@link PlatformUI#isWorkbenchRunning() workbench is running}. * * @return the current state of the running workbench. Returns with an {@link Optional#absent() absent} if the * workbench is not running or the {@link IHandlerService} is not available. */ public static Optional<IEvaluationContext> getCurrentWorkbenchState() { if (!isWorkbenchRunning()) { return absent(); } final Object service = getWorkbench().getService(IHandlerService.class); return service instanceof IHandlerService ? fromNullable(((IHandlerService) service).getCurrentState()) : absent(); }
Example #26
Source File: SarosSourceProvider.java From saros with GNU General Public License v2.0 | 5 votes |
private final void sessionChanged(final ISarosSession session) { SWTUtils.runSafeSWTAsync( null, new Runnable() { @Override public void run() { fireSourceChanged( ISources.WORKBENCH, SAROS_SESSION, session == null ? IEvaluationContext.UNDEFINED_VARIABLE : session); } }); }
Example #27
Source File: CloseViewHandlerPDETest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
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; }
Example #28
Source File: DeleteEditorFileHandler_FilePDETest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
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; }
Example #29
Source File: DeleteEditorFileHandler_FilePDETest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
@Test public void testEnablementWithUriEditorInput() throws IOException { File file = tempFolder.newFile( "foo.txt" ); IEvaluationContext evaluationContext = createEvaluationContext( mockUriEditorInput( file ) ); handler.setEnabled( evaluationContext ); assertThat( handler.isEnabled() ).isTrue(); }
Example #30
Source File: DeleteEditorFileHandler_FilePDETest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
@Test public void testEnablementWithPathEditorInput() throws IOException { File file = tempFolder.newFile( "foo.txt" ); IEvaluationContext evaluationContext = createEvaluationContext( mockPathEditorInput( file ) ); handler.setEnabled( evaluationContext ); assertThat( handler.isEnabled() ).isTrue(); }