Skip to content

Commit

Permalink
[Zest 2.0] Switch to new layout algorithms for tests and snippets
Browse files Browse the repository at this point in the history
This change has been delayed until the very end to avoid accidentally
breaking the Zest 1.x legacy mode.
  • Loading branch information
ptziegler committed Sep 17, 2024
1 parent 5a23c1d commit fb6711c
Show file tree
Hide file tree
Showing 32 changed files with 129 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -125,7 +124,7 @@ public void widgetSelected(SelectionEvent e) {

viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.addSelectionChangedListener(event -> System.out.println("Selection changed: " + (event.getSelection())));
viewer.setInput(new Object());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -117,7 +116,7 @@ public static void main(String[] args) {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.setInput(new Object());
shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm;

/**
Expand Down Expand Up @@ -103,7 +102,7 @@ public static void main(String[] args) throws IOException {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new SimpleGraphContentProvider());
viewer.setLabelProvider(new LabelProvider());
viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm());

shell.open();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

public class GraphJFaceSnippet4 {
Expand Down Expand Up @@ -108,7 +107,7 @@ public static void main(String[] args) {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.setInput(new Object());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static void buildViewer(Composite parent) {
contentProvider = new MyContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.setInput(new Object());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.INestedContentProvider;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -134,7 +133,7 @@ public static void main(String[] args) {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.setInput(new Object());

Button button = new Button(shell, SWT.PUSH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.INestedContentProvider;
import org.eclipse.zest.examples.uml.UMLClassFigure;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

import org.eclipse.draw2d.IFigure;
Expand Down Expand Up @@ -181,7 +180,7 @@ public static void main(String[] args) {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
viewer.setInput(new Object());

Button button = new Button(shell, SWT.PUSH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void main(String[] args) {
viewer = new GraphViewer(shell, SWT.NONE);
viewer.setContentProvider(new MyContentProvider());
viewer.setLabelProvider(new MyLabelProvider());
viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm.Zest1());
viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm());
viewer.setInput(new Object());

shell.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IConnectionStyleProvider;
import org.eclipse.zest.core.viewers.IConnectionStyleProvider2;
import org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider2;
import org.eclipse.zest.core.viewers.IGraphContentProvider;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

}

static class MyConnectionRelationLabelProvider extends LabelProvider implements IConnectionStyleProvider {
static class MyConnectionRelationLabelProvider extends LabelProvider implements IConnectionStyleProvider2 {
final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutEntity;
import org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm;
import org.eclipse.zest.layouts.dataStructures.InternalNode;
import org.eclipse.zest.layouts.dataStructures.InternalRelationship;
import org.eclipse.zest.layouts.interfaces.EntityLayout;

/**
* This snippet shows how to create a custom layout. This layout simply lays the
Expand Down Expand Up @@ -39,63 +37,18 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n, n2);
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n);
g.setLayoutAlgorithm(new AbstractLayoutAlgorithm.Zest1(SWT.NONE) {

private int totalSteps;
private int currentStep;

g.setLayoutAlgorithm(new AbstractLayoutAlgorithm() {
@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout,
InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth,
double boundsHeight) {

totalSteps = entitiesToLayout.length;
double distance = boundsWidth / totalSteps;
public void applyLayout(boolean clean) {
EntityLayout[] entitiesToLayout = context.getEntities();
int totalSteps = entitiesToLayout.length;
double distance = context.getBounds().width / totalSteps;
int xLocation = 0;

fireProgressStarted(totalSteps);

for (currentStep = 0; currentStep < entitiesToLayout.length; currentStep++) {
LayoutEntity layoutEntity = entitiesToLayout[currentStep].getLayoutEntity();
layoutEntity.setLocationInLayout(xLocation, layoutEntity.getYInLayout());
for (EntityLayout layoutEntity : entitiesToLayout) {
layoutEntity.setLocation(xLocation, layoutEntity.getLocation().y);
xLocation += distance;
fireProgressEvent(currentStep, totalSteps);
}
fireProgressEnded(totalSteps);
}

@Override
protected int getCurrentLayoutStep() {
return 0;
}

@Override
protected int getTotalNumberOfLayoutSteps() {
return totalSteps;
}

@Override
protected boolean isValidConfiguration(boolean asynchronous, boolean continuous) {
return true;
}

@Override
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout,
InternalRelationship[] relationshipsToConsider) {
// Do nothing
}

@Override
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout,
InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
// do nothing
}

@Override
public void setLayoutArea(double x, double y, double width, double height) {
// do nothing
}

}, true);

shell.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.internal.NodeSearchDialog;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n, n2);
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

// example for dialog for searching nodes
NodeSearchDialog searchDialog = new NodeSearchDialog(g.getShell(), g.getNodes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public static void main(String[] args) {
connection.setLineWidth(3);
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

Button button = new Button(shell, SWT.PUSH);
button.setText("Change Curve");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

import org.eclipse.draw2d.ColorConstants;
Expand Down Expand Up @@ -60,7 +59,7 @@ public static void main(String[] args) {
createConnection(g, n, n2, ColorConstants.darkGray, 60);
createConnection(g, n, n2, ColorConstants.darkGray, -60);
createConnection(g, n, n2, ColorConstants.black, 0);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

import org.eclipse.draw2d.ColorConstants;
Expand Down Expand Up @@ -156,7 +155,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
new GraphConnection(g, SWT.NONE, n2, n5);
new GraphConnection(g, SWT.NONE, n3, n5);
new GraphConnection(g, SWT.NONE, n4, n5);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.zest.core.widgets.GraphContainer;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

import org.eclipse.draw2d.ColorConstants;
Expand Down Expand Up @@ -173,7 +172,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
GraphConnection connection2 = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, n2, n1);
connection2.setCurveDepth(-30);

g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.HideNodeHelper;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

import org.eclipse.draw2d.Button;
Expand Down Expand Up @@ -53,7 +52,7 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n, n2);
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

// example: hide-nodes reveal-all button
if (g.getHideNodesEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n3);

g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -63,7 +62,7 @@ public void widgetSelected(SelectionEvent e) {
new GraphConnection(g, SWT.NONE, n1, n2);
new GraphConnection(g, SWT.NONE, n2, n3);

g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm;

/**
Expand Down Expand Up @@ -60,7 +59,7 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n3);
}
g.setLayoutAlgorithm(new GridLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new GridLayoutAlgorithm(), true);

shell.open();
while (!shell.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

/**
Expand Down Expand Up @@ -53,7 +52,7 @@ public static void main(String[] args) {
new GraphConnection(g, SWT.NONE, n, n2);
new GraphConnection(g, SWT.NONE, n2, n3);
new GraphConnection(g, SWT.NONE, n3, n);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm.Zest1(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true);

g.addMouseMoveListener(new MouseMoveListener() {

Expand Down
Loading

0 comments on commit fb6711c

Please sign in to comment.