]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Enable routing problem UI feedback for users 85/2585/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 27 Dec 2018 08:38:39 +0000 (10:38 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 27 Dec 2018 08:38:39 +0000 (10:38 +0200)
gitlab #25

Change-Id: I80f6bdb349ca44997d63882ef433813cf45c8504

org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java
org.simantics.district.route/src/org/simantics/district/route/RouteJob.java
org.simantics.district.route/src/org/simantics/district/route/internal/Activator.java

index 36d14fc6427167b3c102469e4623f9a77e7af294..572c65bf0ecc15871431ca3e470e2ef23b4ecbb8 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.district.route.ui.handlers;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
 
@@ -47,11 +48,15 @@ public class SelectRouteOnDiagram {
 
         Display display = activeShell.getDisplay();
         CompletableFuture<List<Resource>> result = new CompletableFuture<>();
-        result.thenAccept(dnElements -> {
-            try {
-                openDiagram(display, dnElements);
-            } catch (DatabaseException e) {
-                LOGGER.error("Failed to open district network diagram with selection {}", dnElements);
+        result
+        .exceptionally(e -> Collections.emptyList())
+        .thenAccept(dnElements -> {
+            if (!dnElements.isEmpty()) {
+                try {
+                    openDiagram(display, dnElements);
+                } catch (DatabaseException e) {
+                    LOGGER.error("Failed to open district network diagram with selection {}", dnElements); //$NON-NLS-1$
+                }
             }
         });
 
index 897366ada886f17308fee48caeda0c8e3a043fee..b58f384422162016d071ad9915542537e91f3938 100644 (file)
@@ -8,6 +8,7 @@ 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.district.route.internal.Activator;
@@ -48,12 +49,15 @@ public class RouteJob extends Job {
                     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));
     }
 
 }
index e628862bd512ae6c0fa3088e791952b44ddbe41e..e1ada18832fd47d24313717b938f8e3c851ec350 100644 (file)
@@ -19,6 +19,9 @@ import org.simantics.district.route.Router;
  */
 public class Activator implements BundleActivator, ServiceListener {
 
+    // The plug-in ID
+    public static final String PLUGIN_ID = "org.simantics.district.route"; //$NON-NLS-1$
+
     private static BundleContext context;
     private static Activator instance;