Executing code in the proper thread is a must for every Swing application, problem is that it's so easy to break the rules. Griffon is aware of this and tries its best to help you deal with the complexity of running code in and out of the EDT.
Since version 1.0.0 of the Swing plugin you can instruct the running application to warn you when an EDT violation occurs. Take the following code for example
griffon-app/models/sample/SampleModel.groovy
griffon-app/views/sample/SampleView.groovy
griffon-app/controllers/sample/SampleController.groovy
Running this application with the EDT violation checker enabled throws some interesting results when the button is clicked.The controller performs 3 tasks
- Check if the current thread is the EDT or not. By default all controller actions are executed outside the EDT so this check should succeed.
- Change the value model.text which should trigger a change in the UI. Groovy bindings are aware that the change will be propagated to an UI component, sending the value in the correct thread.
- Change the button's text directly. This change breaks the Swing rule which is why we get a logged exception.
Keep on Groovying!