Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Custom layout for border nodes
Custom layout for border nodes [message #1801401] Fri, 18 January 2019 10:14 Go to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello,

I have implemented a custom layout using following extensions.

1) org.eclipse.sirius.diagram.ui.layoutProvider
2)org.eclipse.gmf.runtime.diagram.ui.layoutProviders

In my custom layout i to have change the position of nodes and its border nodes.

Facing issues in positioning of border nodes .Only after multiple click on arrange all , the border nodes are placed on expected positions.

On analysis i found that the order of execution of compound command is causing the problem.

I have found a similar post :


Link :
https://www.eclipse.org/forums/index.php/t/1081112/

Can you please help me in resolving this issue ?

Regards,
Rakesh
Re: Custom layout for border nodes [message #1801842 is a reply to message #1801401] Mon, 28 January 2019 10:51 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

Can I see how you implemented these commands?

Meanwhile, there may be an easier alternative for your border nodes if you want them to be always placed at a specific location on their parents all the time. For this, you need to add a BorderItemLocator to the parent edit part. You can look into org.eclipse.sirius.diagram.sequence.ui.tool.internal.figure.SouthCenteredBorderItemLocator.SouthCenteredBorderItemLocator(IFigure, Dimension) that is used in the sequence diagram to have border nodes always on the south border and centered. You can have a look at this documentation [1] to see how to provide the EditPart where you will install your own BorderItemLocator.

Regards,
Steve

[1] https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom_style.html


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Custom layout for border nodes [message #1801891 is a reply to message #1801842] Tue, 29 January 2019 09:45 Go to previous messageGo to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello Steve,

We have set of border nodes to be placed on EAST and WEST sides. There is no issues in this.

We want to have equal spacing between the border nodes on either sides. We are encountering issues in this.

When we open the diagram, the spacing between the border nodes are uneven, after multiple click on arrange all, the border nodes are placed with equal spacing.

I have attached ,image of the diagram with both Actual and expected states.

Please let us know how to handle this spacing issues, between the borders.

Please find the implementation.

The following provider has been registered using org.eclipse.gmf.runtime.diagram.ui.layoutProviders extension.



public class CustomLayout extends AbstractLayoutProvider {

private static final String COMMAND_MESSAGE = "Apply position to the element";

/**
* {@inheritDoc}
*/
@Override
public boolean provides(final IOperation operation) {

return true;
}

/**
* {@inheritDoc}
*/
@Override
public Command layoutEditParts(final List selectedObjects, final IAdaptable layoutHint) {
List<IDiagramNodeEditPart> nodeMap = new ArrayList<>();
CompoundCommand cc = new CompoundCommand();

for (Object object : selectedObjects) {
if (object instanceof IDiagramNodeEditPart) {
IDiagramNodeEditPart nodeEditPart = (IDiagramNodeEditPart) object;
Object model = nodeEditPart.getModel();
if (model instanceof Node) {
Node node = (Node) model;
DNode dNode = (DNode) node.getElement();
nodeMap.add(nodeEditPart);
}
}
}
layoutData(cc, nodeMap);
return cc;
}

/**
* @param cc
* @param runnableNodeMap
*/
private void layoutData(final CompoundCommand cc, final List<IDiagramNodeEditPart> nodeMap) {
int x = 100;
int y = 10;
int count = 0;
for (IDiagramNodeEditPart editPart : nodeMap)) {
count++;
Node node = (Node) editPart.getModel();
DNode dNode = (DNode) node.getElement();
int lSize = getBorderNodes(editPart, "RA").size();
int rSize = getBorderNodes(editPart, "WA").size();
int max = lSize > rSize ? lSize : rSize;
int height = max * 40;
Rectangle r = new Rectangle(x, y, coreEditPart.getFigure().getSize().width, height);
ICommandProxy nodeCommand = new ICommandProxy(new SetBoundsCommand(coreEditPart.getEditingDomain(),
COMMAND_MESSAGE, new EObjectAdapter(coreEditPart.getAdapter(View.class)), r));
cc.add(nodeCommand);
TransactionalEditingDomain editingDomain = coreEditPart.getEditingDomain();
layoutNodeLabel(editPart, 40, y, cc, count);
layoutBorderNodes(x, y, dNode, cc, editingDomain, editPart);
x += 500;
if (y > 10) {
y = 10;
}
else {
y = 200;
}
}
}

/**
* @param editPart
* @param x
* @param y
* @param cc
* @param count
*/
//layout the label of the node, to the center
private void layoutNodeLabel(final IDiagramNodeEditPart editPart, final int x, final int y,
final CompoundCommand cc, final int count) {
int initialX = x;
int intitialy = y;
DNodeNameEditPart nodeLabel = getNodeLabel(editPart);
Rectangle r = new Rectangle(initialX, intitialy - 350, 70, 10);
if (nodeLabel != null) {
EObject adapter = ((IDiagramNameEditPart) nodeLabel).getAdapter(View.class);

DNode dNode = (DNode) ((Node) nodeLabel.getModel()).getElement();
cc.add(new ICommandProxy(
new SetBoundsCommand(nodeLabel.getEditingDomain(), COMMAND_MESSAGE, new EObjectAdapter(adapter), r)));
}
}

/**
* @param nodeEditPart
*/
//fetch the label
private DNodeNameEditPart getNodeLabel(final IDiagramNodeEditPart nodeEditPart) {
IStyleEditPart labelEditPart = null;
List children = nodeEditPart.getChildren();
for (Object object : children) {
if (object instanceof DNodeNameEditPart) {
return (DNodeNameEditPart) object;
}
}
return null;
}

/**
* @param y
* @param x
* @param dNode
* @param cc
* @param editingDomain
* @param editPart
*/
private void layoutBorderNodes(final int x, final int y, final DNode dNode, final CompoundCommand cc,
final TransactionalEditingDomain editingDomain, final IDiagramNodeEditPart editPart) {
Set<IDiagramBorderNodeEditPart> leftBorderedNodes = getBorderNodes(editPart, "RA");
Set<IDiagramBorderNodeEditPart> rightBorderedNodes = getBorderNodes(editPart, "WA");
// get right side nodes
// get left side nodes
// position all.
int initialY = 10;
int initialX = x - 50;
for (IDiagramBorderNodeEditPart borderNode : leftBorderedNodes) {
Rectangle r = new Rectangle(initialX, initialY, 60, 20);
EObject adapter = borderNode.getAdapter(View.class);
cc.add(new ICommandProxy(
new SetBoundsCommand(editPart.getEditingDomain(), COMMAND_MESSAGE, new EObjectAdapter(adapter), r)));
layOutLabels(borderNode, cc, -500, 0);
initialY = initialY + 40;
}
boolean writeMaxNodes = leftBorderedNodes.size() > rightBorderedNodes.size() ? false : true;
initialY = 10;
if (!writeMaxNodes && (rightBorderedNodes.size() > 0)) {
initialY = ((leftBorderedNodes.size() * 40) / rightBorderedNodes.size()) - 20;
}
initialX = x + 150;
for (IDiagramBorderNodeEditPart borderNode : rightBorderedNodes) {
Rectangle r = new Rectangle(initialX, initialY, 60, 20);
EObject adapter = borderNode.getAdapter(View.class);
cc.add(new ICommandProxy(
new SetBoundsCommand(coreEditPart.getEditingDomain(), COMMAND_MESSAGE, new EObjectAdapter(adapter), r)));
layOutLabels(borderNode, cc, 100, 0);
initialY = initialY + 40;
}

}

/**
* @param borderNode
* @param cc
* @param y
* @param x
*/
private void layOutLabels(final IDiagramBorderNodeEditPart borderNode, final CompoundCommand cc, final int x,
final int y) {
int initialX = x;
int intitialy = y;
DNodeNameEditPart label = getLabel(borderNode);
Rectangle r = new Rectangle(initialX, intitialy, 70, 10);
if (label != null) {
EObject adapter = ((IDiagramNameEditPart) label).getAdapter(View.class);
cc.add(new ICommandProxy(
new SetBoundsCommand(label.getEditingDomain(), COMMAND_MESSAGE, new EObjectAdapter(adapter), r)));
}
}


/**
* @param borderNode
* @return
*/
private DNodeNameEditPart getLabel(final IDiagramBorderNodeEditPart borderNode) {
IStyleEditPart labelEditPart = null;
List children = borderNode.getChildren();
for (Object object : children) {
if (object instanceof DNodeNameEditPart) {
return (DNodeNameEditPart) object;
}
}
return null;
}

/**
* @param editPart
* @param string
* @return
*/
private Set<IDiagramBorderNodeEditPart> getBorderNodes(final IDiagramNodeEditPart editPart, final String string) {
Set<IDiagramBorderNodeEditPart> nodes = new HashSet<>();

List borderNodes = editPart.getChildren();
for (Object children : borderNodes) {
if (children instanceof IDiagramBorderNodeEditPart) {
IDiagramBorderNodeEditPart nodeEditPart = (IDiagramBorderNodeEditPart) children;
Node node = (Node) nodeEditPart.getModel();
DNode dNode = (DNode) node.getElement();
if (dNode.getActualMapping().getName().contains(string)) {
nodes.add(nodeEditPart);
}
}
}
return nodes;
}

}

Regards,
Rakesh
Re: Custom layout for border nodes [message #1801908 is a reply to message #1801891] Tue, 29 January 2019 13:35 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

I think you could simplify your implementation by using org.eclipse.sirius.diagram.ui.internal.edit.commands.DistributeCommand with distributeTpe as DistributeAction.HORIZONTALLY_WITH_UNIFORM_GAPS. This way you will avoid to compute the spacing yourself and hopefully resolve your current issue.

Regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Custom layout for border nodes [message #1801982 is a reply to message #1801908] Wed, 30 January 2019 09:33 Go to previous messageGo to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello Steve,

I have modified the layout provider using DistributeCommand.

Even with this implementation, i am facing the same issue.

i.e. When i open then diagram , the spacing between the border nodes are uneven, only after multiple clicks on "Arrange-All" the border nodes are placed with equal spacing between them.

Please find the updated code.

/**
* @param y
* @param x
* @param dNode
* @param cc
* @param editingDomain
* @param editPart
*/
private void layoutBorderNodes(final int x, final int y, final DNode dNode, final CompoundCommand cc,
final TransactionalEditingDomain editingDomain, final IDiagramNodeEditPart editPart) {
Set<IDiagramBorderNodeEditPart> leftBorderedNodes = getBorderNodes(editPart, "RA");
Set<IDiagramBorderNodeEditPart> rightBorderedNodes = getBorderNodes(editPart, "WA");
cc.add(new ICommandProxy(
new DistributeCommand(editingDomain, new ArrayList<>(leftBorderedNodes), DistributeAction.GAPS_VERTICALLY)));
cc.add(new ICommandProxy(
new DistributeCommand(editingDomain, new ArrayList<>(rightBorderedNodes), DistributeAction.GAPS_VERTICALLY)));

}

Regards,
Rakesh
Re: Custom layout for border nodes [message #1802299 is a reply to message #1801982] Wed, 06 February 2019 05:16 Go to previous messageGo to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello Steve/All,

Can you please help me in resolving this issue.

Regards,
Rakesh
Re: Custom layout for border nodes [message #1803058 is a reply to message #1802299] Thu, 21 February 2019 14:09 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

It's strange, I do not know if I can find an answer without debugging it. Do you have the same behaviour if you select the border node on your diagram and execute the distribute tool from the tabbar?

Regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Custom layout for border nodes [message #1803182 is a reply to message #1803058] Mon, 25 February 2019 06:16 Go to previous message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello Steve,

I executed "Arrange Selection" by selecting only border nodes.

The behavior is different. On multiple clicks on 'Arrange Selection', the border nodes are getting moved to left and are getting overlapped a bit.

Regards,
Rakesh
Previous Topic:Creating an updatesite with examples
Next Topic:Selection Wizard Semnatic Candidate: All of one type
Goto Forum:
  


Current Time: Thu Apr 25 14:39:34 GMT 2024

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

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

Back to the top