|
|
|
Re: Modify an object from a different plugin [message #1220963 is a reply to message #1220384] |
Mon, 16 December 2013 11:27 |
Greg Dart Messages: 17 Registered: September 2013 |
Junior Member |
|
|
Hi Ralph,
Thanks for the reply - I finally figured something out, although I'm not sure this is the best way to achieve what we want. This code (below) is called as a result of a right-click menu action in a custom plug-in UI component view (It's actually a treeview).
My basic approach is:
1) get the current GMF editor (and make sure it's the one we were expecting)
2) get ALL the elements in that editor
3) search through them ALL until we find the type we are looking for
4) as we know there's only ever one instance of that type, go ahead and use the command stack to change it's name.
My concern is still that if the diagram gets big, this could be quite a slow process?
This is my working code, called from a menu handler - any suggestions/improvements gratefully received.
Thanks,
Greg
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart instanceof ContractSpecEditorDiagramEditor) {
System.out.println("Found Editor");
ContractSpecEditorDiagramEditor cSEDE = (ContractSpecEditorDiagramEditor) editorPart;
TreeIterator<EObject> allContents = cSEDE.getDiagram().eAllContents();
while (allContents.hasNext()) {
EObject next = allContents.next();
if (next instanceof NodeImpl) {
EObject obj = ((NodeImpl)next).getElement();
if (obj instanceof ClientImpl){
ClientImpl client = (ClientImpl) obj;
System.out.println("Found Client: " + client.getName());
EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(client);
Command cmnd = SetCommand.create(editingDomain, client, ContractSpecEditorPackage.eINSTANCE.getNode_Name(), "Bob");
try {
editingDomain.getCommandStack().execute(cmnd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("New Name is: " + client.getName());
}
}
}
}
return null;
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.02879 seconds