]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added batch validation to import process. The imported model is validated after impor...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Oct 2012 11:48:51 +0000 (11:48 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Oct 2012 11:48:51 +0000 (11:48 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26025 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java

index 827705498ec55f6dfaf1c970514ed41a6962b47f..9057470fd1515290bfa708317bc1b616df639e9e 100644 (file)
@@ -15,24 +15,31 @@ import java.io.File;
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
 import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Set;\r
 \r
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.SubMonitor;\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.Simantics;\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.Issue;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.common.request.WriteRequest;\r
@@ -41,7 +48,10 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
 import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.db.request.Read;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.issues.common.AllBatchIssueSources;\r
+import org.simantics.issues.common.BatchIssueSource;\r
 import org.simantics.issues.ontology.IssueResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
@@ -171,9 +181,35 @@ public class ImportModelHandler extends AbstractHandler {
 \r
                                });\r
                                \r
+                               \r
+                               Collection<Resource> confs = SimanticsUI.getSession().syncRequest(new Read<Collection<Resource>>() {\r
+\r
+                    @Override\r
+                    public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                        return findAllConfigurations(graph, ModelRoot);\r
+                    }\r
+\r
+                               });\r
+\r
 \r
+                               // Batch validate all issue sources after import\r
                                try {\r
-                                   BatchValidations.runAll(null, ModelRoot);\r
+                                   for(Resource conf : confs) {\r
+                                       /*\r
+                                        * This section is copied from BatchValidations.runAll. runAll did\r
+                                        * not find module types to validate.\r
+                                        */\r
+//                                     BatchValidations.runAll(null, mod);\r
+\r
+                                       final Session session = Simantics.getSession();\r
+                                       final Collection<BatchIssueSource> validations = session.sync( new AllBatchIssueSources(ModelRoot) );\r
+                                       SubMonitor progress = SubMonitor.convert(null, "Validate Model", 100);\r
+                                       Collection<Resource> contexts = Collections.singletonList(conf);\r
+                                       for(BatchIssueSource bis : validations) {\r
+                                           Map<Resource, Set<Issue>> is = BatchValidations.validate(progress.newChild(90, SubMonitor.SUPPRESS_NONE), bis, contexts);\r
+                                           BatchValidations.store(progress.newChild(10, SubMonitor.SUPPRESS_NONE), bis.getResource(), is);\r
+                                       }\r
+                                   }\r
                                } catch(Throwable t) {\r
                                    t.printStackTrace();\r
                                } \r