]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Fix deadlock in DistrictDiagramViewer event queuing 07/3307/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 2 Oct 2019 07:06:16 +0000 (10:06 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 2 Oct 2019 07:06:16 +0000 (10:06 +0300)
gitlab #59
APROS-15657

Change-Id: I4fa598154603ed43c2a1a74d96513fbe0bf74f44

org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java

index 7ee2f2faa03a2c5b771e7d52de2d05db1a21f034..d932e0834a2cd2016c3092e5581850c24338af07 100644 (file)
@@ -183,41 +183,32 @@ public class DistrictDiagramViewer extends DiagramViewer {
 
     
     private void queueColoringObjectsChangeEvent(Map<String, DynamicColorContribution> result) {
-        if (result != null && !canvasContext.isDisposed()) {
-            canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLORING_OBJECTS, result);
-            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLORING_OBJECTS_CHANGE));
-        } else {
-            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
-        }
+        queueEventInternal(KEY_MAP_COLORING_OBJECTS, MAP_COLORING_OBJECTS_CHANGE, result);
     }
     
     private void queueColorBarOptionsChangeEvent(ColorBarOptions result) {
-        if (result != null && !canvasContext.isDisposed()) {
-            canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLOR_BAR_OPTIONS, result);
-            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLOR_BAR_OPTIONS_CHANGE));
-        } else {
-            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
-        }
+        queueEventInternal(KEY_MAP_COLOR_BAR_OPTIONS, MAP_COLOR_BAR_OPTIONS_CHANGE, result);
     }
 
     private void queueSizingObjectsChangeEvent(Map<String, DynamicSizeContribution> result) {
-        if (result != null && !canvasContext.isDisposed()) {
-            canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZING_OBJECTS, result);
-            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZING_OBJECTS_CHANGE));
-        } else {
-            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
-        }
+        queueEventInternal(KEY_MAP_SIZING_OBJECTS, MAP_SIZING_OBJECTS_CHANGE, result);
     }
     
     private void queueSizeBarOptionsChangeEvent(SizeBarOptions result) {
+        queueEventInternal(KEY_MAP_SIZE_BAR_OPTIONS, MAP_SIZE_BAR_OPTIONS_CHANGE, result);
+    }
+
+    private void queueEventInternal(Key key, Command command, Object result) {
         if (result != null && !canvasContext.isDisposed()) {
-            canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZE_BAR_OPTIONS, result);
-            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZE_BAR_OPTIONS_CHANGE));
+            canvasContext.getThreadAccess().asyncExec(() -> {
+                canvasContext.getDefaultHintContext().setHint(key, result);
+                canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), command));
+            });
         } else {
             LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
         }
     }
-    
+
     private static class DrawMapEnabledRequest extends UnaryRead<Resource, Boolean> {
 
         public DrawMapEnabledRequest(Resource diagram) {