]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
ExportModule and ExportFunction used old transferable graph requests that did not...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 20 Feb 2013 10:26:03 +0000 (10:26 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 20 Feb 2013 10:26:03 +0000 (10:26 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26813 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java

index 7aafb7cfc5f78346e5327dc7381012740477593f..e583355eaf41e5657ea1a91579fe66e89fb08350 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2013 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -12,8 +12,6 @@
 package org.simantics.sysdyn.ui.handlers.exports;\r
 \r
 import java.io.File;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
 \r
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
@@ -25,24 +23,21 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\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.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2;\r
 import org.simantics.db.request.Read;\r
-import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.graph.db.TransferableGraphSource;\r
+import org.simantics.graph.db.TransferableGraphs;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.utils.imports.ImportUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
  * Exports a function library\r
@@ -101,25 +96,17 @@ public class ExportFunctionLibrary  extends AbstractHandler {
 \r
                // Asynchronously create the file using transferable graph\r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
-                       \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary, l0.HasName, Bindings.STRING ));\r
-                               ArrayList<Pair<Resource, String>> roots = new ArrayList<Pair<Resource, String>>();\r
-                               roots.add(Pair.make(functionLibrary, name));\r
-                               TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary));\r
 \r
-                               try {\r
-                                       DataContainers.writeFile(new File(selected), new DataContainer("sysdynFunctionLibrary", 1, new Variant(TransferableGraph1.BINDING, tg)));\r
-                               } catch (RuntimeBindingConstructionException e) {\r
-                                       e.printStackTrace();\r
-                               } catch (IOException e) {\r
-                                       e.printStackTrace();\r
-                               }\r
-\r
-                               \r
-                       }\r
+                   @Override\r
+                   public void run(ReadGraph graph) throws DatabaseException {\r
+                       TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, functionLibrary);\r
+                       TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));\r
+                       try {\r
+                           TransferableGraphs.writeTransferableGraph(graph, "sysdynFunctionLibrary", 1, s,new File(selected));\r
+                       } catch (Exception e) {\r
+                           e.printStackTrace();\r
+                       }\r
+                   }\r
                });\r
 \r
                return null;\r
index cecb5d8b1b0879aee1c5c39298f2936e109dd87e..53bb5203565b83bb4c29a352bdbfbbb140e12f0a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2013 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -12,7 +12,6 @@
 package org.simantics.sysdyn.ui.handlers.exports;\r
 \r
 import java.io.File;\r
-import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 \r
@@ -28,9 +27,6 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\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.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
@@ -40,9 +36,11 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2;\r
 import org.simantics.db.request.Read;\r
-import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.graph.db.TransferableGraphSource;\r
+import org.simantics.graph.db.TransferableGraphs;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
@@ -227,7 +225,7 @@ public class ExportModuleHandler extends AbstractHandler {
         * @param roots\r
         * @param component Module\r
         */\r
-       private void export(WriteGraph graph, String path, ArrayList<Pair<Resource, String>> roots, Resource component) {\r
+       private void export(WriteGraph graph, final String path, ArrayList<Pair<Resource, String>> roots, final Resource component) {\r
                \r
                // FIXME: Enumeration replacement handling like this is not suitable.\r
                try {\r
@@ -249,16 +247,28 @@ public class ExportModuleHandler extends AbstractHandler {
                        for(Pair<Resource,Resource> replacement : replacements)\r
                                graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second);\r
                        \r
-                       TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component));\r
-                       DataContainers.writeFile(new File(path), new DataContainer("sysdynModule", 1, new Variant(TransferableGraph1.BINDING, tg)));\r
+                       SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+\r
+                           @Override\r
+                           public void run(ReadGraph graph) throws DatabaseException {\r
+                               TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, component);\r
+                               TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));\r
+                               try {\r
+                                   TransferableGraphs.writeTransferableGraph(graph, "sysdynModule", 1, s,new File(path));\r
+                               } catch (Exception e) {\r
+                                   e.printStackTrace();\r
+                               }\r
+                           }\r
+                       });\r
+\r
                        \r
                        for(Pair<Resource,Resource> replacement : replacements)\r
                                graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second);\r
 \r
                } catch (RuntimeBindingConstructionException e) {\r
                        e.printStackTrace();\r
-               } catch (IOException e) {\r
-                       e.printStackTrace();\r
+//             } catch (IOException e) {\r
+//                     e.printStackTrace();\r
                } catch (DatabaseException e) {\r
                        e.printStackTrace();\r
                }\r