Home » Eclipse Projects » Sirius » Custom layout for border nodes
|
Re: Custom layout for border nodes [message #1801842 is a reply to message #1801401] |
Mon, 28 January 2019 10:51 |
|
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 |
Rakesh Nidavani 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 |
|
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 |
Rakesh Nidavani 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
|
|
| | | |
Goto Forum:
Current Time: Tue Sep 24 22:31:23 GMT 2024
Powered by FUDForum. Page generated in 0.04317 seconds
|