Difference between revisions of "Graphical Modeling Framework/Tutorial/Part 3"
m (→Graphical Definition)
m (→Graphical Definition)
|Line 21:||Line 21:|
=== Graphical Definition ===
=== Graphical Definition ===
Open up your graphical definition again and add a new...
Open up your graphical definition again and add a new . .
Revision as of 17:19, 12 April 2006
Note: This is still very much a work in progress...
In this third part of the GMF Tutorial, we will explore some more advanced capabilities related to the tooling components, while also extending what's generated with customizations to the runtime. Specifically we will add a composite figure using the graphical definition, show how to leverage external figures, and how to use an extension plug-in to add a custom action to our diagram. A project containing the full solution set of projects for this segment is found here. Viewlets will be available after appropriate sections below to focus their content and keep them short.
A quick way to get a new polished look for our mindmap diagram is by replacing the generated EMF icons we've seen so far with some that are more, well... distinctive ;) The easiest way to do this is to replace the GIF images found in our org.eclipse.gmf.examples.mindmap.edit/icons/full/obj16/ folder.
In case you'd like to map another image file to a palette item, say in the case of our three Relationship tools, or for our Subtopic link which has no default icon, you can modify the children of your Creation Tool elements in the mindmap.gmftool model. For example, if you delete the 'Delete Image' entry below the 'Creation Tool Subtopic' element that represents the small icon and replace it with a 'Small Icon Bundle Image' and set its Path property to platform:/plugin/org.eclipse.gmf.examples.mindmap.edit/icons/full/obj16/Subtopic.gif, it will use this icon. Of course, you'll need to provide this file or use the one found in the solution to this tutorial section.
Finally, take a look in the mindmap.genmodel for properties to set for the default wizard and diagram file icons. While you're there, you might want to change the diagram file extension from 'mindmap_diagram' to 'mmd' or something similar. Browsing the properties available in the gmfgen model is a useful exercise.
Below is an image of our diagram and palette using some new images.
What we'd like to do is have an actor-style representation for our resources added to our diagram. These will be linked to their respective Topic elements, much like our relationship links between Topic elements. Also, we'd like to have the labels for our Resource figures external and display both the name and email address attribute values of the corresponding domain element.
Open up your graphical definition again and add a new Rectangle named 'ResourceFigure' to your Figure Gallery. Set its Outline property to false, along with its Fill. As you can see from the image to the right, we will be adding a series of children to the rectangle, which will act as a container for the elements that comprise our Resource figure. Specifically, right-click and add an XY Layout, and Ellipse for the head, a Polygon for the Body, and sizing elements. Rather than go through all of the gory details of these, the figure code is found below. Either paste it into your mindmap.gmfgraph in the appropriate location using a text editor, or utilize the default editor and properties view.
To our Canvas, add a new Node named ResourceNode and assign our ResourceFigure as its Figure. Also, notice the new 'BasicLabelFigure' label that is added to the Figure Gallery in the image. Create this and add a new Diagram Label 'ResourceLabel' to the Figure Gallery and Canvas respectively. Note that the Label for our Resource is not a child element of its figure. We want the label to be external, and therefore be allowed to float and be positioned wherever the user would like it.
<figures xsi:type="gmfgraph:Rectangle" name="ResourceFigure" outline="false" fill="false" lineWidth="0"> <layout xsi:type="gmfgraph:XYLayout"/> <children xsi:type="gmfgraph:Ellipse" name="Head"> <foregroundColor xsi:type="gmfgraph:RGBColor" red="220" green="220" blue="250"/> <backgroundColor xsi:type="gmfgraph:RGBColor" red="230" green="230" blue="255"/> <size x="40" y="20"/> </children> <children xsi:type="gmfgraph:Polygon" name="Body"> <foregroundColor xsi:type="gmfgraph:RGBColor" red="220" green="220" blue="250"/> <backgroundColor xsi:type="gmfgraph:RGBColor" red="230" green="230" blue="255"/> <template x="23" y="19"/> <template x="23" y="24"/> <template x="39" y="24"/> <template x="39" y="29"/> <template x="23" y="29"/> <template x="23" y="36"/> <template x="39" y="48"/> <template x="39" y="53"/> <template x="20" y="42"/> <template x="1" y="53"/> <template x="1" y="48"/> <template x="17" y="36"/> <template x="17" y="29"/> <template x="1" y="29"/> <template x="1" y="24"/> <template x="17" y="24"/> <template x="17" y="19"/> </children> <maximumSize dx="40" dy="60"/> <minimumSize dx="40" dy="60"/> <preferredSize dx="40" dy="60"/> <size x="40" y="60"/> </figures>
Tip : It's a bit tedious to add multiple template points in the manner above, so feel free to open the gmfgraph file in a text editor to make life easier. Furthermore, to get it looking right more quickly, open the generated figure class and simply modify the GEF code directly and run the editor to see how it looks. Then, move this information back into your gmfgraph model. Of course, when the WYSIWYG features of GMF become available and mature, none of this should be necessary.
We'll need a tool to add Resource nodes, so as you've done many times before, open the mindmap.gmftool model and add a new node creation tool for the Resource. Next, we'll need to add our mappings, so reopen your mindmap.gmfmap file.
First, we'll need to add...
Here, we'll utilize the edit and view pattern properties of the mapping model to allow a Resource label to be displayed as 'name [email@example.com]'.
Using External Figures
Creating a Customization Plug-in
Although making modifications to the generated code and specifying '@generated NOT' to allow JMerge to preserve our changes works well for some customizations, it's also possible to separate other customizations (extensions) to our generated plug-in using a new plug-in...
The standard means to create a new subtopic is a bit painful at the moment: click on Topic creation tool, then diagram, name with in-place editor, click Subtopic link creation tool, draw link from parent to subtopic. Ideally, we'd like to simply use a right-click menu option on a selected Topic and choose "Create Subtopic" or better yet, press the Insert key (or equivalent) and have the new Topic created, including the link, and with the in-place editor active on the new Topic. In this section, we will explore how to accomplish just this.
In this section of the tutorial, we saw how to add a composite figure, utilize external images and figures, and create a custom action contained within a new extension plug-in.