From a42e7e82f616928cc3f17c53b18ff5580ddad126 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 6 May 2011 13:57:45 +0000 Subject: [PATCH] For convenience: import/export locations are stored and shown the next time that same type of object is imported/exported. SysdynDatasetSelectionListener uses LinkedHashMap so that enumerations are always in the same order (not the case with ordinary HashMap). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20808 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/handlers/ExportFunctionLibrary.java | 11 ++++++++--- .../sysdyn/ui/handlers/ExportModelHandler.java | 9 +++++++-- .../sysdyn/ui/handlers/ExportModuleHandler.java | 9 +++++++-- .../ui/handlers/ImportFunctionLibrary.java | 11 ++++++++++- .../sysdyn/ui/handlers/ImportMdlHandler.java | 11 ++++++++++- .../sysdyn/ui/handlers/ImportModelHandler.java | 14 ++++++++++++-- .../sysdyn/ui/handlers/ImportModuleHandler.java | 11 ++++++++++- .../ui/handlers/NewEnumerationNodeHandler.java | 16 +++++++++------- .../SysdynDatasetSelectionListener.java | 6 +++++- 9 files changed, 78 insertions(+), 20 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java index 4ad047d1..38054f78 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java @@ -36,6 +36,7 @@ import org.simantics.db.layer0.util.TransferableGraphRequest2; import org.simantics.db.request.Read; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; @@ -71,15 +72,19 @@ public class ExportFunctionLibrary extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); - fd.setText("Export.."); + fd.setText("Export Function Library"); fd.setFileName(name); - fd.setFilterPath(Platform.getLocation().toOSString()); + String path = Activator.getDefault().getPreferenceStore().getString(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); final String selected = fd.open(); if(selected == null) return null; - + Activator.getDefault().getPreferenceStore().setValue(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + SimanticsUI.getSession().asyncRequest(new ReadRequest() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java index 5b4d5cc7..f4e007df 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java @@ -36,6 +36,7 @@ import org.simantics.db.layer0.util.TransferableGraphRequest2; import org.simantics.db.request.Read; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; @@ -72,14 +73,18 @@ public class ExportModelHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); - fd.setText("Export.."); + fd.setText("Export Model"); fd.setFileName(name); - fd.setFilterPath(Platform.getLocation().toOSString()); + String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); final String selected = fd.open(); if(selected == null) return null; + Activator.getDefault().getPreferenceStore().setValue(ImportModelHandler.IMPORTMODELTPATH, (new File(selected)).getParent()); SimanticsUI.getSession().asyncRequest(new ReadRequest() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java index 17b5bd05..88bb8d8f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java @@ -45,6 +45,7 @@ import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; @@ -135,14 +136,18 @@ public class ExportModuleHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); - fd.setText("Export.."); + fd.setText("Export Module"); fd.setFileName(name); - fd.setFilterPath(Platform.getLocation().toOSString()); + String path = Activator.getDefault().getPreferenceStore().getString(ImportModuleHandler.IMPORTMODULETPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); final String selected = fd.open(); if(selected == null) return null; + Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent()); SimanticsUI.getSession().asyncRequest(new ReadRequest() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java index 3193d416..7f5a6577 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java @@ -43,12 +43,15 @@ import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; import org.simantics.ui.utils.ResourceAdaptionUtils; public class ImportFunctionLibrary extends AbstractHandler { + + public static String IMPORTFUNCTIONLIBRARYPATH = "IMPORT_FUNCTION_LIBRARY_PATH"; @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -65,12 +68,18 @@ public class ImportFunctionLibrary extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import Function Library"); - fd.setFilterPath(Platform.getLocation().toOSString()); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTFUNCTIONLIBRARYPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); if(selected == null) return null; + Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + TransferableGraph1 tg = null; try { tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java index 603c28aa..156ab7bc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java @@ -16,6 +16,7 @@ import java.io.File; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; @@ -26,10 +27,13 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.sysdyn.mdlImport.MdlParser; import org.simantics.sysdyn.mdlImport.mdlElements.Model; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; public class ImportMdlHandler extends AbstractHandler { + public static String IMPORTMDLTPATH = "IMPORT_MDL_PATH"; + @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -39,7 +43,10 @@ public class ImportMdlHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import .mdl"); - fd.setFilterPath("D:\\DATA\\Openprod\\vensim-malleja"); + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMDLTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.mdl"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); @@ -48,6 +55,8 @@ public class ImportMdlHandler extends AbstractHandler { File file = new File(selected); if(!file.isFile()) return null; + Activator.getDefault().getPreferenceStore().setValue(IMPORTMDLTPATH, (new File(selected)).getParent()); + final Model model = MdlParser.parse(file); SimanticsUI.getSession().asyncRequest(new WriteRequest() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java index ad38e9c9..36be1fd5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java @@ -39,10 +39,13 @@ import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; import org.simantics.ui.SimanticsUI; public class ImportModelHandler extends AbstractHandler { + + public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH"; @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -52,12 +55,19 @@ public class ImportModelHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); - fd.setText("Import..."); - fd.setFilterPath(Platform.getLocation().toOSString()); + fd.setText("Import Model"); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODELTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); if(selected == null) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(selected)).getParent()); + TransferableGraph1 tg = null; try { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java index c973385b..6c0d40fe 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java @@ -32,10 +32,13 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; import org.simantics.graph.db.MissingDependencyException; import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.utils.AdaptionUtils; public class ImportModuleHandler extends AbstractHandler { + public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; + @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = HandlerUtil.getCurrentSelection(event); @@ -50,12 +53,18 @@ public class ImportModuleHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import Module"); - fd.setFilterPath(Platform.getLocation().toOSString()); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODULETPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); String[] filterExt = {"*.tg"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); if(selected == null) return null; + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(selected)).getParent()); + TransferableGraph1 tg = null; try { tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java index 60a45356..8d3212d8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java @@ -8,6 +8,7 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.layer0.Layer0; @@ -49,15 +50,16 @@ public class NewEnumerationNodeHandler extends AbstractHandler { } } - Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); - - Resource enumeration = GraphUtils.create2(g, - sr.Enumeration, - l0.HasName, "Enumeration", - sr.HasEnumerationIndexes, enumerationIndexes); + Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); - g.claim(configuration, l0.ConsistsOf, enumeration); + String name = NameUtils.findFreshName(g, "Enumeration", configuration, l0.ConsistsOf, "%s%d"); + if("Enumeration".equals(name)) name = "Enumeration1"; + GraphUtils.create2(g, + sr.Enumeration, + l0.HasName, name, + sr.HasEnumerationIndexes, enumerationIndexes, + l0.PartOf, configuration); } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index b650cd89..eebc355f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Set; @@ -138,6 +139,9 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen if(activeDataSets != null && !activeDataSets.isEmpty()) datasets.addAll(activeDataSets); } + + for(SysdynDataSet dataset : datasets) + System.out.println(dataset.name); selectionChanged(datasets); } @@ -145,7 +149,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen protected Collection loadAllActive(ReadGraph g, Variable variable) throws DatabaseException { ArrayList dataSets = new ArrayList(); - HashMap rvis = new HashMap(); + HashMap rvis = new LinkedHashMap(); String rvi = Variables.getRVI(g, variable).replace("/", "."); if(rvi.length() > 1) -- 2.47.1