edit this page - page history - about editing

GMF Code Samples

GMF

Here's lots of code samples for GMF. Currently they are stored on SVN purely as text; in the future, once my research is progressing further, they will actually link to real-world code. Also all this code is pretty messy.

For more information on activating shortcuts in GMF and what they can achieve, check out GMF Drag Drop.
  1. Setting up an EMF/JET testing project with JUnit and Eclipse
  2. Add a right click menu to generate code from EMF using Java JET
  3. Loading an EMF model from an XMI file
  4. Getting IDs on EMF model elements
  5. Programatically opening a sub-diagram in GMF
  6. Programatically initialising a new diagram in GMF (SVN)
  7. Programatically creating a new diagram and domain model in GMF (SVN)
  8. Unit testing of GMF diagram editors and shortcuts with JUnit
  9. Programatically exporting a model diagram to one image, or multiple images (SVN, also see GMF's CopyToImageAction)
  10. Automatically re-validating the model when the diagram is saved
  11. Testing all EMF model elements with JUnit
  12. Using EDataTypes in GMF
  13. Custom Property Editors for EDataTypes in GMF
  14. File Property Editor for GMF
  15. Breadcrumbs in GMF Editors
  16. Creating Connections from Shortcut Elements in GMF
  17. Adding a Custom Label in GMF
  18. GMF Label OpenDiagramEditPolicies
  19. Initialising new elements in a new GMF diagram
  20. Exporting entire GMF diagrams into clickable HTML (example coming soon)
  21. Using Platform Resources as EReferences in GMF
  22. Putting Generated GMF Diagram Editors into a New Category

Automatically refresh a GMF EditPart

Here is some code which will automatically refresh all the nodes and connections visible in a given GMF EditPart.
  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/RefreshElementCommand.java?view=markup

Create Missing Shortcuts for a View

If you would like to automatically create shortcuts for a given EditPart, such as to the images on the right, you can use the code provided below.
  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/CreateMissingShortcutsAction.java?view=markup
  2. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/CreateMissingShortcutsCommand.java?view=markup
Basically, the code first searches the current EditPart for elements that it needs to add as shortcuts; it then adds each of these elements along with a shortcut annotation, and finally, the view is refreshed (RefreshElementCommand above) to connect these shortcuts up to the nodes currently viewable.

The XML file for this example could be something like so:

<root>
  <view name="external">
    <operation name="external link 1" />
    <operation name="external link 2" />
  </view>
  <view name="current">
    <component name="component">
      <connection name="connection 1" to="//@view.0/@operation.0" />
      <connection name="connection 2" to="//@view.0/@operation.1" />
    </component>
  </view>
</root>

Automatically creating shortcuts on an EditPart

As an extension to the code above, this will automatically populate an EditPart with the shortcuts it needs when the EditPart is activated.
  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/Uml3ShortcutsEditPartProvider.java?view=markup
The code that is particularly interesting is:
if (part instanceof ComponentEditPart) { ... }

And add this to your plugin.xml:

<extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders">
  <editpartProvider class="org.openiaml.test.uml3.diagram.component.custom.edit.providers.Uml3ShortcutsEditPartProvider">
    <Priority name="Low" />
    <object class="org.eclipse.gmf.runtime.notation.Node" id="MyOverride">
      <method name="getElement()">
        <value class="org.openiaml.test.uml3.model.Component"/>
      </method>
    </object>
    <context
         views="MyOverride"/>
  </editpartProvider>
</extension>

Adding elements and attribute values to a container element

This code will add an "Event" object and set its "title" attribute to "test".
  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/CreateChildContentsCommand.java?view=markup

Automatically adding elements and attributes to a newly created element

As an extension to the code sample above. This code isn't complete; it will happily add the elements to each element every time you both create it and open it for editing. But the basic content is there.
  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/gmf/Uml3ShortcutsEditPartProvider.java?view=markup
The code that is particularly interesting is:
if (part instanceof LinkComponentEditPart) { ... }

edit this page - what links to here? - page history - top
Last edited by jevon jevon 88 months ago