@Override public Context getContext(String id) { Context ctx = contextManager.getContext(id); return ctx; }
@Override public Set getActiveContextIds() { return contextManager.getActiveContextIds(); }
@Inject void setContextIds(@Named(ACTIVE_CONTEXTS) @Optional Set<String> set) { if (set == null || set.isEmpty() || this.contextManager == null) { this.contextSet = ContextSet.EMPTY; if (this.contextManager != null) { this.contextManager.setActiveContextIds(Collections.EMPTY_SET); } return; } ArrayList<@NonNull Context> contexts = new ArrayList<>(); for (String id : set) { Context ctx = this.contextManager.getContext(id); if( ctx != null ) { contexts.add(ctx); } } this.contextSet = BindingTableManager.createContextSet(contexts); this.contextManager.setActiveContextIds(set); }
@PostConstruct public void init(IEclipseContext context) { // global context service. ContextManager manager = context.get(ContextManager.class); if (manager == null) { manager = new ContextManager(); context.set(ContextManager.class, manager); } context.set(EContextService.class.getName(), new ContextContextFunction()); context.set(IServiceConstants.ACTIVE_CONTEXTS, new ActiveContextsFunction()); context.runAndTrack(new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { ContextManager manager = context.get(ContextManager.class); if (manager != null) { Object s = context.get(IServiceConstants.ACTIVE_CONTEXTS); if (s instanceof Set) { manager.setActiveContextIds((Set<?>) s); } else { manager.setActiveContextIds(Collections.EMPTY_SET); } } return true; } }); } }
public void setEnabledContextIds(Set enabledContextIds) { contextManager.setActiveContextIds(enabledContextIds); } }
@Override public void addContextManagerListener( final IContextManagerListener listener) { contextManager.addContextManagerListener(listener); }
@Override public final void contextChanged(final ContextEvent contextEvent) { if (contextEvent.isDefinedChanged()) { final Context context = contextEvent.getContext(); final String contextId = context.getId(); final boolean contextIdAdded = context.isDefined(); if (contextIdAdded) { definedHandleObjects.add(context); } else { definedHandleObjects.remove(context); } if (isListenerAttached()) { fireContextManagerChanged(new ContextManagerEvent(this, contextId, contextIdAdded, false, null)); } } }
/** * Set the manager to cache context id changes. * * @param cache * <code>true</code> to turn caching on, <code>false</code> * to turn caching off and send an event if necessary. * @since 3.3 */ private void setEventCaching(boolean cache) { if (caching == cache) { return; } caching = cache; boolean fireChange = activeContextsChange; Set<String> holdOldIds = (oldIds == null ? Collections.EMPTY_SET : oldIds); if (caching) { oldIds = new HashSet<>(activeContextIds); } else { oldIds = null; } activeContextsChange = false; if (!caching && fireChange) { fireContextManagerChanged(new ContextManagerEvent(this, null, false, true, holdOldIds)); } } }
/** * Adds a listener to this context manager. The listener will be notified * when the set of defined contexts changes. This can be used to track the * global appearance and disappearance of contexts. * * @param listener * The listener to attach; must not be <code>null</code>. */ public final void addContextManagerListener(final IContextManagerListener listener) { addListenerObject(listener); }
/** * Gets the context with the given identifier. If no such context currently * exists, then the context will be created (but be undefined). * * @param contextId * The identifier to find; must not be <code>null</code>. * @return The context with the given identifier; this value will never be * <code>null</code>, but it might be undefined. * @see Context */ public final Context getContext(final String contextId) { checkId(contextId); Context context = (Context) handleObjectsById.get(contextId); if (context == null) { context = new Context(contextId); handleObjectsById.put(contextId, context); context.addContextListener(this); } return context; }
@PostConstruct public void init(IEclipseContext context) { // global context service. ContextManager manager = context.get(ContextManager.class); if (manager == null) { manager = new ContextManager(); context.set(ContextManager.class, manager); } context.set(EContextService.class.getName(), new ContextContextFunction()); context.set(IServiceConstants.ACTIVE_CONTEXTS, new ActiveContextsFunction()); context.runAndTrack(new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { ContextManager manager = context.get(ContextManager.class); if (manager != null) { Object s = context.get(IServiceConstants.ACTIVE_CONTEXTS); if (s instanceof Set) { manager.setActiveContextIds((Set) s); } else { manager.setActiveContextIds(Collections.EMPTY_SET); } } return true; } }); } }
@Override public Collection<String> getActiveContextIds() { @SuppressWarnings("unchecked") Set<String> set = (Set<String>) eclipseContext.get(IServiceConstants.ACTIVE_CONTEXTS); if (set != null) { contextManager.setActiveContextIds(set); } return set; }
/** * Constructs a new instance of <code>MutableContextManager</code>. The * registry is created on the platform's extension registry. * * @param contextManager * The manager which will provided the real support; must not be * <code>null</code>. */ public ContextManagerLegacyWrapper(ContextManager contextManager) { if (contextManager == null) { throw new NullPointerException("The context manager cannot be null"); //$NON-NLS-1$ } this.contextManager = contextManager; this.contextManager.addContextManagerListener(this); }
@Override public final void contextChanged(final ContextEvent contextEvent) { if (contextEvent.isDefinedChanged()) { final Context context = contextEvent.getContext(); final String contextId = context.getId(); final boolean contextIdAdded = context.isDefined(); if (contextIdAdded) { definedHandleObjects.add(context); } else { definedHandleObjects.remove(context); } if (isListenerAttached()) { fireContextManagerChanged(new ContextManagerEvent(this, contextId, contextIdAdded, false, null)); } } }
/** * Set the manager to cache context id changes. * * @param cache * <code>true</code> to turn caching on, <code>false</code> * to turn caching off and send an event if necessary. * @since 3.3 */ private void setEventCaching(boolean cache) { if (caching == cache) { return; } caching = cache; boolean fireChange = activeContextsChange; Set<String> holdOldIds = (oldIds == null ? Collections.EMPTY_SET : oldIds); if (caching) { oldIds = new HashSet<>(activeContextIds); } else { oldIds = null; } activeContextsChange = false; if (!caching && fireChange) { fireContextManagerChanged(new ContextManagerEvent(this, null, false, true, holdOldIds)); } } }
/** * Adds a listener to this context manager. The listener will be notified * when the set of defined contexts changes. This can be used to track the * global appearance and disappearance of contexts. * * @param listener * The listener to attach; must not be <code>null</code>. */ public final void addContextManagerListener(final IContextManagerListener listener) { addListenerObject(listener); }
/** * Gets the context with the given identifier. If no such context currently * exists, then the context will be created (but be undefined). * * @param contextId * The identifier to find; must not be <code>null</code>. * @return The context with the given identifier; this value will never be * <code>null</code>, but it might be undefined. * @see Context */ public final Context getContext(final String contextId) { checkId(contextId); Context context = (Context) handleObjectsById.get(contextId); if (context == null) { context = new Context(contextId); handleObjectsById.put(contextId, context); context.addContextListener(this); } return context; }
@Override public Context getContext(String id) { Context ctx = contextManager.getContext(id); return ctx; }
@Override public boolean isEnabled() { return contextManager.getActiveContextIds().contains( wrappedContext.getId()); }
@PostConstruct public void init(IEclipseContext context) { // global context service. ContextManager manager = context.get(ContextManager.class); if (manager == null) { manager = new ContextManager(); context.set(ContextManager.class, manager); } context.set(EContextService.class.getName(), new ContextContextFunction()); context.set(IServiceConstants.ACTIVE_CONTEXTS, new ActiveContextsFunction()); context.runAndTrack(new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { ContextManager manager = context.get(ContextManager.class); if (manager != null) { Object s = context.get(IServiceConstants.ACTIVE_CONTEXTS); if (s instanceof Set) { manager.setActiveContextIds((Set<?>) s); } else { manager.setActiveContextIds(Collections.EMPTY_SET); } } return true; } }); } }