From: jsimomaa Date: Wed, 30 Oct 2019 08:28:23 +0000 (+0200) Subject: Dynamic visualisations interval and disable support X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F3424%2F1;p=simantics%2Fdistrict.git Dynamic visualisations interval and disable support gitlab #59 Change-Id: I094c96163bfbf435bed5bce21dc674a20277fe99 --- diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index 811fd18b..00dc3d08 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -217,6 +217,10 @@ DN.Diagram.splitToMultipleEnabled -- 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 diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index eeaa39e5..39b46b52 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -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); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index d0b1a8a1..85c23f4d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -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 index 00000000..f0e3669c --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewerListener.java @@ -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); +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java index 72d7cf80..e5e20af1 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java @@ -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 subgraphProviderTracker; private ServiceTracker routeServiceTracker; + private ServiceTracker 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") diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index 38b57a93..c4afb80e 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -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 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 colorContributions = visualisation.getColorContributions(); for (Entry entry : colorContributions.entrySet()) { diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java index 84bfb739..565227d9 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java @@ -41,6 +41,9 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph); Map defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc)); @@ -71,6 +74,8 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead colorContributions; private final Map 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 colorContributions, Map defaultColoringObjects, ColorBarOptions colorBarOptions, Map 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; + } }