From e69bbe40d840e8f390dd4819817a10db77d49012 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Sun, 28 Apr 2019 10:56:11 +0200 Subject: [PATCH] GUIMultiModelHandler: Inhibit creation of WaitParseThread during GUI startup Previously, during the constructor of GUIMultiModelHandler, a WaitParseThread was created. If the startup of the other plugins takes longer than the configured delay (default = 1s, but can be much shorter via settings), the attempted parse can generate events that reach other plugins/components that are not yet fully initialised, leading to NullPointerExceptions, etc. Now, we inhibit the creation of the WaitParseThread until the startup has completed. Fixes #111. --- .../userinterface/model/GUIMultiModel.java | 7 +++++++ .../model/GUIMultiModelHandler.java | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/prism/src/userinterface/model/GUIMultiModel.java b/prism/src/userinterface/model/GUIMultiModel.java index 89da859e..4c0712e5 100644 --- a/prism/src/userinterface/model/GUIMultiModel.java +++ b/prism/src/userinterface/model/GUIMultiModel.java @@ -120,6 +120,13 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener } } + @Override + public void onInitComponentsCompleted() + { + // forward to multi-model handler + handler.onInitComponentsCompleted(); + } + public GUIMultiModelHandler getHandler() { return handler; diff --git a/prism/src/userinterface/model/GUIMultiModelHandler.java b/prism/src/userinterface/model/GUIMultiModelHandler.java index 68b218b7..661209f3 100644 --- a/prism/src/userinterface/model/GUIMultiModelHandler.java +++ b/prism/src/userinterface/model/GUIMultiModelHandler.java @@ -113,6 +113,9 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener private Style pepaEditorCommentFast = Style.defaultStyle(); + // flag to indicate whether onInitComponentsCompleted() has already been called + private boolean startupCompleted = false; + // Modification Parse updater private WaitParseThread waiter; private boolean parsing = false; @@ -142,8 +145,6 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener prism = theModel.getPrism(); prism.addModelListener(this); - int parseDelay = theModel.getPrism().getSettings().getInteger(PrismSettings.MODEL_PARSE_DELAY); - waiter = new WaitParseThread(parseDelay, this); editor = new GUITextModelEditor("", this); tree = new GUIMultiModelTree(this); splitter = new JSplitPane(); @@ -227,6 +228,14 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener private synchronized void restartWaitParseThread() { + // If the GUIPrism startup has not been completed, as + // indicated by the call to onInitComponentsCompleted(), + // ignore requests to start the WaitParseThread. This prevents + // it from triggering events that are handled by parts of the + // GUI that have not been completely initialised. + if (!startupCompleted) + return; + if (waiter != null) { waiter.interrupt(); } @@ -236,6 +245,14 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener //Funky thread waiting stuff } + public void onInitComponentsCompleted() + { + startupCompleted = true; + + // initially, start WaitParseThread + restartWaitParseThread(); + } + // New model... public void newPRISMModel()