I have a large existing application written in SWT I have to modify.
The GUI consists in shell opening non Dialog child shells.
Now I have to update information on parent shell when child shell is closed.
I imagined two options:
- Convert all child to extend Dialog class. Problem is it requires large refactoring.
- Pass a reference of the parent logic class so that before closing child I can call a method of the parent. I don’t like this design.
It would be nice if in parent code I could listen the child shell events and take action depending of what happen on child shell. This is kind of Observable pattern. I read in “SWT: a developper notebook”:
No event loop is required for the ChildShell. Why? Because the event loop for the parent shell handles the dispatching of events for all objects opened within the parent. The child remains open until it is closed by the user or until the parent is closed.
I’m not experimented in SWT and examples are scarce. So what is the SWT way to do this? Can I use the parent loop for such purpose?
Thanks.
I will suggest you to use
ShellListeneron the child shell. Then you can override theshellClosedmethod.Example
Note
You can also use
DisposeListenerbut in this scenario you can not usetext.setText(childText.getText());(see the example above). To handle this, save the text in a String variable and then use the string variable to populate the parents text box.