Access GMF Diagram Elements and Attributes/Properties [message #885637] |
Wed, 13 June 2012 11:06  |
Eclipse User |
|
|
|
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 #971149 is a reply to message #886355] |
Sun, 04 November 2012 16:43  |
Eclipse User |
|
|
|
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();
|
|
|
Powered by
FUDForum. Page generated in 0.03262 seconds