Sunday, March 7, 2010

Swinging Task Dialog (part 2)

This week's focus was on adding more functionality.
The API was extended with an ability to set commands (buttons on the bottom of the dialog). TaskDialog features a set of standard commands ( currently only Ok and Cancel ). But it is very easy to add any arbitrary command. The only requirement is that the command has to implement TaskDialog.Command interface.
TaskDialog's getResult() method returns last executed command. A simpler way to use it is show() method which shows the dialog and returns last executed command. Here is a warning dialog:


Sometimes custom command has to not just close the dialog but execute some additional logic.  To accomplish this PropertyChangeListener can be attached to the TaskDialog's "result" property. As soon as result changes (command button is pressed ) your code will be notified.
It is possible now to add any fixed component to the dialog ( in addition to expandable one ). Here is the example of the  dialog with the progress bar.


More work is required in the area as I want to to provide prebuilt components such as command links. To even further simplify usage I added TaskDialogs class. It makes creation of certain task dialogs a one liner.

The above code produces three task dialogs:


The project is available at under BSD license.
As always - comments and suggestions are welcome.