Reputation: 1
I'm working on a GMF diagram and I need to find a way to get the diagram elements from my own java class. The idea is to have a GMF editor and generate code from the diagram created with that editor.
My first goal is to have a right-click context menue inside the diagram which offers a menue point that prints the names of all current diagram nodes in console.
I've made it so far that I have a menue point in context menue that runs a java class (implementing IObjectActionDelegate) in my plugin that prints text in the console.
But how can I get the diagram elements from that class? Is there any way to receive a list of all diagram nodes?
Thanks for your help Joe
Upvotes: 0
Views: 578
Reputation: 11
Try something like the following:
IWorkbenchPage page = window.getActivePage();
if (page == null) return null;
IEditorPart editor = workbenchPage.getActiveEditor();
if (editor == null) return null;
if (! (editor instanceof DiagramDocumentEditor)) return null;
DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editorPart;
DiagramEditPart diagramEditPart = diagramEditor.getDiagramEditPart();
Object diagramObject = diagramEditPart.getModel();
if (! (diagramObject instanceof DiagramImpl)) return null;
DiagramImpl diagramImpl = (DiagramImpl) diagramObject;
EObject myGmfDiagramElements = diagramImpl.getElement();
...
Upvotes: 0