--- /dev/null
+package org.simantics.sysdyn.refactoring;\r
+\r
+import java.io.File;\r
+import java.net.URLDecoder;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
+import org.simantics.graph.representation.External;\r
+import org.simantics.graph.representation.Identity;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+\r
+public class TGRefactoring {\r
+ \r
+ public static void main(String[] args) throws Exception {\r
+ // Select the directory where this file is\r
+ File dir = new File(URLDecoder.decode(TGRefactoring.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile();\r
+ System.out.println(dir);\r
+ \r
+ // Choose input and output files for refactoring. Files are relative to the selected directory.\r
+ File input = new File(dir, "input.tg"); // use your own file names\r
+ File output = new File(dir, "output.tg");\r
+\r
+ // Get a map containing the changed names \r
+ HashMap<String, String> map = getMap();\r
+ \r
+ // Read input file \r
+ DataContainer dc = DataContainers.readFile(input);\r
+ \r
+ // Get transferable graph from the input file\r
+ TransferableGraph1 tg1 = (TransferableGraph1) dc.content.getValue(TransferableGraph1.BINDING);\r
+\r
+ \r
+ // Loop through input file and change all names found from the map\r
+ for(Identity i : tg1.identities) {\r
+ if(i.definition instanceof External) {\r
+ External e = (External)i.definition;\r
+ String newName = map.get(e.name);\r
+ if(newName != null) {\r
+ System.out.println(e.name + " -> " + newName);\r
+ e.name = newName;\r
+ }\r
+ }\r
+ }\r
+ \r
+ // Rewrite DataContainer content\r
+ dc.content = new Variant(TransferableGraph1.BINDING, tg1);\r
+ \r
+ // Write the refactored graph to output file\r
+ DataContainers.writeFile(output, dc);\r
+ }\r
+ \r
+ private static HashMap<String, String> getMap() {\r
+ HashMap<String, String> map = new HashMap<String, String>();\r
+\r
+ // 4.9.2012 ontology changes\r
+ map.put("Layer0-1.0", "Layer0-1.1");\r
+ map.put("Layer0X-1.0", "Layer0X-1.1");\r
+ map.put("G2D-1.0", "G2D-1.1");\r
+ map.put("Structural-1.0", "Structural-1.2");\r
+ map.put("Diagram-2.1", "Diagram-2.2");\r
+ map.put("Simulation-1.0", "Simulation-1.1");\r
+ map.put("Modeling-1.1", "Modeling-1.2");\r
+ map.put("Project-1.1", "Project-1.2");\r
+ map.put("Spreadsheet-1.1", "Spreadsheet-1.2");\r
+ map.put("Viewpoint-1.1", "Viewpoint-1.2");\r
+ map.put("Image2-1.1", "Image2-1.2");\r
+ map.put("Color-1.0", "Color-1.1");\r
+ map.put("Action-1.0", "Action-1.1");\r
+ map.put("Silk-1.0", "Silk-1.1");\r
+ map.put("Issue-1.1", "Issue-1.2");\r
+ map.put("User-1.0", "User-1.1");\r
+ map.put("Documentation-1.0", "Documentation-1.1");\r
+ map.put("Document-1.1", "Document-1.2");\r
+ map.put("SelectionView-1.1", "SelectionView-1.2");\r
+ \r
+ return map;\r
+ }\r
+}\r