]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Added a browser context for route-related actions.
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 26 Jul 2019 12:26:11 +0000 (15:26 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:10:12 +0000 (23:10 +0300)
gitlab #58

Change-Id: I32760b2dd7feb15827cb234ed315a53dfcbc3a7e

org.simantics.district.route.ontology/META-INF/MANIFEST.MF
org.simantics.district.route.ontology/graph/DistrictNetworkRoutesViewpoint.pgraph [new file with mode: 0644]
org.simantics.district.route.ontology/src/org/simantics/district/route/ontology/RouteResource.java
org.simantics.district.route.ui/adapters.xml [new file with mode: 0644]
org.simantics.district.route.ui/build.properties
org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/SelectRouteAction.java [new file with mode: 0644]

index ee4c1e64ad52d578c67a8d0db8fad0d06b26c35f..61ec5737d9fcaaab4bfef73a5e563e1139f7f869 100644 (file)
@@ -6,7 +6,10 @@ Bundle-Version: 1.0.0.qualifier
 Bundle-Vendor: Semantum Oy
 Require-Bundle: org.simantics.layer0,
  org.simantics.district.network.ontology;bundle-version="1.0.0",
- org.simantics.diagram.ontology;bundle-version="2.2.0"
+ org.simantics.diagram.ontology;bundle-version="2.2.0",
+ org.simantics.action.ontology;bundle-version="1.1.0",
+ org.simantics.silk.ontology;bundle-version="1.1.0",
+ org.simantics.viewpoint.ontology;bundle-version="1.2.0"
 Automatic-Module-Name: fi.vtt.apros.district.route.ontology
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.district.route.ontology
diff --git a/org.simantics.district.route.ontology/graph/DistrictNetworkRoutesViewpoint.pgraph b/org.simantics.district.route.ontology/graph/DistrictNetworkRoutesViewpoint.pgraph
new file mode 100644 (file)
index 0000000..f01d26b
--- /dev/null
@@ -0,0 +1,13 @@
+L0 = <http://www.simantics.org/Layer0-1.1>
+DN = <http://www.simantics.org/DistrictNetwork-1.0>
+DNR = <http://www.simantics.org/DistrictNetworkRoutes-1.0>
+VP = <http://www.simantics.org/Viewpoint-1.2>
+ACT = <http://www.simantics.org/Action-1.1>
+SILK = <http://www.simantics.org/Silk-1.1>
+
+RAC = DNR.RouteActionContext : VP.BrowseContext
+    @VP.actionContribution "Select Route" DNR.Route SILK.wand VP.EditActionCategory DNR.Actions.SelectRoute
+
+DNR.Actions : L0.Library
+
+DNR.Actions.SelectRoute : ACT.Action
index def312552f17b6e1a1cf0b95d6005762d2a549af..c77dbf0f86034748bfac3d17a3d1f3a999131ac7 100644 (file)
@@ -10,11 +10,17 @@ import org.simantics.db.service.QueryControl;
 
 public class RouteResource {
     
+    public final Resource Actions;
+    public final Resource Actions_SelectRoute;
     public final Resource Route;
+    public final Resource RouteActionContext;
     public final Resource RouteFolder;
         
     public static class URIs {
+        public static final String Actions = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions";
+        public static final String Actions_SelectRoute = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/SelectRoute";
         public static final String Route = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Route";
+        public static final String RouteActionContext = "http://www.simantics.org/DistrictNetworkRoutes-1.0/RouteActionContext";
         public static final String RouteFolder = "http://www.simantics.org/DistrictNetworkRoutes-1.0/RouteFolder";
     }
     
@@ -28,7 +34,10 @@ public class RouteResource {
     }
     
     public RouteResource(ReadGraph graph) {
+        Actions = getResourceOrNull(graph, URIs.Actions);
+        Actions_SelectRoute = getResourceOrNull(graph, URIs.Actions_SelectRoute);
         Route = getResourceOrNull(graph, URIs.Route);
+        RouteActionContext = getResourceOrNull(graph, URIs.RouteActionContext);
         RouteFolder = getResourceOrNull(graph, URIs.RouteFolder);
     }
     
diff --git a/org.simantics.district.route.ui/adapters.xml b/org.simantics.district.route.ui/adapters.xml
new file mode 100644 (file)
index 0000000..66c37e3
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<adapters>
+       <target interface="org.simantics.db.layer0.adapter.ActionFactory">
+               <resource uri="http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/SelectRoute"
+                       class="org.simantics.district.route.ui.actions.SelectRouteAction" />
+       </target>
+</adapters>
index e29652c54b9e2e94d1a281d88f22c2e3b8c8cb7a..34579a4ca2b55910a5e4649f92c1bed09e158d06 100644 (file)
@@ -3,5 +3,6 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.xml,\
+               adapters.xml,\
                fragment.e4xmi,\
                OSGI-INF/
diff --git a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/SelectRouteAction.java b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/SelectRouteAction.java
new file mode 100644 (file)
index 0000000..11de4cc
--- /dev/null
@@ -0,0 +1,67 @@
+package org.simantics.district.route.ui.actions;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.swt.widgets.Display;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+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.district.route.internal.RoutePersistence;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SelectRouteAction implements ActionFactory {
+
+    protected static final Logger LOGGER = LoggerFactory.getLogger(SelectRouteAction.class);
+
+    @Override
+    public Runnable create(Object target) {
+        if (!(target instanceof Resource))
+            return null;
+
+        return new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    Route route = Simantics.getSession().syncRequest(new RoutePersistence.RouteRequest((Resource)target));
+                    if (route == null) {
+                        LOGGER.error("Reading a route object failed"); //$NON-NLS-1$
+                        return;
+                    }
+                    
+                    CompletableFuture<List<Resource>> result = new CompletableFuture<>();
+                    result
+                    .exceptionally(e -> Collections.emptyList())
+                    .thenAccept(dnElements -> {
+                        if (!dnElements.isEmpty()) {
+                            try {
+                                Display display = Display.getDefault();
+                                if (display != null)
+                                    DistrictNetworkUIUtil.openDNDiagramWithSelection(display, dnElements);
+                                else
+                                    LOGGER.error("No display found"); //$NON-NLS-1$
+                            } catch (DatabaseException e) {
+                                LOGGER.error("Failed to open district network diagram with selection " + dnElements, e); //$NON-NLS-1$
+                                
+                            }
+                        }
+                    });
+                    
+                    RouterConfiguration config = new RouterConfiguration();
+                    new RouteJob(config, route, result).schedule();
+                }
+                catch (DatabaseException e) {
+                    LOGGER.error("Error in selecting route " + target, e); //$NON-NLS-1$
+                }
+            }
+        };
+    }
+
+}