X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.route.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Froute%2Fui%2Fhandlers%2FSelectRouteOnDiagram.java;fp=org.simantics.district.route.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Froute%2Fui%2Fhandlers%2FSelectRouteOnDiagram.java;h=36d14fc6427167b3c102469e4623f9a77e7af294;hb=92904091e630d96b15286d3ddca833289f0ba926;hp=7568ea308d7b6e975cb3564ee28c6674092e5355;hpb=0e8411115bcfa632f880953c7e49c5389de28a31;p=simantics%2Fdistrict.git 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 7568ea30..36d14fc6 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 @@ -5,22 +5,37 @@ import java.util.concurrent.CompletableFuture; import javax.inject.Named; +import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.simantics.db.layer0.variable.Variable; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.district.network.ui.DistrictNetworkUIUtil; import org.simantics.district.route.Route; import org.simantics.district.route.RouteJob; import org.simantics.district.route.RouterConfiguration; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Tuukka Lehtonen */ public class SelectRouteOnDiagram { + private static final Logger LOGGER = LoggerFactory.getLogger(SelectRouteOnDiagram.class); + + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) { + return ISelectionUtils.filterSingleSelection(selection, Route.class) != null; + } + @Execute public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell, @Named(IServiceConstants.ACTIVE_PART) MPart part, @@ -30,9 +45,32 @@ public class SelectRouteOnDiagram { if (route == null) return; - CompletableFuture> result = new CompletableFuture<>(); + 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); + } + }); + RouterConfiguration config = new RouterConfiguration(); new RouteJob(config, route, result).schedule(); } + public static boolean openDiagram(Display display, List dnElements) throws DatabaseException { + if (dnElements.isEmpty()) + return false; + + DistrictNetworkUIUtil.Input in = Simantics.getSession().syncRequest( + new DistrictNetworkUIUtil.ElementToInput(dnElements.get(0))); + if (in == null) + return false; + + SWTUtils.asyncExec(display, + () -> DistrictNetworkUIUtil.openDNDiagramEditorWithSelection(in, dnElements.toArray())); + return true; + } + } \ No newline at end of file