From 63bc9deadd3754affc9543a465eb8d05300f008d Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 7 Nov 2019 20:35:59 +0200 Subject: [PATCH] Prevent IndexRoot requests from crashing when network diagram is removed Use PossibleIndexRoot instead. gitlab #65 Change-Id: I344249dc125d057c17718ad2fdfb98ef267c702b (cherry picked from commit 320681ec7f81eccbdaf8b168ee001d0a43df31f1) --- .../network/ui/DistrictDiagramViewer.java | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) 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 25956b31..0e0a2f52 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 @@ -12,7 +12,7 @@ import java.util.function.Supplier; import org.simantics.datatypes.literal.RGB; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.IndexRoot; +import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; @@ -154,8 +154,9 @@ public class DistrictDiagramViewer extends DiagramViewer { public void dispose() { DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners(); if (listeners != null) { + Resource runtime = getRuntime(); for (DistrictDiagramViewerListener listener : listeners) { - listener.diagramDisposed(getRuntime(), canvasContext); + listener.diagramDisposed(runtime, canvasContext); } } super.dispose(); @@ -346,15 +347,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public ColorBarOptions perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.colorBarOptions(graph, activeVisualisation); + Resource model = graph.syncRequest(new PossibleIndexRoot(parameter)); + if (model != null) { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DynamicVisualisations.colorBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return ColorBarOptions.useDefault(); } @@ -369,15 +372,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public Map perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.colorContributions(graph, activeVisualisation); + Resource model = graph.syncRequest(new PossibleIndexRoot(parameter)); + if (model != null) { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DynamicVisualisations.colorContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } @@ -450,15 +455,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public SizeBarOptions perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.sizeBarOptions(graph, activeVisualisation); + Resource model = graph.syncRequest(new PossibleIndexRoot(parameter)); + if (model != null) { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DynamicVisualisations.sizeBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return SizeBarOptions.useDefault(); } @@ -501,15 +508,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public Map perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.sizeContributions(graph, activeVisualisation); + Resource model = graph.syncRequest(new PossibleIndexRoot(parameter)); + if (model != null) { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DynamicVisualisations.sizeContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } -- 2.47.1