]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java
Merge changes I78c3a258,I7bf72f04
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / handler / RunActiveValidations.java
index 0ab0ef98cb75b824978d0ca3743ecd2cad225f7e..f6121ce19ec6179d824a98ffed7a5493cf4a2a3e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2019 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - Reorganization
  *******************************************************************************/
 package org.simantics.issues.ui.handler;
 
@@ -57,12 +58,25 @@ public class RunActiveValidations extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        Runnable postValidation = null;
-        run(postValidation);
+        try {
+            run();
+        } catch (DatabaseException e) {
+            throw new ExecutionException("Error while running active validations", e);
+        }
         return null;
     }
 
-    public void run(Runnable postValidation) {
+    public static void run() throws DatabaseException {
+        Resource model = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+        if(model != null)
+            run(model);
+    }
+
+    public static void run(Resource model) {
+        run(model, null);
+    }
+
+    public static void run(Resource model, Runnable postValidation) {
 
         final Session session = Simantics.getSession();
 
@@ -77,8 +91,6 @@ public class RunActiveValidations extends AbstractHandler {
                     @Override
                     public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                         try {
-                            Resource model = session.sync(new PossibleActiveModel(Simantics.getProjectResource()));
-                            if(model == null) return;
 
                             toBatchIssueSources(session,
                                     session.syncRequest(new SelectedModelBatchIssueSources(model)),
@@ -151,7 +163,7 @@ public class RunActiveValidations extends AbstractHandler {
                                             Resource list = graph.getSingleObject(issue, ISSUE.Issue_HasContexts);
                                             List<Resource> l = ListUtils.toList(graph, list);
                                             if (l.size() > 0) {
-                                                Resource mainContext = l.get(0); 
+                                                Resource mainContext = l.get(0);
                                                 if (!BatchValidations.isLinkedToOtherThan(graph, mainContext, issue))
                                                     result.add(mainContext);
                                             }
@@ -174,7 +186,7 @@ public class RunActiveValidations extends AbstractHandler {
 
                             }
                         } catch (OperationCanceledException e) {
-                               throw e;
+                            throw e;
                         } catch (Exception e) {
                             throw new InvocationTargetException(e);
                         } finally {