Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » ELK Auto Layout - Get Class names of ELKNodes
ELK Auto Layout - Get Class names of ELKNodes [message #1848460] Thu, 02 December 2021 22:18 Go to next message
Jonathan Li is currently offline Jonathan LiFriend
Messages: 10
Registered: November 2021
Junior Member
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]

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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7517
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 296
Registered: July 2009
Senior Member
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


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848521 is a reply to message #1848467] Mon, 06 December 2021 23:09 Go to previous messageGo to next message
Jonathan Li is currently offline Jonathan LiFriend
Messages: 10
Registered: November 2021
Junior Member
Thanks for the response.

How do I access the stringRepresentingTheSemanticClassName within the class that implements IELKLayoutExtention? The getGraphMap() seems to return a map<ELK Object, Object>, but I'm having trouble retrieving the class name from the Object as it doesn't have any useful methods

[Updated on: Mon, 06 December 2021 23:11]

Report message to a moderator

Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848537 is a reply to message #1848521] Tue, 07 December 2021 08:19 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 296
Registered: July 2009
Senior Member
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()
        ...
    }
}


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848561 is a reply to message #1848537] Tue, 07 December 2021 23:33 Go to previous messageGo to next message
Jonathan Li is currently offline Jonathan LiFriend
Messages: 10
Registered: November 2021
Junior Member
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]

Report message to a moderator

Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848566 is a reply to message #1848561] Wed, 08 December 2021 08:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7517
Registered: July 2009
Senior Member
Hi

As I commented earlier.

Quote:
The modelled class name, probably DataElement, is available using EObject.eClass().getName().


Regards

Ed Willink
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848581 is a reply to message #1848566] Wed, 08 December 2021 15:45 Go to previous messageGo to next message
Jonathan Li is currently offline Jonathan LiFriend
Messages: 10
Registered: November 2021
Junior Member
This worked thank you
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1848632 is a reply to message #1848561] Fri, 10 December 2021 10:22 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 296
Registered: July 2009
Senior Member
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.


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: ELK Auto Layout - Get Class names of ELKNodes [message #1849294 is a reply to message #1848467] Tue, 11 January 2022 20:08 Go to previous message
Jonathan Li is currently offline Jonathan LiFriend
Messages: 10
Registered: November 2021
Junior Member
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]

Report message to a moderator

Previous Topic:Exporting VSP as Plugin Project
Next Topic:Cannot Modify Resource Set
Goto Forum:
  


Current Time: Wed Sep 28 16:30:26 GMT 2022

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

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

Back to the top