diff --git a/org.eclipse.zest.core/META-INF/MANIFEST.MF b/org.eclipse.zest.core/META-INF/MANIFEST.MF index 2a0f02aee..3a0f98086 100644 --- a/org.eclipse.zest.core/META-INF/MANIFEST.MF +++ b/org.eclipse.zest.core/META-INF/MANIFEST.MF @@ -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 diff --git a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java index c306f8688..71eb1b873 100644 --- a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java +++ b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java @@ -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); @@ -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); @@ -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) { @@ -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()); } @@ -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. * diff --git a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/InternalLayoutContext.java b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/InternalLayoutContext.java index 41a323a25..7e1734aa0 100644 --- a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/InternalLayoutContext.java +++ b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/InternalLayoutContext.java @@ -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; } diff --git a/org.eclipse.zest.tests/.settings/.api_filters b/org.eclipse.zest.tests/.settings/.api_filters new file mode 100644 index 000000000..35d63f37d --- /dev/null +++ b/org.eclipse.zest.tests/.settings/.api_filters @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphTests.java b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphTests.java index ba374993f..f21d35c8f 100644 --- a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphTests.java +++ b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphTests.java @@ -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; @@ -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); + } }