Java Reference
In-Depth Information
The easiest way to get started modifying or augmenting GMF templates is to
bring the appropriate *. codegen plug-in into the workspace. For figures, we're
interested in the org.eclipse.gmf.graphdef.codegen plug-in, so switching
to the Plug-Ins view of our Plug-In Development perspective, we locate it and
right-click, choosing Import As
Source Project . Browsing the contents of this
plug-in, we discover the /templates/top/Figure.xpt Xpand template. This
template provides an expansion of the Extras::extraMethods «DEFINE»
that looks like just what we need to add our overridden fillShape() method.
The Extras.xpt template contains this «DEFINE» block that we can use to cre-
ate an «AROUND» that will add our method.
« DEFINE extraMethods FOR gmfgraph::Figure-»
« ENDDEFINE »
We create a /templates-figures/aspects/Extras.xpt template in
our org.eclipse.dsl.dnc project. As discussed in Section 4.2.3, “Custom-
ization Options,” GMF uses the convention of prefixing the directory structure
for aspects with a folder named aspects, followed by the original path to the tem-
plate, as defined in the *. codegen project. In this case, we want to provide an
aspect for the Extras.xpt template, which is located directly in the /templates
folder. We'll use the path /org.eclipse.dsl.dnc/templates-figures/ in
the wizard dialog, as shown in Figure 4-45. When the generator finds the aspects
folder, it will know to add this as an aspect template path.
Following is our template, which, as you can see, uses the polymorphic fea-
ture of Xpand to add our gradient code only for RoundedRectangle figures.
We need to provide the obligatory «DEFINE» for the Figure supertype as well.
Also note that we're adding a useGradient Boolean to control whether to dis-
play gradients, which we can later hook up to a diagram preferences option.
« IMPORT "http://www.eclipse.org/gmf/2006/GraphicalDefinition"»
« IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
« AROUND extraMethods FOR gmfgraph::Figure-»
« EXPAND gradient-»
«targetDef.proceed()»
«ENDAROUND»
« DEFINE gradient FOR gmfgraph::Figure»« ENDDEFINE »
« DEFINE gradient FOR gmfgraph::RoundedRectangle-»
/**
* @generated
*/
private boolean useGradient = true;
Search WWH ::




Custom Search