Java Reference
In-Depth Information
@Override
protected void setForegroundColor(Color) {
super .setForegroundColor( new Color( null , 250, 145, 145));
}
We need to do a bit more for the color to be obtained from the diagram pref-
erences, and for diagram elements to respond to changes in the default values.
Plus, we again want to modify our code-generation templates so that these
changes will not be overridden if we forget to add the appropriate @generated
NOT tag, or if we need to delete and regenerate our diagram plug-in entirely.
BEST PRACTICE
Even though it might require a little more effort to implement, adding cus-
tom templates to implement a feature for your diagram is likely worthwhile
if you find yourself regenerating clean diagram plug-ins due to refactorings,
and given the reality of code merge technology limitations.
This time, we need to import the org.eclipse.gmf.codegen plug-in into
our workspace as a source project, just as we did for the org.eclipse.gmf.
graphdef.codegen plug-in earlier. You will find a lot of templates and exten-
sion files in this project, so consider it a resource for understanding how to use
Xpand, not to mention how to modify GMF generation. Another good source of
examples for working with GMF, custom templates, and extensions is the UML2
Tools project. Looking at our generated diagram code, we see that the
DiagramAppearancePreferencePage class is the best location for our arche-
type color preferences. Currently, this page provides default font, line color, and
fill color preferences, among others. We can add another group for archetype
color preferences below the existing group.
As before, we first code our changes manually and then “templify” the
changes in our custom templates. Looking at the AppearancePreferencePage
superclass of this preference page, we see that adding our own group and color
defaults should be straightforward. Using copy and paste, we insert the follow-
ing code into our diagram's preference page, which started as a simple subclass
designed for extension. Note that we override the addFields() method to
allow for the addition of the archetype color group. To save space, some repeti-
tive code is commented out.
 
Search WWH ::




Custom Search