]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Refactoring of diagram element selection method to utils. 49/2649/3
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 13 Feb 2019 08:36:02 +0000 (10:36 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 13 Feb 2019 13:47:49 +0000 (13:47 +0000)
Change-Id: I568c2b93661eb7dab33c0e1e2966abac1183abde

org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkUIUtil.java
org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/SelectRouteOnDiagram.java

index 9ce6937a50b5fbea4866cb222e3ab22da442e17e..b9ac68f8b1bd9e10c96e39b98cd77413f466515a 100644 (file)
@@ -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<Resource> 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;
+    }
+
 }
index 572c65bf0ecc15871431ca3e470e2ef23b4ecbb8..962c560a85cf28c064c1d1f68a6d570b548ffa20 100644 (file)
@@ -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<Resource> 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
+}