I am implementing some Java services for allowing changing the type of certain elements:


In the java service, I create a new model element, copy the old attributes and delete the original model element.
I finally managed to make Sirius place it in the same location and with the same size as the previous element, but I can't place the pins on the Container edge at the same position on the new container.

How should I do it?
Calling the service in an Operation "changeContext" like:
aql:self.oclAsType(myPackage::Component).transformToComponent(views)
And here is the Service code so far:
public void transformToComponent(Component c, ArrayList<EObject> containingViews) {
final Component newComponent = myFactory.eINSTANCE.createComponent();
// ... copy attributes ...
// Give to the new component the same size/position as the old one.
if (containingViews != null && containingViews.size() > 0) {
DNodeContainer existingNode = (DNodeContainer) containingViews.get(0);
IGraphicalEditPart editPart = getEditPart(existingNode);
if (editPart instanceof ShapeEditPart) {
ShapeEditPart part = (ShapeEditPart) editPart;
SiriusLayoutDataManager.INSTANCE
.addData(new RootLayoutData(existingNode.eContainer(), part.getLocation(), part.getSize()));
}
//TODO: Place bordered nodes at the same position:
existingNode.getOwnedBorderedNodes().stream().forEach(bn -> {
IGraphicalEditPart editPart2 = getEditPart(bn);
System.out.println(editPart2.toString());
if (editPart2 instanceof ShapeEditPart) {
ShapeEditPart part = (ShapeEditPart) editPart2;
SiriusLayoutDataManager.INSTANCE
.addData(new RootLayoutData(bn.eContainer(), part.getLocation(), part.getSize()));
}
});
}
// Delete the old component
EcoreUtil.remove(c);
}
Thanks in advance for any hint :)
[Updated on: Wed, 30 June 2021 05:11] by Moderator