import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.WriteOnlyGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.exception.ResourceNotFoundException;\r
import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
\r
final Resource functionLibrary = r;\r
\r
- Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
fd.setText("Import Function Library");\r
\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
- e.printStackTrace();\r
- }\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
\r
e.printStackTrace();\r
}\r
\r
- SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ final Resource root = ia.getRoot();\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
@Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\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: Function Library (" + ft +")");\r
+ mb.open(); \r
+ }\r
+ });\r
+ } else {\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+ }\r
+\r
}\r
});\r
return null;\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.MessageBox;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.databoard.Bindings;\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.common.utils.NameUtils;\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
Resource project = SimanticsUI.getProject().get();\r
if(project == null) return null;\r
\r
- Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
fd.setText("Import Model");\r
\r
} catch (RuntimeBindingConstructionException e1) {\r
e1.printStackTrace();\r
} catch (IOException e1) {\r
- e1.printStackTrace();\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
+ return null;\r
}\r
}\r
if(tg == null) return null;\r
DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia);\r
\r
\r
- // Fix changes made to old ontology versions\r
+ // Check that imported resource was actually a model \r
+ //and fix changes made to old ontology versions\r
final Resource root = ia.getRoot();\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- updateOldConfigurationToBaseRealization(graph, root);\r
- addDefaultOntologyLinks(graph, root);\r
- addURIsToDiagrams(graph, root);\r
+ \r
+ if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) {\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 Model (" + ft +")");\r
+ mb.open(); \r
+ }\r
+ });\r
+\r
+ } else {\r
+ updateOldConfigurationToBaseRealization(graph, root);\r
+ addDefaultOntologyLinks(graph, root);\r
+ addURIsToDiagrams(graph, root);\r
+ }\r
}\r
});\r
} catch (DatabaseException e) {\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\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.Files;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\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.common.utils.NameUtils;\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
import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
public class ImportModuleHandler extends AbstractHandler {\r
\r
final Resource model = node.data;\r
\r
- Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
fd.setText("Import Module");\r
\r
} catch (RuntimeBindingConstructionException e) {\r
e.printStackTrace();\r
} catch (IOException e) {\r
- e.printStackTrace();\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
e.printStackTrace();\r
}\r
\r
+ final Resource root = ia.getRoot();\r
+ \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
\r