import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary));\r
\r
try {\r
- Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+ DataContainers.writeFile(new File(selected), new DataContainer("sysdynFunctionLibrary", 1, new Variant(TransferableGraph1.BINDING, tg)));\r
} catch (RuntimeBindingConstructionException e) {\r
e.printStackTrace();\r
} catch (IOException e) {\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second);\r
\r
TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component));\r
- Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+ DataContainers.writeFile(new File(path), new DataContainer("sysdynModule", 1, new Variant(TransferableGraph1.BINDING, tg)));\r
\r
for(Pair<Resource,Resource> replacement : replacements)\r
graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second);\r
\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.HashMap;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Files;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
+import org.simantics.databoard.container.DataFormatException;\r
+import org.simantics.databoard.container.FormatHandler;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
\r
Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent());\r
\r
- // Load the transferable graph\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
- 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
- // Make sure the "http://SharedOntologies resource exists\r
- try {\r
- Boolean hasSharedOntologies;\r
- hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
+ // Ensure that shared functions ontology exists\r
+ ensureSharedOntologies();\r
+ \r
+ // Handler for importing function libraries\r
+ HashMap<String, FormatHandler<Object>> handlers = new HashMap<String, FormatHandler<Object>>();\r
+ handlers.put("sysdynFunctionLibrary:1", new FormatHandler<Object>() {\r
+ @Override\r
+ public Binding getBinding() {\r
+ return TransferableGraph1.BINDING;\r
+ }\r
\r
- @Override\r
- public Boolean perform(ReadGraph graph) throws DatabaseException {\r
- try {\r
- graph.getResource("http://SharedOntologies");\r
- } catch (ResourceNotFoundException e) {\r
- return false;\r
- } \r
- return true;\r
+ @Override\r
+ public Object process(DataContainer container) throws DataFormatException {\r
+ SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary);\r
+ try {\r
+ DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), functionLibrary, ia);\r
+ return ia.getRoot();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return null;\r
}\r
- });\r
-\r
- if(!hasSharedOntologies) {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
-\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- GraphUtils.create2(graph, l0.Library, \r
- l0.HasName, "SharedOntologies",\r
- l0.PartOf, graph.getResource("http:/"));\r
- }\r
- });\r
-\r
}\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- return null;\r
- }\r
+ });\r
\r
- \r
- // Import a function library from the transferable graph\r
- SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary);\r
+ // Read function library file\r
+ Object result = null;\r
try {\r
- DefaultPasteHandler.defaultExecute(tg, functionLibrary, ia);\r
- } catch (Exception e) {\r
+ File file = new File(selected);\r
+ if(!file.isFile()) {\r
+ displayErrorMessage(shell, "File " + selected + " not found");\r
+ return null;\r
+ } else { \r
+ result = DataContainers.readFile(file, handlers);\r
+ }\r
+ } catch(DataFormatException e) {\r
+ e.printStackTrace();\r
+ } catch(IOException e) {\r
e.printStackTrace();\r
+ } catch(Exception e) {\r
+ if(e instanceof RuntimeException)\r
+ throw (RuntimeException)e;\r
+ else\r
+ throw new RuntimeException(e);\r
}\r
\r
- final Resource root = ia.getRoot(); // Root of the library\r
- \r
- // Link the imported library to the selected resource (functionLibrary)\r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
- /**\r
- * Link the imported library to the selected resource (functionLibrary)\r
- * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology\r
- */\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- // Case: SharedFunctionOntology. Link to SharedOntologies\r
- if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
- Resource library = graph.getResource("http://SharedOntologies");\r
- if(!graph.hasStatement(library, l0.ConsistsOf, root)) {\r
- graph.claim(library, l0.ConsistsOf, root);\r
- }\r
+ if(result == null || !(result instanceof Resource)) {\r
+ displayErrorMessage(shell, "Function library could not be imported.");\r
+ } else {\r
+ final Resource FunctionLibraryRoot = (Resource) result;\r
+ // Link the imported library to the selected resource (functionLibrary)\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
- // Link model to the shared library\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Resource model = functionLibrary;\r
- while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
- model = graph.getSingleObject(model, l0.PartOf);\r
- if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
- graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root);\r
- }\r
+ /**\r
+ * Link the imported library to the selected resource (functionLibrary)\r
+ * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology\r
+ */\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ // Case: SharedFunctionOntology. Link to SharedOntologies\r
+ if(graph.isInstanceOf(FunctionLibraryRoot, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
+ Resource library = graph.getResource("http://SharedOntologies");\r
+ if(!graph.hasStatement(library, l0.ConsistsOf, FunctionLibraryRoot)) {\r
+ graph.claim(library, l0.ConsistsOf, FunctionLibraryRoot);\r
+ }\r
\r
- // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. \r
- } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
- Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf);\r
- String type = "...";\r
- if(instanceOf != null)\r
- type = NameUtils.getSafeName(graph, instanceOf);\r
- else {\r
- Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits);\r
- if(inheritedFrom != null)\r
- type = NameUtils.getSafeName(graph, inheritedFrom);\r
- }\r
- final String ft = type; \r
- \r
- // Remove the functionLibrary ConsistsOf root relation\r
- graph.deny(root, l0.PartOf);\r
- \r
- // Display error message\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
+ // Link model to the shared library\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource model = functionLibrary;\r
+ while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
+ model = graph.getSingleObject(model, l0.PartOf);\r
+ if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
+ graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, FunctionLibraryRoot);\r
}\r
- });\r
- } else {\r
- // imported library is already in the right place. Update function library files.\r
- FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
- }\r
\r
- }\r
- });\r
+ // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. \r
+ } else if(!graph.isInstanceOf(FunctionLibraryRoot, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
+ Resource instanceOf = graph.getPossibleObject(FunctionLibraryRoot,l0.InstanceOf);\r
+ String type = "...";\r
+ if(instanceOf != null)\r
+ type = NameUtils.getSafeName(graph, instanceOf);\r
+ else {\r
+ Resource inheritedFrom = graph.getPossibleObject(FunctionLibraryRoot, l0.Inherits);\r
+ if(inheritedFrom != null)\r
+ type = NameUtils.getSafeName(graph, inheritedFrom);\r
+ }\r
+ final String ft = type; \r
+\r
+ // Remove the functionLibrary ConsistsOf root relation\r
+ graph.deny(FunctionLibraryRoot, l0.PartOf);\r
+\r
+ // Display error message\r
+ shell.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ displayErrorMessage(shell, "The imported file is not of type: Function Library (" + ft +")"); \r
+ }\r
+ });\r
+ } else {\r
+ // imported library is already in the right place. Update function library files.\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+ }\r
+\r
+ }\r
+ });\r
+ }\r
return null;\r
}\r
\r
}\r
\r
}\r
+ \r
+ private void ensureSharedOntologies() {\r
+ // Make sure the "http://SharedOntologies resource exists\r
+ try {\r
+ Boolean hasSharedOntologies;\r
+ hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+ try {\r
+ graph.getResource("http://SharedOntologies");\r
+ } catch (ResourceNotFoundException e) {\r
+ return false;\r
+ } \r
+ return true;\r
+ }\r
+ });\r
+\r
+ if(!hasSharedOntologies) {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ GraphUtils.create2(graph, l0.Library, \r
+ l0.HasName, "SharedOntologies",\r
+ l0.PartOf, graph.getResource("http:/"));\r
+ }\r
+ });\r
+\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ }\r
+ \r
+ private void displayErrorMessage(Shell shell, String message) {\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
+ }\r
\r
}\r
public Object process(DataContainer container) throws DataFormatException {\r
DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project);\r
try {\r
- DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), SimanticsUI.getProject().get(), ia);\r
+ DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), project, ia);\r
return ia.getRoot();\r
\r
} catch (Exception e) {\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
+ displayErrorMessage(shell, "The imported file is not of type: System Dynamics Model (" + ft +")");\r
}\r
});\r
\r
\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.HashMap;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Files;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
+import org.simantics.databoard.container.DataFormatException;\r
+import org.simantics.databoard.container.FormatHandler;\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.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
*/\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
-\r
- @SuppressWarnings("unchecked")\r
- AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
- if (node == null)\r
- return null;\r
-\r
- final Resource model = node.data;\r
-\r
- // Get imported transferable graph file using FileDialog\r
- final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
- FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
- fd.setText("Import Module");\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
- // Get the transferable graph from file\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
- 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
-\r
- // Import the module to model\r
- DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model);\r
- try {\r
- DefaultPasteHandler.defaultExecute(tg, model, ia);\r
- } catch (MissingDependencyException e) {\r
- e.printStackTrace();\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
-\r
- final Resource root = ia.getRoot();\r
-\r
- // Check that the imported file actually was a module. Display error message otherwise.\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
+ 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
+\r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ final Resource model = node.data;\r
+\r
+ // Get imported transferable graph file using FileDialog\r
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+ fd.setText("Import Module");\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
+ // Handler for importing modules\r
+ HashMap<String, FormatHandler<Object>> handlers = new HashMap<String, FormatHandler<Object>>();\r
+ handlers.put("sysdynModule:1", new FormatHandler<Object>() {\r
+ @Override\r
+ public Binding getBinding() {\r
+ return TransferableGraph1.BINDING;\r
+ }\r
+\r
+ @Override\r
+ public Object process(DataContainer container) throws DataFormatException {\r
+ DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model);\r
+ try {\r
+ DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), model, ia);\r
+ return ia.getRoot();\r
+\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+ }\r
+ });\r
+\r
+ // Read module file\r
+ Object result = null;\r
+ try {\r
+ File file = new File(selected);\r
+ if(!file.isFile()) {\r
+ displayErrorMessage(shell, "File " + selected + " not found");\r
+ return null;\r
+ } else { \r
+ result = DataContainers.readFile(file, handlers);\r
+ }\r
+ } catch(DataFormatException e) {\r
+ e.printStackTrace();\r
+ } catch(IOException e) {\r
+ e.printStackTrace();\r
+ } catch(Exception e) {\r
+ if(e instanceof RuntimeException)\r
+ throw (RuntimeException)e;\r
+ else\r
+ throw new RuntimeException(e);\r
+ }\r
+\r
+\r
+ if(result == null || !(result instanceof Resource)) {\r
+ displayErrorMessage(shell, "Module could not be imported.");\r
+ } else {\r
+ final Resource ModuleRoot = (Resource) result;\r
+ // Check that the imported file actually was a module. Display error message otherwise.\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(!graph.isInheritedFrom(ModuleRoot, SysdynResource.getInstance(graph).Module)) {\r
+ Resource instanceOf = graph.getPossibleObject(ModuleRoot, Layer0.getInstance(graph).InstanceOf);\r
+ String type = "...";\r
+ if(instanceOf != null)\r
+ type = NameUtils.getSafeName(graph, instanceOf);\r
+ else {\r
+ Resource inheritedFrom = graph.getPossibleObject(ModuleRoot, Layer0.getInstance(graph).Inherits);\r
+ if(inheritedFrom != null)\r
+ type = NameUtils.getSafeName(graph, inheritedFrom);\r
+ }\r
+ final String ft = type; \r
+ graph.deny(ModuleRoot, Layer0.getInstance(graph).PartOf);\r
+\r
+ shell.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ displayErrorMessage(shell, "The imported file is not of type: System Dynamics Module (" + ft +")");\r
+ }\r
+ });\r
+ } \r
+ }\r
+ });\r
+\r
+ }\r
+ return null;\r
+ }\r
+\r
+\r
+ private void displayErrorMessage(Shell shell, String message) {\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
+ }\r
\r
}\r
\r
import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
import org.simantics.sysdyn.expressionParser.ParseException;\r
+import org.simantics.sysdyn.expressionParser.Token;\r
import org.simantics.sysdyn.representation.utils.FormatUtils;\r
import org.simantics.sysdyn.representation.utils.RepresentationUtils;\r
\r
return Variability.PARAMETER;\r
} else {\r
Set<String> references = parser.getReferences().keySet();\r
+ \r
+ if(parser.getForIndices()!=null) {\r
+ for(Token t : parser.getForIndices().keySet()) {\r
+ references.remove(t.image);\r
+ }\r
+ }\r
\r
// Go through each reference\r
for(String reference : references) {\r