Eclipse Platform
Release 3.1

org.eclipse.ui.contexts
Interface IContextService


public interface IContextService

Provides services related to contexts in the Eclipse workbench. This provides access to contexts.

This interface should not be implemented or extended by clients.

Since:
3.1

Field Summary
static String CONTEXT_ID_DIALOG
          The identifier for the context that is active when a shell registered as a dialog.
static String CONTEXT_ID_DIALOG_AND_WINDOW
          The identifier for the context that is active when a shell is registered as either a window or a dialog.
static String CONTEXT_ID_WINDOW
          The identifier for the context that is active when a shell is registered as a window.
static int TYPE_DIALOG
          The type used for registration indicating that the shell should be treated as a dialog.
static int TYPE_NONE
          The type used for registration indicating that the shell should not receive any key bindings be default.
static int TYPE_WINDOW
          The type used for registration indicating that the shell should be treated as a window.
 
Method Summary
 IContextActivation activateContext(String contextId)
           Activates the given context within the context of this service.
 IContextActivation activateContext(String contextId, Expression expression, int sourcePriorities)
           Activates the given context within the context of this service.
 void addSourceProvider(ISourceProvider provider)
          Adds a source provider to this service.
 void deactivateContext(IContextActivation activation)
          Deactivates the given context within the context of this service.
 void deactivateContexts(Collection activations)
          Deactivates the given contexts within the context of this service.
 Context getContext(String contextId)
          Retrieves the context with the given identifier.
 Collection getDefinedContextIds()
          Returns the collection of the identifiers for all of the defined contexts in the workbench.
 int getShellType(Shell shell)
          Returns the shell type for the given shell.
 void readRegistry()
           Reads the context information from the registry and the preferences.
 boolean registerShell(Shell shell, int type)
           Registers a shell to automatically promote or demote some basic types of contexts.
 void removeSourceProvider(ISourceProvider provider)
          Removes a source provider from this service.
 boolean unregisterShell(Shell shell)
           Unregisters a shell that was previously registered.
 

Field Detail

CONTEXT_ID_DIALOG

public static final String CONTEXT_ID_DIALOG
The identifier for the context that is active when a shell registered as a dialog.

See Also:
Constant Field Values

CONTEXT_ID_DIALOG_AND_WINDOW

public static final String CONTEXT_ID_DIALOG_AND_WINDOW
The identifier for the context that is active when a shell is registered as either a window or a dialog.

See Also:
Constant Field Values

CONTEXT_ID_WINDOW

public static final String CONTEXT_ID_WINDOW
The identifier for the context that is active when a shell is registered as a window.

See Also:
Constant Field Values

TYPE_DIALOG

public static final int TYPE_DIALOG
The type used for registration indicating that the shell should be treated as a dialog. When the given shell is active, the "In Dialogs" context should also be active.

See Also:
Constant Field Values

TYPE_NONE

public static final int TYPE_NONE
The type used for registration indicating that the shell should not receive any key bindings be default. When the given shell is active, we should not provide any EnabledSubmission instances for the "In Dialogs" or "In Windows" contexts.

See Also:
Constant Field Values

TYPE_WINDOW

public static final int TYPE_WINDOW
The type used for registration indicating that the shell should be treated as a window. When the given shell is active, the "In Windows" context should also be active.

See Also:
Constant Field Values
Method Detail

activateContext

public IContextActivation activateContext(String contextId)

Activates the given context within the context of this service. If this service was retrieved from the workbench, then this context will be active globally. If the service was retrieved from a nested component, then the context will only be active within that component.

Also, it is guaranteed that the contexts submitted through a particular service will be cleaned up when that services is destroyed. So, for example, a service retrieved from a IWorkbenchPartSite would deactivate all of its contexts when the site is destroyed.

Parameters:
contextId - The identifier for the context which should be activated; must not be null.
Returns:
A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.

activateContext

public IContextActivation activateContext(String contextId,
                                          Expression expression,
                                          int sourcePriorities)

Activates the given context within the context of this service. The context becomes active when expression evaluates to true.

Also, it is guaranteed that the context submitted through a particular service will be cleaned up when that services is destroyed. So, for example, a service retrieved from a IWorkbenchPartSite would deactivate all of its handlers when the site is destroyed.

Parameters:
contextId - The identifier for the context which should be activated; must not be null.
expression - This expression must evaluate to true before this context will really become active. The expression must not be null.
sourcePriorities - The source priorities for the expression.
Returns:
A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.
See Also:
ISources

addSourceProvider

public void addSourceProvider(ISourceProvider provider)
Adds a source provider to this service. A source provider will notify the service when the source it provides changes. An example of a source might be an active editor or the current selection. This amounts to a pluggable state tracker for the service.

Parameters:
provider - The provider to add; must not be null.

deactivateContext

public void deactivateContext(IContextActivation activation)
Deactivates the given context within the context of this service. If the handler was context with a different service, then it must be deactivated from that service instead. It is only possible to retract a context activation with this method. That is, you must have the same IContextActivation used to activate the context.

Parameters:
activation - The token that was returned from a call to activateContext; must not be null.

deactivateContexts

public void deactivateContexts(Collection activations)
Deactivates the given contexts within the context of this service. If the contexts were activated with a different service, then they must be deactivated from that service instead. It is only possible to retract context activations with this method. That is, you must have the same IContextActivation instances used to activate the contexts.

Parameters:
activations - The tokens that were returned from a call to activateContext. This collection must only contain instances of IContextActivation. The collection must not be null.

getContext

public Context getContext(String contextId)
Retrieves the context with the given identifier. If no such context exists, then an undefined context with the given id is created.

Parameters:
contextId - The identifier to find; must not be null.
Returns:
A context with the given identifier, either defined or undefined.

getDefinedContextIds

public Collection getDefinedContextIds()
Returns the collection of the identifiers for all of the defined contexts in the workbench.

Returns:
The collection of context identifiers (String) that are defined; never null, but may be empty.

getShellType

public int getShellType(Shell shell)
Returns the shell type for the given shell.

Parameters:
shell - The shell for which the type should be determined. If this value is null, then IContextService.TYPE_NONE is returned.
Returns:
IContextService.TYPE_WINDOW, IContextService.TYPE_DIALOG, or IContextService.TYPE_NONE.

readRegistry

public void readRegistry()

Reads the context information from the registry and the preferences. This will overwrite any of the existing information in the context service. This method is intended to be called during start-up. When this method completes, this context service will reflect the current state of the registry and preference store.


registerShell

public boolean registerShell(Shell shell,
                             int type)

Registers a shell to automatically promote or demote some basic types of contexts. The "In Dialogs" and "In Windows" contexts are provided by the system. This a convenience method to ensure that these contexts are promoted when the given is shell is active.

If a shell is registered as a window, then the "In Windows" context is enabled when that shell is active. If a shell is registered as a dialog -- or is not registered, but has a parent shell -- then the "In Dialogs" context is enabled when that shell is active. If the shell is registered as none -- or is not registered, but has no parent shell -- then the neither of the contexts will be enabled (by us -- someone else can always enabled them).

If the provided shell has already been registered, then this method will change the registration.

Parameters:
shell - The shell to register for key bindings; must not be null.
type - The type of shell being registered. This value must be one of the constants given in this interface.
Returns:
true if the shell had already been registered (i.e., the registration has changed); false otherwise.

removeSourceProvider

public void removeSourceProvider(ISourceProvider provider)
Removes a source provider from this service. Most of the time, this method call is not required as source provider typically share the same life span as the workbench itself.

Parameters:
provider - The provider to remove; must not be null.

unregisterShell

public boolean unregisterShell(Shell shell)

Unregisters a shell that was previously registered. After this method completes, the shell will be treated as if it had never been registered at all. If you have registered a shell, you should ensure that this method is called when the shell is disposed. Otherwise, a potential memory leak will exist.

If the shell was never registered, or if the shell is null, then this method returns false and does nothing.

Parameters:
shell - The shell to be unregistered; does nothing if this value is null.
Returns:
true if the shell had been registered; false otherwise.

Eclipse Platform
Release 3.1

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.