| author | Fabian Steeg | 2011-02-26 15:47:56 (EST) |
|---|---|---|
| committer | Fabian Steeg | 2011-02-26 15:47:56 (EST) |
| commit | 3a37e2f51dc355a30642682defd99d14111cc9f7 (patch) (side-by-side diff) | |
| tree | 4d40283ad08601f90afe0f455ecce1ce03a9bd83 | |
| parent | b78a507cbe58fdf77695ef9d8ef9e8b2645e0bd8 (diff) | |
| download | org.eclipse.zest-3a37e2f51dc355a30642682defd99d14111cc9f7.zip org.eclipse.zest-3a37e2f51dc355a30642682defd99d14111cc9f7.tar.gz org.eclipse.zest-3a37e2f51dc355a30642682defd99d14111cc9f7.tar.bz2 | |
Added a Graph#clear method that removes all subgraphs, nodes, and connections
| -rw-r--r-- | org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java | 25 | ||||
| -rw-r--r-- | org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphSelectionTests.java | 12 |
2 files changed, 34 insertions, 3 deletions
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 d99455b..1802f56 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 @@ -215,11 +215,11 @@ public class Graph extends FigureCanvas implements IContainer { } /** - * Gets a list of the GraphModelNode children objects under the root node in - * this diagram. If the root node is null then all the top level nodes are + * Gets a list of the GraphNode children objects under the root node in this + * graph. If the root node is null then all the top level nodes are * returned. * - * @return List of GraphModelNode objects + * @return List of GraphNode objects */ public List getNodes() { return nodes; @@ -358,6 +358,8 @@ public class Graph extends FigureCanvas implements IContainer { } /** + * Apply this graphs's layout cleanly and display all changes. + * * @since 2.0 */ public void applyLayoutNow() { @@ -917,6 +919,23 @@ public class Graph extends FigureCanvas implements IContainer { return connsArray; } + /** + * Clear the graph of all its content. + * + * @since 2.0 + */ + public void clear() { + for (Iterator i = new ArrayList(connections).iterator(); i.hasNext();) { + removeConnection((GraphConnection) i.next()); + } + for (Iterator i = new HashSet(subgraphFigures).iterator(); i.hasNext();) { + removeSubgraphFigure((IFigure) i.next()); + } + for (Iterator i = new ArrayList(nodes).iterator(); i.hasNext();) { + removeNode((GraphNode) i.next()); + } + } + void removeConnection(GraphConnection connection) { IFigure figure = connection.getConnectionFigure(); PolylineConnection sourceContainerConnectionFigure = connection diff --git a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphSelectionTests.java b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphSelectionTests.java index f82df84..e98d3c6 100644 --- a/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphSelectionTests.java +++ b/org.eclipse.zest.tests/src/org/eclipse/zest/tests/GraphSelectionTests.java @@ -141,6 +141,18 @@ public class GraphSelectionTests extends TestCase { selectionEvents.size()); } + public void testClearGraphCheckSelection() throws Exception { + graph.setSelection(nodes); + assertEquals(2, graph.getSelection().size()); + graph.clear(); + assertEquals(0, graph.getNodes().size()); + assertEquals(0, graph.getConnections().size()); + assertEquals(0, graph.getSelection().size()); + setUp(); + assertEquals(2, graph.getNodes().size()); + assertEquals(1, graph.getConnections().size()); + } + private SelectionListener setupListener(final List events) { return new SelectionListener() { public void widgetSelected(SelectionEvent e) { |

