Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Programmatically Select Elements in GMF Diagram(I need help figuring out how to programmatically set selections in generated GMF diagrams)
Programmatically Select Elements in GMF Diagram [message #1069461] Mon, 15 July 2013 23:28 Go to next message
Phillip Drew is currently offline Phillip Drew
Messages: 75
Registered: October 2012
Member
Could swear I posted this question last week but I can't find it so perhaps something went wrong

I'm looking to synchronise selections between multiple EMF and GMF editors using the Eclipse selection service.

I have the EMF editors working fine but I'm having trouble figuring out what I need to do to programmatically select elements in the GMF diagrams. Essentially I'll be receiving an EObject over the selection service and I want to have the same object (or rather the node that represents it) selected in the GMF diagram editor.

Thanks for your help
Re: Programmatically Select Elements in GMF Diagram [message #1069662 is a reply to message #1069461] Tue, 16 July 2013 10:25 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
Registered: November 2009
Senior Member
Hi,

I have the following code (shortened) running to select a model element based on an EObject in a GMF generated editor:

if (elementToSelect.eResource() == null)
  return;

for (IEditorReference reference : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences())
  if (reference.getPartName().equals(nameToLookAt))
    editorReference = reference;
		
if (editorReference == null)
  return;
		
IEditorPart editorPart = editorReference.getEditor(true);
		
if (! (editorPart instanceof xxxDiagramEditor) )
  return;
		
List editParts = yyyDiagramEditor.getDiagramGraphicalViewer().findEditPartsForElement(EMFCoreUtil.getProxyID(elementToSelect), xxxEditPart.class);
		
IGraphicalEditPart editPart = (IGraphicalEditPart)editParts.get(0);
yyyDiagramEditor.getDiagramGraphicalViewer().select(editPart);
yyyDiagramEditor.getDiagramGraphicalViewer().reveal(editPart);


Ralph
Re: Programmatically Select Elements in GMF Diagram [message #1069937 is a reply to message #1069461] Tue, 16 July 2013 23:26 Go to previous messageGo to next message
Phillip Drew is currently offline Phillip Drew
Messages: 75
Registered: October 2012
Member
Haven't tried it yet but looks like exactly what I'm after - thanks!
Re: Programmatically Select Elements in GMF Diagram [message #1070423 is a reply to message #1069937] Wed, 17 July 2013 23:51 Go to previous messageGo to next message
Phillip Drew is currently offline Phillip Drew
Messages: 75
Registered: October 2012
Member
So the code you provided works perfectly but unfortunately the visual impact of selection is fairly minimal (or non-existent for compartments with list layouts).

What would I have to do to as well as selecting the element associated with an EObject, change its color or some other obvious visual detail?

Thanks
Re: Programmatically Select Elements in GMF Diagram [message #1070555 is a reply to message #1070423] Thu, 18 July 2013 07:57 Go to previous message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
Registered: November 2009
Senior Member
Hi,

you can access the edit parts IFigure and manipulate it as you like. You could place this into a selection editpolicy that you install into the editpart. Such an edit policy has methods which are executed in selection/deselection.

Ralph
Previous Topic:Compartments in Phantom Nodes
Next Topic:Custom XML output
Goto Forum:
  


Current Time: Tue Sep 23 00:34:06 GMT 2014

Powered by FUDForum. Page generated in 0.02911 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software