Part 1 - Part 2 - Part 3 - Part 4 - Part 5
As stated above, we already prepared an SWT/JFace-based GUI for DVDStorage. Because it is based on SWT and JFace, we first need to add the relevant libraries to our lib path, as seen in the following dialog. Note that you need to select the swt.jar suitable for your system.
Also, you need to download the GUI package and the icon folder from this web site and unzip it into the root of your project. The resulting project structure should look like this:
Note the interface "DVDStorageGUIActionListener" inside the GUI package. This is the link between the GUI and our prevayler-based implementation; we will need to implement this interface in some class to be able to act on user selections in the GUI. "DVDStorageGUIActionListener" looks like this:
Let's create a "GUIControl" class inside the main package of DVDStorage which implements the DVDStorageGUIActionListener:
We want start the GUI from this control class, too, so we add a constructor which will be handed the current instance of Prevayler and start the GUI. We store the Prevayler instance in a field, because we will need it later (see below):
Now, we need to implement the methods of DVDStorageGUIActionListener. The first method, "newDVDAction", will be called whenever the user chooses to create new DVD. The method parameters correspond to the user's input. Implementing this method is quite straightfoward: We simple create a new DVDCreateTransaction and hand it over to Prevayler for processing:
Implementing the next two methods is just as simple:
Finally, we want to provide a snapshot functionality for the snapshot button; also, the GUI needs a complete list of the DVDs to be able to display them. Note that it is no problem to read data from inside a BO, only the changes must be part of transaction classes. We first add a getDVDList() method to our DVDStorage class:
Now, we can use this method inside the GUIControl class:
We're done! Lets call our GUIControl class from inside the main method of our application:
It's time to fire up the system. Be sure to include the SWT native code base of your system in the Java library path when starting the application (or simply copy it into the project root directory):
And voilá: Our result:
Feel free to play around with your new toy :)
You may download the entire source from CVS or here.
Some pointers on how to implement more difficult applications and a review of Preclipse's other functionality will be provided in the 5th and final part.