Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Access GMF Diagram Elements and Attributes/Properties (How to access all elements in a diagram?)
Access GMF Diagram Elements and Attributes/Properties [message #885637] Wed, 13 June 2012 11:06 Go to next message
Selim Güler is currently offline Selim GülerFriend
Messages: 3
Registered: January 2012
Junior Member
Dear GMF Experts,

I need assistance and guidence about diagram elements.

I've finally created a GMF plugin (diagram code) and working as expected.
Now, what I want to do is actually sounds simple, but I cannot move on because of my lack of knowledge about gmf.

I want to access all the figures and their attribues so that I would transfer the information gathered from properties view (attribute values) to a database.

I'm able to do it using the selected elements however, I could not figure out how to do it without selecting any elements in the diagram.

Do you have any ideas how to access to each element one by one in the diagram?

Here is the code I use for selecting element and getting an attribute value:

ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
		 
EditPart editPart = (IGraphicalEditPart
                    ((IStructuredSelection)sel).getFirstElement();

//MyStakeholder is a node/figure which is assumed to be selected here, just for testing purposes.
if(editPart instanceof MyStakeholder)
{
    final MyStakeholder test2 = (MyStakeholder) ((GraphicalEditPart)        editPart).resolveSemanticElement();

   System.out.println(test2.getName());
   System.out.println(test2.getQuantity());
   System.out.println(test2.getXXX());
   //.. and so on..
}



In short, I want to repeat this procedure for all elements drawn onto the diagram.

Thanks in advance!
Re: Access GMF Diagram Elements and Attributes/Properties [message #886060 is a reply to message #885637] Thu, 14 June 2012 06:56 Go to previous messageGo to next message
Marco Franke is currently offline Marco FrankeFriend
Messages: 10
Registered: April 2012
Location: Bremen
Junior Member
Good morning,
it is very easy. Follow these steps and you have access to all diagram elements within few minutes:

1. Get your actual workbench (IWorkbench workbench = MYGMFPROGRAM.getInstance().getWorkbench()Wink
2. Get your actual editor (editor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor()Wink
3. Casting the editor to a DiagramEditor (diagramEditor = (DiagramEditor) page.getActiveEditor();
diagram = diagramEditor.getDiagram()Wink

4. Get the top of your diagram with: diagram.getElement();

Now you can go throuph your diagramm over your specific nodes and edges.

Hope, it was helpful

Regards,
Marco

[Updated on: Thu, 14 June 2012 06:59]

Report message to a moderator

Re: Access GMF Diagram Elements and Attributes/Properties [message #886355 is a reply to message #886060] Thu, 14 June 2012 19:31 Go to previous messageGo to next message
Selim Güler is currently offline Selim GülerFriend
Messages: 3
Registered: January 2012
Junior Member
Done and it is working as expected! Confused

Thank you Marco!




Re: Access GMF Diagram Elements and Attributes/Properties [message #971149 is a reply to message #886355] Sun, 04 November 2012 16:43 Go to previous message
Cagdas Dönmez is currently offline Cagdas DönmezFriend
Messages: 1
Registered: October 2012
Junior Member
Hello!

I have pretty much the same problem as Selim. The thing is i applied this code already and it makes sense. The twist is that i need to print out the values and attributes of the elements of my GMF Diagram on an Eclipse-View, not on the console itself. I already tried to print them through label.setText("...."); but somehow it did not work out. How can i ensure that i have the information regarding the elements in my hand? Guys what would you suggest? It will be really appreciated, thanks in advance.


IWorkbench workbench = PlatformUI.getWorkbench();
IEditorPart editor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();

diagramEditor = (DiagramEditor) page.getActiveEditor();
Diagram diagram = diagramEditor.getDiagram();

EObject element = diagram.getElement();
EList<EObject> eContents = element.eContents();

Iterator<EObject> diagramContents = eContents.iterator();

Previous Topic:Record and Capture GUI Testing Tool
Next Topic:Insert an image in a diagram node
Goto Forum:
  


Current Time: Thu Mar 28 15:26:52 GMT 2024

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

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

Back to the top