]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
For convenience: import/export locations are stored and shown the next time that...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 May 2011 13:57:45 +0000 (13:57 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 May 2011 13:57:45 +0000 (13:57 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20808 ac1ea38d-2e2b-0410-8846-a27921b304fc

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

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..7f5a657750962c9ab74f002c52ac4fc2e06766ca 100644 (file)
@@ -43,12 +43,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
@@ -65,12 +68,18 @@ public class ImportFunctionLibrary  extends AbstractHandler {
                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
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..36be1fd5a097ae0d6e5a9a2a907e72cd9f5ede30 100644 (file)
@@ -39,10 +39,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
@@ -52,12 +55,19 @@ public class ImportModelHandler extends AbstractHandler {
 \r
                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
index c973385bb04e0e38f70dcfaea2453bfec94c308f..6c0d40fe44618f9cd66f4afd2fc0720e989482ae 100644 (file)
@@ -32,10 +32,13 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
 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.sysdyn.ui.Activator;\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
@@ -50,12 +53,18 @@ public class ImportModuleHandler extends AbstractHandler {
                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
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