瀏覽代碼

Merged Jascha

Jan Enders 7 年之前
父節點
當前提交
b149f4782b

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

@@ -1,15 +1,19 @@
 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.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 
 public class GraphHelper {
@@ -66,7 +70,13 @@ 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  {
+						target.getEdge(newId).addAttribute("originalElement",(Object) e.getAttribute("originalElement"));
+					}
+
 				} else {
 					newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
 				}
@@ -90,6 +100,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')));
 				}
@@ -145,7 +160,9 @@ public class GraphHelper {
 			if (n.hasAttribute("xyz")) {
 				coords = Toolkit.nodePointPosition(n);
 				n.setAttribute("x", coords.x);
+				propagateAttribute(g, n, "x", coords.x);
 				n.setAttribute("y", coords.y);
+				propagateAttribute(g, n, "y", coords.y);
 				n.removeAttribute("xyz");
 			}
 		}
@@ -215,4 +232,131 @@ 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 String propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
+		Iterator<? extends Element> elementIter = col.iterator();
+		while (elementIter.hasNext()){
+			Element e = elementIter.next();
+			return propagateElementDeletion(g, e);
+		}
+		return null;
+	}
+
+	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();
+		while(graphIter.hasNext()){
+			MyGraph temp = graphIter.next();
+			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() {
+
+	}
 }

+ 17 - 3
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,6 +107,7 @@ public class GraphManager {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
+		graphDeleteId = GraphHelper.propagateElementDeletion(g, deletedNode);
 	}
 
 	/**
@@ -120,6 +123,7 @@ public class GraphManager {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
+		graphDeleteId = GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
 
 	/**
@@ -145,6 +149,7 @@ public class GraphManager {
 				deletedEdges.add(g.removeEdge(e));
 			}
 		}
+		GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
 
 	/**
@@ -155,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()) {
@@ -164,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) {
@@ -182,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;
 	}
@@ -359,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);
 	}
 

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

@@ -80,7 +80,7 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 		mergeGraph(underlay, UNDERLAY, UNDERLAYER_MOVE_Y);
 		mergeGraph(operator, OPERATOR, OPERATOR_MOVE_Y);
 		autoMapSourcesAndSinks(underlay, operator);
-
+		
 		view.getCamera().resetView();
 	}
 
@@ -96,10 +96,13 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 				resetCapacity(n);
 			}
 		}
+		
+		// recreates mapping edges from saved Attributes
+		autoMapLoadedEdgeAttributes(underlay, operator);
 
 		// recreates every mapping edge to properly calculate capacities
 		for (Edge e : g.getEdgeSet()) {
-			if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
+			if (e.getAttribute(ATTRIBUTE_KEY_MAPPING) != null &&(boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
 				createEdge(e.getSourceNode().getId(), e.getTargetNode().getId());
 			}
 		}
@@ -255,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);
 	}
 
@@ -377,6 +380,12 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 		e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
 		Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to " + underlayNode);
 
+		//adds an Attribute for loading Edges from file
+		GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", newID);
+		underlay.getGraph().getNode(underlayNode.getId().substring(8)).addAttribute("mappingEdge", newID);
+		GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", newID);
+		operator.getGraph().getNode(operatorNode.getId().substring(8)).addAttribute("mappingEdge", newID);
+
 		e.addAttribute("ui.class", UI_CLASS_MAPPING);
 		e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
 
@@ -531,10 +540,18 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 	public void deleteEdge(final String id) {
 		Edge e = g.getEdge(id);
 		if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
-			Node operatorNode = e.getSourceNode();
+			Node operatorNode = e.getSourceNode();		
 			Node underlayNode = e.getTargetNode();
+			
+			//delete mapping attriute
+			GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", null);
+			underlay.getGraph().getNode(underlayNode.getId().substring(8)).removeAttribute("mappingEdge");
+			GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", null);
+			operator.getGraph().getNode(operatorNode.getId().substring(8)).removeAttribute("mappingEdge");
+			
 			removeMapping(underlayNode, operatorNode);
 			super.deleteEdge(id);
+			
 		}
 	}
 
@@ -604,4 +621,16 @@ public class MappingGraphManager extends GraphManager implements EdgeCreatedList
 		return result;
 	}
 
-}
+	private void autoMapLoadedEdgeAttributes(GraphManager underlay2, GraphManager operator2) {
+		for (Node operatorNode : getOperatorNodeSet()) {
+			for (Node underlayNode : getUnderlayNodeSet()) {
+				String identifier = operatorNode.getAttribute("mappingEdge");
+				if (identifier != null && identifier.equals(underlayNode.getAttribute("mappingEdge"))) {
+					createEdge(operatorNode.getId(), underlayNode.getId());
+				}
+			}
+		}
+	}
+
+}
+

+ 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;
@@ -105,6 +106,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) {

+ 31 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -6,6 +6,7 @@ import java.io.IOException;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.stage.FileChooser;
+import javafx.stage.FileChooser.ExtensionFilter;
 import javafx.stage.Stage;
 
 /**
@@ -25,12 +26,12 @@ public class GraphMLExporter {
 	 * @param fileName
 	 *            The Location on disk the File will be saved on
 	 */
-	public void writeGraph(final MyGraph g, final String fileName) {
+	public void writeGraph(final MyGraph g, final String fileName, boolean exportAsSingleGraph) {
 		MyFileSinkGraphML writer = new MyFileSinkGraphML();
 		String newFileName = fileName;
-		if (g.isComposite()) {
-			writer.exportGraphs(g.getAllSubGraphs(), fileNameAppend(fileName, "appended"));
-			newFileName = fileNameAppend(fileName, "merged");
+		if (g.isComposite() && !exportAsSingleGraph) {
+			writer.exportGraphs(g.getAllSubGraphs(), fileName);
+			return;
 		}
 		try {
 			writer.writeAll(g, new FileOutputStream(newFileName));
@@ -53,11 +54,16 @@ public class GraphMLExporter {
 		String fileName;
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("Saving graph");
+		fileChooser.setInitialFileName("*.graphml");
+		ExtensionFilter standard = new ExtensionFilter("GraphML Files", "*.graphml");
+		fileChooser.getExtensionFilters().add(standard);
+		fileChooser.getExtensionFilters().add(new ExtensionFilter("all Files", "*"));
+		fileChooser.setSelectedExtensionFilter(standard);
 		try {
 			fileName = fileChooser.showSaveDialog(stage).getPath();
 			Main.getInstance().getGraphManager().setCurrentPath(fileName);
 			if (fileName != null) {
-				writeGraph(g, fileName);
+				writeGraph(g, fileName, false);
 			}
 		} catch (NullPointerException e) {
 
@@ -88,4 +94,24 @@ public class GraphMLExporter {
 
 		return fileName;
 	}
+
+
+	public void exportMapping(MyGraph g){
+		Stage stage = Main.getInstance().getPrimaryStage();
+		String fileName;
+		FileChooser fileChooser = new FileChooser();
+		fileChooser.setTitle("Saving graph");
+		fileChooser.setInitialFileName("*.graphmlMap");
+		ExtensionFilter standard = new ExtensionFilter("GraphML Mapping underlay Files", "*.graphmlMap");
+		fileChooser.getExtensionFilters().add(standard);
+		fileChooser.getExtensionFilters().add(new ExtensionFilter("all Files", "*.*"));
+		fileChooser.setSelectedExtensionFilter(standard);
+		try {
+			fileName = fileChooser.showSaveDialog(stage).getPath();
+			Main.getInstance().getGraphManager().setCurrentPath(fileName);
+			if (fileName != null) {
+				writeGraph(g, fileName, false);
+			}
+		} catch (NullPointerException e) {}
+	}
 }

+ 7 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -12,6 +12,7 @@ import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.stage.FileChooser;
 import javafx.stage.Stage;
+import javafx.stage.FileChooser.ExtensionFilter;
 
 /**
  * Importer to import a graph from a GraphML file and return it as a Graph
@@ -69,6 +70,10 @@ public class GraphMLImporter {
 	public MyGraph readGraph(final String id, final Stage stage) {
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("open graph");
+		ExtensionFilter standard = new ExtensionFilter("GraphML Files", "*.graphml");
+		fileChooser.getExtensionFilters().add(standard);
+		fileChooser.getExtensionFilters().add(new ExtensionFilter("all Files", "*"));
+		fileChooser.setSelectedExtensionFilter(standard);
 		try {
 			String fileName = fileChooser.showOpenDialog(stage).getPath();
 			Main.getInstance().getGraphManager().setCurrentPath(fileName);
@@ -117,7 +122,8 @@ public class GraphMLImporter {
 	public void yEdConversion(MyGraph g) {
 		for (Node n : g.getNodeSet()) {
 			// yed conversion
-			if (!n.hasAttribute("ui.label") && n.hasAttribute("yEd.label")) {
+			if ((!n.hasAttribute("ui.label") || n.getAttribute("ui.label").equals("")) 
+					&& n.hasAttribute("yEd.label")) {
 				n.addAttribute("ui.label", n.getAttribute("yEd.label").toString());
 				n.removeAttribute("yEd.label");
 			} else if (n.hasAttribute("ui.label")) {

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

@@ -102,7 +102,7 @@ public class MainApp extends Application {
 			public void handle(WindowEvent event) {
 				if (exportOnClose) {
 					GraphMLExporter exporter = new GraphMLExporter();
-					exporter.writeGraph(Main.getInstance().getGraphManager().getGraph(), "shutdown.graphml");
+					exporter.writeGraph(Main.getInstance().getGraphManager().getGraph(), "shutdown.graphml", false);
 				}
 
 				System.exit(0);

+ 5 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/metrics/BasicMappingOperator.java

@@ -39,10 +39,9 @@ public class BasicMappingOperator implements ScopvizGraphOperator {
 			successfull = false;
 			while (procEnIterator.hasNext() && !successfull) {
 				successfull = map.createEdge(procEnIterator.next().getId(), n.getId());
-				Debug.out(new Boolean(successfull).toString());
 			}
 			if (!successfull) {
-				Debug.out("WARNING: BasicMappingOperator could not map all Nodes");
+				Debug.out("WARNING: BasicMappingOperator could not map all Nodes", 2);
 			}
 
 		}
@@ -82,16 +81,17 @@ public class BasicMappingOperator implements ScopvizGraphOperator {
 		@Override
 		public int compare(Node o1, Node o2) {
 			Main m = Main.getInstance();
-
+			
+			// the cmparator uses a reverse ordering so that the resulting list is sorted descending
 			// this does: process-need(o1) - process-need(o2)
 			Double result = m.convertAttributeTypes(o1.getAttribute("process-need"), new Double(0))
 					- m.convertAttributeTypes(o2.getAttribute("process-need"), new Double(0));
 			if (result == 0.0) {
 				return 0;
 			} else if (result < 0.0) {
-				return -1;
-			} else {
 				return 1;
+			} else {
+				return -1;
 			}
 		}
 	};

+ 40 - 57
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GraphDisplayManager.java

@@ -3,6 +3,8 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui;
 import java.awt.Dimension;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
 
 import org.apache.commons.math3.exception.NullArgumentException;
 import org.graphstream.graph.Edge;
@@ -22,7 +24,9 @@ import javafx.beans.property.SimpleBooleanProperty;
 import javafx.event.EventHandler;
 import javafx.scene.input.ScrollEvent;
 import javafx.scene.layout.Pane;
+import javafx.stage.FileChooser;
 import javafx.stage.Stage;
+import javafx.stage.FileChooser.ExtensionFilter;
 
 /**
  * This class holds all GraphManagers, provides Functions to add Graphs and get
@@ -380,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();
@@ -407,67 +407,54 @@ public final class GraphDisplayManager {
 	 * accordingly
 	 */
 	public static void readMapping() {
+		//import the root Graph
+		MyGraph g = null;
 		GraphMLImporter reader = new GraphMLImporter();
-		MyGraph g = reader.readGraph(getGraphStringID(count), Main.getInstance().getPrimaryStage());
-		Layer tempLayer = currentLayer;
-
-		// underlay Graph
-		MyGraph tempGraph = new MyGraph(getGraphStringID(count++));
-		count++;
-		for (Node n : g.getNodeSet()) {
-			String id = n.getId();
-			if (id.startsWith(MappingGraphManager.UNDERLAY)) {
-				id = id.substring(MappingGraphManager.UNDERLAY.length());
-				Node tempNode = tempGraph.addNode(id);
-				for (String s : n.getAttributeKeySet()) {
-					tempNode.addAttribute(s, (Object) n.getAttribute(s));
-				}
-			}
+		FileChooser fileChooser = new FileChooser();
+		fileChooser.setTitle("open graph");
+		ExtensionFilter standard = new ExtensionFilter("GraphML Mapping Files", "*.graphmlMap");
+		fileChooser.getExtensionFilters().add(standard);
+		fileChooser.getExtensionFilters().add(new ExtensionFilter("all Files", "*"));
+		fileChooser.setSelectedExtensionFilter(standard);
+		try {
+			String fileName = fileChooser.showOpenDialog(Main.getInstance().getPrimaryStage()).getPath();
+			Main.getInstance().getGraphManager().setCurrentPath(fileName);
+			g =  reader.readGraph(getGraphStringID(count++), fileName);
+			g.getId();
+		} catch (NullPointerException e) {
+			Debug.out("INFORMATION: Mapping loading aborted", 1);
+			return;
 		}
-		for (Edge e : g.getEdgeSet()) {
-			String id = e.getId();
-			if (id.startsWith(MappingGraphManager.UNDERLAY)) {
-				id = id.substring(MappingGraphManager.UNDERLAY.length());
-				Edge tempEdge = tempGraph.addEdge(id,
-						e.getSourceNode().getId().substring(MappingGraphManager.UNDERLAY.length()),
-						e.getTargetNode().getId().substring(MappingGraphManager.UNDERLAY.length()), e.isDirected());
-				for (String s : e.getAttributeKeySet()) {
-					tempEdge.addAttribute(s, (Object) e.getAttribute(s));
-				}
+		
+		
+		//splitting graphs
+		//saving the layer for reuse later
+		Layer tempLayer = currentLayer;
+		
+		//underlay graph
+		LinkedList<MyGraph> graphs = g.getAllSubGraphs();
+		Iterator<MyGraph> graphIter = graphs.iterator();
+		while(graphIter.hasNext()){
+			if(!"UNDERLAY".equalsIgnoreCase(graphIter.next().getAttribute("layer"))){
+				graphIter.remove();
 			}
 		}
-		// TODO get Graphmanager?
+		MyGraph tempGraph = GraphHelper.newMerge(false, graphs.toArray(new MyGraph[0]));
 		currentLayer = Layer.UNDERLAY;
 		addGraph(tempGraph, true);
 		GraphManager und = getGraphManager(Layer.UNDERLAY);
 
 		// operator graph
-		MyGraph tempGraph2 = new MyGraph(getGraphStringID(count++));
-		count++;
-		for (Node n : g.getNodeSet()) {
-			String id = n.getId();
-			if (id.startsWith(MappingGraphManager.OPERATOR)) {
-				id = id.substring(MappingGraphManager.OPERATOR.length());
-				Node tempNode = tempGraph2.addNode(id);
-				for (String s : n.getAttributeKeySet()) {
-					tempNode.addAttribute(s, (Object) n.getAttribute(s));
-				}
-			}
-		}
-		for (Edge e : g.getEdgeSet()) {
-			String id = e.getId();
-			if (id.startsWith(MappingGraphManager.OPERATOR)) {
-				id = id.substring(MappingGraphManager.OPERATOR.length());
-				Edge tempEdge = tempGraph2.addEdge(id,
-						e.getSourceNode().getId().substring(MappingGraphManager.OPERATOR.length()),
-						e.getTargetNode().getId().substring(MappingGraphManager.OPERATOR.length()), e.isDirected());
-				for (String s : e.getAttributeKeySet()) {
-					tempEdge.addAttribute(s, (Object) e.getAttribute(s));
-				}
+		graphs = g.getAllSubGraphs();
+		graphIter = graphs.iterator();
+		while(graphIter.hasNext()){
+			if(!"OPERATOR".equalsIgnoreCase(graphIter.next().getAttribute("layer"))){
+				graphIter.remove();
 			}
 		}
+		tempGraph = GraphHelper.newMerge(false, graphs.toArray(new MyGraph[0]));
 		currentLayer = Layer.OPERATOR;
-		addGraph(tempGraph2, true);
+		addGraph(tempGraph, true);
 		GraphManager op = getGraphManager(Layer.OPERATOR);
 
 		// Mapping graph
@@ -481,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();

+ 9 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MenuBarManager.java

@@ -55,8 +55,12 @@ public final class MenuBarManager {
 	 */
 	public static void saveAction(ActionEvent event) {
 		GraphManager v = Main.getInstance().getGraphManager();
+		if(GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)){
+			new GraphMLExporter().exportMapping(v.getGraph());
+			return;
+		}
 		if (v.getCurrentPath() != null) {
-			new GraphMLExporter().writeGraph(v.getGraph(), v.getCurrentPath());
+			new GraphMLExporter().writeGraph(v.getGraph(), v.getCurrentPath(), false);
 		} else {
 			new GraphMLExporter().writeGraph(v.getGraph(), Main.getInstance().getPrimaryStage());
 		}
@@ -67,6 +71,10 @@ public final class MenuBarManager {
 	 */
 	public static void saveAsAction(ActionEvent event) {
 		GraphManager v = Main.getInstance().getGraphManager();
+		if(GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)){
+			new GraphMLExporter().exportMapping(v.getGraph());
+			return;
+		}
 		new GraphMLExporter().writeGraph(v.getGraph(), Main.getInstance().getPrimaryStage());
 	}
 

+ 21 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -11,6 +11,7 @@ import org.graphstream.graph.Element;
 import org.graphstream.graph.Node;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphHelper;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
@@ -122,6 +123,7 @@ public final class PropertiesManager {
 		itemVisibilityRules.put("mapping-parent", -2);
 		itemVisibilityRules.put("mapping-parent-id", -2);
 		itemVisibilityRules.put("ui.class", -2);
+		itemVisibilityRules.put("originalElement", -2);
 
 	}
 
@@ -152,36 +154,44 @@ public final class PropertiesManager {
 			Element selected = getSelected();
 
 			// Type-Check the input
-			if (classType.equals(Integer.class) && newValue.matches(IS_INT)) {
+			if (classType.equals(Integer.class) && newValue.matches(IS_INT)){
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, key, newValue);
 				selected.changeAttribute(key, Integer.valueOf(newValue));
 				editedPair.setValue(newValue);
 				Debug.out("Edited integer Attribute " + key);
 
 			} else if (classType.equals(Boolean.class) && newValue.matches(IS_BOOL)) {
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, key, newValue);
 				selected.changeAttribute(key, Boolean.valueOf(newValue));
 				editedPair.setValue(newValue);
 				Debug.out("Edited boolean Attribute " + key);
 
 			} else if (classType.equals(Float.class) && newValue.matches(IS_FLOAT)) {
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, key, newValue);
 				selected.changeAttribute(key, Float.valueOf(newValue));
 				editedPair.setValue(newValue);
 				Debug.out("Edited float Attribute " + key);
 
 			} else if (classType.equals(Double.class) && newValue.matches(IS_FLOAT)) {
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, key, newValue);
 				selected.changeAttribute(key, Double.valueOf(newValue));
 				editedPair.setValue(newValue);
 				Debug.out("Edited double Attribute " + key);
 
 			} else if (classType.equals(String.class)) {
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, key, newValue);
 				selected.changeAttribute(key, newValue);
 				editedPair.setValue(newValue);
 				Debug.out("Edited String Attribute " + key);
+				if(key.equals("typeofNode")){
+					selected.changeAttribute("ui.class", newValue);
+				}
 
 			} else {
 				editedPair.setValue(oldValue);
 				t.getTableView().getItems().get(t.getTablePosition().getRow()).setKey(oldValue);
 				setItemsProperties();
-				Debug.out("invalid input for this attribute type", 2);
+				Debug.out("WARNING: invalid input for this attribute type", 2);
 			}
 
 			// Unselect row after updating Property
@@ -364,7 +374,7 @@ public final class PropertiesManager {
 		Element selected = getSelected();
 
 		selected.removeAttribute(pair.getKey());
-
+		GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), selected, pair.getKey(), null);
 	}
 
 	/**
@@ -527,12 +537,20 @@ public final class PropertiesManager {
 
 			if (t.get(2).equals("Integer")) {
 				selected.addAttribute(t.get(0), Integer.valueOf(t.get(1)));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph()
+						, selected, t.get(0), Integer.valueOf(t.get(1)));
 			} else if (t.get(2).equals("Float")) {
 				selected.addAttribute(t.get(0), Float.valueOf(t.get(1)));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph()
+						, selected, t.get(0), Float.valueOf(t.get(1)));
 			} else if (t.get(2).equals("String")) {
 				selected.addAttribute(t.get(0), String.valueOf(t.get(1)));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph()
+						, selected, t.get(0), String.valueOf(t.get(1)));
 			} else if (t.get(2).equals("Boolean")) {
 				selected.addAttribute(t.get(0), Boolean.valueOf(t.get(1)));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph()
+						, selected, t.get(0), Boolean.valueOf(t.get(1)));
 			}
 
 			showNewDataSet(selected);

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

@@ -4,6 +4,7 @@ import java.util.Optional;
 
 import org.graphstream.graph.Edge;
 
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphHelper;
 import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
@@ -282,6 +283,9 @@ public final class ToolboxManager {
 			Optional<String> result = weightDialog.showAndWait();
 			if (result.isPresent()) {
 				e.addAttribute("weight", Double.parseDouble(result.get()));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), 
+						e, "weight", Double.parseDouble(result.get()));
+
 			}
 		});
 	}
@@ -369,6 +373,8 @@ public final class ToolboxManager {
 			Optional<String> result = weightDialog.showAndWait();
 			if (result.isPresent()) {
 				n.addAttribute("process-max", Double.parseDouble(result.get()));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), 
+						n, "process-max", Double.parseDouble(result.get()));
 			}
 		});
 	}
@@ -386,6 +392,8 @@ public final class ToolboxManager {
 			Optional<String> result = weightDialog.showAndWait();
 			if (result.isPresent()) {
 				n.addAttribute("process-need", Double.parseDouble(result.get()));
+				GraphHelper.propagateAttribute(Main.getInstance().getGraphManager().getGraph(), 
+				n, "process-need", Double.parseDouble(result.get()));
 			}
 		});
 	}