From 65c53bff95339c4b45e084b7094084be41b060e2 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 27 Dec 2018 10:38:39 +0200 Subject: [PATCH] Enable routing problem UI feedback for users gitlab #25 Change-Id: I80f6bdb349ca44997d63882ef433813cf45c8504 --- .../route/ui/handlers/SelectRouteOnDiagram.java | 15 ++++++++++----- .../org/simantics/district/route/RouteJob.java | 8 ++++++-- .../district/route/internal/Activator.java | 3 +++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java index 36d14fc6..572c65bf 100644 --- a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java +++ b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java @@ -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> 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$ + } } }); diff --git a/org.simantics.district.route/src/org/simantics/district/route/RouteJob.java b/org.simantics.district.route/src/org/simantics/district/route/RouteJob.java index 897366ad..b58f3844 100644 --- a/org.simantics.district.route/src/org/simantics/district/route/RouteJob.java +++ b/org.simantics.district.route/src/org/simantics/district/route/RouteJob.java @@ -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)); } } diff --git a/org.simantics.district.route/src/org/simantics/district/route/internal/Activator.java b/org.simantics.district.route/src/org/simantics/district/route/internal/Activator.java index e628862b..e1ada188 100644 --- a/org.simantics.district.route/src/org/simantics/district/route/internal/Activator.java +++ b/org.simantics.district.route/src/org/simantics/district/route/internal/Activator.java @@ -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; -- 2.47.1