From: lempinen Date: Tue, 10 May 2011 05:50:48 +0000 (+0000) Subject: Update 1.4 to latest code X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8a678f231079e16c628aa63b095e889361f0df4e;p=simantics%2Fsysdyn.git Update 1.4 to latest code git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/simantics-1.4@20844 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 index 00000000..3d4b6913 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java @@ -0,0 +1,15 @@ +package org.simantics.objmap.rules.adapters; + +public enum IdentityAdapter implements ValueAdapter { + INSTANCE; + + @Override + public Object domainToRange(Object domainValue) { + return domainValue; + } + + @Override + public Object rangeToDomain(Object rangeValue) { + return rangeValue; + } +} 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 index 00000000..c8d0d2d0 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java @@ -0,0 +1,6 @@ +package org.simantics.objmap.rules.adapters; + +public interface ValueAdapter { + Object domainToRange(Object domainValue); + Object rangeToDomain(Object rangeValue); +} 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 index 00000000..a6df00b0 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java @@ -0,0 +1,25 @@ +package org.simantics.objmap.rules.range; + +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.adapters.ValueAdapter; + +public class AdaptedRangeAccessor implements IRangeAccessor { + IRangeAccessor baseAccessor; + ValueAdapter adapter; + + public AdaptedRangeAccessor(IRangeAccessor baseAccessror, + ValueAdapter adapter) { + this.baseAccessor = baseAccessror; + this.adapter = adapter; + } + + @Override + public Object get(Object element) throws MappingException { + return adapter.rangeToDomain(baseAccessor.get(element)); + } + + @Override + public boolean set(Object element, Object value) throws MappingException { + return baseAccessor.set(element, adapter.domainToRange(value)); + } +} 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..3b6bc8e1 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 @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; @@ -30,8 +31,8 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.WriteOnlyGraph; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ResourceNotFoundException; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; @@ -43,12 +44,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 { @@ -62,23 +66,34 @@ public class ImportFunctionLibrary extends AbstractHandler { final Resource functionLibrary = r; - Shell shell = HandlerUtil.getActiveShellChecked(event); + final 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)); } catch (RuntimeBindingConstructionException e) { e.printStackTrace(); + return null; } catch (IOException e) { - e.printStackTrace(); - } + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Function Library"); + mb.open(); + return null; + } if(tg == null) return null; @@ -123,11 +138,39 @@ public class ImportFunctionLibrary extends AbstractHandler { e.printStackTrace(); } - SimanticsUI.getSession().asyncRequest(new ReadRequest() { + final Resource root = ia.getRoot(); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { @Override - public void run(ReadGraph graph) throws DatabaseException { - FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Function Library (" + ft +")"); + mb.open(); + } + }); + } else { + FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); + } + } }); return null; 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..ddeaec1b 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 @@ -21,6 +21,7 @@ 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.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; @@ -29,6 +30,7 @@ import org.simantics.databoard.binding.error.RuntimeBindingConstructionException 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.exception.DatabaseException; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; @@ -39,10 +41,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 { @@ -50,14 +55,21 @@ public class ImportModelHandler extends AbstractHandler { Resource project = SimanticsUI.getProject().get(); if(project == null) return null; - Shell shell = HandlerUtil.getActiveShellChecked(event); + final 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 { @@ -71,7 +83,11 @@ public class ImportModelHandler extends AbstractHandler { } catch (RuntimeBindingConstructionException e1) { e1.printStackTrace(); } catch (IOException e1) { - e1.printStackTrace(); + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Model"); + mb.open(); + return null; } } if(tg == null) return null; @@ -82,15 +98,43 @@ public class ImportModelHandler extends AbstractHandler { DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); - // Fix changes made to old ontology versions + // Check that imported resource was actually a model + //and fix changes made to old ontology versions final Resource root = ia.getRoot(); SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { - updateOldConfigurationToBaseRealization(graph, root); - addDefaultOntologyLinks(graph, root); - addURIsToDiagrams(graph, root); + + if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: System Dynamics Model (" + ft +")"); + mb.open(); + } + }); + + } else { + updateOldConfigurationToBaseRealization(graph, root); + addDefaultOntologyLinks(graph, root); + addURIsToDiagrams(graph, root); + } } }); } catch (DatabaseException e) { 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..acbfc95a 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 @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.browsing.ui.common.node.AbstractNode; @@ -28,14 +29,24 @@ import org.simantics.databoard.Bindings; import org.simantics.databoard.Files; import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; 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.exception.DatabaseException; 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.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; 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); @@ -47,22 +58,32 @@ public class ImportModuleHandler extends AbstractHandler { final Resource model = node.data; - Shell shell = HandlerUtil.getActiveShellChecked(event); + final 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)); } catch (RuntimeBindingConstructionException e) { e.printStackTrace(); } catch (IOException e) { - e.printStackTrace(); + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Module Type"); + mb.open(); + return null; } if(tg == null) return null; @@ -76,6 +97,38 @@ public class ImportModuleHandler extends AbstractHandler { e.printStackTrace(); } + final Resource root = ia.getRoot(); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")"); + mb.open(); + } + }); + } + } + }); return null; } 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)