]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java
Merge remote-tracking branch 'origin/release/1.37.0' into release/1.35.1
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / participants / RoutingMode.java
index d274a617931b11d1641149bbc722ae4826f45699..4f023c880a2968d2a3d306fff7ed685551956c47 100644 (file)
@@ -8,6 +8,7 @@ import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.dialogs.IInputValidator;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
 import org.simantics.db.Resource;
@@ -40,6 +41,7 @@ import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
 import org.simantics.utils.datastructures.hints.IHintContext.Key;
 import org.simantics.utils.datastructures.hints.IHintObservable;
 import org.simantics.utils.ui.AdaptionUtils;
+import org.simantics.utils.ui.SWTUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -158,8 +160,17 @@ public class RoutingMode extends AbstractMode {
                 return false;
             KeyPressedEvent kpe = (KeyPressedEvent) e;
             if (kpe.keyCode == java.awt.event.KeyEvent.VK_ENTER) {
-                routeService.persistRoute(route);
+                Route committedRoute = route;
                 route = null;
+                SWTUtils.asyncExec(Display.getDefault(), () -> {
+                    String newName = askRouteName("Confirm Route", committedRoute.getName());
+                    if (newName != null) {
+                        committedRoute.setName(newName);
+                        routeService.persistRoute(committedRoute);
+                    } else {
+                        routeService.discardRoute(committedRoute);
+                    }
+                });
                 dispose();
             }
         } else if (e instanceof CommandEvent) {
@@ -167,20 +178,32 @@ public class RoutingMode extends AbstractMode {
             if (cmd.equals(Commands.CANCEL)) {
                 return dispose();
             } else if (cmd.equals(Commands.RENAME)) {
-                InputDialog dialog = new InputDialog(
-                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
-                        "Rename Route",
-                        "Route name",
-                        route.getName(),
-                        s -> s.trim().length() > 0 ? null : "Name must be non-empty");
-                if (dialog.open() == Window.OK) {
-                    route.setName(dialog.getValue());
-                }
+                // TODO: still needs key binding contribution for the district diagram editor
+                SWTUtils.asyncExec(Display.getDefault(), () -> {
+                    String newName = askRouteName("Rename Route", route.getName());
+                    if (newName != null) {
+                        route.setName(newName);
+                        routeService.refreshRoute(route);
+                    }
+                });
             }
         }
         return false;
     }
 
+    private String askRouteName(String dialogTitle, String initialValue) {
+        InputDialog dialog = new InputDialog(
+                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                dialogTitle,
+                "Route name",
+                initialValue,
+                s -> s.trim().length() > 0 ? null : "Name must be non-empty");
+        if (dialog.open() == Window.OK) {
+            return dialog.getValue();
+        }
+        return null;
+    }
+
     protected boolean dispose() {
         setDirty();
         remove();