Home » Eclipse Projects » Sirius » Custom layout for border nodes
Custom layout for border nodes [message #1801401] |
Fri, 18 January 2019 05:14  |
Eclipse User |
|
|
|
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 #1801891 is a reply to message #1801842] |
Tue, 29 January 2019 04:45   |
Eclipse User |
|
|
|
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 #1801982 is a reply to message #1801908] |
Wed, 30 January 2019 04:33   |
Eclipse User |
|
|
|
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 #1803182 is a reply to message #1803058] |
Mon, 25 February 2019 01:16  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Wed Jul 23 06:21:07 EDT 2025
Powered by FUDForum. Page generated in 0.07702 seconds
|