I'm displaying a model using the Tree Layout within Zest. However, the text that I have assigned to be displayed in each node is too long. I want the text to move to the next line within the node so all of it can be displayed instead of having most of it cut off. I tried using setSize() for each node that I add to the graph but that doesn't seem to make any difference. Could anyone please tell me how I can achieve this ? Thanks. * I have added code that shows the current situation where words get cut off.
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.CGraphNode;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.ImageFigure;
//import org.eclipse.zest.layout.algorithms.RadialLayoutAlgorithm;
//import org.eclipse.zest.layout.interfaces.LayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
public class TreeLayoutExample {
public static void main(String[] args) {
// Create the shell
Display d = new Display();
Shell shell = new Shell(d);
shell.setText("GraphSnippet1");
shell.setLayout(new FillLayout());
shell.setSize(500, 500);
final Graph g = new Graph(shell, SWT.NONE);
g.setSize(500, 500);
GraphNode root = new GraphNode(g, SWT.NONE, "");
root.setSize(1000, 1000);
for (int i = 0; i < 3; i++) {
GraphNode n = new GraphNode(g, SWT.NONE, "GIANT LONG TEXT");
n.setSize(300, 300);
for (int j = 0; j < 3; j++) {
GraphNode n2 = new GraphNode(g, SWT.NONE, "MORE GIANT LONG TEXT");
n2.setSize(300, 300);
new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1);
}
new GraphConnection(g, SWT.NONE, root, n);
}
final TreeLayoutAlgorithm layoutAlgorithm = new org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm();
g.setLayoutAlgorithm(layoutAlgorithm, true);
shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}
The solution to this one is not quite intuitive, but here goes:
Pass
LayoutStyles.NO_LAYOUT_NODE_RESIZING
as the style to theTreeLayoutAlgorithm
:Set the size of your nodes to
setSize(-1, -1)
.Make sure you have enough available space, otherwise the nodes will overlap
Here is the final code snippet:
Looks like this: