Class ContextManager
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.core.commands.common.HandleObjectManager
-
- org.eclipse.core.commands.contexts.ContextManager
-
- All Implemented Interfaces:
IContextListener
public final class ContextManager extends HandleObjectManager implements IContextListener
A context manager tracks the sets of defined and enabled contexts within the application. The manager sends notification events to listeners when these sets change. It is also possible to retrieve any given context with its identifier.
This class is not intended to be extended by clients.
- Since:
- 3.1
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEBUG
This flag can be set totrue
if the context manager should print information toSystem.out
when certain boundary conditions occur.-
Fields inherited from class org.eclipse.core.commands.common.HandleObjectManager
definedHandleObjects, handleObjectsById
-
-
Constructor Summary
Constructors Constructor Description ContextManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActiveContext(String contextId)
Activates a context in this context manager.void
addContextManagerListener(IContextManagerListener listener)
Adds a listener to this context manager.void
contextChanged(ContextEvent contextEvent)
Notifies that one or more properties of an instance ofIContext
have changed.void
deferUpdates(boolean defer)
Informs the manager that a batch operation has started.Set
getActiveContextIds()
Returns the set of active context identifiers.Context
getContext(String contextId)
Gets the context with the given identifier.Set
getDefinedContextIds()
Returns the set of identifiers for those contexts that are defined.Context[]
getDefinedContexts()
Returns the those contexts that are defined.void
removeActiveContext(String contextId)
Deactivates a context in this context manager.void
removeContextManagerListener(IContextManagerListener listener)
Removes a listener from this context manager.void
setActiveContextIds(Set activeContextIds)
Changes the set of active contexts for this context manager.-
Methods inherited from class org.eclipse.core.commands.common.HandleObjectManager
checkId, getDefinedHandleObjectIds
-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
-
-
-
Method Detail
-
deferUpdates
public void deferUpdates(boolean defer)
Informs the manager that a batch operation has started.Note: You must insure that if you call
deferUpdates(true)
that nothing in your batched operation will prevent the matching call todeferUpdates(false)
.- Parameters:
defer
- true when starting a batch operation false when ending the operation- Since:
- 3.5
-
addActiveContext
public final void addActiveContext(String contextId)
Activates a context in this context manager.- Parameters:
contextId
- The identifier of the context to activate; must not benull
.
-
addContextManagerListener
public final void addContextManagerListener(IContextManagerListener listener)
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.- Parameters:
listener
- The listener to attach; must not benull
.
-
contextChanged
public final void contextChanged(ContextEvent contextEvent)
Description copied from interface:IContextListener
Notifies that one or more properties of an instance ofIContext
have changed. Specific details are described in theContextEvent
.- Specified by:
contextChanged
in interfaceIContextListener
- Parameters:
contextEvent
- the context event. Guaranteed not to benull
.
-
getActiveContextIds
public final Set getActiveContextIds()
Returns the set of active context identifiers.- Returns:
- The set of active context identifiers; this value may be
null
if no active contexts have been set yet. If the set is notnull
, then it contains only instances ofString
.
-
getContext
public final Context getContext(String contextId)
Gets the context with the given identifier. If no such context currently exists, then the context will be created (but be undefined).- Parameters:
contextId
- The identifier to find; must not benull
.- Returns:
- The context with the given identifier; this value will never be
null
, but it might be undefined. - See Also:
Context
-
getDefinedContextIds
public final Set getDefinedContextIds()
Returns the set of identifiers for those contexts that are defined.- Returns:
- The set of defined context identifiers; this value may be empty,
but it is never
null
.
-
getDefinedContexts
public final Context[] getDefinedContexts()
Returns the those contexts that are defined.- Returns:
- The defined contexts; this value may be empty, but it is never
null
. - Since:
- 3.2
-
removeActiveContext
public final void removeActiveContext(String contextId)
Deactivates a context in this context manager.- Parameters:
contextId
- The identifier of the context to deactivate; must not benull
.
-
removeContextManagerListener
public final void removeContextManagerListener(IContextManagerListener listener)
Removes a listener from this context manager.- Parameters:
listener
- The listener to be removed; must not benull
.
-
setActiveContextIds
public final void setActiveContextIds(Set activeContextIds)
Changes the set of active contexts for this context manager. The whole set is required so that internal consistency can be maintained and so that excessive recomputations do nothing occur.- Parameters:
activeContextIds
- The new set of active context identifiers; may benull
.
-
-