'''NOTE:''' This problem (and a solution) is also discussed here: http://code.google.com/p/gmftools/wiki/SharedEditingDomain.

−

= [[Image:New-small.gif]] Sharing single EditingDomain instance across several diagrams =

+

Generated code always creates new (own) instance of EditingDomain for each opened diagram editor. Since EditingDomain owns ResourceSet, different instances of domain model elements will be loaded for each opened diagram editor. Sometimes it is important to share the same domain model instances across several diagram editors (for example to get rid of synchronization problems). This leads us to the question of sharing same instance of EditingDomain across several generated diagram editors. Below you can find step by step description of necessary modifications you have to apply to the generated code to share the same EditingDomain instance between two diagrams of different types.

−

Generated code always creates new (own) instance of EditingDomain for each opened diagram editor. Since EditingDomain owns ResourceSet, different instances of domain model elements will be loaded for each opened diagram editor. Sometimes it is important to share the same domain model instances across several diagram editors (for example to get rid of synchronization problems). This leads us to the question of sharing same instance of EditingDomain across several generated diagram editors. Below you can find step by step description of necessary modifications you have to apply to the generated code to share the same EditingDomain instance between two diagrams of different types.

+

1. Make sure you have org.eclipse.gmf.bridge.trace plugin installed as a part of GMF SDK. (It is provided with the GMF Experimental SDK.)

−

1. Make sure you have org.eclipse.gmf.bridge.trace plugin installed as a part of GMF SDK. (It is provided with the GMF Experimental SDK.)

<br>4. Modify diagram2.trace file to use different visualID values then specified in diagram1.trace file - the easiest way is to replace “"200”-&gt; “"210”, .., “"800” -&gt; “"810” – and regenerate diagram2.gmfgen from diagram2.gmfmap

+

5. Open diagram2.gmfgen and modify visualID property for GenDiagram to make it different then visualID of GenDiagram in diagram1.gmfgen:

−

4. Modify diagram2.trace file to use different visualID values then specified in diagram1.trace file - the easiest way is to replace “"200”-> “"210”, .., “"800” -> “"810” – and regenerate diagram2.gmfgen from diagram2.gmfmap

+

[[Image:Diagram2Visual ID.PNG]]

−

5. Open diagram2.gmfgen and modify visualID property for GenDiagram to make it different then visualID of GenDiagram in diagram1.gmfgen:

+

<br>6. Ensure both diagram1.gmfgen and diagram2.gmfgen are using the same EditingDomain ID:

−

[[Image:Diagram2Visual_ID.PNG]]

+

[[Image:EditingDomain ID.PNG]]

+

<br>7. Generate code for both diagram plugins.

−

6. Ensure both diagram1.gmfgen and diagram2.gmfgen are using the same EditingDomain ID:

NOTE-1: If you are using GMF older then 2.0 M5 you have to modify generated ???DiagramEditor.createEditingDomain() instead to simply call the superclass implementation of following method:

+

NOTE-1: If you are using GMF older then 2.0 M5 you have to modify generated&nbsp;???DiagramEditor.createEditingDomain() instead to simply call the superclass implementation of following method:

/**

/**

Line 142:

Line 128:

}

}

−

NOTE-2: The idea of this step is to let two connected instances of GMF editors using the same instance of EditingDomain. You can easily create your own EditingDomain registry/accessor and call it from the corresponding methods instead of calling TransactionalEditingDomain.Registry.

+

NOTE-2: The idea of this step is to let two connected instances of GMF editors using the same instance of EditingDomain. You can easily create your own EditingDomain registry/accessor and call it from the corresponding methods instead of calling TransactionalEditingDomain.Registry.

−

You can see an example of alternative ???DocumentProvider modification in the following article: http://www.eclipse.org/articles/Article-Integrating-EMF-GMF-Editors/index.html#extending_the_editor_input.

+

You can see an example of alternative&nbsp;???DocumentProvider modification in the following article: http://www.eclipse.org/articles/Article-Integrating-EMF-GMF-Editors/index.html#extending_the_editor_input.

NOTE: This step is necessary to initialize TransactionalEditingDomain.Registry used above with the proper EditingDomain id. If you are not using TransactionalEditingDomain.Registry to access/create EditingDomain instance (e.g. following the article: http://www.eclipse.org/articles/Article-Integrating-EMF-GMF-Editors/index.html#extending_the_editor_input) then you should skip this step.

+

NOTE: This step is necessary to initialize TransactionalEditingDomain.Registry used above with the proper EditingDomain id. If you are not using TransactionalEditingDomain.Registry to access/create EditingDomain instance (e.g. following the article: http://www.eclipse.org/articles/Article-Integrating-EMF-GMF-Editors/index.html#extending_the_editor_input) then you should skip this step.

−

10. Only one metamodelType could be registered for each EClass in scope of one EditingDomain. During this step you have to replace by specializationType declaration all the metamodelType declarations inside plugin.xml for diagram2 duplicating metamodelType declarations inside plugin.xml for diagram1 (having the same eclass attribute). Following part of plugin.xml:

+

10. Only one metamodelType could be registered for each EClass in scope of one EditingDomain. During this step you have to replace by specializationType declaration all the metamodelType declarations inside plugin.xml for diagram2 duplicating metamodelType declarations inside plugin.xml for diagram1 (having the same eclass attribute). Following part of plugin.xml:

12. To correctly unload (model) resources associated with diagram you can add method to generated ???DocumentProvider:

+

12. To correctly unload (model) resources associated with diagram you can add method to generated&nbsp;???DocumentProvider:

protected void disposeElementInfo(Object element, ElementInfo info) {

protected void disposeElementInfo(Object element, ElementInfo info) {

Line 213:

Line 198:

}

}

−

= Making figures sensitive to attributes of semantic elements =

+

= Making figures sensitive to attributes of semantic elements =

−

'''TASK:'''

+

'''TASK:'''

−

Change a diagram editor generated by GMF to make its figures sensitive to changes of semantic elements’ attributes’ values. Changes of attributes’ values should be automatically detected and reflected in figures’ look.

+

Change a diagram editor generated by GMF to make its figures sensitive to changes of semantic elements’ attributes’ values. Changes of attributes’ values should be automatically detected and reflected in figures’ look.

−

'''SOLUTION:'''

+

'''SOLUTION:'''

−

You have to make a little change in ''*EditPart'' class. I’m going to change edit part for the semantic model element named '''Port''', so I have to edit ''my.package''.diagram.edit.parts.'''''PortEditPart''''' class.

+

You have to make a little change in ''*EditPart'' class. I’m going to change edit part for the semantic model element named '''Port''', so I have to edit ''my.package''.diagram.edit.parts.'''''PortEditPart''''' class.

−

'''1.''' Add a new method to the '''''PortFigure''''' class, which is a ''PortEditPart''’s inner class:

+

'''1.''' Add a new method to the '''''PortFigure''''' class, which is a ''PortEditPart''’s inner class:

The ''updateFace'' method makes actual changes to the figure’s look. This example implementation sets the line’s width according to the number of Port’s children (''port.getLogicalUnits().size()'') and sets the tool-tip text to the value of element’s attribute named ''description''.

−

The ''updateFace'' method makes actual changes to the figure’s look. This example implementation sets the line’s width according to the number of Port’s children (''port.getLogicalUnits().size()'') and sets the tool-tip text to the value of element’s attribute named ''description''.

+

Then you have to hook up this method in two places: ''PortFigure''’s constructor to update the look when editor starts and the ''handleNotificationEvent'' method to react to live changes.

−

Then you have to hook up this method in two places: ''PortFigure''’s constructor to update the look when editor starts and the ''handleNotificationEvent'' method to react to live changes.

+

'''2.''' Change ''PortFigure''’s constructor to make it use new method.

−

+

<pre> /**

−

'''2.''' Change ''PortFigure''’s constructor to make it use new method.

Without this method you would need to restart editor to reflect element's changes in figure parameters.

−

Without this method you would need to restart editor to reflect element's changes in figure parameters.

+

Tested on GMF version 2.0. → [http://serdom.eu/ser/2009/01/21/eclipse-gmf-making-figures-sensitive-to-attributes-of-semantic-elements Original post]

−

Tested on GMF version 2.0. &rarr; [http://serdom.eu/ser/2009/01/21/eclipse-gmf-making-figures-sensitive-to-attributes-of-semantic-elements Original post]

+

= Printing multiple diagrams =

−

= Printing multiple diagrams =

+

See this [http://cyberpen.wordpress.com/2008/07/27/print-all-gmf-diagrams-with-a-single-click/ blog posting] by Anoop Menon.

−

See this [http://cyberpen.wordpress.com/2008/07/27/print-all-gmf-diagrams-with-a-single-click/ blog posting] by Anoop Menon.

+

−

= Rotating a border item =

+

= Rotating a border item =

−

From a newsgroup posting by Jaap Reitsma on 01/31/08:

+

−

I have fond a solution that rotates my bordered triangle (always pointing inwards in a container) as well as being initialized properly when opening the diagram. In my first attempt I used MyTriangleEditPart.refreshBounds() to manipulate the orientation. Although it works when dragging the triangle around the container, it does not get initialized properly as the refreshBounds of the bordered item is called when the layout of the parent has not been done yet.

+

From a newsgroup posting by Jaap Reitsma on 01/31/08:

−

The seemingly elegant solution is to hook into the layout of the border item container, i.e. the parent of my bordered triangle figure. The code I have used follows below:

+

I have fond a solution that rotates my bordered triangle (always pointing inwards in a container) as well as being initialized properly when opening the diagram. In my first attempt I used MyTriangleEditPart.refreshBounds() to manipulate the orientation. Although it works when dragging the triangle around the container, it does not get initialized properly as the refreshBounds of the bordered item is called when the layout of the parent has not been done yet.

−

<pre>

+

−

/* (non-Javadoc)

+

The seemingly elegant solution is to hook into the layout of the border item container, i.e. the parent of my bordered triangle figure. The code I have used follows below:

'''TASK:''' You want to create ER diagram like connections. This means draw a connection from node A to B and a node C will be automatically created in the middle of the new connection.

+

+

'''SOLUTION:''' Well, ok then, I am going to post the proposed solution first and then would be happy to discuss at the [http://www.eclipse.org/forums/index.php?t=msg&S=57cd7f15d71268396073a2e9cd913829&th=201023&goto=642541#msg_642541 forum].

+

+

[[Image:Implicit-in-the-middle.PNG]]

+

+

As you probably got by now there are no one-line solutions to this use case. The only good news is that I am going to try to push this solution to GMF-tooling, and with a bit of luck it will be possible to define and generate the code below in Indigo. To be honest, it is one of the reason for me to describe this somewhat long story here.

+

+

The complete code is available in the public SVN repoistory at http://www.assembla.com/code/gmf-association-class-links/subversion/nodes

There is very simple diagram definition in the *.gmf/gmf/def/ folder. There is nothing special here, except that we set the incoming link creations to true for both GenLink’s in the gmfgen model, to allow user to start drawing of the link from the Rectangle instead of not-yet-created Rhomb.

+

+

Also I was somewhat lazy to play with gmfgraph today, so don’t be surprised that Rhomb model elements are rendered as rounded rectangles at the diagram :).

+

+

Proposed solution consists of 2 parts:

+

a) modifying the GraphicalNodeEditPolicy (GNEP) to collect and pass the diagram information into the semantic creation command and

+

b) implementing the composite creation command itself

+

+

a) So we are going to replace org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy with tweaked ITMGraphicalNodeEditPolicy from the *.gmf plugin. The changes made are as follows:

+

+

- Default GNEP packs the CompositeTransactionalCommand and then uses the ordering to access the different parts of the pack. E.g, lines 508-515 in the default GNEP looks like:

This is clearly bad, so the changed code introduces ITMCreateLinkCommand with explicit access to its parts. It also has a code to register the results pack in the parameters of original request, so our semantic command will be able to access the whole pack at the execution time.

+

+

The changed code also computes an additional ITMCreateParameters describing the diagram information about the link source and target, but, while useful in general, it may be out of scope of this particular use case.

+

+

To register all the ITM* staff above in the generated diagram I used the following custom templates (*.gmf plugin, /gmf/templates/...)

+

+

<pre>

+

itm::graphicalnodeep::Guard.qvto

+

it is the guard that prevents generation of the new code for unrelated diagrams (I had more than 1):

Ok, at this point we can regenerate the diagram, and the new one will install the tweaked GNEPs to all the right places. Now its time time to use it:

+

+

(*.gmf plugin)AbstractImplicitMiddleElementLinkCreateCommand.java is the base class for all creation commands for use cases like that. It does not have dependencies to our diagram and as such prepared to be moved somewhere into GMF runtime.

+

+

IElementTypeAwareAdapter.java, EObjectAndElementTypeAdapter.java and ElementTypeOnlyAdapter are the helper interface and 2 implementations to describe the concrete element type for node in the middle and links.

+

+

and finally the concrete implementation ImplicitRhombCreateCommand (*.diagram plugin, custom-src root) that contains the configuration (what are the visual ids of links, what is the node in the middle, etc) specific for my own diagram.

+

+

Finally, this all is bound together by the @generated NOT code in the RectangleItemSemanticEditPolicy -- this is the only place in the code where @generated and custom code lives together:

Thats it, if you run this code in the helios, in the generated diagram it should be possible to choose the Link tool at palette, draw the link directly from Artist to Song rectangles and have the ‘rhomb’ auto-created in the middle:

+

+

+

= Using EEF and GMF =

+

+

'''TASK:''' You want to use EEF and GMF together

+

+

'''Solution:''' from http://www.eclipse.org/forums/index.php/t/466110/

+

+

GMF does not know which plugin provides the property tabs for the editor, it just declares the contributor ID for someone who wants to provide its contents here. So there is no code in diagram plugin to change. Instead, you need to reference this diagram controbutor ID from EEF plugin:

+

+

*in the diagram plugin. search for: org.eclipse.ui.views.properties.tabbed.propertyContributor extension, it will be like this:

*note one of the existing categories ( &lt;propertyCategory category="domain"/&gt;)

+

*copy/paste the "org.eclipse.ui.views.properties.tabbed.propertyTabs" and "org.eclipse.ui.views.properties.tabbed.propertySections" extensions from EEF-generated plugin.xml fragment to the real plugin.xml for edit plugin (if you followed the EEF tutorial, you may already have one copy of these 2 extensions there for EMF tree editor)

+

*in the BOTH copy/pasted duplicated extensions replace the EEF contributorID to the GMF contributor id (first bold from step1), so in my sample it would be:

Sharing single EditingDomain instance across several diagrams

Generated code always creates new (own) instance of EditingDomain for each opened diagram editor. Since EditingDomain owns ResourceSet, different instances of domain model elements will be loaded for each opened diagram editor. Sometimes it is important to share the same domain model instances across several diagram editors (for example to get rid of synchronization problems). This leads us to the question of sharing same instance of EditingDomain across several generated diagram editors. Below you can find step by step description of necessary modifications you have to apply to the generated code to share the same EditingDomain instance between two diagrams of different types.

1. Make sure you have org.eclipse.gmf.bridge.trace plugin installed as a part of GMF SDK. (It is provided with the GMF Experimental SDK.)

3. Modify generated diagram1.gmfgen and diagram2.gmfgen files to use different Model IDs, Plugin IDs, Editor IDs. Optionally two different diagrams could has different diagram file extensions as well:

4. Modify diagram2.trace file to use different visualID values then specified in diagram1.trace file - the easiest way is to replace “"200”-> “"210”, .., “"800” -> “"810” – and regenerate diagram2.gmfgen from diagram2.gmfmap

5. Open diagram2.gmfgen and modify visualID property for GenDiagram to make it different then visualID of GenDiagram in diagram1.gmfgen:

6. Ensure both diagram1.gmfgen and diagram2.gmfgen are using the same EditingDomain ID:

NOTE-2: The idea of this step is to let two connected instances of GMF editors using the same instance of EditingDomain. You can easily create your own EditingDomain registry/accessor and call it from the corresponding methods instead of calling TransactionalEditingDomain.Registry.

10. Only one metamodelType could be registered for each EClass in scope of one EditingDomain. During this step you have to replace by specializationType declaration all the metamodelType declarations inside plugin.xml for diagram2 duplicating metamodelType declarations inside plugin.xml for diagram1 (having the same eclass attribute). Following part of plugin.xml:

Making figures sensitive to attributes of semantic elements

TASK:

Change a diagram editor generated by GMF to make its figures sensitive to changes of semantic elements’ attributes’ values. Changes of attributes’ values should be automatically detected and reflected in figures’ look.

SOLUTION:

You have to make a little change in *EditPart class. I’m going to change edit part for the semantic model element named Port, so I have to edit my.package.diagram.edit.parts.PortEditPart class.

1. Add a new method to the PortFigure class, which is a PortEditPart’s inner class:

The updateFace method makes actual changes to the figure’s look. This example implementation sets the line’s width according to the number of Port’s children (port.getLogicalUnits().size()) and sets the tool-tip text to the value of element’s attribute named description.

Then you have to hook up this method in two places: PortFigure’s constructor to update the look when editor starts and the handleNotificationEvent method to react to live changes.

Printing multiple diagrams

Rotating a border item

From a newsgroup posting by Jaap Reitsma on 01/31/08:

I have fond a solution that rotates my bordered triangle (always pointing inwards in a container) as well as being initialized properly when opening the diagram. In my first attempt I used MyTriangleEditPart.refreshBounds() to manipulate the orientation. Although it works when dragging the triangle around the container, it does not get initialized properly as the refreshBounds of the bordered item is called when the layout of the parent has not been done yet.

The seemingly elegant solution is to hook into the layout of the border item container, i.e. the parent of my bordered triangle figure. The code I have used follows below:

Implicit node in the middle creation

TASK: You want to create ER diagram like connections. This means draw a connection from node A to B and a node C will be automatically created in the middle of the new connection.

SOLUTION: Well, ok then, I am going to post the proposed solution first and then would be happy to discuss at the forum.

As you probably got by now there are no one-line solutions to this use case. The only good news is that I am going to try to push this solution to GMF-tooling, and with a bit of luck it will be possible to define and generate the code below in Indigo. To be honest, it is one of the reason for me to describe this somewhat long story here.

There is very simple diagram definition in the *.gmf/gmf/def/ folder. There is nothing special here, except that we set the incoming link creations to true for both GenLink’s in the gmfgen model, to allow user to start drawing of the link from the Rectangle instead of not-yet-created Rhomb.

Also I was somewhat lazy to play with gmfgraph today, so don’t be surprised that Rhomb model elements are rendered as rounded rectangles at the diagram :).

This is clearly bad, so the changed code introduces ITMCreateLinkCommand with explicit access to its parts. It also has a code to register the results pack in the parameters of original request, so our semantic command will be able to access the whole pack at the execution time.

The changed code also computes an additional ITMCreateParameters describing the diagram information about the link source and target, but, while useful in general, it may be out of scope of this particular use case.

To register all the ITM* staff above in the generated diagram I used the following custom templates (*.gmf plugin, /gmf/templates/...)

itm::graphicalnodeep::Guard.qvto
it is the guard that prevents generation of the new code for unrelated diagrams (I had more than 1):
helper requiresSpecificGraphicalNodeEditPolicy(diagram : genModel::GenDiagram) : Boolean {
return
'your.diagram.plugin.id = diagram.editorGen.plugin.iD
}
This guard allows every other affected template to have something like
«EXTENSION itm::graphicalnodeep::Guard»
...
«IF requiresSpecificGraphicalNodeEditPolicy(self.getDiagram())-»
//....some changes
«ENDIF-»

which, after all, allowed me to find all the affected parts and write this post :)

itm::graphicalnodeep::graphicalNodeEditPolicy.xpt - here comes the code to register the tweaked version of the GNEP
aspects::impl::diagram::editparts::LinkEditPart.xpt and aspects::impl::diagram::editparts::NodeEditPart.xpt - just registering the tweaked editpolicies for all nodes and links by calling

«EXPAND itm::graphicalnodeep::graphicalNodeEditPolicy::install-»

finally, if you also have notes at your diagram you also need to replace the NoteEditPart because in its default GMF version it expects the default GNEP. This is done by:

Ok, at this point we can regenerate the diagram, and the new one will install the tweaked GNEPs to all the right places. Now its time time to use it:

(*.gmf plugin)AbstractImplicitMiddleElementLinkCreateCommand.java is the base class for all creation commands for use cases like that. It does not have dependencies to our diagram and as such prepared to be moved somewhere into GMF runtime.

IElementTypeAwareAdapter.java, EObjectAndElementTypeAdapter.java and ElementTypeOnlyAdapter are the helper interface and 2 implementations to describe the concrete element type for node in the middle and links.

and finally the concrete implementation ImplicitRhombCreateCommand (*.diagram plugin, custom-src root) that contains the configuration (what are the visual ids of links, what is the node in the middle, etc) specific for my own diagram.

Finally, this all is bound together by the @generated NOT code in the RectangleItemSemanticEditPolicy -- this is the only place in the code where @generated and custom code lives together:

Thats it, if you run this code in the helios, in the generated diagram it should be possible to choose the Link tool at palette, draw the link directly from Artist to Song rectangles and have the ‘rhomb’ auto-created in the middle:

Using EEF and GMF

GMF does not know which plugin provides the property tabs for the editor, it just declares the contributor ID for someone who wants to provide its contents here. So there is no code in diagram plugin to change. Instead, you need to reference this diagram controbutor ID from EEF plugin:

in the diagram plugin. search for: org.eclipse.ui.views.properties.tabbed.propertyContributor extension, it will be like this:

note one of the existing categories ( <propertyCategory category="domain"/>)

copy/paste the "org.eclipse.ui.views.properties.tabbed.propertyTabs" and "org.eclipse.ui.views.properties.tabbed.propertySections" extensions from EEF-generated plugin.xml fragment to the real plugin.xml for edit plugin (if you followed the EEF tutorial, you may already have one copy of these 2 extensions there for EMF tree editor)

in the BOTH copy/pasted duplicated extensions replace the EEF contributorID to the GMF contributor id (first bold from step1), so in my sample it would be: