From: jsimomaa Date: Wed, 2 Oct 2019 07:06:16 +0000 (+0300) Subject: Fix deadlock in DistrictDiagramViewer event queuing X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F3308%2F1;p=simantics%2Fdistrict.git Fix deadlock in DistrictDiagramViewer event queuing gitlab #59 APROS-15657 Change-Id: I4fa598154603ed43c2a1a74d96513fbe0bf74f44 (cherry picked from commit 2d2564b511ad13107e5a9cb3466bf19e66a9d645) --- 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 7ee2f2fa..d932e083 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 @@ -183,41 +183,32 @@ public class DistrictDiagramViewer extends DiagramViewer { private void queueColoringObjectsChangeEvent(Map 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 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 { public DrawMapEnabledRequest(Resource diagram) {