From: lempinen Date: Thu, 6 Jun 2013 05:34:04 +0000 (+0000) Subject: Moved some import and result handling from sysdyn.ui to sysdyn (fixes #4314) X-Git-Tag: 1.8.1~304 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=679d8f869106d29e9c9405ebbe8e6d13172d06ce;p=simantics%2Fsysdyn.git Moved some import and result handling from sysdyn.ui to sysdyn (fixes #4314) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27506 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 66e2ea9e..91680a01 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/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 9fa3788b..809a1425 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -392,6 +392,8 @@ SYSDYN.Result -- SYSDYN.Result.resultFile --> L0.String -- SYSDYN.Result.showResult --> SYSDYN.Result -- SYSDYN.Result.time --> L0.Long >{ + + private Resource resource; + + public ActiveResults(Resource resource) { + this.resource = resource; + } + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource SR = SysdynResource.getInstance(graph); + ModelingResources MR = ModelingResources.getInstance(graph); + + Collection result = new ArrayList(); + + Collection experiments; + if(graph.isInstanceOf(resource, MR.StructuralModel)) + experiments = graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, SR.Experiment)); + else { + experiments = new ArrayList(); + experiments.add(resource); + } + + for(Resource experiment : experiments) { + Collection experimentResults = graph.getObjects(experiment, SR.Experiment_result); + for(Resource r : experimentResults) { + if(graph.hasStatement(r, SR.Result_showResult)) { + result.add(r); + } + } + } + + return result; + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SaveResultJob.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SaveResultJob.java index 797bdc68..7b0ea6ba 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SaveResultJob.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SaveResultJob.java @@ -94,7 +94,8 @@ public class SaveResultJob extends Job { l0.HasLabel, name, l0.HasName, name, l0.PartOf, model, - sr.Result_resultFile, file.getAbsolutePath()); + sr.Result_resultFile, file.getAbsolutePath(), + sr.Result_time, System.currentTimeMillis()); graph.claim(experiment.getResource(), sr.Experiment_result, res); } }); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index e4c55433..4d091dc6 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -26,7 +26,6 @@ import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; -import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; @@ -195,27 +194,24 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti Resource model = graph.getPossibleObject(getConfigurationResource(), SIMU.IsConfigurationOf); if(model == null) return null; - Collection experiments = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.Experiment)); - for(Resource experiment : experiments) { - Collection experimentResults = graph.getObjects(experiment, sr.Experiment_result); - for(Resource result : experimentResults) { - if(graph.hasStatement(result, sr.Result_showResult)) { - SysdynResult sysdynResult = null; - if(graph.isInstanceOf(result, sr.HistoryDataset)) { - HistoryDatasetResult r = new HistoryDatasetResult(); - listeningHistories.add(r); - sysdynResult = new MemoryResult(r, NameUtils.getSafeLabel(graph, result)); - r.read((MemoryResult)sysdynResult, result); - } else { - sysdynResult = new FileResult( - (String) graph.getPossibleRelatedValue(result, l0.HasLabel), - (String) graph.getPossibleRelatedValue(result, sr.Result_resultFile)); - } - - if(sysdynResult != null) - displayedResults.add(sysdynResult); - + + Collection results = graph.syncRequest(new ActiveResults(model)); + for(Resource result : results) { + if(graph.hasStatement(result, sr.Result_showResult)) { + SysdynResult sysdynResult = null; + if(graph.isInstanceOf(result, sr.HistoryDataset)) { + HistoryDatasetResult r = new HistoryDatasetResult(); + listeningHistories.add(r); + sysdynResult = new MemoryResult(r, NameUtils.getSafeLabel(graph, result)); + r.read((MemoryResult)sysdynResult, result); + } else { + sysdynResult = new FileResult( + (String) graph.getPossibleRelatedValue(result, l0.HasLabel), + (String) graph.getPossibleRelatedValue(result, sr.Result_resultFile)); } + + if(sysdynResult != null) + displayedResults.add(sysdynResult); } } } catch (Exception e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java similarity index 90% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java index d7fae469..48ee948c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java @@ -10,7 +10,7 @@ * VTT Technical Research Centre of Finland - initial API and implementation * Semantum Oy - Bug #4192 *******************************************************************************/ -package org.simantics.sysdyn.ui.utils.imports; +package org.simantics.sysdyn.utils.imports; import java.io.File; import java.io.IOException; @@ -26,7 +26,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.swt.widgets.Shell; import org.simantics.Simantics; import org.simantics.databoard.container.DataContainers; import org.simantics.databoard.container.DataFormatException; @@ -61,8 +60,7 @@ import org.simantics.operation.Layer0X; 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.ui.SimanticsUI; +import org.simantics.sysdyn.Activator; /** * Utilities for importing tg files: Models, Modules and Function libraries @@ -71,10 +69,6 @@ import org.simantics.ui.SimanticsUI; */ public class ImportUtils { - public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH"; - public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; - public static String IMPORTFUNCTIONLIBRARYPATH = "IMPORT_FUNCTION_LIBRARY_PATH"; - /** * Null-checked begin task for monitor * @param monitor @@ -139,21 +133,19 @@ public class ImportUtils { /* ********************************* */ /* ******* IMPORT MODEL ********* */ /* ********************************* */ - public static IStatus importModelFile(String path, final Shell shell, final IProgressMonitor monitor) { - final Resource project = SimanticsUI.getProject().get(); + public static IStatus importModelFile(String path, final IProgressMonitor monitor) { + final Resource project = Simantics.getProject().get(); if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null); beginTask(monitor, "Import model", 9); - Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent()); - MigrationState state = MigrationUtils.newState(); state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE); Resource result = null; try { - result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(project), project); + result = MigrationUtils.importMigrated(monitor, Simantics.getSession(), new File(path), state, new DefaultPasteImportAdvisor(project), project); } catch (Exception e1) { e1.printStackTrace(); } @@ -163,7 +155,7 @@ public class ImportUtils { } else { try { final Resource ModelRoot = result; - IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { + IStatus status = Simantics.getSession().syncRequest(new WriteResultRequest() { @Override public IStatus perform(WriteGraph graph) throws DatabaseException { @@ -213,7 +205,7 @@ public class ImportUtils { return status; subTask(monitor, "Validate model"); - Collection confs = SimanticsUI.getSession().syncRequest(new Read>() { + Collection confs = Simantics.getSession().syncRequest(new Read>() { @Override public Collection perform(ReadGraph graph) throws DatabaseException { @@ -399,19 +391,16 @@ public class ImportUtils { /* ********************************* */ /* ******* IMPORT MODULE ********* */ /* ********************************* */ - public static IStatus importModuleFile(final Resource model, String path, final Shell shell, final IProgressMonitor monitor) { + public static IStatus importModuleFile(final Resource model, String path, final IProgressMonitor monitor) { beginTask(monitor, "Import Module", 3); - - Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(path)).getParent()); - MigrationState state = MigrationUtils.newState(); state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE); Resource result = null; try { - result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(model), model); + result = MigrationUtils.importMigrated(monitor, Simantics.getSession(), new File(path), state, new DefaultPasteImportAdvisor(model), model); } catch (Exception e1) { e1.printStackTrace(); } @@ -424,7 +413,7 @@ public class ImportUtils { // Check that the imported file actually was a module. Display error message otherwise. try { subTask(monitor, "Validate model"); - IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { + IStatus status = Simantics.getSession().syncRequest(new WriteResultRequest() { @Override public IStatus perform(WriteGraph graph) throws DatabaseException { @@ -465,11 +454,9 @@ public class ImportUtils { /* *** IMPORT FUNCTION LIBRARY *** */ /* ********************************* */ - public static IStatus importFunctionLibrary(final Resource functionLibrary, final String path, final Shell shell, final IProgressMonitor monitor) { + public static IStatus importFunctionLibrary(final Resource functionLibrary, final String path, final IProgressMonitor monitor) { beginTask(monitor, "Import Module", 3); - Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(path)).getParent()); - // Ensure that shared functions ontology exists ensureSharedOntologies(); @@ -479,7 +466,7 @@ public class ImportUtils { Resource result = null; try { - result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(functionLibrary), functionLibrary); + result = MigrationUtils.importMigrated(monitor, Simantics.getSession(), new File(path), state, new DefaultPasteImportAdvisor(functionLibrary), functionLibrary); } catch (Exception e1) { e1.printStackTrace(); } @@ -491,7 +478,7 @@ public class ImportUtils { // Link the imported library to the selected resource (functionLibrary) try { subTask(monitor, "Validate model"); - IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { + IStatus status = Simantics.getSession().syncRequest(new WriteResultRequest() { /** * Link the imported library to the selected resource (functionLibrary) @@ -556,7 +543,7 @@ public class ImportUtils { // Make sure the "http://SharedOntologies resource exists try { Boolean hasSharedOntologies; - hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { + hasSharedOntologies = Simantics.getSession().syncRequest(new Read() { @Override public Boolean perform(ReadGraph graph) throws DatabaseException { @@ -570,7 +557,7 @@ public class ImportUtils { }); if(!hasSharedOntologies) { - SimanticsUI.getSession().syncRequest(new WriteRequest() { + Simantics.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynFunctionLibraryImportAdvisor.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFunctionLibraryImportAdvisor.java similarity index 95% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynFunctionLibraryImportAdvisor.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFunctionLibraryImportAdvisor.java index b23385af..3373d68f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynFunctionLibraryImportAdvisor.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFunctionLibraryImportAdvisor.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.utils.imports; +package org.simantics.sysdyn.utils.imports; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynImportFormatHandler.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynImportFormatHandler.java similarity index 95% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynImportFormatHandler.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynImportFormatHandler.java index a7ae4129..260c058b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/SysdynImportFormatHandler.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynImportFormatHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.utils.imports; +package org.simantics.sysdyn.utils.imports; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -27,7 +27,7 @@ import org.simantics.db.layer0.migration.MigrationStateKeys; import org.simantics.db.layer0.migration.MigrationStep; import org.simantics.db.layer0.migration.MigrationUtils; import org.simantics.graph.representation.TransferableGraph1; -import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.Activator; /** * Handler for migrating a tg and importing it to database