Browse Source

Manually made partial reset to Jaschas version

Jan Enders 7 years ago
parent
commit
7bbd620c90

+ 86 - 27
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphHelper.java

@@ -1,35 +1,29 @@
 package de.tu_darmstadt.informatik.tk.scopviz.graphs;
-
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Random;
-
 import org.graphstream.algorithm.Toolkit;
 import org.graphstream.graph.Edge;
+import org.graphstream.graph.Element;
 import org.graphstream.graph.Node;
 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.ui.OptionsManager;
-
 public class GraphHelper {
-
 	public static MyGraph newMerge(boolean vertical, MyGraph... sources) {
-
 		String newID = "Composite";
 		for (MyGraph g : sources) {
 			newID = newID.concat("_" + g.getId());
 		}
 		MyGraph result = new MyGraph(newID);
-
 		for (MyGraph g : sources) {
 			result.addSubGraph(g);
 			mergeInto(result, g);
 		}
-
 		return result;
 	}
-
 	// TODO better way to do scaling
 	private static void mergeInto(MyGraph target, MyGraph source) {
 		double targetMinX = target.getMinX();
@@ -39,23 +33,18 @@ public class GraphHelper {
 		double scalingFactorX = ((targetMaxX - targetMinX + 1) / (target.getNodeCount() + 1))
 				/ ((sourceMaxX - sourceMinX + 1) / (source.getNodeCount() + 1));
 		double xOffset = targetMaxX - sourceMinX + 10;
-
 		double targetMinY = target.getMinY();
 		double sourceMinY = source.getMinY();
 		double scalingFactorY = scalingFactorX;
-
 		// adjust Cordinates and Attributes
 		adjustSourceXCoordinates(source, scalingFactorX, xOffset, sourceMinX);
 		graphAttribute(target);
 		graphAttribute(source);
 		adjustSourceYCoordinates(source, scalingFactorY, targetMinY, sourceMinY);
-
 		// Copy Nodes and Edges
 		HashMap<String, String> newIds = copyNodes(target, source);
 		copyEdges(target, source, newIds);
-
 	}
-
 	private static void copyEdges(MyGraph target, MyGraph source, HashMap<String, String> newIds) {
 		Random ran = new Random();
 		boolean searchingForId = true;
@@ -67,6 +56,11 @@ public class GraphHelper {
 				if (target.getEdge(newId) == null) {
 					searchingForId = false;
 					target.addEdge(newId, newIds.get(e.getSourceNode().getId()), newIds.get(e.getTargetNode().getId()));
+					if(e.getAttribute("originalElement") == null) {
+						target.getEdge(newId).addAttribute("originalElement", source.getId().concat("+#" + e.getId()));
+					} else  {
+						target.getEdge(newId).addAttribute("originalElement",(Object) e.getAttribute("originalElement"));
+					}
 				} else {
 					newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
 				}
@@ -76,7 +70,6 @@ public class GraphHelper {
 			}
 		}
 	}
-
 	private static HashMap<String, String> copyNodes(MyGraph target, MyGraph source) {
 		HashMap<String, String> newIds = new HashMap<>();
 		Random ran = new Random();
@@ -90,6 +83,11 @@ public class GraphHelper {
 					searchingForId = false;
 					target.addNode(newId);
 					newIds.put(n.getId(), newId);
+					if(n.getAttribute("originalElement") == null) {
+						target.getNode(newId).addAttribute("originalElement", source.getId().concat("+#" + n.getId()));
+					} else  {
+						target.getNode(newId).addAttribute("originalElement",(Object) n.getAttribute("originalElement"));
+					}
 				} else {
 					newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
 				}
@@ -98,10 +96,8 @@ public class GraphHelper {
 				target.getNode(newId).addAttribute(s, (Object) n.getAttribute(s));
 			}
 		}
-
 		return newIds;
 	}
-
 	private static void adjustSourceYCoordinates(MyGraph g, double scalingFactor, double targetMinY,
 			double sourceMinY) {
 		for (Node n : g.getNodeSet()) {
@@ -112,7 +108,6 @@ public class GraphHelper {
 			n.addAttribute("y", d);
 		}
 	}
-
 	private static void graphAttribute(MyGraph g) {
 		for (Node n : g.getNodeSet()) {
 			if (n.getAttribute("originalGraph") == null) {
@@ -120,7 +115,6 @@ public class GraphHelper {
 			}
 		}
 	}
-
 	private static void adjustSourceXCoordinates(MyGraph g, Double scalingFactor, Double xOffset, Double SourceMinX) {
 		for (Node n : g.getNodeSet()) {
 			Double d = (Double) n.getAttribute("x");
@@ -131,7 +125,6 @@ public class GraphHelper {
 			n.addAttribute("x", d);
 		}
 	}
-
 	/**
 	 * Converts the Coordinates of all Nodes into a saveable and uniform Format.
 	 */
@@ -139,7 +132,6 @@ public class GraphHelper {
 		Point3 coords;
 		Node n = null;
 		Iterator<Node> allNodes = g.getNodeIterator();
-
 		while (allNodes.hasNext()) {
 			n = allNodes.next();
 			if (n.hasAttribute("xyz")) {
@@ -150,7 +142,6 @@ public class GraphHelper {
 			}
 		}
 	}
-
 	/**
 	 * Converts the weight property into a label to display on the Graph.
 	 * Removes all labels if that option is set
@@ -161,7 +152,6 @@ public class GraphHelper {
 		}
 		Edge e = null;
 		Iterator<Edge> allEdges = g.getEdgeIterator();
-
 		while (allEdges.hasNext()) {
 			e = allEdges.next();
 			if (!e.hasAttribute("weight")) {
@@ -174,7 +164,6 @@ public class GraphHelper {
 			}
 		}
 	}
-
 	/**
 	 * adds default to all Nodes and converts yEd attributes to regular ones.
 	 * 
@@ -190,7 +179,6 @@ public class GraphHelper {
 			if (!n.hasAttribute("typeofNode") || n.getAttribute("typeofNode").equals("")) {
 				n.addAttribute("typeofNode", "standard");
 			}
-
 			// underlay defaults
 			if (Layer.UNDERLAY.equals(g.getAttribute("layer"))) {
 				if (!n.hasAttribute("typeofDevice") || n.getAttribute("typeofDevice").equals("")) {
@@ -206,7 +194,6 @@ public class GraphHelper {
 					n.addAttribute("process-max", 0.0);
 				}
 			}
-
 			// operator defaults
 			if (Layer.OPERATOR.equals(g.getAttribute("layer"))) {
 				if (!n.hasAttribute("process-need") || n.getAttribute("process-need").equals("")) {
@@ -215,4 +202,76 @@ public class GraphHelper {
 			}
 		}
 	}
-}
+	public static void propagateAttribute (MyGraph g, Element n, String attribute, Object value){
+		if(n.getAttribute("originalElement") == null){
+			Debug.out("Debug: Attribute originalElement does not Exist");
+			return;
+		}
+		String origGraph = n.getAttribute("originalElement").toString().split("\\+#")[0];
+		String origNode = n.getAttribute("originalElement").toString().split("\\+#")[1];
+		Node oldNode = null;
+		Edge oldEdge = null;
+		MyGraph old = null;
+		Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
+		while(graphIter.hasNext()){
+			old = graphIter.next();
+			if(old.getId().equals(origGraph)){
+				Iterator<Node> nodeIter = old.getNodeIterator();
+				while (nodeIter.hasNext()){
+					oldNode = nodeIter.next();
+					if(oldNode.getId().equals(origNode)){
+						if(value == null){
+							oldNode.removeAttribute(attribute);
+						} else {
+							oldNode.addAttribute(attribute, value);
+						}
+						Debug.out("Debug: propagating successfull");
+						return;
+					}
+				}
+				Iterator<Edge> edgeIter = old.getEdgeIterator();
+				while (edgeIter.hasNext()){
+					oldEdge = edgeIter.next();
+					if(oldEdge.getId().equals(origNode)){
+						if(value == null){
+							oldEdge.removeAttribute(attribute);
+						} else {
+							oldEdge.addAttribute(attribute, value);
+						}
+						Debug.out("Debug: propagating successfull");
+						return;
+					}
+				}
+				Debug.out("WARNING: could not find the specified Element " + origNode + " in the Graph " + origGraph, 2);
+				return;
+			}
+		}
+		Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
+	}
+	public static void propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
+		Iterator<? extends Element> elementIter = col.iterator();
+		while (elementIter.hasNext()){
+			Element e = elementIter.next();
+			propagateElementDeletion(g, e);
+		}
+	}
+	
+	public static void propagateElementDeletion(MyGraph g, Element e){
+		String origGraph = e.getAttribute("originalElement").toString().split("\\+#")[0];
+		String origId = e.getAttribute("originalElement").toString().split("\\+#")[1];
+		Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
+		while(graphIter.hasNext()){
+			MyGraph temp = graphIter.next();
+			if (temp.getId().equals(origGraph)){
+				if(e instanceof Node && temp.getNode(origId) != null){
+					temp.removeNode(origId);
+				} else if (e instanceof Edge && temp.getEdge(origId) != null){
+					temp.removeEdge(origId);
+				} else {
+					Debug.out("INFORMATION: could not Delete Element bećause it didn't exist: " + origGraph + ":" + origId ,1);
+				}
+			}
+		}
+		Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
+	}
+}

+ 28 - 129
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -1,16 +1,13 @@
 package de.tu_darmstadt.informatik.tk.scopviz.graphs;
-
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
-
 import org.graphstream.graph.Edge;
 import org.graphstream.graph.Element;
 import org.graphstream.graph.Node;
 import org.graphstream.ui.swingViewer.ViewPanel;
 import org.graphstream.ui.view.Viewer;
 import org.graphstream.ui.view.ViewerPipe;
-
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
@@ -19,7 +16,6 @@ import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.StylesheetManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyMouseManager;
-
 /**
  * Interface between GUI and internal Graph representation. Manages internal
  * representation of the Graph to accommodate creation and deletion of nodes and
@@ -30,41 +26,27 @@ import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyMouseManager;
  *
  */
 public class GraphManager {
-
 	/** String for the processing enabled type of node. */
 	public static final String UI_CLASS_PROCESSING_ENABLED = "procEn";
-
 	/** The Graph this instance of GraphManager manages. */
 	protected MyGraph g;
-
-	/**
-	 * The Subgraph to add new Nodes and Edges to if the current Graph is a
-	 * composite.
-	 */
-	protected MyGraph graphToAddTo;
-
 	/**
 	 * The Stylesheet for this Graph, excluding parts that can be set by
 	 * NodeGraphics.
 	 */
 	protected String stylesheet = "";
-
 	/** The last Node that was deleted. */
 	protected Node deletedNode;
 	/** The last Edge that was deleted. */
 	protected LinkedList<Edge> deletedEdges = new LinkedList<>();
-
 	/** The currently selected Node, mutually exclusive with selectedEdgeID. */
 	protected String selectedNodeID = null;
 	/** The currently selected Edge, mutually exclusive with selectedNodeID. */
 	protected String selectedEdgeID = null;
-
 	/** The ViewPanel the Graph is drawn in. */
 	protected ViewPanel view;
-
 	/** The Path on Disk the Graph will be saved to. */
 	protected String currentPath;
-
 	/** The Viewer the Graph provides, grants Access to Camera Manipulation. */
 	protected Viewer viewer;
 	/**
@@ -72,12 +54,10 @@ public class GraphManager {
 	 * graphic Representation.
 	 */
 	protected ViewerPipe fromViewer;
-
 	/**
 	 * The Id of the Node that was last clicked.
 	 */
 	protected String lastClickedID;
-
 	/**
 	 * Creates a new Manager for the given graph.
 	 * 
@@ -86,16 +66,14 @@ public class GraphManager {
 	 */
 	public GraphManager(MyGraph graph) {
 		g = graph;
-		graphToAddTo = graph;
-		viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
+		/* Viewer */ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
 		view = viewer.addDefaultView(false);
 		viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
-		fromViewer = viewer.newViewerPipe();
+		/* ViewerPipe */fromViewer = viewer.newViewerPipe();
 		view.setMouseManager(new MyMouseManager(this));
 		fromViewer.addSink(graph);
 		fromViewer.removeElementSink(graph);
 	}
-
 	/**
 	 * Deletes the Node corresponding to the given ID from the Graph. The
 	 * referenced Graph is modified directly. Will throw an
@@ -112,11 +90,8 @@ public class GraphManager {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
-		if (graphToAddTo != g) {
-			graphToAddTo.removeNode(id);
-		}
+		GraphHelper.propagateElementDeletion(g, deletedNode);
 	}
-
 	/**
 	 * Deletes the Edge corresponding to the given ID from the Graph. The
 	 * referenced Graph is modified directly. Will throw an
@@ -130,11 +105,8 @@ public class GraphManager {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
-		if (graphToAddTo != g) {
-			graphToAddTo.removeEdge(id);
-		}
+		GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
-
 	/**
 	 * Deletes all Edges connected to the given Node. The referenced Graph is
 	 * modified directly. Will throw an ElementNotFoundException if the Node is
@@ -150,19 +122,15 @@ public class GraphManager {
 		deletedNode = null;
 		Edge[] temp = new Edge[0];
 		temp = g.getEdgeSet().toArray(temp);
-
 		for (Edge e : temp) {
 			if (e.getSourceNode().equals(node) || e.getTargetNode().equals(node)) {
 				// adds the Edge to the list of deleted Edges and remove sit
 				// from the Graph
 				deletedEdges.add(g.removeEdge(e));
-				if (graphToAddTo != g) {
-					graphToAddTo.removeEdge(e);
-				}
 			}
 		}
+		GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
-
 	/**
 	 * Undoes the last deleting operation on the given Graph. Deleting
 	 * operations are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes
@@ -171,6 +139,7 @@ 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()) {
@@ -179,12 +148,7 @@ public class GraphManager {
 			newId = Main.getInstance().getUnusedID();
 			g.addNode(newId);
 			g.getNode(newId).addAttributes(attributes);
-			if (graphToAddTo != g) {
-				graphToAddTo.addNode(newId);
-				graphToAddTo.getNode(newId).addAttributes(attributes);
-			}
 		}
-
 		for (Edge e : deletedEdges) {
 			String sourceId = null;
 			String targetId = null;
@@ -199,19 +163,13 @@ public class GraphManager {
 			} else {
 				sourceId = e.getSourceNode().getId();
 				targetId = e.getTargetNode().getId();
-
 			}
 			g.addEdge(id, sourceId, targetId);
 			g.getEdge(id).addAttributes(attributes);
-			if (graphToAddTo != g) {
-				graphToAddTo.addEdge(id, sourceId, targetId);
-				graphToAddTo.getEdge(id).addAttributes(attributes);
-			}
 		}
 		deletedEdges = new LinkedList<>();
 		deletedNode = null;
 	}
-
 	/**
 	 * returns a View of the Graph. The View lives in the Swing Thread and the
 	 * Graph in the Main thread.
@@ -222,7 +180,6 @@ public class GraphManager {
 	public ViewPanel getView() {
 		return view;
 	}
-
 	/**
 	 * Returns the ID of the currently selected Node.
 	 * 
@@ -231,7 +188,6 @@ public class GraphManager {
 	public String getSelectedNodeID() {
 		return selectedNodeID;
 	}
-
 	/**
 	 * Returns the ID of the currently selected Edge.
 	 * 
@@ -240,7 +196,6 @@ public class GraphManager {
 	public String getSelectedEdgeID() {
 		return selectedEdgeID;
 	}
-
 	/**
 	 * Selects the Node with the given ID, resets Edge selection.
 	 * 
@@ -251,7 +206,6 @@ public class GraphManager {
 		if (nodeID != null && g.getNode(nodeID) != null) {
 			deselect();
 			this.selectedNodeID = nodeID;
-
 			Node n = g.getNode(nodeID);
 			// set selected node color to red
 			if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED)
@@ -261,7 +215,6 @@ public class GraphManager {
 			}
 		}
 	}
-
 	/**
 	 * Selects the Edge with the given ID, resets Node selection.
 	 * 
@@ -272,12 +225,10 @@ public class GraphManager {
 		if (edgeID != null && g.getEdge(edgeID) != null) {
 			deselect();
 			this.selectedEdgeID = edgeID;
-
 			addClass(edgeID, "selected");
 			PropertiesManager.setItemsProperties();
 		}
 	}
-
 	/**
 	 * Deselect any currently selected nodes or edges.
 	 */
@@ -301,7 +252,6 @@ public class GraphManager {
 		this.selectedNodeID = null;
 		this.selectedEdgeID = null;
 	}
-
 	/**
 	 * Returns a reference to the Graph object managed by this visualizer.
 	 * 
@@ -310,21 +260,18 @@ public class GraphManager {
 	public MyGraph getGraph() {
 		return g;
 	}
-
 	/**
 	 * Zooms in the view of the graph by 5 percent.
 	 */
 	public void zoomIn() {
 		zoom(-0.05);
 	}
-
 	/**
 	 * Zooms out the view of the graph by 5 percent.
 	 */
 	public void zoomOut() {
 		zoom(0.05);
 	}
-
 	/**
 	 * Zooms the view by the given Amount, positive values zoom out, negative
 	 * values zoom in.
@@ -336,7 +283,6 @@ public class GraphManager {
 	public void zoom(double amount) {
 		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * (1 + amount));
 	}
-
 	/**
 	 * Pumps the Pipe from the graphical Representation to the underlying Graph,
 	 * propagating all Changes made.
@@ -344,12 +290,10 @@ public class GraphManager {
 	public void pumpIt() {
 		fromViewer.pump();
 	}
-
 	@Override
 	public String toString() {
 		return "Visualizer for Graph \"" + g.getId() + "\"";
 	}
-
 	/**
 	 * Returns the current Save Path on Disk for the Graph.
 	 * 
@@ -358,7 +302,6 @@ public class GraphManager {
 	public String getCurrentPath() {
 		return currentPath;
 	}
-
 	/**
 	 * Sets the Save Path.
 	 * 
@@ -368,7 +311,6 @@ public class GraphManager {
 	public void setCurrentPath(String currentPath) {
 		this.currentPath = currentPath;
 	}
-
 	/**
 	 * Adds a <b>Copy</b> of the given Edge to the graph. The Copy retains the
 	 * ID and all attributes.
@@ -378,26 +320,12 @@ public class GraphManager {
 	 */
 	public void addEdge(Edge e) {
 		HashMap<String, Object> attributes = new HashMap<>();
-
 		for (String s : e.getAttributeKeySet()) {
 			attributes.put(s, e.getAttribute(s));
 		}
-
-		Node sourceNode = e.getSourceNode();
-		Node targetNode = e.getTargetNode();
-
-		if (graphToAddTo.getNode(sourceNode.getId()) != null && graphToAddTo.getNode(targetNode.getId()) != null) {
-			g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
-			g.getEdge(e.getId()).addAttributes(attributes);
-			if (graphToAddTo != g) {
-				graphToAddTo.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
-				graphToAddTo.getEdge(e.getId()).addAttributes(attributes);
-			}
-		} else {
-			Debug.out("Trying to create an Edge where both nodes do not belong to the same subgraph!", 2);
-		}
+		g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
+		g.getEdge(e.getId()).addAttributes(attributes);
 	}
-
 	/**
 	 * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
 	 * ID and all attributes.
@@ -407,54 +335,56 @@ public class GraphManager {
 	 */
 	public void addNode(Node n) {
 		HashMap<String, Object> attributes = new HashMap<>();
-
 		for (String s : n.getAttributeKeySet()) {
-			attributes.put(s, n.getAttribute(s));
+			attributes.put(s, deletedNode.getAttribute(s));
 		}
 		g.addNode(n.getId());
 		g.getNode(n.getId()).addAttributes(attributes);
-		if (graphToAddTo != g) {
-			graphToAddTo.addNode(n.getId());
-			graphToAddTo.getNode(n.getId()).addAttributes(attributes);
-		}
 	}
-
 	/**
 	 * Returns the smallest X Coordinate of any Node in the Graph.
 	 * 
 	 * @return the smallest X Coordinate in the Graph
+	 * @deprecated Use
+	 *             {@link de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph#getMinX()}
+	 *             instead
 	 */
 	public double getMinX() {
 		return g.getMinX();
 	}
-
 	/**
 	 * Returns the biggest X Coordinate of any Node in the Graph.
 	 * 
 	 * @return the biggest X Coordinate in the Graph
+	 * @deprecated Use
+	 *             {@link de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph#getMaxX()}
+	 *             instead
 	 */
 	public double getMaxX() {
 		return g.getMaxX();
 	}
-
 	/**
 	 * Returns the smallest Y Coordinate of any Node in the Graph.
 	 * 
 	 * @return the smallest Y Coordinate in the Graph
+	 * @deprecated Use
+	 *             {@link de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph#getMinY()}
+	 *             instead
 	 */
 	public double getMinY() {
 		return g.getMinY();
 	}
-
 	/**
 	 * Returns the biggest Y Coordinate of any Node in the Graph.
 	 * 
 	 * @return the biggest Y Coordinate in the Graph
+	 * @deprecated Use
+	 *             {@link de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph#getMaxY()}
+	 *             instead
 	 */
 	public double getMaxY() {
 		return g.getMaxY();
 	}
-
 	/**
 	 * Returns the Stylesheet used by the Graph.
 	 * 
@@ -463,7 +393,6 @@ public class GraphManager {
 	public String getStylesheet() {
 		return stylesheet;
 	}
-
 	/**
 	 * Sets the Stylesheet to be used by the Graph.
 	 * 
@@ -479,7 +408,6 @@ public class GraphManager {
 				.concat(StylesheetManager.getLayerStyle((Layer) g.getAttribute("layer")));
 		g.addAttribute("ui.stylesheet", completeStylesheet);
 	}
-
 	/**
 	 * adds the given listener to the underlying graph the listener will be
 	 * notified, when an Edge is added.
@@ -490,7 +418,6 @@ public class GraphManager {
 	public void addEdgeCreatedListener(EdgeCreatedListener e) {
 		((MyGraph) g).addEdgeCreatedListener(e);
 	}
-
 	/**
 	 * adds the given listener to the underlying graph the listener will be
 	 * notified, when a Node is added.
@@ -501,14 +428,12 @@ public class GraphManager {
 	public void addNodeCreatedListener(NodeCreatedListener n) {
 		((MyGraph) g).addNodeCreatedListener(n);
 	}
-
 	/**
 	 * Updates the Stylesheet, causing any changes to it to come into effect.
 	 */
 	public void updateStylesheet() {
 		setStylesheet(this.stylesheet);
 	}
-
 	/**
 	 * Sets typeofNode as the ui.class of all Nodes.
 	 * 
@@ -521,7 +446,6 @@ public class GraphManager {
 			}
 		}
 	}
-
 	/**
 	 * Create Edges based on CreateMode.
 	 * 
@@ -547,7 +471,6 @@ public class GraphManager {
 		}
 		PropertiesManager.setItemsProperties();
 	}
-
 	/**
 	 * creates a edge between two nodes.
 	 * 
@@ -562,30 +485,16 @@ public class GraphManager {
 		if (getGraph().getNode(from).hasEdgeBetween(to))
 			return false;
 		String newID = Main.getInstance().getUnusedID();
-		boolean isDirected = (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE);
-
-		if (graphToAddTo.getNode(from) != null && graphToAddTo.getNode(to) != null) {
-			g.addEdge(newID, from, to, isDirected);
-			if (graphToAddTo != g) {
-				graphToAddTo.addEdge(newID, from, to, isDirected);
-			}
+		if (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE) {
+			getGraph().addEdge(newID, from, to, true);
+			Debug.out("Created an directed edge with Id " + newID + " between " + from + " and " + to);
 		} else {
-			Debug.out("Trying to create an Edge where both nodes do not belong to the same subgraph!", 2);
+			getGraph().addEdge(newID, from, to);
+			Debug.out("Created an undirected edge with Id " + newID + " between " + from + " and " + to);
 		}
-		/*
-		 * if (Main.getInstance().getCreationMode() ==
-		 * CreationMode.CREATE_DIRECTED_EDGE) { getGraph().addEdge(newID, from,
-		 * to, true); Debug.out("Created an directed edge with Id " + newID +
-		 * " between " + from + " and " + to); } else {
-		 * getGraph().addEdge(newID, from, to);
-		 * Debug.out("Created an undirected edge with Id " + newID + " between "
-		 * + from + " and " + to); }
-		 */
 		selectEdge(newID);
-
 		return true;
 	}
-
 	/**
 	 * Selects a Node as the starting point for creating a new Edge.
 	 * 
@@ -600,9 +509,8 @@ public class GraphManager {
 		}
 		return true;
 	}
-
 	/**
-	 * Reset the Selection of the Node after Edge has been successfully created.
+	 * Reset the Selection of the Node after Edge has been suddenly created.
 	 * 
 	 * @param nodeID
 	 *            the Id of the node to deselect.
@@ -617,7 +525,6 @@ public class GraphManager {
 			n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
 		}
 	}
-
 	/**
 	 * Resets the selction of the Node for Edge selection
 	 */
@@ -626,7 +533,6 @@ public class GraphManager {
 			deselectNodesAfterEdgeCreation(lastClickedID);
 		lastClickedID = null;
 	}
-
 	protected boolean addClass(String id, String className) {
 		Element e = getGraph().getEdge(id);
 		if (e == null)
@@ -639,12 +545,10 @@ public class GraphManager {
 		else if (!(eClass.equals(className) || eClass.startsWith(className.concat(", "))
 				|| eClass.contains(", ".concat(className))))
 			eClass = className.concat(", ").concat(eClass);
-
 		e.addAttribute("ui.class", eClass);
 		Debug.out("added " + className + ": " + eClass);
 		return true;
 	}
-
 	protected boolean removeClass(String id, String className) {
 		Element e = getGraph().getEdge(id);
 		if (e == null)
@@ -656,12 +560,10 @@ public class GraphManager {
 			eClass = "";
 		else
 			eClass = eClass.replace(className.concat(", "), "").replace(", ".concat(className), "");
-
 		e.addAttribute("ui.class", eClass);
 		Debug.out("removed " + className + ": " + eClass);
 		return true;
 	}
-
 	protected boolean toggleClass(String id, String className) {
 		Element e = getGraph().getEdge(id);
 		if (e == null)
@@ -674,7 +576,6 @@ public class GraphManager {
 			return addClass(id, className);
 		return removeClass(id, className);
 	}
-
 	protected boolean hasClass(String id, String className) {
 		Element e = getGraph().getEdge(id);
 		if (e == null)
@@ -685,7 +586,6 @@ public class GraphManager {
 		return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
 				|| eClass.contains(", ".concat(className))));
 	}
-
 	protected boolean hasClass(Edge e, String className) {
 		if (e == null)
 			return false;
@@ -693,7 +593,6 @@ public class GraphManager {
 		return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
 				|| eClass.contains(", ".concat(className))));
 	}
-
 	protected boolean hasClass(Node n, String className) {
 		if (n == null)
 			return false;
@@ -707,4 +606,4 @@ public class GraphManager {
 		 */
 		return (nClass != null && nClass.contains(className));
 	}
-}
+}