]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Fixed DynamicVisualisationContributionsParticipant to cancel hover task 77/3577/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 Nov 2019 11:50:45 +0000 (13:50 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 Nov 2019 12:08:07 +0000 (12:08 +0000)
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
(cherry picked from commit f97150acbd65924d45b7ab545d3398a8b070e2b5)

org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java

index 0e0bace92245003ed5b7fec4f22745a4c9a5ede5..7dd11b7ab83225bcd5e943b42099fffa24df1d1f 100644 (file)
@@ -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);
                                 }
                             }
                         });