Java Reference
In-Depth Information
« IMPORT "http://www.eclipse.org/gmf/2006/GenModel"»
« EXTENSION Utils »
« AROUND additions FOR gmfgen::GenNode-»
« EXPAND fieldPreferencePropertyChangeListener FOR this
« EXPAND PreferencePropertyChangeListener FOR this
« EXPAND addNotationalListeners FOR this
« EXPAND updateArchetypeColor FOR this
« EXPAND getPreferenceColor FOR this
« EXPAND initPreferenceStoreListener FOR this
« EXPAND setForegroundColorMethod FOR this
« ENDAROUND »
As you can see, we're breaking up the implementation into a series of
«DEFINE» blocks, each corresponding to a method. This is another best practice
for using Xpand, and one you'll see throughout the GMF templates. Note, how-
ever, that the context for this custom template remains gmfgen::GenNode . This
means that all EditPart classes that are generated for nodes will have these cus-
tomizations added, not only archetypes. Our diagram has two other types of
nodes, package nodes, and annotations. This doesn't present a problem in our
case because we default all nodes not recognized as archetypes during execution
as the plug-in point archetype. The «EXTENSION» at the top of our template
points to our Util.ext file that contains the logic used, as shown here:
String toPreferenceConstant(ecore::EClass type) :
switch (type.name) {
case "MomentInterval" : "PREF_MI_ARCHETYPE_COLOR"
case "MIDetail" : "PREF_MI_ARCHETYPE_COLOR"
case "Role" : "PREF_ROLE_ARCHETYPE_COLOR"
case "Party" : "PREF_PPT_ARCHETYPE_COLOR"
case "Place" : "PREF_PPT_ARCHETYPE_COLOR"
case "Thing" : "PREF_PPT_ARCHETYPE_COLOR"
case "Description" : "PREF_DESC_ARCHETYPE_COLOR"
default : "PREF_PIP_ARCHETYPE_COLOR"
}
;
You'll see where this function is invoked shortly, but it's clear from this how
each archetype is mapped to its corresponding preference constant. The first tem-
plate definition invoked appears next and simply adds a field for our inner
PreferencePropertyChangeListener class. Note the use of the xpt::Common::
generatedMemberComment and xpt::Common::generatedMemberComent
expansions throughout the template, which insert the familiar @generated tags
above class, field, and method declarations.
Search WWH ::




Custom Search