]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Update 1.4 to latest code
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 05:50:48 +0000 (05:50 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 05:50:48 +0000 (05:50 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/simantics-1.4@20844 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java

diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java
new file mode 100644 (file)
index 0000000..3d4b691
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.objmap.rules.adapters;\r
+\r
+public enum IdentityAdapter implements ValueAdapter {\r
+    INSTANCE;\r
+\r
+    @Override\r
+    public Object domainToRange(Object domainValue) {\r
+        return domainValue;\r
+    }\r
+\r
+    @Override\r
+    public Object rangeToDomain(Object rangeValue) {\r
+        return rangeValue;\r
+    }\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java
new file mode 100644 (file)
index 0000000..c8d0d2d
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.objmap.rules.adapters;\r
+\r
+public interface ValueAdapter {\r
+    Object domainToRange(Object domainValue);\r
+    Object rangeToDomain(Object rangeValue);\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java b/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java
new file mode 100644 (file)
index 0000000..a6df00b
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.objmap.rules.range;\r
+\r
+import org.simantics.objmap.MappingException;\r
+import org.simantics.objmap.rules.adapters.ValueAdapter;\r
+\r
+public class AdaptedRangeAccessor implements IRangeAccessor<Object> {\r
+    IRangeAccessor<Object> baseAccessor;\r
+    ValueAdapter adapter;\r
+    \r
+    public AdaptedRangeAccessor(IRangeAccessor<Object> baseAccessror,\r
+            ValueAdapter adapter) {\r
+        this.baseAccessor = baseAccessror;\r
+        this.adapter = adapter;\r
+    }\r
+\r
+    @Override\r
+    public Object get(Object element) throws MappingException {\r
+        return adapter.rangeToDomain(baseAccessor.get(element));    \r
+    }\r
+    \r
+    @Override\r
+    public boolean set(Object element, Object value) throws MappingException {\r
+        return baseAccessor.set(element, adapter.domainToRange(value));\r
+    }\r
+}\r
index 4ad047d168491c0c6e09c867132bac204ed7a491..38054f78c2f08506c3514824dd41b39eb9ffa016 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.layer0.util.TransferableGraphRequest2;
 import org.simantics.db.request.Read;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.datastructures.Pair;\r
@@ -71,15 +72,19 @@ public class ExportFunctionLibrary  extends AbstractHandler {
                \r
                Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
-               fd.setText("Export..");\r
+               fd.setText("Export Function Library");\r
                fd.setFileName(name);\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               String path = Activator.getDefault().getPreferenceStore().getString(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                final String selected = fd.open();\r
                if(selected == null) return null;\r
                \r
-               \r
+               Activator.getDefault().getPreferenceStore().setValue(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent());\r
+\r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
                        @Override\r
index 5b4d5cc73d6580323a7b4326a7402b5f650559f6..f4e007dfb7b079023ebc2e8a5bcc868bf8c3329f 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.layer0.util.TransferableGraphRequest2;
 import org.simantics.db.request.Read;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.datastructures.Pair;\r
@@ -72,14 +73,18 @@ public class ExportModelHandler extends AbstractHandler {
                \r
                Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
-               fd.setText("Export..");\r
+               fd.setText("Export Model");\r
                fd.setFileName(name);\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                final String selected = fd.open();\r
                if(selected == null) return null;\r
                \r
+               Activator.getDefault().getPreferenceStore().setValue(ImportModelHandler.IMPORTMODELTPATH, (new File(selected)).getParent());\r
                \r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
index 17b5bd0585a7fadfa51c5552f0d3874ddb143f28..88bb8d8f3e08685e31aa3503bd37231d5855b0ea 100644 (file)
@@ -45,6 +45,7 @@ import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.datastructures.Pair;\r
@@ -135,14 +136,18 @@ public class ExportModuleHandler  extends AbstractHandler {
                \r
                Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
-               fd.setText("Export..");\r
+               fd.setText("Export Module");\r
                fd.setFileName(name);\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               String path = Activator.getDefault().getPreferenceStore().getString(ImportModuleHandler.IMPORTMODULETPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                final String selected = fd.open();\r
                if(selected == null) return null;\r
                \r
+               Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent());\r
                \r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
index 3193d41635a1d6c0ba4c21d333f6b8b0d76ee2e8..3b6bc8e1edcfced07e3d3796413a6b12a425dcea 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.databoard.Bindings;\r
@@ -30,8 +31,8 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.WriteOnlyGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
 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.exception.ResourceNotFoundException;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
@@ -43,12 +44,15 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
 public class ImportFunctionLibrary  extends AbstractHandler {\r
+       \r
+       public static String IMPORTFUNCTIONLIBRARYPATH = "IMPORT_FUNCTION_LIBRARY_PATH";\r
 \r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
@@ -62,23 +66,34 @@ public class ImportFunctionLibrary  extends AbstractHandler {
         \r
         final Resource functionLibrary = r;\r
         \r
-               Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+               final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
                fd.setText("Import Function Library");\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               \r
+               String path = Activator.getDefault().getPreferenceStore().getString(IMPORTFUNCTIONLIBRARYPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                String selected = fd.open();\r
                if(selected == null) return null;\r
 \r
+               Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent());\r
+               \r
                TransferableGraph1 tg = null;\r
                try {\r
                        tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
                } catch (RuntimeBindingConstructionException e) {\r
                        e.printStackTrace();\r
+                       return null;\r
                } catch (IOException e) {\r
-                       e.printStackTrace();\r
-               }\r
+                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                       mb.setText("Error");\r
+                       mb.setMessage("The imported file is not of type: Function Library");\r
+                       mb.open();\r
+                       return null;\r
+               } \r
                if(tg == null) return null;\r
 \r
        \r
@@ -123,11 +138,39 @@ public class ImportFunctionLibrary  extends AbstractHandler {
                        e.printStackTrace();\r
                }\r
                \r
-               SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+               final Resource root = ia.getRoot();\r
+               \r
+               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
                        \r
                        @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
+                                       Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
+                                       String type = "...";\r
+                                       if(instanceOf != null)\r
+                                               type = NameUtils.getSafeName(graph, instanceOf);\r
+                                       else {\r
+                                               Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
+                                               if(inheritedFrom != null)\r
+                                                       type = NameUtils.getSafeName(graph, inheritedFrom);\r
+                                       }\r
+                                       final String ft = type; \r
+                                       graph.deny(root, Layer0.getInstance(graph).PartOf);\r
+                                       \r
+                                       shell.getDisplay().asyncExec(new Runnable() {\r
+                                               \r
+                                               @Override\r
+                                               public void run() {\r
+                                                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                                                       mb.setText("Error");\r
+                                                       mb.setMessage("The imported file is not of type: Function Library (" + ft +")");\r
+                                                       mb.open();                                                              \r
+                                               }\r
+                                       });\r
+                               } else {\r
+                                       FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+                               }\r
+\r
                        }\r
                });\r
                return null;\r
index 603c28aaf1a637c6a6eaa227d10ad28d3721dcc0..156ab7bc7b7dcb2be4bc84a871dfd99ed05e478e 100644 (file)
@@ -16,6 +16,7 @@ import java.io.File;
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
 import org.eclipse.swt.widgets.Shell;\r
@@ -26,10 +27,13 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.mdlImport.MdlParser;\r
 import org.simantics.sysdyn.mdlImport.mdlElements.Model;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 public class ImportMdlHandler extends AbstractHandler {\r
 \r
+       public static String IMPORTMDLTPATH = "IMPORT_MDL_PATH";\r
+\r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
                \r
@@ -39,7 +43,10 @@ public class ImportMdlHandler extends AbstractHandler {
                Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
                fd.setText("Import .mdl");\r
-               fd.setFilterPath("D:\\DATA\\Openprod\\vensim-malleja");\r
+               String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMDLTPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.mdl"};\r
                fd.setFilterExtensions(filterExt);\r
                String selected = fd.open();\r
@@ -48,6 +55,8 @@ public class ImportMdlHandler extends AbstractHandler {
                File file = new File(selected);\r
                if(!file.isFile()) return null;\r
                \r
+               Activator.getDefault().getPreferenceStore().setValue(IMPORTMDLTPATH, (new File(selected)).getParent());\r
+               \r
                final Model model = MdlParser.parse(file);\r
                \r
                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
index ad38e9c99e4fd19f6c359169d4bc3b4d2a23c062..ddeaec1bc6b29a328a69554e45eedb916d74fc11 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.Platform;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.databoard.Bindings;\r
@@ -29,6 +30,7 @@ import org.simantics.databoard.binding.error.RuntimeBindingConstructionException
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 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.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
@@ -39,10 +41,13 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.utils.OldTransferableGraph1;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 public class ImportModelHandler extends AbstractHandler {\r
+       \r
+       public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH";\r
 \r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
@@ -50,14 +55,21 @@ public class ImportModelHandler extends AbstractHandler {
                Resource project = SimanticsUI.getProject().get();\r
                if(project == null) return null;\r
 \r
-               Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+               final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
-               fd.setText("Import...");\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               fd.setText("Import Model");\r
+               \r
+               String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODELTPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                String selected = fd.open();\r
                if(selected == null) return null;\r
+               \r
+               Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(selected)).getParent());\r
+               \r
 \r
                TransferableGraph1 tg = null;\r
                try {\r
@@ -71,7 +83,11 @@ public class ImportModelHandler extends AbstractHandler {
                        } catch (RuntimeBindingConstructionException e1) {\r
                                e1.printStackTrace();\r
                        } catch (IOException e1) {\r
-                               e1.printStackTrace();\r
+                               MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                               mb.setText("Error");\r
+                               mb.setMessage("The imported file is not of type: Model");\r
+                               mb.open();\r
+                               return null;\r
                        }\r
                }\r
                if(tg == null) return null;\r
@@ -82,15 +98,43 @@ public class ImportModelHandler extends AbstractHandler {
                        DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia);\r
 \r
                        \r
-                       // Fix changes made to old ontology versions\r
+                       // Check that imported resource was actually a model \r
+                       //and fix changes made to old ontology versions\r
                        final Resource root = ia.getRoot();\r
                        SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                                \r
                                @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r
-                                       updateOldConfigurationToBaseRealization(graph, root);\r
-                                       addDefaultOntologyLinks(graph, root);\r
-                                       addURIsToDiagrams(graph, root);\r
+                                       \r
+                                       if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) {\r
+                                               Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
+                                               String type = "...";\r
+                                               if(instanceOf != null)\r
+                                                       type = NameUtils.getSafeName(graph, instanceOf);\r
+                                               else {\r
+                                                       Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
+                                                       if(inheritedFrom != null)\r
+                                                               type = NameUtils.getSafeName(graph, inheritedFrom);\r
+                                               }\r
+                                               final String ft = type; \r
+                                               graph.deny(root, Layer0.getInstance(graph).PartOf);\r
+                                               \r
+                                               shell.getDisplay().asyncExec(new Runnable() {\r
+                                                       \r
+                                                       @Override\r
+                                                       public void run() {\r
+                                                               MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                                                               mb.setText("Error");\r
+                                                               mb.setMessage("The imported file is not of type: System Dynamics Model (" + ft +")");\r
+                                                               mb.open();                                                              \r
+                                                       }\r
+                                               });\r
+\r
+                                       } else {\r
+                                               updateOldConfigurationToBaseRealization(graph, root);\r
+                                               addDefaultOntologyLinks(graph, root);\r
+                                               addURIsToDiagrams(graph, root);\r
+                                       }\r
                                }\r
                        });\r
                } catch (DatabaseException e) {\r
index c973385bb04e0e38f70dcfaea2453bfec94c308f..acbfc95ac1f9d1a2e9140fab5749f6c135b45f46 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
@@ -28,14 +29,24 @@ import org.simantics.databoard.Bindings;
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+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.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
 import org.simantics.graph.db.MissingDependencyException;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
 \r
 public class ImportModuleHandler extends AbstractHandler {\r
 \r
+       public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH";\r
+       \r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
@@ -47,22 +58,32 @@ public class ImportModuleHandler extends AbstractHandler {
 \r
         final Resource model = node.data;\r
         \r
-               Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+               final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
                fd.setText("Import Module");\r
-               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               \r
+               String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODULETPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               fd.setFilterPath(path);\r
                String[] filterExt = {"*.tg"};\r
                fd.setFilterExtensions(filterExt);\r
                String selected = fd.open();\r
                if(selected == null) return null;\r
 \r
+               Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(selected)).getParent());\r
+               \r
                TransferableGraph1 tg = null;\r
                try {\r
                        tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
                } catch (RuntimeBindingConstructionException e) {\r
                        e.printStackTrace();\r
                } catch (IOException e) {\r
-                       e.printStackTrace();\r
+                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                       mb.setText("Error");\r
+                       mb.setMessage("The imported file is not of type: Module Type");\r
+                       mb.open();\r
+                       return null;\r
                }\r
                if(tg == null) return null;\r
 \r
@@ -76,6 +97,38 @@ public class ImportModuleHandler extends AbstractHandler {
                        e.printStackTrace();\r
                }\r
                \r
+               final Resource root = ia.getRoot();\r
+               \r
+               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                       \r
+                       @Override\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) {\r
+                                       Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
+                                       String type = "...";\r
+                                       if(instanceOf != null)\r
+                                               type = NameUtils.getSafeName(graph, instanceOf);\r
+                                       else {\r
+                                               Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
+                                               if(inheritedFrom != null)\r
+                                                       type = NameUtils.getSafeName(graph, inheritedFrom);\r
+                                       }\r
+                                       final String ft = type; \r
+                                       graph.deny(root, Layer0.getInstance(graph).PartOf);\r
+                                       \r
+                                       shell.getDisplay().asyncExec(new Runnable() {\r
+                                               \r
+                                               @Override\r
+                                               public void run() {\r
+                                                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
+                                                       mb.setText("Error");\r
+                                                       mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")");\r
+                                                       mb.open();                                                              \r
+                                               }\r
+                                       });\r
+                               } \r
+                       }\r
+               });\r
                return null;\r
        }\r
 \r
index 60a45356415bb1ad2c206ecdec11625cb90ead65..8d3212d828442d3d180efae6d5e3147c702e4e03 100644 (file)
@@ -8,6 +8,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
@@ -49,15 +50,16 @@ public class NewEnumerationNodeHandler extends AbstractHandler {
                        }\r
                }\r
 \r
-                               Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
-                               \r
-                               Resource enumeration = GraphUtils.create2(g, \r
-                                               sr.Enumeration,\r
-                                               l0.HasName, "Enumeration",\r
-                                               sr.HasEnumerationIndexes, enumerationIndexes);\r
+               Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
                \r
-               g.claim(configuration, l0.ConsistsOf, enumeration);\r
+               String name = NameUtils.findFreshName(g, "Enumeration", configuration, l0.ConsistsOf, "%s%d");\r
+               if("Enumeration".equals(name)) name = "Enumeration1";\r
                \r
+               GraphUtils.create2(g, \r
+                               sr.Enumeration,\r
+                               l0.HasName, name,\r
+                               sr.HasEnumerationIndexes, enumerationIndexes,\r
+                               l0.PartOf, configuration);\r
             }\r
         });\r
                return null;\r
index b650cd89d294e2e8de36752d5e0cbe45106f1651..eebc355fb76bf56b68a095990b2acd9f45cff0de 100644 (file)
@@ -15,6 +15,7 @@ import java.util.ArrayList;
 import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
+import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Set;\r
 \r
@@ -138,6 +139,9 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
                        if(activeDataSets != null && !activeDataSets.isEmpty())\r
                                datasets.addAll(activeDataSets);\r
                }\r
+               \r
+               for(SysdynDataSet dataset : datasets)\r
+                       System.out.println(dataset.name);\r
                selectionChanged(datasets);\r
 \r
        }\r
@@ -145,7 +149,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
 \r
        protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Variable variable) throws DatabaseException {\r
                ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
-               HashMap<String, String> rvis = new HashMap<String, String>();\r
+               HashMap<String, String> rvis = new LinkedHashMap<String, String>();\r
 \r
                String rvi = Variables.getRVI(g, variable).replace("/", ".");           \r
                if(rvi.length() > 1)\r