private void fillArgs(Object[] actualArgs, String[] keys, boolean[] active) { for (int i = 0; i < keys.length; i++) { if (keys[i] == null) continue; IEclipseContext targetContext = (active[i]) ? context.getActiveLeaf() : context; if (ECLIPSE_CONTEXT_NAME.equals(keys[i])) actualArgs[i] = targetContext; else if (targetContext.containsKey(keys[i])) actualArgs[i] = targetContext.get(keys[i]); } }
private IEclipseContext prepareContext() { final IEclipseContext parentContext = (IEclipseContext) getSite().getService(IEclipseContext.class); final IEclipseContext context = parentContext.getActiveLeaf(); context.set(RedProjectEditorInput.class, editorInput); context.set(IEditorSite.class, getEditorSite()); context.set(RedProjectEditor.class, this); ContextInjectionFactory.inject(this, context); return context; }
/** * Dispatch the given object to a dispatch handler if a matching filter can be found for the * object's class. The dispatch handler is instantiated using the {@link ContextInjectionFactory}, * which injects the handler using the provided context. * * @param object Object to dispatch * @param intent Intent that loaded the dispatched object, <code>null</code> if object is not the * result of an intent * @param context Context to use for injection into the handler * @return True if a dispatch handler was found to handle the object */ public boolean dispatch(Object object, Intent intent, IEclipseContext context) { if (object == null) { return false; } DispatchFilter filter = findFilter(object); Class<? extends IDispatchHandler> handlerClass = filter == null ? null : filter.getHandler(); if (handlerClass == null) { logger.error("Could not find dispatch handler for object: " + object); // $NON-NLS-1$ return false; } IEclipseContext activeLeaf = context.getActiveLeaf(); IEclipseContext child = activeLeaf.createChild(); IDispatchHandler handler = ContextInjectionFactoryThreadSafe.make(handlerClass, child); handler.handle(object, intent); return true; }
@Override public void dispose() { final IEclipseContext parentContext = (IEclipseContext) getEditorSite().getService(IEclipseContext.class); final IEclipseContext context = parentContext.getActiveLeaf(); for (final IEditorPart part : parts) { ContextInjectionFactory.uninject(part, context); } if (resourceListener != null) { ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener); } super.dispose(); SwtThread.asyncExec( new Runnable() { @Override public void run() { final IDecoratorManager manager = PlatformUI.getWorkbench().getDecoratorManager(); manager.update(RobotValidationExcludedDecorator.ID); } }); }
@Override public boolean update(IEclipseContext eventsContext, int eventType, Object[] extraArguments) { if (eventType == ContextChangeEvent.INITIAL) { // needs to be done inside runnable to establish dependencies for (int i = 0; i < keys.length; i++) { if (keys[i] == null) continue; IEclipseContext targetContext = (active[i]) ? context.getActiveLeaf() : context; if (ECLIPSE_CONTEXT_NAME.equals(keys[i])) { result[i] = targetContext; IEclipseContext parent = targetContext.getParent(); // creates pseudo-link if (parent == null) targetContext.get(ECLIPSE_CONTEXT_NAME); // pseudo-link in case there is no parent } else if (targetContext.containsKey(keys[i])) result[i] = targetContext.get(keys[i]); } return true; } if (eventType == ContextChangeEvent.DISPOSE) { if (eventsContext == context) { ContextObjectSupplier originatingSupplier = eventsContext.getLocal(ContextObjectSupplier.class); requestor.disposed(originatingSupplier); return false; } } else if (eventType == ContextChangeEvent.UNINJECTED) { if (eventsContext == context) { ContextObjectSupplier originatingSupplier = eventsContext.getLocal(ContextObjectSupplier.class); return requestor.uninject(extraArguments[0], originatingSupplier); } } else { if (!requestor.isValid()) return false; // remove this listener requestor.resolveArguments(false); requestor.execute(); } return true; }
private void activate(MPart part, boolean requiresFocus, boolean activateBranch) { if (part == null) { if (constructed && activePart != null) { firePartDeactivated(activePart); } activePart = part; return; } // Delegate activations to a CompositePart's inner part (if any) if (part instanceof MCompositePart) { if (part.getContext() != null) { IEclipseContext pContext = part.getContext(); if (pContext.getActiveLeaf() != null) { MPart inner = pContext.getActiveLeaf().get(MPart.class); if (inner != null) { part = inner; } } } } // only activate parts that is under our control if (!isInContainer(part)) { return; } MWindow window = getWindow(); IEclipseContext windowContext = window.getContext(); // check if the active part has changed or if we are no longer the active window if (windowContext.getParent().getActiveChild() == windowContext && part == activePart) { // insert it in the beginning of the activation history, it may not have been inserted // pending when this service was instantiated partActivationHistory.prepend(part); UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part); return; } if (contextService != null) { contextService.deferUpdates(true); } if (contextManager != null) { contextManager.deferUpdates(true); } MPart lastActivePart = activePart; activePart = part; if (constructed && lastActivePart != null && lastActivePart != activePart) { firePartDeactivated(lastActivePart); } try { // record any sibling into the activation history if necessary, this will allow it to be // reselected again in the future as it will be an activation candidate in the future, // this // prevents other unrendered elements from being selected arbitrarily which would cause // unwanted bundle activation recordStackActivation(part); delegateBringToTop(part); window.getParent().setSelectedElement(window); partActivationHistory.activate(part, activateBranch); if (requiresFocus) { IPresentationEngine pe = part.getContext().get(IPresentationEngine.class); pe.focusGui(part); } firePartActivated(part); UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part); } finally { if (contextService != null) { contextService.deferUpdates(false); } if (contextManager != null) { contextManager.deferUpdates(false); } } }
/** * @param context the context to start the lookup process * @param commandId * @return a handler, or <code>null</code> */ public static Object lookUpHandler(IEclipseContext context, String commandId) { return context.getActiveLeaf().get(H_ID + commandId); }
public IEclipseContext getExecutionContext() { return context.getActiveLeaf(); }