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;
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;
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) {
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();