]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.route/src/org/simantics/district/route/RouteJob.java
Enable routing problem UI feedback for users
[simantics/district.git] / org.simantics.district.route / src / org / simantics / district / route / RouteJob.java
index 84414937d7344aa1f22c89f705b8d3ca4949672a..b58f384422162016d071ad9915542537e91f3938 100644 (file)
@@ -8,9 +8,9 @@ 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.osgi.util.NLS;
 import org.simantics.ObjectIdentitySchedulingRule;
 import org.simantics.db.Resource;
-import org.simantics.db.layer0.variable.Variable;
 import org.simantics.district.route.internal.Activator;
 import org.simantics.district.route.internal.RoutePersistence;
 import org.slf4j.Logger;
@@ -26,9 +26,9 @@ public class RouteJob extends Job {
 
     private RouterConfiguration config;
     private List<Resource> waypoints;
-    private CompletableFuture<List<Variable>> callback;
+    private CompletableFuture<List<Resource>> callback;
 
-    public RouteJob(RouterConfiguration config, Route route, CompletableFuture<List<Variable>> callback) {
+    public RouteJob(RouterConfiguration config, Route route, CompletableFuture<List<Resource>> callback) {
         super("Compute route");
         Objects.requireNonNull(callback, "Callback must be non-null");
         setUser(true);
@@ -43,18 +43,21 @@ public class RouteJob extends Job {
         List<Router> routers = Activator.getInstance().getRouteService().routers();
         for (Router router : routers) {
             try {
-                List<Variable> path = router.findShortestPath(config, waypoints);
+                List<Resource> path = router.findShortestPath(config, waypoints);
                 if (!path.isEmpty()) {
                     callback.complete(path);
                     return Status.OK_STATUS;
                 }
             } catch (RoutingException e) {
-                LOGGER.error("Routing failed for waypoints {} and router {}", waypoints, router, e);
+                LOGGER.error("Routing failed for waypoints {} and router '{}'", waypoints, router, e);
                 callback.completeExceptionally(e);
+                // This results in UI feedback of the error.
+                // Perhaps later we get rid of this and let the UI code handle the notifications.
+                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
             }
         }
         LOGGER.info("No router could calculate route between waypoints {}. Available routers: {}", waypoints, routers);
-        return Status.OK_STATUS;
+        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind("No router could calculate route between waypoints {0}. Available routers: {1}", waypoints, routers));
     }
 
 }