edit this page - page history - about editing

Programatically opening a sub-diagram in GMF


This is an extension to GMF Diagram Partitioning: In this case, the desired outcome is going from a ShapeNodeEditPart, and emulating a double-click to open the sub-diagram in a new editor. Here is a partial listing of the code required.

First we have to load the target file, then get the loaded editor, and finally emulate double clicking it.

// get the target diagram file
IFile targetDiagram = project.getFile("generation-sync-multiple.iaml_diagram");

// try loading it up with Eclipse
ResourceSet resSet = new ResourceSetImpl();          
Resource res = resSet.getResource(URI.createPlatformResourceURI(targetDiagram.getFullPath().toString(), false), true);

// get the current loaded editor
IWorkbenchPage page = PlatformUI.getWorkbench()
IEditorPart ep = page.getActiveEditor();
IamlDiagramEditor editor = (IamlDiagramEditor) ep;
ShapeNodeEditPart store = editor.getDiagramEditorPart().getChildren().get(0);

// double click the "store" element (assuming it exists)
// based on org.eclipse.gef.tools.SelectEditPartTracker#performOpen()
SelectionRequest request = new SelectionRequest();
request.setModifiers(0 /*getCurrentInput().getModifiers()*/);

You can also see this code on SVN.
Categories: GMF | Technology
edit this page - what links to here? - page history - top
Last edited by jevon jevon 114 months ago