From f97150acbd65924d45b7ab545d3398a8b070e2b5 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Wed, 20 Nov 2019 13:50:45 +0200 Subject: [PATCH] Fixed DynamicVisualisationContributionsParticipant to cancel hover task Previously a possible hover info update task was never cancelled properly if the participant was removed from the context due to e.g. disposal of the diagram editor. gitlab #67 Change-Id: I0d98673190ddbf836d40713f9c0b9c8608076552 --- ...VisualisationContributionsParticipant.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java index 0e0bace9..7dd11b7a 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java @@ -75,6 +75,11 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas @Override public void removedFromContext(ICanvasContext ctx) { + // Ensure hover polling is stopped + if (hoverUpdateSchedule != null && !hoverUpdateSchedule.isDone()) { + hoverUpdateSchedule.cancel(false); + } + getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS, hintListener); getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener); getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener); @@ -145,6 +150,7 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas } private ScheduledFuture hoverUpdateSchedule; + private static final Object COMPLETE = new Object(); public void hoverNode(Resource runtimeDiagram, Resource mapElement, G2DParentNode hoveredNode) { IThreadWorkQueue thread = getThread(); @@ -168,8 +174,13 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas public void run(ReadGraph graph) throws DatabaseException { boolean keyVariablesVertexHover = visualisation.isKeyVariablesVertexHover(); boolean keyVariablesEdgesHover = visualisation.isKeyVariablesEdgesHover(); - - Resource mapElementInstanceOf = graph.getSingleObject(mapElement, Layer0.getInstance(graph).InstanceOf); + + Resource mapElementInstanceOf = graph.getPossibleObject(mapElement, Layer0.getInstance(graph).InstanceOf); + if (mapElementInstanceOf == null) { + future.complete(COMPLETE); + return; + } + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); boolean doHover = true; @@ -195,10 +206,10 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas } else { hoverInfoNode.hover2(null); } - future.complete(new Object()); + future.complete(COMPLETE); }); } else { - future.complete(new Object()); + future.complete(COMPLETE); } } }); -- 2.47.1