Browse Source

moar propagation

now propagates Element deletions
now propagates Attribute adding/removing
export and import now use Extensionfilters
changing typeofNode now also changes ui.class
jascha Bohne 7 years ago
parent
commit
e4689b3b1e

+ 40 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphHelper.java

@@ -1,5 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.graphs;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Random;
@@ -74,7 +75,7 @@ public class GraphHelper {
 					} else  {
 						target.getEdge(newId).addAttribute("originalElement",(Object) e.getAttribute("originalElement"));
 					}
-				
+
 				} else {
 					newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
 				}
@@ -228,7 +229,7 @@ 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");
@@ -247,7 +248,11 @@ public class GraphHelper {
 				while (nodeIter.hasNext()){
 					oldNode = nodeIter.next();
 					if(oldNode.getId().equals(origNode)){
-						oldNode.addAttribute(attribute, value);
+						if(value == null){
+							oldNode.removeAttribute(attribute);
+						} else {
+							oldNode.addAttribute(attribute, value);
+						}
 						Debug.out("Debug: propagating successfull");
 						return;
 					}
@@ -256,7 +261,11 @@ public class GraphHelper {
 				while (edgeIter.hasNext()){
 					oldEdge = edgeIter.next();
 					if(oldEdge.getId().equals(origNode)){
-						oldEdge.addAttribute(attribute, value);
+						if(value == null){
+							oldEdge.removeAttribute(attribute);
+						} else {
+							oldEdge.addAttribute(attribute, value);
+						}
 						Debug.out("Debug: propagating successfull");
 						return;
 					}
@@ -267,4 +276,31 @@ public class GraphHelper {
 		}
 		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);
+	}
 }

+ 3 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -105,6 +105,7 @@ public class GraphManager {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
+		GraphHelper.propagateElementDeletion(g, deletedNode);
 	}
 
 	/**
@@ -120,6 +121,7 @@ public class GraphManager {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
+		GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
 
 	/**
@@ -145,6 +147,7 @@ public class GraphManager {
 				deletedEdges.add(g.removeEdge(e));
 			}
 		}
+		GraphHelper.propagateElementDeletion(g, deletedEdges);
 	}
 
 	/**

+ 46 - 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,39 @@ 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("*.graphmlSub");
+		ExtensionFilter standard = new ExtensionFilter("GraphML Mapping underlay Files", "*.graphmlSub");
+		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) {}
+		fileChooser = new FileChooser();
+		fileChooser.setTitle("Saving graph");
+		fileChooser.setInitialFileName("*.graphmlMap"
+				+ "");
+		standard = new ExtensionFilter("GraphML Mapping 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, true);
+			}
+		} 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

@@ -100,7 +100,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);

+ 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());
 	}