From: lempinen Date: Mon, 26 Nov 2012 12:11:17 +0000 (+0000) Subject: Version migration support to sysdyn. Changes paths in .tg files to enable importing... X-Git-Tag: simantics-1.10.1~104 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b2b5ea5074786e5f0944e0fde466df33a9aede42;p=simantics%2Fsysdyn.git Version migration support to sysdyn. Changes paths in .tg files to enable importing to a newer database. (fixes #3037) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26446 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 94ba196f..2299b42f 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Migration.pgraph b/org.simantics.sysdyn.ontology/graph/Migration.pgraph new file mode 100644 index 00000000..a1d6d1ff --- /dev/null +++ b/org.simantics.sysdyn.ontology/graph/Migration.pgraph @@ -0,0 +1,100 @@ +L0 = +SYSDYN = + +move : L0.Template + @template %subject %base %from %to + %subject : L0.NamespaceMigrationStep.Prefix + L0.NamespaceMigrationStep.Prefix.base %base + L0.NamespaceMigrationStep.Prefix.from %from + L0.NamespaceMigrationStep.Prefix.to %to + +MIGRATION = SYSDYN."from1.6to1.7" : L0.MigrationSequence + @L0.list + MIGRATION.Ontologies + MIGRATION.Spreadsheets + MIGRATION.SysdynChanges + +MIGRATION.Ontologies : L0.NamespaceMigrationStep + @L0.list + _ + @move "http://www.simantics.org/Layer0-" "1.0" "1.1" + _ + @move "http://www.simantics.org/Layer0X-" "1.0" "1.1" + _ + @move"http://www.simantics.org/G2D-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Structural-" "1.0" "1.2" + _ + @move"http://www.simantics.org/Structural-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Diagram-" "2.1" "2.2" + _ + @move"http://www.simantics.org/Simulation-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Diagram-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Modeling-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Project-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Spreadsheet-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Viewpoint-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Image2-" "1.1" "1.2" + _ + @move"http://www.simantics.org/Color-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Action-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Silk-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Issue-" "1.1" "1.2" + _ + @move"http://www.simantics.org/User-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Documentation-" "1.0" "1.1" + _ + @move"http://www.simantics.org/Document-" "1.1" "1.2" + _ + @move"http://www.simantics.org/SelectionView-" "1.1" "1.2" + +MIGRATION.Spreadsheets : L0.NamespaceMigrationStep + @L0.list + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "HasContent" "Cell/content" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "FitRows" "Dimensions/fitRows" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "FitColumns" "Dimensions/fitColumns" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnCount" "Dimensions/columnCount" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnLabels" "Headers/columnLabels" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "RowCount" "Dimensions/rowCount" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnWidths" "Headers/columnWidths" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ContentOf" "Cell/content/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "FitRowsOf" "Dimensions/fitRows/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "FitColumnsOf" "Dimensions/fitColumns/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnCountOf" "Dimensions/columnCount/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnLabelsOf" "Headers/columnLabels/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "RowCountOf" "Dimensions/rowCount/Inverse" + _ + @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnWidthsOf" "Headers/columnWidths/Inverse" + +MIGRATION.SysdynChanges : L0.NamespaceMigrationStep + @L0.list + _ + @move "http://www.simantics.org/Sysdyn-1.1/" "HasTail" "Variable/HasTail" + _ + @move "http://www.simantics.org/Sysdyn-1.1/" "HasHead" "Variable/HasHead" + _ + @move "http://www.simantics.org/Sysdyn-1.1/" "SharedModuleOntolofgy" "SharedModuleOntology" diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 4c743105..9790d620 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -208,9 +208,6 @@ SYSDYN.SysdynModuleLibrary -- SYSDYN.Dependency.angle --> L0.Double -- SYSDYN.Dependency.refersTo --> SYSDYN.Variable > handlers = new HashMap>(); - handlers.put("sysdynModel:1", new FormatHandler() { - @Override - public Binding getBinding() { - return TransferableGraph1.BINDING; - } - - @Override - public Object process(DataContainer container) throws DataFormatException { - DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); - try { - DefaultPasteHandler.defaultExecute((TransferableGraph1)container.content.getValue(), project, ia); - return ia.getRoot(); - - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - }); - - 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, "Model could not be imported."); - } else { - try { - final Resource ModelRoot = (Resource) result; - SimanticsUI.getSession().syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - if(!graph.isInstanceOf(ModelRoot, SysdynResource.getInstance(graph).SysdynModel)) { - // Imported model was not a SysdynModel, display error message. - Resource instanceOf = graph.getPossibleObject(ModelRoot, Layer0.getInstance(graph).InstanceOf); - String type = "..."; - if(instanceOf != null) - type = NameUtils.getSafeName(graph, instanceOf); - else { - Resource inheritedFrom = graph.getPossibleObject(ModelRoot, Layer0.getInstance(graph).Inherits); - if(inheritedFrom != null) - type = NameUtils.getSafeName(graph, inheritedFrom); - } - final String ft = type; - graph.deny(ModelRoot, Layer0.getInstance(graph).PartOf); - - shell.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - displayErrorMessage(shell, "The imported file is not of type: System Dynamics Model (" + ft +")"); - } - }); - - } else { - fixHasTailAndHasHead(graph, ModelRoot); - addDependencies(graph, ModelRoot); - removeIssueSourcesFromModules(graph, ModelRoot); - addEnumerationIssueSource(graph, ModelRoot); - - activateModel(graph, ModelRoot); - } - } - - }); - - - Collection confs = SimanticsUI.getSession().syncRequest(new Read>() { + public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // Get imported transferable graph file using FileDialog + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + 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); + final String selected = fd.open(); + if(selected == null) return null; + + Job job = new DatabaseJob("Import model") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + IStatus status = importFile(selected, shell, monitor); + return status; + } + }; + job.setUser(true); + job.schedule(); + + return null; + + } + + private IStatus importFile(String path, final Shell shell, final IProgressMonitor monitor) { + final Resource project = SimanticsUI.getProject().get(); + if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null); + + monitor.beginTask("Import model", 7); + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent()); + + + + HashMap> handlers = new HashMap>(); + handlers.put("sysdynModel:1", new FormatHandler() { + @Override + public Binding getBinding() { + return TransferableGraph1.BINDING; + } + + @Override + public Object process(DataContainer container) throws DataFormatException { + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); + + try { + monitor.subTask("Migrate"); + Session session = Simantics.getSession(); + TransferableGraph1 tg = (TransferableGraph1)container.content.getValue(); + + MigrationStep step = MigrationUtils.getStep(session, SysdynResource.URIs.from1$6to1$7); + MigrationState state = MigrationUtils.newState(); + state.setProperty(MigrationStateKeys.CURRENT_TG, tg); + step.applyTo(session, state); + tg = state.getProperty(MigrationStateKeys.CURRENT_TG); + + monitor.worked(1); + monitor.subTask("Import"); + DefaultPasteHandler.defaultExecute(tg, project, ia); + monitor.worked(1); + return ia.getRoot(); + + } catch (DatabaseException e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed", e); + } catch (Exception e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed", e); + } + } + }); + + Object result = null; + try { + File file = new File(path); + if(!file.isFile()) { +// displayErrorMessage(shell, "File " + path + " not found"); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: File " + path + " not found", null); + } else { + result = DataContainers.readFile(file, handlers); + } + } catch(DataFormatException e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e); + } catch(IOException e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e); + } catch(Exception e) { + if(e instanceof RuntimeException) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e); +// throw (RuntimeException)e; + } else { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e); +// throw new RuntimeException(e); + } + } + + if(result == null || !(result instanceof Resource)) { +// displayErrorMessage(shell, "Model could not be imported."); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", null); + } else { + try { + final Resource ModelRoot = (Resource) result; + IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { + + @Override + public IStatus perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInstanceOf(ModelRoot, SysdynResource.getInstance(graph).SysdynModel)) { + // Imported model was not a SysdynModel, display error message. + Resource instanceOf = graph.getPossibleObject(ModelRoot, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(ModelRoot, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(ModelRoot, Layer0.getInstance(graph).PartOf); + +// shell.getDisplay().asyncExec(new Runnable() { +// +// @Override +// public void run() { +// displayErrorMessage(shell, "The imported file is not of type: System Dynamics Model (" + ft +")"); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The imported file is not of type: System Dynamics Model (" + ft +")", null); +// } +// }); + + } else { + monitor.subTask("Add required dependencies"); + addDependencies(graph, ModelRoot); + monitor.worked(1); + monitor.subTask("Remove unnecessary issue sources"); + removeIssueSourcesFromModules(graph, ModelRoot); + monitor.worked(1); + monitor.subTask("Add enumeration issue source"); + addEnumerationIssueSource(graph, ModelRoot); + monitor.worked(1); + monitor.subTask("Activate model"); + activateModel(graph, ModelRoot); + monitor.worked(1); + } + return null; + + } + + }); + + if(status != null) + return status; + + monitor.subTask("Validate model"); + Collection confs = SimanticsUI.getSession().syncRequest(new Read>() { @Override public Collection perform(ReadGraph graph) throws DatabaseException { return findAllConfigurations(graph, ModelRoot); } - }); - - - // Batch validate all issue sources after import - try { - for(Resource conf : confs) { - /* - * This section is copied from BatchValidations.runAll. runAll did - * not find module types to validate. - */ -// BatchValidations.runAll(null, mod); - - final Session session = Simantics.getSession(); - final Collection validations = session.sync( new AllBatchIssueSources(ModelRoot) ); - SubMonitor progress = SubMonitor.convert(null, "Validate Model", 100); - Collection contexts = Collections.singletonList(conf); - for(BatchIssueSource bis : validations) { - Map> is = BatchValidations.validate(progress.newChild(90, SubMonitor.SUPPRESS_NONE), bis, contexts); - BatchValidations.store(progress.newChild(10, SubMonitor.SUPPRESS_NONE), bis.getResource(), is); - } - } - } catch(Throwable t) { - t.printStackTrace(); - } - - - - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - return null; - - } - - protected void removeIssueSourcesFromModules(WriteGraph graph, Resource modelRoot) throws DatabaseException { + }); + + + // Batch validate all issue sources after import + try { + for(Resource conf : confs) { + /* + * This section is copied from BatchValidations.runAll. runAll did + * not find module types to validate. + */ +// BatchValidations.runAll(null, mod); + + final Session session = Simantics.getSession(); + final Collection validations = session.sync( new AllBatchIssueSources(ModelRoot) ); + SubMonitor progress = SubMonitor.convert(monitor, "Validate Model", 100); + Collection contexts = Collections.singletonList(conf); + for(BatchIssueSource bis : validations) { + Map> is = BatchValidations.validate(progress.newChild(90, SubMonitor.SUPPRESS_NONE), bis, contexts); + BatchValidations.store(progress.newChild(10, SubMonitor.SUPPRESS_NONE), bis.getResource(), is); + } + } + } catch(Throwable t) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", t); + } + + monitor.worked(1); + + } catch (DatabaseException e) { + e.printStackTrace(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e); + } + + return Status.OK_STATUS; + } + } + + protected void removeIssueSourcesFromModules(WriteGraph graph, Resource modelRoot) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); IssueResource ISSUE = IssueResource.getInstance(graph); - + for(Resource m : findAllModelsAndModules(graph, modelRoot)) { if(m.equals(modelRoot)) continue; - + // Module may contain issue sources due to legacy reasons. Remove these. for(Resource issueSource : graph.syncRequest(new ObjectsWithType(m, L0.ConsistsOf, ISSUE.IssueSource))) { // Issues are created to virtual graphs, so they should not need to be removed. Just in case they are created, remove them first for(Resource issue : graph.getObjects(issueSource, ISSUE.IssueSource_Manages)) { RemoverUtil.remove(graph, issue); } - + // finally remove the issue source RemoverUtil.remove(graph, issueSource); } } - + } protected void activateModel(WriteGraph graph, Resource modelRoot) throws DatabaseException { @@ -259,31 +320,37 @@ public class ImportModelHandler extends AbstractHandler { } protected void addDependencies(WriteGraph graph, Resource modelRoot) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - - ArrayList links = new ArrayList(); - for(Resource link : graph.getObjects(modelRoot, L0.IsLinkedTo)) - links.add(graph.getURI(link)); - - - if(!links.contains("http://www.simantics.org/Documentation-1.0")) { - Resource documentation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.0"); - if(documentation != null) - graph.claim(modelRoot, L0.IsLinkedTo, documentation); - } - - if(!links.contains("http://www.simantics.org/SelectionView-1.1")) { - Resource selectionView = graph.getPossibleResource("http://www.simantics.org/SelectionView-1.1"); - if(selectionView != null) - graph.claim(modelRoot, L0.IsLinkedTo, selectionView); - } - } - - protected void addEnumerationIssueSource(WriteGraph graph, Resource modelRoot) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - Collection enumerationIssueSources = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, sr.Validations_Enumerations_EnumerationIssueSource)); + Layer0 L0 = Layer0.getInstance(graph); + + ArrayList links = new ArrayList(); + for(Resource link : graph.getObjects(modelRoot, L0.IsLinkedTo)) + links.add(graph.getURI(link)); + + + if(!links.contains("http://www.simantics.org/Documentation-1.1")) { + Resource documentation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1"); + if(documentation != null) + graph.claim(modelRoot, L0.IsLinkedTo, documentation); + } + + if(!links.contains("http://www.simantics.org/SelectionView-1.2")) { + Resource selectionView = graph.getPossibleResource("http://www.simantics.org/SelectionView-1.2"); + if(selectionView != null) + graph.claim(modelRoot, L0.IsLinkedTo, selectionView); + } + + if(!links.contains("http://www.simantics.org/DocumentWorkbench-1.0")) { + Resource documentWb = graph.getPossibleResource("http://www.simantics.org/DocumentWorkbench-1.0"); + if(documentWb != null) + graph.claim(modelRoot, L0.IsLinkedTo, documentWb); + } + } + + protected void addEnumerationIssueSource(WriteGraph graph, Resource modelRoot) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Collection enumerationIssueSources = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, sr.Validations_Enumerations_EnumerationIssueSource)); if(enumerationIssueSources.isEmpty()) { GraphUtils.create2(graph, sr.Validations_Enumerations_EnumerationIssueSource, @@ -292,64 +359,42 @@ public class ImportModelHandler extends AbstractHandler { ); } } - protected void fixHasTailAndHasHead(WriteGraph graph, Resource modelRoot) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - for(Resource configuration : findAllConfigurations(graph, modelRoot)) { - Collection connections = graph.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, sr.Dependency)); - connections.addAll(graph.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, sr.Flow))); - - for(Resource connection : connections) { - Resource head = graph.getPossibleObject(connection, sr.HasHead); - Resource tail = graph.getPossibleObject(connection, sr.HasTail); - - if(head != null && tail != null) { - graph.deny(connection, sr.HasHead, head); - graph.deny(connection, sr.HasTail, tail); - - graph.claim(connection, sr.Variable_HasHead, head); - graph.claim(connection, sr.Variable_HasTail, tail); - } - } - } - } - - private Collection findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - StructuralResource2 SR2 = StructuralResource2.getInstance(graph); - Collection modulesAndModels = findAllModelsAndModules(graph, modelRoot); - Collection configurations = new ArrayList(); - - for(Resource r : modulesAndModels) { - if(graph.isInheritedFrom(r, sr.Module)) { - configurations.add(graph.getPossibleObject(r, SR2.IsDefinedBy)); - } else if(graph.isInstanceOf(r, sr.SysdynModel)) { - configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration)); - } - } - - return configurations; - } - - private Collection findAllModelsAndModules(ReadGraph graph, Resource modelRoot) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - Collection modelsAndModules = new ArrayList(); - modelsAndModules.add(modelRoot); - - for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) { - if(graph.isInheritedFrom(r, sr.Module)) { - modelsAndModules.add(r); - } - } - - return modelsAndModules; - } - - 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(); - } + private Collection findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 SR2 = StructuralResource2.getInstance(graph); + Collection modulesAndModels = findAllModelsAndModules(graph, modelRoot); + Collection configurations = new ArrayList(); + + for(Resource r : modulesAndModels) { + if(graph.isInheritedFrom(r, sr.Module)) { + configurations.add(graph.getPossibleObject(r, SR2.IsDefinedBy)); + } else if(graph.isInstanceOf(r, sr.SysdynModel)) { + configurations.add(graph.getPossibleObject(modelRoot, SimulationResource.getInstance(graph).HasConfiguration)); + } + } + + return configurations; + } + + private Collection findAllModelsAndModules(ReadGraph graph, Resource modelRoot) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Collection modelsAndModules = new ArrayList(); + modelsAndModules.add(modelRoot); + + for(Resource r : graph.getObjects(modelRoot, L0.ConsistsOf)) { + if(graph.isInheritedFrom(r, sr.Module)) { + modelsAndModules.add(r); + } + } + + return modelsAndModules; + } + +// 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/newComponents/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java index 393d5ae8..d60a1854 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java @@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.simantics.DatabaseJob; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; @@ -37,7 +38,7 @@ public class NewModelHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { - Job job = new Job("Creating System Dynamics Model") { + Job job = new DatabaseJob("Creating System Dynamics Model") { @Override protected IStatus run(IProgressMonitor monitor) { try { @@ -54,7 +55,7 @@ public class NewModelHandler extends AbstractHandler { } } }; - job.setUser(true); +// job.setUser(true); job.schedule(); return null;