Jump to: navigation, search

Difference between revisions of "FAQ How do I add activities to my plug-in?"

 
m (Added <source lang="xml">)
 
Line 31: Line 31:
 
A category is simply a container for one or more activities.  Here is a  
 
A category is simply a container for one or more activities.  Here is a  
 
simple category defined in the FAQ Examples plug-in:
 
simple category defined in the FAQ Examples plug-in:
<pre>
+
<source lang="xml">
  &lt;category
+
<category
      name=&quot;FAQ Category&quot;
+
    name="FAQ Category"
      id=&quot;org.eclipse.faq.faqCategory&quot;&gt;
+
    id="org.eclipse.faq.faqCategory">
  &lt;/category&gt;
+
</category>
</pre>
+
</source>
 
<i>Note:</i> All configuration elements in this FAQ must be contained in an
 
<i>Note:</i> All configuration elements in this FAQ must be contained in an
 
extension to the <tt>org.eclipse.ui.activities</tt> extension point. The
 
extension to the <tt>org.eclipse.ui.activities</tt> extension point. The
Line 44: Line 44:
 
Next, you need to define one or more activities and connect them to
 
Next, you need to define one or more activities and connect them to
 
a category.
 
a category.
<pre>
+
<source lang="xml">
  &lt;activity
+
<activity
      name=&quot;FAQ Activity&quot;
+
  name="FAQ Activity"
      id=&quot;org.eclipse.faq.faqActivity&quot;&gt;
+
  id="org.eclipse.faq.faqActivity">
  &lt;/activity&gt;
+
</activity>
  &lt;categoryActivityBinding
+
<categoryActivityBinding
      activityId=&quot;org.eclipse.faq.faqActivity&quot;
+
  activityId="org.eclipse.faq.faqActivity"
      categoryId=&quot;org.eclipse.faq.faqCategory&quot;&gt;
+
  categoryId="org.eclipse.faq.faqCategory">
  &lt;/categoryActivityBinding&gt;
+
</categoryActivityBinding>
</pre>
+
</source>
 
Note that activities, categories, and bindings are all separate top-level
 
Note that activities, categories, and bindings are all separate top-level
 
elements.  This allows you to define each of them in different plug-ins
 
elements.  This allows you to define each of them in different plug-ins
Line 77: Line 77:
 
This all sounds very confusing, so let&#146;s look at a
 
This all sounds very confusing, so let&#146;s look at a
 
concrete example from the FAQ Examples plug-in:
 
concrete example from the FAQ Examples plug-in:
<pre>
+
<source lang="xml">
  &lt;activityPatternBinding
+
<activityPatternBinding
      activityId=&quot;org.eclipse.faq.faqActivity&quot;
+
    activityId="org.eclipse.faq.faqActivity"
      pattern=&quot;org.eclipse.faq*&quot;&gt;
+
    pattern="org.eclipse.faq*">
  &lt;/activityPatternBinding&gt;
+
</activityPatternBinding>
</pre>
+
</source>
 
This pattern binding says, when <tt>faqActivity</tt> is disabled, hide
 
This pattern binding says, when <tt>faqActivity</tt> is disabled, hide
 
all functionality associated with any plug-in whose ID starts with  
 
all functionality associated with any plug-in whose ID starts with  
Line 88: Line 88:
  
 
Let&#146;s try a slightly more complicated pattern:
 
Let&#146;s try a slightly more complicated pattern:
<pre>
+
<source lang="xml">
  &lt;activityPatternBinding
+
<activityPatternBinding
       activityId=&quot;org.eclipse.faq.faqWizard&quot;
+
       activityId="org.eclipse.faq.faqWizard"
       pattern=&quot;org.eclipse.faq.examples/[a-z[.]]*addingWizard&quot;&gt;
+
       pattern="org.eclipse.faq.examples/[a-z[.]]*addingWizard">
  &lt;/activityPatternBinding&gt;
+
</activityPatternBinding>
</pre>
+
</source>
 
This pattern is much more selective.  It will disable functionality only in
 
This pattern is much more selective.  It will disable functionality only in
 
the <tt>org.eclipse.faq.examples</tt> plug-in whose
 
the <tt>org.eclipse.faq.examples</tt> plug-in whose

Latest revision as of 18:09, 9 June 2008


You don’t. An important feature of activities is that they are not defined in the plug-ins alongside the functionality they describe. Because activities are designed to solve a scaling problem when large numbers of plug-ins are used together, attempting to define them at the plug-in level would be futile. For example, let’s say that you create a small handful of plug-ins that implement development tools for the PHP programming language. If you are providing only basic editing and debugging functionality, chances are that your plug-ins alone do not present a UI scalability problem. However, if someone then takes your small handful of plug-ins and combines them with 500 more plug-ins from other sources, the UI starts to become cluttered and difficult to use. If you introduced a couple of activities in your plug-in to separate different types of PHP development and if the other 500 plug-ins also introduced activities, the activities themselves would become cluttered and unusable. The moral of the story is that activities need to be defined at the level where the scalability problem exists.


Typically activities will be defined by an administrator or product manager who is assembling an end-user application from a large pool of plug-ins. A power user who wants to coordinate a large set of plug-ins downloaded from the Web also may establish some activities. The administrator or power user defines activities entirely declaratively in a plugin.xml file in a plug-in. No Java code is involved! Let’s dig into the actual mechanics of defining activities. Before you create any activities, you need to establish one or more activity categories. A category is simply a container for one or more activities. Here is a simple category defined in the FAQ Examples plug-in:

<category
    name="FAQ Category"
    id="org.eclipse.faq.faqCategory">
</category>

Note: All configuration elements in this FAQ must be contained in an extension to the org.eclipse.ui.activities extension point. The ID and name of the extension itself are not used.


Next, you need to define one or more activities and connect them to a category.

<activity
   name="FAQ Activity"
   id="org.eclipse.faq.faqActivity">
</activity>
<categoryActivityBinding
   activityId="org.eclipse.faq.faqActivity"
   categoryId="org.eclipse.faq.faqCategory">
</categoryActivityBinding>

Note that activities, categories, and bindings are all separate top-level elements. This allows you to define each of them in different plug-ins if desired.

After creating appropriate activities and categories, we get to the interesting part, connecting functionality to activities. An activity-pattern binding associates an activity with a regular expression that is used to match identifiers. The syntax of the regular expressions conforms to the usage defined in java.util.regex.Pattern. The identifiers describing functionality that can be filtered from the UI are of the form <plugin-id>/<local-id> or simply <local-id>.

When an activity is enabled, all functionality that matches the identifier patterns associated with that activity will be visible. If an identifier matches a disabled activity and does not match any enabled activity, the functionality associated with that ID will be invisible. Interpretation of exactly what <local-id> means is left up to the UI component that is doing the filtering, but typically it is the ID of an extension.

This all sounds very confusing, so let’s look at a concrete example from the FAQ Examples plug-in:

<activityPatternBinding
    activityId="org.eclipse.faq.faqActivity"
    pattern="org.eclipse.faq*">
</activityPatternBinding>

This pattern binding says, when faqActivity is disabled, hide all functionality associated with any plug-in whose ID starts with org.eclipse.faq.

Let’s try a slightly more complicated pattern:

<activityPatternBinding
      activityId="org.eclipse.faq.faqWizard"
      pattern="org.eclipse.faq.examples/[a-z[.]]*addingWizard">
</activityPatternBinding>

This pattern is much more selective. It will disable functionality only in the org.eclipse.faq.examples plug-in whose ID ends with the string addingWizard. This will disable only the addingWizard extension from the org.eclipse.faq.examples plug-in. By selecting your patterns carefully, you can define precisely which parts of the UI are filtered by a given activity.


To learn more about regular expressions in Java, see Jeffrey E. F. Friedl, Mastering Regular Expressions (O'Reilly, 1997).


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.