Author: koen.aers(a)jboss.com
Date: 2008-07-30 04:41:10 -0400 (Wed, 30 Jul 2008)
New Revision: 9414
Added:
trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools/flow/editor/core/DefaultConnectionWrapper.java
Log:
create DefaultConnectionWrapper and pull up implementation from TransitionWrapper
Added:
trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools/flow/editor/core/DefaultConnectionWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools/flow/editor/core/DefaultConnectionWrapper.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools/flow/editor/core/DefaultConnectionWrapper.java 2008-07-30
08:41:10 UTC (rev 9414)
@@ -0,0 +1,65 @@
+package org.jboss.tools.flow.editor.core;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.jboss.tools.flow.common.core.Connection;
+import org.jboss.tools.flow.common.core.DefaultConnection;
+import org.jboss.tools.flow.common.core.Node;
+
+
+public class DefaultConnectionWrapper extends AbstractConnectionWrapper {
+
+ public Connection getConnection() {
+ return (Connection)getElement();
+ }
+
+ protected List<Point> internalGetBendpoints() {
+ return (List<Point>) stringToBendpoints((String)
getConnection().getMetaData("bendpoints"));
+ }
+
+ protected void internalSetBendpoints(List<Point> bendpoints) {
+ getConnection().setMetaData("bendpoints",
bendpointsToString(bendpoints));
+ }
+
+ private String bendpointsToString(List<Point> bendpoints) {
+ if (bendpoints == null) {
+ return null;
+ }
+ String result = "[";
+ for (Iterator<Point> iterator = bendpoints.iterator(); iterator.hasNext();
) {
+ Point point = iterator.next();
+ result += point.x + "," + point.y + (iterator.hasNext() ?
";" : "");
+ }
+ result += "]";
+ return result;
+ }
+
+ private List<Point> stringToBendpoints(String s) {
+ List<Point> result = new ArrayList<Point>();
+ if (s == null) {
+ return result;
+ }
+ s = s.substring(1, s.length() - 1);
+ String[] bendpoints = s.split(";");
+ for (String bendpoint: bendpoints) {
+ String[] xy = bendpoint.split(",");
+ result.add(new Point(new Integer(xy[0]), new Integer(xy[1])));
+ }
+ return result;
+ }
+
+
+ public void connect(NodeWrapper source, NodeWrapper target) {
+ super.connect(source, target);
+ Node from = (Node)getSource().getElement();
+ Node to = (Node)getTarget().getElement();
+ setElement(createConnection(from, to));
+ }
+
+ protected Connection createConnection(Node from, Node to) {
+ return new DefaultConnection(from, to);
+ }
+}
Show replies by date