X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fparticipants%2FRoutingMode.java;h=4f023c880a2968d2a3d306fff7ed685551956c47;hb=6f963a4a4ee67c7b346472e675ad71e6a0a85ba9;hp=d274a617931b11d1641149bbc722ae4826f45699;hpb=00103b12908c5071e641ca2bea2c42030ff67770;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java index d274a617..4f023c88 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java @@ -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();