]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Dynamic visualisations interval and disable support 25/3425/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 30 Oct 2019 08:28:23 +0000 (10:28 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Wed, 30 Oct 2019 08:39:22 +0000 (08:39 +0000)
gitlab #59

Change-Id: I094c96163bfbf435bed5bce21dc674a20277fe99
(cherry picked from commit b3108a7380f0492ddb40c839c223715d59bbfe9a)

org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewerListener.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java
org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisations.java
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java

index 811fd18b8f6acbc5bbd26304fcd4dbfdbfe774fb..00dc3d086d357456eed59f18aebcc46fc8ed519e 100644 (file)
@@ -217,6 +217,10 @@ DN.Diagram.splitToMultipleEnabled <R L0.HasProperty : SEL.GenericParameterType
 DN.VisualisationsFolder <T L0.Entity
 
 DN.Diagram.Visualisations <T L0.Entity
+    >-- DN.Diagram.Visualisations.Interval
+        @defProperty "Interval" L0.Long
+    >-- DN.Diagram.Visualisations.Disabled
+        @defProperty "Disabled" L0.Boolean
     >-- DN.Diagram.Visualisations.ShowColorBars
         @defProperty "Show Color Bars" L0.Boolean
     >-- DN.Diagram.Visualisations.ShowColorBarTicks
index eeaa39e563f5cf64e397673a4f824c25324bc74f..39b46b524e8774395aa9e2736f07bc81c606b605 100644 (file)
@@ -30,6 +30,8 @@ public class DistrictNetworkResource {
     public final Resource Diagram_Visualisations_ColorBarSize;
     public final Resource Diagram_Visualisations_ColorBarSize_Inverse;
     public final Resource Diagram_Visualisations_ColorContribution;
+    public final Resource Diagram_Visualisations_Disabled;
+    public final Resource Diagram_Visualisations_Disabled_Inverse;
     public final Resource Diagram_Visualisations_DynamicSymbolsProducers;
     public final Resource Diagram_Visualisations_DynamicSymbolsProducers_Inverse;
     public final Resource Diagram_Visualisations_DynamicSymbolsPumpingStations;
@@ -50,6 +52,8 @@ public class DistrictNetworkResource {
     public final Resource Diagram_Visualisations_HidePumpingStations_Inverse;
     public final Resource Diagram_Visualisations_HideValves;
     public final Resource Diagram_Visualisations_HideValves_Inverse;
+    public final Resource Diagram_Visualisations_Interval;
+    public final Resource Diagram_Visualisations_Interval_Inverse;
     public final Resource Diagram_Visualisations_ShowColorBarTicks;
     public final Resource Diagram_Visualisations_ShowColorBarTicks_Inverse;
     public final Resource Diagram_Visualisations_ShowColorBars;
@@ -465,6 +469,8 @@ public class DistrictNetworkResource {
         public static final String Diagram_Visualisations_ColorBarSize = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarSize";
         public static final String Diagram_Visualisations_ColorBarSize_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarSize/Inverse";
         public static final String Diagram_Visualisations_ColorContribution = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorContribution";
+        public static final String Diagram_Visualisations_Disabled = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/Disabled";
+        public static final String Diagram_Visualisations_Disabled_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/Disabled/Inverse";
         public static final String Diagram_Visualisations_DynamicSymbolsProducers = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/DynamicSymbolsProducers";
         public static final String Diagram_Visualisations_DynamicSymbolsProducers_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/DynamicSymbolsProducers/Inverse";
         public static final String Diagram_Visualisations_DynamicSymbolsPumpingStations = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/DynamicSymbolsPumpingStations";
@@ -485,6 +491,8 @@ public class DistrictNetworkResource {
         public static final String Diagram_Visualisations_HidePumpingStations_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/HidePumpingStations/Inverse";
         public static final String Diagram_Visualisations_HideValves = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/HideValves";
         public static final String Diagram_Visualisations_HideValves_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/HideValves/Inverse";
+        public static final String Diagram_Visualisations_Interval = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/Interval";
+        public static final String Diagram_Visualisations_Interval_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/Interval/Inverse";
         public static final String Diagram_Visualisations_ShowColorBarTicks = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBarTicks";
         public static final String Diagram_Visualisations_ShowColorBarTicks_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBarTicks/Inverse";
         public static final String Diagram_Visualisations_ShowColorBars = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBars";
@@ -910,6 +918,8 @@ public class DistrictNetworkResource {
         Diagram_Visualisations_ColorBarSize = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarSize);
         Diagram_Visualisations_ColorBarSize_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarSize_Inverse);
         Diagram_Visualisations_ColorContribution = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorContribution);
+        Diagram_Visualisations_Disabled = getResourceOrNull(graph, URIs.Diagram_Visualisations_Disabled);
+        Diagram_Visualisations_Disabled_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_Disabled_Inverse);
         Diagram_Visualisations_DynamicSymbolsProducers = getResourceOrNull(graph, URIs.Diagram_Visualisations_DynamicSymbolsProducers);
         Diagram_Visualisations_DynamicSymbolsProducers_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_DynamicSymbolsProducers_Inverse);
         Diagram_Visualisations_DynamicSymbolsPumpingStations = getResourceOrNull(graph, URIs.Diagram_Visualisations_DynamicSymbolsPumpingStations);
@@ -930,6 +940,8 @@ public class DistrictNetworkResource {
         Diagram_Visualisations_HidePumpingStations_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_HidePumpingStations_Inverse);
         Diagram_Visualisations_HideValves = getResourceOrNull(graph, URIs.Diagram_Visualisations_HideValves);
         Diagram_Visualisations_HideValves_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_HideValves_Inverse);
+        Diagram_Visualisations_Interval = getResourceOrNull(graph, URIs.Diagram_Visualisations_Interval);
+        Diagram_Visualisations_Interval_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_Interval_Inverse);
         Diagram_Visualisations_ShowColorBarTicks = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBarTicks);
         Diagram_Visualisations_ShowColorBarTicks_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBarTicks_Inverse);
         Diagram_Visualisations_ShowColorBars = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBars);
index d0b1a8a1ac9d6a1e5dd73848815d74c17d72c523..85c23f4de06a2c66f4e3a520f5871d7f2ee278f1 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.procedure.Listener;
 import org.simantics.diagram.ui.DiagramModelHints;
 import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.internal.Activator;
 import org.simantics.district.network.ui.nodes.DistrictRenderingPreparationNode;
 import org.simantics.district.network.ui.participants.DNPointerInteractor;
 import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant;
@@ -138,6 +139,25 @@ public class DistrictDiagramViewer extends DiagramViewer {
         setupColorBarOptions();
         setupSizingObjects();
         setupSizeBarOptions();
+        
+        // add listeners
+        DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners();
+        if (listeners != null) {
+            for (DistrictDiagramViewerListener listener : listeners) {
+                listener.diagramLoaded(getRuntime(), canvasContext);
+            }
+        }
+    }
+    
+    @Override
+    public void dispose() {
+        DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners();
+        if (listeners != null) {
+            for (DistrictDiagramViewerListener listener : listeners) {
+                listener.diagramDisposed(getRuntime(), canvasContext);
+            }
+        }
+        super.dispose();
     }
     
     private void setupDrawMapEnabled() {
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewerListener.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewerListener.java
new file mode 100644 (file)
index 0000000..f0e3669
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.district.network.ui;
+
+import org.simantics.db.Resource;
+import org.simantics.g2d.canvas.ICanvasContext;
+
+public interface DistrictDiagramViewerListener {
+
+    void diagramLoaded(Resource runtimeDiagram, ICanvasContext canvasContext);
+
+    void diagramDisposed(Resource runtimeDiagram, ICanvasContext canvasContext);
+}
index 72d7cf80a350fb5ae606c909745e598a2b029cab..e5e20af1b97f8b50a6e623211951164a560c29ec 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.DistrictDiagramViewerListener;
 import org.simantics.district.network.ui.DistrictNetworkUIUtil;
 import org.simantics.district.network.ui.breakdown.SubgraphProvider;
 import org.simantics.district.route.RouteService;
@@ -82,6 +83,7 @@ public class Activator extends AbstractUIPlugin {
 
     private ServiceTracker<SubgraphProvider, SubgraphProvider> subgraphProviderTracker;
     private ServiceTracker<RouteService, RouteService> routeServiceTracker;
+    private ServiceTracker<DistrictDiagramViewerListener, DistrictDiagramViewerListener> districtDiagramViewerListenerTracker;
 
        private HighlightSelectionEventHandler eventHandler;
 
@@ -94,6 +96,8 @@ public class Activator extends AbstractUIPlugin {
         subgraphProviderTracker.open();
         routeServiceTracker = new ServiceTracker<>(context, RouteService.class.getName(), null);
         routeServiceTracker.open();
+        districtDiagramViewerListenerTracker = new ServiceTracker<>(context, DistrictDiagramViewerListener.class.getName(), null);
+        districtDiagramViewerListenerTracker.open();
         
         initializeEventListener();
     }
@@ -122,6 +126,10 @@ public class Activator extends AbstractUIPlugin {
     public RouteService getRouteService() {
         return routeServiceTracker.getService();
     }
+    
+    public DistrictDiagramViewerListener[] getDistrictDiagramViewerListeners() {
+        return districtDiagramViewerListenerTracker.getServices(new DistrictDiagramViewerListener[0]);
+    }
 
        private void initializeEventListener() {
                @SuppressWarnings("restriction")
index 38b57a93f616ed0fac8bfdea659280e9594fd6b3..c4afb80e5090be6f69b85521fbfe808cb2ceedb3 100644 (file)
@@ -119,6 +119,8 @@ public class DynamicVisualisationsUI {
     private Button dynamicSymbolsValvesButton;
     private Button dynamicSymbolsPumpingStationsButton;
 
+    private Text intervalText;
+
     public DynamicVisualisationsUI(Composite parent) {
         this.parent = parent;
         ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
@@ -171,6 +173,11 @@ public class DynamicVisualisationsUI {
             }
         });
         
+        Composite intervalElementsComposite = new Composite(parent, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(intervalElementsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(intervalElementsComposite);
+        initializeIntervalElements(intervalElementsComposite);
+        
         Composite hideElementsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(hideElementsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(hideElementsComposite);
@@ -235,16 +242,28 @@ public class DynamicVisualisationsUI {
                 removeVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
             }
         });
+    }
+    
+    private void initializeIntervalElements(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Interval");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(4).margins(5, 5).applyTo(group);
         
-        disableUpdatesButton = new Button(buttonBarsComposite, SWT.CHECK);
+        createIntervalElements(group);
+    }
+    
+    private void createIntervalElements(Composite parent) {
+
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Generic");
+        intervalText = new Text(parent, SWT.BORDER);
+        addSelectionListener(intervalText);
+        
+        disableUpdatesButton = new Button(parent, SWT.CHECK);
         disableUpdatesButton.setText("Disable updates");
-        disableUpdatesButton.addSelectionListener(new SelectionAdapter() {
-            
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                disableUpdates();
-            }
-        });
+        addSelectionListener(disableUpdatesButton);
+
     }
     
     private void initializeHideElements(Composite parent) {
@@ -498,10 +517,6 @@ public class DynamicVisualisationsUI {
         };
     }
 
-    protected void disableUpdates() {
-        
-    }
-
     protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
         if (of.isPresent()) {
             Resource visualisation = of.get();
@@ -595,6 +610,16 @@ public class DynamicVisualisationsUI {
         boolean dynamicSymbolsValves = dynamicSymbolsValvesButton.getSelection();
         boolean dynamicSymbolsPumpingStations = dynamicSymbolsPumpingStationsButton.getSelection();
         
+        boolean disabled = disableUpdatesButton.getSelection();
+        Long interval;
+        try {
+            interval = Long.parseLong(intervalText.getText());
+        } catch (NumberFormatException e) {
+            // ignore
+            interval = 2000L;
+        }
+        long ii = interval;
+        
         Simantics.getSession().asyncRequest(new WriteRequest() {
             
             @Override
@@ -605,6 +630,7 @@ public class DynamicVisualisationsUI {
                 } else {
                     exist = DynamicVisualisations.createVisualisation(graph, parentResource, templateName);
                 }
+                DynamicVisualisations.setIntervalAndDisabled(graph, exist, ii, disabled);
                 DynamicVisualisations.setColorContributions(graph, exist, colorCollect);
                 DynamicVisualisations.setColorBarOptions(graph, exist, colorBarOptions);
                 DynamicVisualisations.setSizeContributions(graph, exist, sizeCollect);
@@ -1397,6 +1423,9 @@ public class DynamicVisualisationsUI {
                     }
                 }
                 
+                intervalText.setText(Long.toString(visualisation.getInterval()));
+                disableUpdatesButton.setSelection(visualisation.disabled());
+                
                 Map<String, DynamicColorContribution> colorContributions = visualisation.getColorContributions();
                 for (Entry<String, DynamicColorContribution> entry : colorContributions.entrySet()) {
                     
index 84bfb7393bbd96b681b2c1978f3c9da0dc4f0f14..565227d9f56c3a5254339de268cd0c64010913f2 100644 (file)
@@ -41,6 +41,9 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisu
             if (visualisationResource != null) {
                 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
                 
+                Long interval = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_Interval, Bindings.LONG);
+                Boolean disabled = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_Disabled, Bindings.BOOLEAN);
+                
                 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
                 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
                 
@@ -71,6 +74,8 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisu
                 Boolean dynamicSymbolsPumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsPumpingStations, Bindings.BOOLEAN);
                 
                 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource,
+                        interval != null ? interval : 2000,
+                        disabled != null ? disabled : false,
                         colorContributions,
                         defaultColoringObjects,
                         colorBarOptions,
index 2212c0481520ce7a2d9d2ba943b71883a54409aa..5ae265b8ceb35d0d044995547c4421a3f4adb909 100644 (file)
@@ -329,4 +329,10 @@ public class DynamicVisualisations {
         graph.claimLiteral(visualisation, DN.Diagram_Visualisations_DynamicSymbolsValves, valves, Bindings.BOOLEAN);
         graph.claimLiteral(visualisation, DN.Diagram_Visualisations_DynamicSymbolsPumpingStations, pumpingStations, Bindings.BOOLEAN);
     }
+
+    public static void setIntervalAndDisabled(WriteGraph graph, Resource visualisation, long interval, boolean disabled) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_Interval, interval, Bindings.LONG);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_Disabled, disabled, Bindings.BOOLEAN);
+    }
 }
index 3903b5540c359bf1c8c2bc08e284862c7a4e4e2d..6202e2de5acb1bcccf499adb2c52a712fad182b8 100644 (file)
@@ -11,6 +11,9 @@ public class DynamicVisualisation {
 
     private final String name;
     private final Resource visualisationResource;
+    
+    private final long interval;
+    private final boolean disabled;
 
     private final Map<String, DynamicColorContribution> colorContributions;
     private final Map<String, DynamicColoringObject> defaultColorContributions;
@@ -37,7 +40,7 @@ public class DynamicVisualisation {
     private final boolean dynamicSymbolsValves;
     private final boolean dynamicSymbolsPumpingStations;
     
-    public DynamicVisualisation(String name, Resource visualisationResource,
+    public DynamicVisualisation(String name, Resource visualisationResource, long interval, boolean disabled,
             Map<String, DynamicColorContribution> colorContributions,
             Map<String, DynamicColoringObject> defaultColoringObjects, ColorBarOptions colorBarOptions,
             Map<String, DynamicSizeContribution> sizeContributions,
@@ -60,6 +63,8 @@ public class DynamicVisualisation {
             ) {
         this.name = name;
         this.visualisationResource = visualisationResource;
+        this.interval = interval;
+        this.disabled = disabled;
         this.colorContributions = colorContributions;
         this.defaultColorContributions = defaultColoringObjects;
         this.colorBarOptions = colorBarOptions;
@@ -176,4 +181,12 @@ public class DynamicVisualisation {
     public boolean isDynamicSymbolsValves() {
         return dynamicSymbolsValves;
     }
+
+    public long getInterval() {
+        return interval;
+    }
+    
+    public boolean disabled() {
+        return disabled;
+    }
 }