From 88d09381e6c4e8007e8cb3c560a7c21a3af18370 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 13 Feb 2019 10:36:02 +0200 Subject: [PATCH] Refactoring of diagram element selection method to utils. Change-Id: I568c2b93661eb7dab33c0e1e2966abac1183abde --- .../network/ui/DistrictNetworkUIUtil.java | 18 ++++++++++++++++ .../ui/handlers/SelectRouteOnDiagram.java | 21 ++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkUIUtil.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkUIUtil.java index 9ce6937a..b9ac68f8 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkUIUtil.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkUIUtil.java @@ -2,10 +2,13 @@ package org.simantics.district.network.ui; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.function.Consumer; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; +import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.UnaryRead; @@ -24,6 +27,7 @@ import org.simantics.scl.runtime.tuple.Tuple4; import org.simantics.ui.selection.WorkbenchSelectionUtils; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; /** * @author Tuukka Lehtonen @@ -165,4 +169,18 @@ public class DistrictNetworkUIUtil { openEditorWithSelection(DistrictDiagramEditor.ID, input, selection); } + public static boolean openDNDiagramWithSelection(Display display, List dnElements) throws DatabaseException { + if (dnElements.isEmpty()) + return false; + + Input in = Simantics.getSession().syncRequest( + new ElementToInput(dnElements.get(0))); + if (in == null) + return false; + + SWTUtils.asyncExec(display, + () -> openDNDiagramEditorWithSelection(in, dnElements.toArray())); + return true; + } + } 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 572c65bf..962c560a 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 @@ -13,7 +13,6 @@ 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.Simantics; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.district.network.ui.DistrictNetworkUIUtil; @@ -21,7 +20,6 @@ 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; @@ -53,7 +51,7 @@ public class SelectRouteOnDiagram { .thenAccept(dnElements -> { if (!dnElements.isEmpty()) { try { - openDiagram(display, dnElements); + DistrictNetworkUIUtil.openDNDiagramWithSelection(display, dnElements); } catch (DatabaseException e) { LOGGER.error("Failed to open district network diagram with selection {}", dnElements); //$NON-NLS-1$ } @@ -63,19 +61,4 @@ public class SelectRouteOnDiagram { 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 +} -- 2.47.1