Skip to content

Commit

Permalink
Implement IGNORE_INVISIBLE_LAYOUT Zest Style for Zest 2.0
Browse files Browse the repository at this point in the history
With this change, invisible graph nodes and connections are ignored
within the LayoutContext and therefore within the layout algorithms.

Note that as part of this change, the Zest styles are no longer set
inside the Graph constructor, but via a separate setGraphStyle() method.
This is because the constructor styles are also used for creating the
underlying FigureCanvas, which would otherwise throw an exception due to
the unsupported styles.

While it technically breaks compatibility, it is practically impossible
to have used those styles up until now.

Fixes #608
  • Loading branch information
ptziegler authored and azoitl committed Dec 27, 2024
1 parent 0ff4c71 commit 1dd8b35
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## GEF

## Zest
- The Zest Graph style have to be set via the `setGraphStyle()` method rather than the constructor. Reason being that otherwise, the same style is used to initialize the underlying `FigureCanvas`.

# GEF Classic 3.22.0

Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.zest.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.zest.core;singleton:=true
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Bundle-Version: 1.14.100.qualifier
Bundle-Version: 1.15.0.qualifier
Require-Bundle: org.eclipse.zest.layouts,
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.draw2d;visibility:=reexport
Expand Down
55 changes: 47 additions & 8 deletions org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,18 @@ public class Graph extends FigureCanvas implements IContainer2 {
private ConnectionRouter defaultConnectionRouter;
private ZoomManager zoomManager = null;

private final ZoomGestureListener zoomListener;
private final RotateGestureListener rotateListener;

/**
* Constructor for a Graph. This widget represents the root of the graph, and
* can contain graph items such as graph nodes and graph connections.
*
* @param parent
* @param style
* @param style The SWT style used for the underlying {@link FigureCanvas}. See
* {@link FigureCanvas#ACCEPTED_STYLES} for a list of all
* supported styles. Use {@link #setGraphStyle(int)} to set the
* Zest-specific styles.
*/
public Graph(Composite parent, int style) {
this(parent, style, false);
Expand All @@ -155,13 +161,16 @@ public Graph(Composite parent, int style) {
* can contain graph items such as graph nodes and graph connections.
*
* @param parent
* @param style
* @param style The SWT style used for the underlying
* {@link FigureCanvas}. See
* {@link FigureCanvas#ACCEPTED_STYLES} for a list of all
* supported styles. Use {@link #setGraphStyle(int)} to
* set the Zest-specific styles.
* @param enableHideNodes
* @since 1.8
*/
public Graph(Composite parent, int style, boolean enableHideNodes) {
super(parent, style | SWT.DOUBLE_BUFFERED);
this.style = style;
this.setBackground(ColorConstants.white);

LIGHT_BLUE = new Color(Display.getDefault(), 216, 228, 248);
Expand Down Expand Up @@ -226,6 +235,8 @@ public void dispatchMouseMoved(org.eclipse.swt.events.MouseEvent me) {
this.figure2ItemMap = new HashMap<>();
this.enableHideNodes = enableHideNodes;
this.subgraphFigures = new HashSet<>();
this.zoomListener = new ZoomGestureListener();
this.rotateListener = new RotateGestureListener();

this.addPaintListener(event -> {
if (shouldSheduleLayout) {
Expand All @@ -247,11 +258,8 @@ public void controlResized(ControlEvent e) {
}
}
});
if ((style & (ZestStyles.GESTURES_DISABLED)) == 0) {
// Only add default gestures if not disabled by style bit
this.addGestureListener(new ZoomGestureListener());
this.addGestureListener(new RotateGestureListener());
}
this.addGestureListener(zoomListener);
this.addGestureListener(rotateListener);
this.addDisposeListener(event -> release());
}

Expand Down Expand Up @@ -359,6 +367,37 @@ public int getNodeStyle() {
return nodeStyle;
}

/**
* Sets the default graph style.
*
* @param style the graph style to set.
* @since 1.15
* @see ZestStyles
*/
public final void setGraphStyle(int style) {
// Remove old Gesture listeners (if not already disabled)
if (!ZestStyles.checkStyle(this.style, ZestStyles.GESTURES_DISABLED)) {
removeGestureListener(zoomListener);
removeGestureListener(rotateListener);
}
this.style = style;
// Add new Gesture listeners (if not disabled)
if (!ZestStyles.checkStyle(this.style, ZestStyles.GESTURES_DISABLED)) {
addGestureListener(zoomListener);
addGestureListener(rotateListener);
}
}

/**
* Gets the default graph style.
*
* @return the default graph style
* @since 1.15
*/
public final int getGraphStyle() {
return style;
}

/**
* Gets the list of GraphModelConnection objects.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ boolean isLayoutItemFiltered(GraphItem item) {
return true;
}
}
if (!item.isVisible()) {
return ZestStyles.checkStyle(container.getGraph().getGraphStyle(), ZestStyles.IGNORE_INVISIBLE_LAYOUT);
}
return false;
}

Expand Down
12 changes: 12 additions & 0 deletions org.eclipse.zest.tests/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.zest.tests" version="2">
<resource path="src/org/eclipse/zest/tests/GraphTests.java" type="org.eclipse.zest.tests.GraphTests">
<filter id="640712815">
<message_arguments>
<message_argument value="Graph"/>
<message_argument value="GraphTests"/>
<message_argument value="getLayoutContext()"/>
</message_arguments>
</filter>
</resource>
</component>
43 changes: 43 additions & 0 deletions org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphItem;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.core.widgets.internal.ZestRootLayer;
import org.eclipse.zest.layouts.interfaces.LayoutContext;

import org.eclipse.draw2d.Figure;

Expand Down Expand Up @@ -137,4 +139,45 @@ public void testDisposal() {

}

/**
* Check that the {@link ZestStyles#IGNORE_INVISIBLE_LAYOUT} style can be set
* and used correctly.
*
* @See https://bugs.eclipse.org/bugs/show_bug.cgi?id=254584
*/
@Test
public void testInvisibleLayoutStyle() {
LayoutContext layoutContext = graph.getLayoutContext();
GraphNode node = graph.getNodes().get(0);
node.setVisible(false);
GraphConnection conn = graph.getConnections().get(0);
conn.setVisible(false);

assertEquals(layoutContext.getNodes().length, 2);
assertEquals(layoutContext.getConnections().length, 1);
assertEquals(layoutContext.getEntities().length, 2);
graph.setGraphStyle(ZestStyles.IGNORE_INVISIBLE_LAYOUT);
assertEquals(layoutContext.getNodes().length, 1);
assertEquals(layoutContext.getConnections().length, 0);
assertEquals(layoutContext.getEntities().length, 1);
graph.setGraphStyle(ZestStyles.NONE);
assertEquals(layoutContext.getNodes().length, 2);
assertEquals(layoutContext.getConnections().length, 1);
assertEquals(layoutContext.getEntities().length, 2);
}

/**
* Check that the {@link ZestStyles#GESTURES_DISABLED} style can be set and used
* correctly.
*
* @See https://bugs.eclipse.org/bugs/show_bug.cgi?id=254584
*/
@Test
public void testGestureStyle() {
assertEquals(graph.getListeners(SWT.Gesture).length, 2);
graph.setGraphStyle(ZestStyles.GESTURES_DISABLED);
assertEquals(graph.getListeners(SWT.Gesture).length, 0);
graph.setGraphStyle(ZestStyles.NONE);
assertEquals(graph.getListeners(SWT.Gesture).length, 2);
}
}

0 comments on commit 1dd8b35

Please sign in to comment.