In the following text, we will be using the following terms to distinguish between the two uses of activities:
Certain user operations serve as trigger points for enabling an activity. For example, creating a new Java project could trigger the enabling of the Java development activity. In this way, users are exposed to new functionality as they need it, and gradually learn about the activities that are available to them and how they affect the UI. When a user first starts the platform, it is desirable for as many activities as possible to be disabled, so that the application is as simple as possible. Choices made in the welcome page can help determine what activities should be enabled.
There are certain places in the UI where the user can ask to see all contributions - even the ones filtered by conventional activities, for example in the New... wizard. UI elements that are filtered by conventional activities can also still be used programmatically using the Eclipse API.
Activities are a higher level of organization. Individual UI contributions are not aware of activities and do not refer to the activities in their extension definitions. Rather, the activities are expected to be configured at a higher level such as platform integration/configuration or product install. Individual plug-ins typically do not define new activities, unless the plug-in is a systems-level plug-in defined by a systems integrator. In a typical scenario, a systems integrator determines how functions are grouped into activities and which ones are enabled by default. Activities are associated with UI contributions using activity pattern bindings, patterns that are matched against the id of the UI contributions made by plug-ins. An example will help demonstrate these concepts.
<extension point="org.eclipse.ui.activities"> <activity name="Java Activity" description="Developing Java Software" id="org.eclipse.javaDevelopment"> </activity> <activity name="Plug-in Activity" description="Developing Eclipse Plug-ins" id="org.eclipse.plugInDevelopment"> </activity> ...Activities are assigned a name and description. This name and description can be shown to the user whenever the they are enabling and disabling conventional activities, or otherwise shown information about an activity. The id of the activity is used when defining pattern bindings or other relationships between activities. For example, for conventional activities, it is possible to declare that one activity requires another activity.
<activityRequirementBinding activityId="org.eclipse.plugInDevelopment" requiredActivityId="org.eclipse.javaDevelopment"> </activityRequirementBinding>
<category name="Development" description="Software Development" id="org.eclipse.categories.developmentCategory"> </category> <categoryActivityBinding activityId="org.eclipse.javaDevelopment" categoryId="org.eclipse.categories.developmentCategory"> </categoryActivityBinding> <categoryActivityBinding activityId="org.eclipse.plugInDevelopment" categoryId="org.eclipse.categories.developmentCategory"> </categoryActivityBinding>
plug-in-identifier + "/" + local-identifierFor example, the following activity pattern binding states that a UI contribution from any JDT plug-in id (org.eclipse.jdt.*) is associated with the Java development activity regardless of its local identifier (.*).
<activityPatternBinding activityId="org.eclipse.javaDevelopment" pattern="org\.eclipse\.jdt\..*/.*"> </activityPatternBinding>The next binding is more specific. It states that the contribution named javanature defined in the JDT core (org.eclipse.jdt.core) is associated with the Java development activity.
<activityPatternBinding activityId="org.eclipse.javaDevelopment" pattern="org\.eclipse\.jdt\.core/javanature"> </activityPatternBinding>It is also possible to refer to a single UI contribution using its id without having to use regular expression syntax if the attribute isEqualityPattern is set to true.
<activityPatternBinding activityId="org.eclipse.javaDevelopment" pattern="org\.eclipse\.jdt\..*/.*"> </activityPatternBinding>When the Java development activity is disabled, help books contributed by JDT plug-ins, or any sub-books (TOCs linked to, or linked by JDT books), even if contributed by a different plug-in, will not show in the help UI. The topics defined in these books will also not show in the search results. In the case where JDT TOCs were not displayed as primary TOCs, but were instead linked from another TOC to appear as sub-trees in a book, disabling the JDT activity has the effect of hiding the sub-trees. The containing book will appear to define less topics in the UI. Using more specific binding, it is possible to associate activities with selected TOCs from plug-ins that contribute multiple TOCs to the help system. For example, the following activity pattern binding associates the "Examples" TOC with the Java development examples activity.
<activityPatternBinding activityId="org.eclipse.javaDevelopmentExamples" pattern="org\.eclipse\.jdt\.doc\.isv\.topics_Samples.xml"> </activityPatternBinding>With such pattern binding, disabling the Java development examples activity will hide the "Examples" section from the "JDT Plug-in Developer Guide" book.
IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport(); IActivityManager activityManager = workbenchActivitySupport.getActivityManager();The following snippet enables the Java development activity (if it is not already enabled). It shows a simplified version of a trigger.
... //the user did something Java related. Enable the Java activity. Set enabledActivityIds = new HashSet(activityManager.getEnabledActivityIds()); if (enabledIds.add("org.eclipse.javaDevelopment")) workbenchActivitySupport.setEnabledActivityIds(enabledActivityIds);
IActivityManager also defines protocol for getting all defined activity and category ids, and for getting the associated IActivity or ICategory for a particular id. These objects can be used to traverse the definition for an activity or category in API, such as getting the pattern bindings or requirement bindings. Listeners can be registered on the activity manager or on the activities and categories themselves to detect changes in the definition of a particular activity or in the activity manager itself. See the package org.eclipse.ui.activities for more information.
Note that the API methods will silently ignore attempts to enable expression-based activities, or similar requests that do not apply to expression-based activities.
The following code snippets show how to control the variable "rightsVariable" that appears in the activity's "enabledWhen" expression. New variables can be added through the org.eclipse.ui.services extension point as subclasses of AbstractSourceProvider.
import java.util.HashMap;
...
import org.eclipse.ui.AbstractSourceProvider;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.services.IEvaluationService;
public class RightsSourceProvider extends AbstractSourceProvider {
public final static String RIGHT_FORBIDDEN = "grantShowForbidden";
public final static String RIGHTS_VARIABLE = "rightsVariable";
private final static String[] PROVIDED_SOURCE_NAMES = new String[] { RIGHTS_VARIABLE };
private final static Map<String, List<String>> stateMap = new HashMap<String, List<String>>();
public Map getCurrentState() {
/* "YourRightsHandler" is here just an example for a
static class
* which returns the list of
rights as a list of strings. */
stateMap.put(RIGHTS_VARIABLE, YourRightsHandler.getUserRights());
return stateMap;
}
public String[] getProvidedSourceNames() {
return PROVIDED_SOURCE_NAMES;
}
/* This triggers an update of the rights variable state, and
will update also all
* listeners to the evaluation
service. So that every menu point, which is also
* expression
controlled, gets updated too. */
public void updateRights() {
fireSourceChanged(0, getCurrentState());
}
// ...
}