فهرست منبع

added propagating of undeletes

fixed all nodes being undirected at multiple places
fixed a bug that involved using listeners
	fix: no longer use listeners
jascha Bohne 8 سال پیش
والد
کامیت
5da98a8375

+ 59 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphHelper.java

@@ -13,6 +13,7 @@ import org.graphstream.ui.geom.Point3;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 
 public class GraphHelper {
@@ -69,7 +70,7 @@ public class GraphHelper {
 			while (searchingForId) {
 				if (target.getEdge(newId) == null) {
 					searchingForId = false;
-					target.addEdge(newId, newIds.get(e.getSourceNode().getId()), newIds.get(e.getTargetNode().getId()));
+					target.addEdge(newId, newIds.get(e.getSourceNode().getId()), newIds.get(e.getTargetNode().getId()), e.isDirected());
 					if(e.getAttribute("originalElement") == null) {
 						target.getEdge(newId).addAttribute("originalElement", source.getId().concat("+#" + e.getId()));
 					} else  {
@@ -277,15 +278,19 @@ public class GraphHelper {
 		Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
 	}
 
-	public static void propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
+	public static String propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
 		Iterator<? extends Element> elementIter = col.iterator();
 		while (elementIter.hasNext()){
 			Element e = elementIter.next();
-			propagateElementDeletion(g, e);
+			return propagateElementDeletion(g, e);
 		}
+		return null;
 	}
-	
-	public static void propagateElementDeletion(MyGraph g, Element e){
+
+	public static String propagateElementDeletion(MyGraph g, Element e){
+		if(e.getAttribute("originalElement") == null){
+			return null;
+		}
 		String origGraph = e.getAttribute("originalElement").toString().split("\\+#")[0];
 		String origId = e.getAttribute("originalElement").toString().split("\\+#")[1];
 		Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
@@ -294,13 +299,62 @@ public class GraphHelper {
 			if (temp.getId().equals(origGraph)){
 				if(e instanceof Node && temp.getNode(origId) != null){
 					temp.removeNode(origId);
+					return temp.getId();
 				} else if (e instanceof Edge && temp.getEdge(origId) != null){
 					temp.removeEdge(origId);
+					return temp.getId();
 				} else {
 					Debug.out("INFORMATION: could not Delete Element bećause it didn't exist: " + origGraph + ":" + origId ,1);
 				}
+				return null;
 			}
 		}
 		Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
+		return null;
+	}
+
+	public static String propagateElementUndeletion(MyGraph g,Element e, String newNodeId){
+		if(e.getAttribute("originalElement") == null){
+			return null;
+		}
+		String origGraph = e.getAttribute("originalElement").toString().split("\\+#")[0];
+		String origId = e.getAttribute("originalElement").toString().split("\\+#")[1];
+		Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
+		HashMap<String, Object> attributes = new HashMap<String, Object>();
+		for (String s : e.getAttributeKeySet()) {
+			attributes.put(s, e.getAttribute(s));
+		}
+
+		while(graphIter.hasNext()){
+			MyGraph temp = graphIter.next();
+			if (temp.getId().equals(origGraph)){
+				String newId = Main.getInstance().getUnusedID(new GraphManager(temp));
+				if(e instanceof Node){
+					temp.addNode(newId);
+					temp.getNode(newId).addAttributes(attributes);
+					return temp.getId() + "+#" + newId;//the id of Graph+newNode
+				} else if (e instanceof Edge){
+					Edge ed = (Edge) e;
+					String sourceId = ed.getSourceNode().getAttribute("originalElement").toString()
+							.split("\\+#")[newNodeId.split("\\+#").length-1];
+					String targetId = ed.getTargetNode().getAttribute("originalElement").toString()
+							.split("\\+#")[newNodeId.split("\\+#").length-1];
+					if(temp.getNode(sourceId) == null){
+						sourceId = newNodeId.split("\\+#")[newNodeId.split("\\+#").length-1];
+					} else {
+						targetId = newNodeId.split("\\+#")[newNodeId.split("\\+#").length-1];
+					}
+					temp.addEdge(newId, sourceId, targetId, ed.isDirected());
+					temp.getEdge(newId).addAttributes(attributes);
+					return temp.getId() + "+#" + newId;//the id of graph+newEdge
+				}
+			}
+		}
+		Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
+		return null;
+	}
+
+	public static void resetUndelete() {
+
 	}
 }

+ 16 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -43,6 +43,8 @@ public class GraphManager {
 	 */
 	protected String stylesheet = "";
 
+	/** the grpah that a Node was last deleted of */
+	private String graphDeleteId;
 	/** The last Node that was deleted. */
 	protected Node deletedNode;
 	/** The last Edge that was deleted. */
@@ -105,7 +107,7 @@ public class GraphManager {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
-		GraphHelper.propagateElementDeletion(g, deletedNode);
+		graphDeleteId = GraphHelper.propagateElementDeletion(g, deletedNode);
 	}
 
 	/**
@@ -121,7 +123,7 @@ public class GraphManager {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
-		GraphHelper.propagateElementDeletion(g, deletedEdges);
+		graphDeleteId = GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
 
 	/**
@@ -158,7 +160,6 @@ public class GraphManager {
 	 */
 	public void undelete() {
 		String newId = "";
-		// System.out.println("test-undel");
 		HashMap<String, Object> attributes = new HashMap<String, Object>();
 		if (deletedNode != null) {
 			for (String s : deletedNode.getAttributeKeySet()) {
@@ -167,6 +168,10 @@ public class GraphManager {
 			newId = Main.getInstance().getUnusedID();
 			g.addNode(newId);
 			g.getNode(newId).addAttributes(attributes);
+			String origElement = GraphHelper.propagateElementUndeletion(g, deletedNode, null);
+			if(origElement != null){
+			g.getNode(newId).addAttribute("originalElement", origElement);
+			}
 		}
 
 		for (Edge e : deletedEdges) {
@@ -185,9 +190,15 @@ public class GraphManager {
 				targetId = e.getTargetNode().getId();
 
 			}
-			g.addEdge(id, sourceId, targetId);
+			g.addEdge(id, sourceId, targetId, e.isDirected());
 			g.getEdge(id).addAttributes(attributes);
+			String origElement = GraphHelper.propagateElementUndeletion(g, e, g.getNode(newId).getAttribute("originalElement"));
+			if(origElement != null){
+				g.getEdge(id).addAttribute("originalElement", origElement);
+			}
+
 		}
+
 		deletedEdges = new LinkedList<>();
 		deletedNode = null;
 	}
@@ -362,7 +373,7 @@ public class GraphManager {
 		for (String s : e.getAttributeKeySet()) {
 			attributes.put(s, e.getAttribute(s));
 		}
-		g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
+		g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode(), e.isDirected());
 		g.getEdge(e.getId()).addAttributes(attributes);
 	}
 

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/MappingGraphManager.java

@@ -258,7 +258,7 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 		attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT, idPrefix);
 		attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT_ID, parentsID.get(idPrefix));
 
-		g.addEdge(idPrefix + e.getId(), idPrefix + e.getSourceNode().getId(), idPrefix + e.getTargetNode().getId());
+		g.addEdge(idPrefix + e.getId(), idPrefix + e.getSourceNode().getId(), idPrefix + e.getTargetNode().getId(), e.isDirected());
 		g.getEdge(idPrefix + e.getId()).addAttributes(attributes);
 	}
 

+ 2 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/MyGraph.java

@@ -7,6 +7,7 @@ import org.graphstream.graph.Edge;
 import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.SingleGraph;
 
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
@@ -106,6 +107,7 @@ public class MyGraph extends SingleGraph {
 				|| (e.getAttribute("weight") != null
 				&& (OptionsManager.getDefaultWeight() == Main.getInstance().convertAttributeTypes(e.getAttribute("weight"), new Double(0.0)))));
 		if (doWeight) {
+			Debug.out("MyGraph:105 " + e.getId() + " " + e.getAttribute("weight"));
 			ToolboxManager.createWeightDialog(e);
 		}
 		for (EdgeCreatedListener list : allEdgeListeners) {

+ 0 - 8
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GraphDisplayManager.java

@@ -384,10 +384,6 @@ public final class GraphDisplayManager {
 			mapping.setStylesheet(StylesheetManager.DEFAULT_STYLESHEET);
 			vList.add(mapping);
 
-			underlay.addEdgeCreatedListener(mapping);
-			underlay.addNodeCreatedListener(mapping);
-			operator.addEdgeCreatedListener(mapping);
-			operator.addNodeCreatedListener(mapping);
 		}
 		mapping.activated();
 		switchActiveGraph();
@@ -472,10 +468,6 @@ public final class GraphDisplayManager {
 		currentLayer = Layer.MAPPING;
 		removeAllCurrentGraphs();
 		vList.add(map);
-		und.addEdgeCreatedListener(map);
-		und.addNodeCreatedListener(map);
-		op.addEdgeCreatedListener(map);
-		op.addNodeCreatedListener(map);
 		map.loadGraph(g);
 		currentLayer = tempLayer;
 		switchActiveGraph();