From: lempinen Date: Mon, 21 May 2012 09:42:22 +0000 (+0000) Subject: Import and export of modules and function libraries (refs #3414) X-Git-Tag: simantics-1.6~5^2~1 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=987e0b6332ca4060f8ed1bddd75e210139173a38;p=simantics%2Fsysdyn.git Import and export of modules and function libraries (refs #3414) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25023 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java index 0b65cfd8..0784dd7c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java @@ -25,8 +25,10 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.container.DataContainer; +import org.simantics.databoard.container.DataContainers; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.PossibleRelatedValue; @@ -107,7 +109,7 @@ public class ExportFunctionLibrary extends AbstractHandler { TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary)); try { - Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + DataContainers.writeFile(new File(selected), new DataContainer("sysdynFunctionLibrary", 1, new Variant(TransferableGraph1.BINDING, tg))); } catch (RuntimeBindingConstructionException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java index 7b12325e..34958a0e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java @@ -27,8 +27,10 @@ import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.container.DataContainer; +import org.simantics.databoard.container.DataContainers; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -246,7 +248,7 @@ public class ExportModuleHandler extends AbstractHandler { graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component)); - Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + DataContainers.writeFile(new File(path), new DataContainer("sysdynModule", 1, new Variant(TransferableGraph1.BINDING, tg))); for(Pair replacement : replacements) graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java index b20206c4..dad7c060 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; import java.io.IOException; +import java.util.HashMap; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -25,8 +26,11 @@ import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.container.DataContainer; +import org.simantics.databoard.container.DataContainers; +import org.simantics.databoard.container.DataFormatException; +import org.simantics.databoard.container.FormatHandler; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -91,127 +95,113 @@ public class ImportFunctionLibrary extends AbstractHandler { Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); - // Load the transferable graph - 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) { - 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; - - // Make sure the "http://SharedOntologies resource exists - try { - Boolean hasSharedOntologies; - hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { + // Ensure that shared functions ontology exists + ensureSharedOntologies(); + + // Handler for importing function libraries + HashMap> handlers = new HashMap>(); + handlers.put("sysdynFunctionLibrary:1", new FormatHandler() { + @Override + public Binding getBinding() { + return TransferableGraph1.BINDING; + } - @Override - public Boolean perform(ReadGraph graph) throws DatabaseException { - try { - graph.getResource("http://SharedOntologies"); - } catch (ResourceNotFoundException e) { - return false; - } - return true; + @Override + public Object process(DataContainer container) throws DataFormatException { + SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary); + try { + DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), functionLibrary, ia); + return ia.getRoot(); + } catch (Exception e) { + e.printStackTrace(); + return null; } - }); - - if(!hasSharedOntologies) { - SimanticsUI.getSession().syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - GraphUtils.create2(graph, l0.Library, - l0.HasName, "SharedOntologies", - l0.PartOf, graph.getResource("http:/")); - } - }); - } - } catch (DatabaseException e) { - e.printStackTrace(); - return null; - } + }); - - // Import a function library from the transferable graph - SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary); + // Read function library file + Object result = null; try { - DefaultPasteHandler.defaultExecute(tg, functionLibrary, ia); - } catch (Exception e) { + File file = new File(selected); + if(!file.isFile()) { + displayErrorMessage(shell, "File " + selected + " not found"); + return null; + } else { + result = DataContainers.readFile(file, handlers); + } + } catch(DataFormatException e) { + e.printStackTrace(); + } catch(IOException e) { e.printStackTrace(); + } catch(Exception e) { + if(e instanceof RuntimeException) + throw (RuntimeException)e; + else + throw new RuntimeException(e); } - final Resource root = ia.getRoot(); // Root of the library - - // Link the imported library to the selected resource (functionLibrary) - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - /** - * Link the imported library to the selected resource (functionLibrary) - * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology - */ - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - // Case: SharedFunctionOntology. Link to SharedOntologies - if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) { - Resource library = graph.getResource("http://SharedOntologies"); - if(!graph.hasStatement(library, l0.ConsistsOf, root)) { - graph.claim(library, l0.ConsistsOf, root); - } + if(result == null || !(result instanceof Resource)) { + displayErrorMessage(shell, "Function library could not be imported."); + } else { + final Resource FunctionLibraryRoot = (Resource) result; + // Link the imported library to the selected resource (functionLibrary) + SimanticsUI.getSession().asyncRequest(new WriteRequest() { - // Link model to the shared library - SysdynResource sr = SysdynResource.getInstance(graph); - Resource model = functionLibrary; - while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology)) - model = graph.getSingleObject(model, l0.PartOf); - if(graph.isInstanceOf(model, sr.SysdynModel)) { - graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root); - } + /** + * Link the imported library to the selected resource (functionLibrary) + * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology + */ + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + // Case: SharedFunctionOntology. Link to SharedOntologies + if(graph.isInstanceOf(FunctionLibraryRoot, SysdynResource.getInstance(graph).SharedFunctionOntology)) { + Resource library = graph.getResource("http://SharedOntologies"); + if(!graph.hasStatement(library, l0.ConsistsOf, FunctionLibraryRoot)) { + graph.claim(library, l0.ConsistsOf, FunctionLibraryRoot); + } - // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. - } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { - Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf); - String type = "..."; - if(instanceOf != null) - type = NameUtils.getSafeName(graph, instanceOf); - else { - Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits); - if(inheritedFrom != null) - type = NameUtils.getSafeName(graph, inheritedFrom); - } - final String ft = type; - - // Remove the functionLibrary ConsistsOf root relation - graph.deny(root, l0.PartOf); - - // Display error message - 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(); + // Link model to the shared library + SysdynResource sr = SysdynResource.getInstance(graph); + Resource model = functionLibrary; + while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology)) + model = graph.getSingleObject(model, l0.PartOf); + if(graph.isInstanceOf(model, sr.SysdynModel)) { + graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, FunctionLibraryRoot); } - }); - } else { - // imported library is already in the right place. Update function library files. - FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); - } - } - }); + // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. + } else if(!graph.isInstanceOf(FunctionLibraryRoot, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { + Resource instanceOf = graph.getPossibleObject(FunctionLibraryRoot,l0.InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(FunctionLibraryRoot, l0.Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + + // Remove the functionLibrary ConsistsOf root relation + graph.deny(FunctionLibraryRoot, l0.PartOf); + + // Display error message + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + displayErrorMessage(shell, "The imported file is not of type: Function Library (" + ft +")"); + } + }); + } else { + // imported library is already in the right place. Update function library files. + FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); + } + + } + }); + } return null; } @@ -252,5 +242,48 @@ public class ImportFunctionLibrary extends AbstractHandler { } } + + private void ensureSharedOntologies() { + // Make sure the "http://SharedOntologies resource exists + try { + Boolean hasSharedOntologies; + hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + try { + graph.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + return false; + } + return true; + } + }); + + if(!hasSharedOntologies) { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + GraphUtils.create2(graph, l0.Library, + l0.HasName, "SharedOntologies", + l0.PartOf, graph.getResource("http:/")); + } + }); + + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + private void displayErrorMessage(Shell shell, String message) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Model"); + mb.open(); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java index 03c8bc65..64c06a70 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java @@ -87,7 +87,7 @@ public class ImportModelHandler extends AbstractHandler { public Object process(DataContainer container) throws DataFormatException { DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); try { - DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), SimanticsUI.getProject().get(), ia); + DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), project, ia); return ia.getRoot(); } catch (Exception e) { @@ -144,10 +144,7 @@ public class ImportModelHandler extends AbstractHandler { @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(); + displayErrorMessage(shell, "The imported file is not of type: System Dynamics Model (" + ft +")"); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java index 9a0cfceb..cf422425 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; import java.io.IOException; +import java.util.HashMap; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -25,9 +26,11 @@ 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; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.container.DataContainer; +import org.simantics.databoard.container.DataContainers; +import org.simantics.databoard.container.DataFormatException; +import org.simantics.databoard.container.FormatHandler; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; @@ -35,7 +38,6 @@ 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; @@ -51,95 +53,122 @@ 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); - - @SuppressWarnings("unchecked") - AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); - if (node == null) - return null; - - final Resource model = node.data; - - // Get imported transferable graph file using FileDialog - final Shell shell = HandlerUtil.getActiveShellChecked(event); - FileDialog fd = new FileDialog(shell, SWT.OPEN); - fd.setText("Import Module"); - - 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()); - - // Get the transferable graph from file - TransferableGraph1 tg = null; - try { - tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - 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; - - - // Import the module to model - DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model); - try { - DefaultPasteHandler.defaultExecute(tg, model, ia); - } catch (MissingDependencyException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - final Resource root = ia.getRoot(); - - // Check that the imported file actually was a module. Display error message otherwise. - 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; - } + public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + final Resource model = node.data; + + // Get imported transferable graph file using FileDialog + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Module"); + + 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()); + + // Handler for importing modules + HashMap> handlers = new HashMap>(); + handlers.put("sysdynModule:1", new FormatHandler() { + @Override + public Binding getBinding() { + return TransferableGraph1.BINDING; + } + + @Override + public Object process(DataContainer container) throws DataFormatException { + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model); + try { + DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), model, ia); + return ia.getRoot(); + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + }); + + // Read module file + Object result = null; + try { + File file = new File(selected); + if(!file.isFile()) { + displayErrorMessage(shell, "File " + selected + " not found"); + return null; + } else { + result = DataContainers.readFile(file, handlers); + } + } catch(DataFormatException e) { + e.printStackTrace(); + } catch(IOException e) { + e.printStackTrace(); + } catch(Exception e) { + if(e instanceof RuntimeException) + throw (RuntimeException)e; + else + throw new RuntimeException(e); + } + + + if(result == null || !(result instanceof Resource)) { + displayErrorMessage(shell, "Module could not be imported."); + } else { + final Resource ModuleRoot = (Resource) result; + // Check that the imported file actually was a module. Display error message otherwise. + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInheritedFrom(ModuleRoot, SysdynResource.getInstance(graph).Module)) { + Resource instanceOf = graph.getPossibleObject(ModuleRoot, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(ModuleRoot, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(ModuleRoot, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + displayErrorMessage(shell, "The imported file is not of type: System Dynamics Module (" + ft +")"); + } + }); + } + } + }); + + } + return null; + } + + + private void displayErrorMessage(Shell shell, String message) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Model"); + mb.open(); + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java index 2b85df43..7a5f165b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java @@ -18,6 +18,7 @@ import java.util.Set; import org.simantics.sysdyn.expressionParser.ExpressionParser; import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.expressionParser.Token; import org.simantics.sysdyn.representation.utils.FormatUtils; import org.simantics.sysdyn.representation.utils.RepresentationUtils; @@ -229,6 +230,12 @@ public enum Variability { return Variability.PARAMETER; } else { Set references = parser.getReferences().keySet(); + + if(parser.getForIndices()!=null) { + for(Token t : parser.getForIndices().keySet()) { + references.remove(t.image); + } + } // Go through each reference for(String reference : references) {