![]() ![]() |
||||
|
||||
Finally,
we must describe our action in the plug-ins plugin.xml file. Our action
is to be
runnable from both a toolbar button and a menu item. Actions are grouped into related sets of
actions called action sets. Thus before we describe our action, we must describe its
action
set. An action set is described using an actionSet XML element within an extension XML
element (within the top-level plugin XML element):
<extension point="org.eclipse.ui.actionSets">
<actionSet
id="edu.cmu.sei.osate.statistics.actionSet"
label="Statistics Action Set"
visible="true">
</actionSet>
</extension>
An
action set is always declared as an Eclipse extension point of type
org.eclipse.ui.actionSets. The id, label, and visible attributes of the
actionSet element provide an internal name for the action set, provide a human-readable
label for the action set, and indicate whether the contents of the action set are visible in the
Eclipse user interface, respectively.
Because
we would like a menu item for our action, we must also describe a menu in which the
action will be located. We use a menu element inside the actionSet:
<menu
id="analysisMenu"
label="Analysis
&Menu"/>
Once
again, we give the element an internal id, as well as a human-readable label. This label is
used in the menu bar. The character to use as the shortcut key is preceded by an ampersand
character, denoted in XML as &.
We
can now describe the action using the action element inside the actionSet:
<action
id="edu.cmu.sei.osate.statistics.DoModelStatistics"
label="&Model
statistics"
class="edu.cmu.sei.osate.statistics.DoModelStatistics"
icon="icons/stats.gif"
disabledIcon="icons/noStats.gif"
tooltip="Determine
model statistics"
enablesFor="1"
toolbarPath="edu.cmu.sei.osate.statistics.actionSet"
menubarPath="analysisMenu/statisticsGroup">
</action>
An
action also has an internal id and label. The label is used to label the action in the drop-
down menu. Again, in the label an ampersand precedes the shortcut key. The class attribute
names the fully qualified Java class that implements the action. In this case, that class is
DoModelStatistics. We can provide icons for the action: the icon and disabledIcon
attributes refer to the icons to use when the action is enabled and disabled, respectively. The
path to the image file is relative to the root of the plug-in project. The tooltip attribute
provides a short description of the action be displayed when the mouse pointer hovers over the
toolbar button or menu item.
Our
action should be enabled only when exactly one item is selected in the workspace, thus we
set attribute enablesFor="1".
Finally,
we locate the action within the user interface. The attribute toolbarPath describes
where in the toolbar the button for the action is located. Actions with the same path appear
near each other in the toolbar. The attribute menubarPath describes in which drop-down
menu the action should appear using the id of the menu element. Again, actions with the same
path appear near each other in the menu. Here we locate the action in the previously declared
analysisMenu. For a more detailed explanation of toolbar and menu paths see XXX.
This
is enough to make our action implemented by DoModelStatistics accessible within the
user interface. We can, however, further refine when the action is enabled by including within
the action element an enablement element that provides
a Boolean expression describing
when the action should be enabled:
<enablement>
<or>
<and>
<objectClass name="org.eclipse.core.resources.IFile"/>
<objectState name="extension" value="aaxl"/>
</and>
<objectClass
name="edu.cmu.sei.aadl.model.core.AObject"/>
<objectClass
name=
"org.eclipse.emf.edit.provider.IWrapperItemProvider"/>
</or>
</enablement>
In
this case, our action will be enabled when any of the three conditions are true (due to the or
element):
It
is a good idea to include the enablement expression in your action description because it
prevents the action from being enabled in situations where it obviously does not apply. |
||||
The
complete plugin.xml file for the model statistics
plug-in should look something like the
following:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
id="edu.cmu.sei.osate.statistics"
name="Statistics
Plug-in"
version="1.0.0"
provider-name=""
class="edu.cmu.sei.osate.statistics.StatisticsPlugin">
<runtime>
<library
name="statistics.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import
plugin="org.eclipse.ui"/>
<import
plugin="org.eclipse.core.runtime"/>
<import
plugin="edu.cmu.sei.aadl.model"/>
<import
plugin="org.eclipse.emf.ecore"/>
</requires>
<extension point="org.eclipse.ui.actionSets">
<actionSet
id="edu.cmu.sei.osate.statistics.actionSet"
label="Statistics Action Set"
visible="true">
<menu
id="analysisMenu"
label="Analysis &Menu"/>
<action
id="edu.cmu.sei.osate.statistics.DoModelStatistics"
label="&Model statistics"
class="edu.cmu.sei.osate.statistics.DoModelStatistics"
icon="icons/stats.gif"
disabledIcon="icons/noStats.gif"
tooltip="Determine model statistics"
enablesFor="1"
toolbarPath="edu.cmu.sei.osate.statistics.actionSet"
menubarPath="analysisMenu/statisticsGroup">
<enablement>
<or>
<and>
<objectClass
name="org.eclipse.core.resources.IFile"/>
<objectState name="extension" value="aaxl"/>
</and>
<objectClass
name="edu.cmu.sei.aadl.model.core.AObject"/>
<objectClass
name=
"org.eclipse.emf.edit.provider.IWrapperItemProvider"/>
</or>
</enablement>
</action>
</actionSet>
</extension>
</plugin> |
||||