Composite Example

This example plug-in demonstrates basic usages of the diagram composite API introduced with Graphiti 0.10.0. This API allows clients to add Graphiti diagrams to views or other UIs so that users can display and edit the diagrams there.

The example plug-in org.eclipse.graphiti.examples.composite is available as executable but also as source in the SDK download and within our repository under the examples folder. It demonstrates the basics of placing diagrams into other locations than editors.

Diagrams in View

The plug-in adds a view org.eclipse.graphiti.examples.composite.view.DiagramCompositeViewExample to the Eclipse views extension point and to the Graphiti test perspective. The view is populated with a Graphiti DiagramComposite that will display a diagram that is stored locally in the plugin (test.diagram in the root folder of the plugin). The URL of that diagram is hard-coded in the view and cannot be replaced. In a real usage scenario the handling would of course be similar to the handling of an editor. An operation to show the view is triggered on a diagram e.g. in the context menu of the Project Explorer, the diagram URI is retrieved and passed to the composite.

Screenshot of the Diagram View

The only other things that this simply example cares about is delegating the focus and adapter retrieval mechanism (both standard Eclipse) to the diagram composite. For a real usage scenario much more is needed, e.g. the view does not care about changes that are done to the diagram in the view; users can modify the diagram but there is no way to persist them.

Diagrams in a Popup

The plug-in also adds a dialog that can be invoked by a context menu entry in the project explorer (select two Graphiti diagrams with .diagram) file extension and select the entry Show Diagrams in Popup) to display the two selected diagrams side-by-side in a popup.

Screenshot of the Diagrams Popup

The implementation of the popup is in the class org.eclipse.graphiti.examples.composite.dialog.DoubleDiagramDialog and is also kept very simple; e.g. just as the views example it does not care about persisting any changes the user did to the diagrams on the popup. It simply takes two resources (the diagram files), tries to extract a diagram URI for each and created a DiagramComposite passing the URI.