Java Reference
In-Depth Information
10.9.2 Custom Style
To add an action that facilitates the switching of figures for our intermediate
event, we need someplace to store the current state. Clearly, the underlying
domain model is an inappropriate place to store information regarding the visual
display of its information, which leaves us with the runtime's notation model. As
we saw from the discussion in Section 10.2, “Notation Model,” the Style element
can be extended to store the additional information we need. While we're at it,
we'll add a field to store a URL to allow hyperlinking from our notation element
to an external source.
TIP
Adding a new
Style
is one approach, but note that the
View
element of
the runtime's notation model extends
ecore::EModelElement
and,
therefore, is capable of holding
EAnnotation
elements. So instead of
adding a new style, we could just create a new annotation on our
View
element and use that to hold additional information. In fact, the generated
diagrams use this approach for shortcut decorators.
In a new
/model
folder within our custom diagram plug-in, we can create a
style.ecore
Ecore model. We' only need to create a single class named
CustomStyle
with
default:EBoolean
and
hyperlink:EString
attributes.
Using
Load Resource
we'll browse the registered models and select our GMF
runtime notation model, identified by its NS URI of
http://www.eclipse.
extend the
Style
class in the notation model. Create an EMF generator model
named
style.genmodel
and set the
Base Package
property of the style pack-
age to
org.eclipse.scenario.diagram.custom
. Generating the model
code only to our custom diagram plug-in enables us to move forward with imple-
menting our action for switching figures. In our
plugin.xml
file, we'll create a
new extension to the
contributionItemProviders
extension-point.
<extension point="org.eclipse.gmf.runtime.common.ui.services.action.
contributionItemProviders">
<contributionItemProvider
class="org.eclipse.scenario.diagram.custom.providers.
ContributionItemProvider">
<Priority name="Medium"/>
<popupContribution
class="org.eclipse.gmf.runtime.diagram.ui.providers.
Search WWH ::
Custom Search