Browse Source

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.
accumulation-v4.7
Joachim Klein 7 years ago
committed by Dave Parker
parent
commit
e69bbe40d8
  1. 7
      prism/src/userinterface/model/GUIMultiModel.java
  2. 21
      prism/src/userinterface/model/GUIMultiModelHandler.java

7
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;

21
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()

Loading…
Cancel
Save