Progress monitoring to users Pgraph compilation 81/1181/7
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 26 Oct 2017 09:15:24 +0000 (12:15 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 3 Nov 2017 12:51:40 +0000 (14:51 +0200)
refs #7576

Change-Id: I98004732bb8d3e1171dbd846bd2c476e00fd9f72

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java
bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java

index 783244a6176a1c4c3be4ee9fc0e6459c375c35b0..eda0228f9049d08ab1fba7e8ea0e5983d603de48 100644 (file)
@@ -2,6 +2,10 @@ package org.simantics.modeling.ui.actions;
 
 import java.io.IOException;
 
+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.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
@@ -16,6 +20,7 @@ import org.simantics.db.layer0.adapter.ActionFactory;
 import org.simantics.graph.compiler.CompilationResult;
 import org.simantics.ltk.Problem;
 import org.simantics.modeling.CompilePGraphs;
+import org.simantics.modeling.ui.Activator;
 import org.simantics.utils.ui.ExceptionUtils;
 
 /**
@@ -28,11 +33,21 @@ public class CompilePGraphsAction implements ActionFactory {
         if (!(target instanceof Resource))
             return null;
         return () -> {
-            try {
-                CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent());
-            } catch (IOException | DatabaseException e) {
-                ExceptionUtils.logAndShowError(e);
-            }
+            Job job = new Job("Compile PGraphs") {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    try {
+                        CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent(), monitor);
+                        return Status.OK_STATUS;
+                    } catch (IOException | DatabaseException e) {
+                        ExceptionUtils.logAndShowError(e);
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
+                    } finally {
+                        monitor.done();
+                    }
+                }
+            };
+            job.schedule();
         };
     }
 
index 10e23c65bbd72340277652d8c9618ab4f7032147..7f7171dca54a8b82ece8f27441e7d58c7079eb29 100644 (file)
@@ -16,6 +16,8 @@ import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.osgi.framework.Bundle;
 import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
@@ -86,6 +88,10 @@ public class CompilePGraphs {
     }
 
     public static void compilePGraphs(Resource r, UserAgent userAgent) throws IOException, DatabaseException {
+        compilePGraphs(r, userAgent, new NullProgressMonitor());
+    }
+    
+    public static void compilePGraphs(Resource r, UserAgent userAgent, IProgressMonitor monitor) throws IOException, DatabaseException {
         final Collection<ISource> sources = new ArrayList<>();
         Collection<TransferableGraph1> dependencies = new ArrayList<>();
 
@@ -249,6 +255,9 @@ public class CompilePGraphs {
                 }
             });
         }
+        
+        // Delete index to get rid of floating old instances of the same ontology
+//        DatabaseIndexing.deleteAllIndexes();
     }
 
     private static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {