ELK Auto Layout - Get Class names of ELKNodes [message #1848460] |
Thu, 02 December 2021 22:18  |
Eclipse User |
|
|
|
Is it possible to get the class names of the object that an ELKNode is representing? For example, in the picture Element1 and Element2 have class names of Data Element which extends org.eclipse.emf.ecore.EObject. Any way to extract this information inside my auto-layout algorithm that extends org.eclipse.elk.core.AbstractLayoutProvider.
My model has different objects that I want to group together during auto layout
[Updated on: Thu, 02 December 2021 22:36] by Moderator Report message to a moderator
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848464 is a reply to message #1848460] |
Fri, 03 December 2021 05:45   |
Eclipse User |
|
|
|
Hi
The true Java class name, probably DataElementImpl, is available using Java#s Object.getClass().
The modelled class name, probably DataElement, is available using EObject.eClass().getName().
The name of the modelled class, probably Element1, is available using ENamedElement.getName().
Regards
Ed Willink
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848467 is a reply to message #1848464] |
Fri, 03 December 2021 08:24   |
Eclipse User |
|
|
|
Hi Jonathan,
I'm not sure to understand. Do you want to have access to the class name of the semantic element representing by the DDiagramElement? When you are in the "ELK world", this is the case when you are doing your own layout by extending AbstractLayoutProvider, there is no link between ELK Node and GMF/Sirius elements.
If your algorithm needs this kind of information, I think there is a way. You have to add specific properties to ELKNode before the algorithm is called, through org.eclipse.elk.graph.properties.IPropertyHolder.setProperty(IProperty<? super T>, T). For example : node.setProperty(MyIPropertyForSemanticName, stringRepresentingTheSemanticClassName).
And for that, you can use the extension point "org.eclipse.sirius.diagram.elk.layout.extension" to add this property with the method org.eclipse.sirius.diagram.elk.IELKLayoutExtension.beforeELKLayout(LayoutMapping). This extension point is experimental but I think this is the only way to do what you expect (if I understand correctly).
Best regards,
Laurent
|
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848537 is a reply to message #1848521] |
Tue, 07 December 2021 08:19   |
Eclipse User |
|
|
|
The key of the map is an ElkGraphElement and the value is an edit part. So you have to check the type of edit part (org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNodeEditPart, org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramEdgeEditPart for example) and then you can access to your semantic element with something like:
BiMap<ElkGraphElement, Object> graphMap...;
ELKNode aNode...;
Object editPart = graphMap.get(aNode);
if (editPart instanceof AbstractDiagramNodeEditPart) {
EObject siriusDiagramElement = ((AbstractDiagramNodeEditPart) editPart).resolveSemanticElement();
if (siriusDiagramElement instanceof DDiagramElement) {
EObject anObjectOfYourDomain = ((DDiagramElement) siriusDiagramElement).getTarget();
String stringRepresentingTheSemanticClassName = anObjectOfYourDomain.getClass().getSimpleName()
...
}
}
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848561 is a reply to message #1848537] |
Tue, 07 December 2021 23:33   |
Eclipse User |
|
|
|
The class name of my ecore obejct is Data_Element. I was able to get "Data_ElementImpl" from printing the editPart.resolveTargetSemnaticElement(), but it adds the "Impl" at the end of it. Does this happen to all editParts? If so I think I could just strip the Impl.
Also, the code never reaches the code block of if( siriusDiagramElement instanceof DDiagramElement). Was wondering if it would be important to get the actual DDiagramElement
ArrayList<ElkNode> nodes = new ArrayList<>(layoutMapping.getLayoutGraph().getChildren());
for (Entry<ElkGraphElement, Object> entry : layoutMapping.getGraphMap().entrySet()) {
Object editPart = entry.getValue();
System.out.println(entry.getKey());
System.out.println(entry.getValue().getClass());
if (editPart instanceof DNodeListEditPart) {
EObject siriusDiagramElement = ((DNodeListEditPart) editPart).resolveTargetSemanticElement();
if (siriusDiagramElement instanceof DDiagramElement) {
EObject ecoreObj = ((DDiagramElement) siriusDiagramElement).getTarget();
System.out.println("Got here");
System.out.println(ecoreObj.getClass().getSimpleName());
}
System.out.println(siriusDiagramElement.getClass().getSimpleName());
}
}
[Updated on: Tue, 07 December 2021 23:33] by Moderator Report message to a moderator
|
|
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848632 is a reply to message #1848561] |
Fri, 10 December 2021 10:22   |
Eclipse User |
|
|
|
Quote:the code never reaches the code block of if( siriusDiagramElement instanceof DDiagramElement).
It is "normal" because in your code sample, you directly call resolveTargetSemanticElement() on the edit part. In my code, I call resolveSemanticElement() and then getTarget().
All the better if you managed to do what you wanted.
|
|
|
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1849294 is a reply to message #1848467] |
Tue, 11 January 2022 20:08  |
Eclipse User |
|
|
|
I've successfully added a new property to the respective nodes.
String elementName = siriusDiagramElement.eClass().getName();
IProperty<String> property = new Property("ObjectName");
entry.getKey().setProperty(property, elementName);
Now inside, my LayoutProvider, I would like to retrieve the property. From the documentation it seems I'm supposed to use the auto-generated LayoutOptions file for provided properties. How would I retrieve this custom property that I've added?
[Updated on: Tue, 11 January 2022 20:09] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03569 seconds