Today, I’d like to show you how to create the last gui-component to finish the RCP application based on the NetBeans Platform. This gui-component will allow you to create new or edit existing album entries in your database. I called this component ‚AlbumEditDialog‘ which is a simple JPanel. Create this component by right clicking the package in which you have already created the AlbumTopComponent and select ‚New/JPanel Form…‘ or ‚New/Other…/Swing GUI Forms/JPanel From‘.
Click yourself through the opened Wizard. Name your component with a name of your choice and finish the Wizard. Then a new JPanel will open up and you will be able to design the component. The following screenshot shows my JPanel:
Again I won’t rewrite all the code in this post. But I will explain what this class does. You can download the final version of my MediaDB from my Windows Live SkyDrive Share and there you will find the implementation of that JPanel.
When you open this dialog the first thing it does is to receive all the existing genres from the database and insert them into the drop-down menu. Depending on which button you have pressed in your TopComponent (New… or Edit) you will either see or not see the corresponding album information which has been mapped to each JTextfield to which the information belongs.
The NetBeans Platform provides dialog components that I’ve used for our dialog:
- DialogDescriptor desc = new DialogDescriptor(d, "New…");
- DialogDescriptor desc = new DialogDescriptor(d, "Edit…");
This component provides a simple Ok-Cancel dialog so you don’t have to write any extra boiler plate code. Of course there are many more of those dialogs which can be found in the NetBeans Dialogs API. After you have finished implementing this final step you should have a project structure looking like the following screenshot:
Now press the Run button. The application should start up and the table should be filled at least with one row. You will find the INSERT-statement in the Installer class. Today I also wrote a simple JUnit test-class which you will find under ‚Unit Test Packages‘. It will insert up to 99 rows in your database and tests the typical create, read, update and delete functionality.
So, if you want to have more than one row in your table, please execute this test before you start up your application. After executing the test, starting up the application, closing the startup screen and resizing my TopComponent you should see something like this:
Also try out the New, Edit and Delete functionality of your application. I hope you liked this tutorial. Don’t be afraid of posting any questions. I’ll try to answer them as soon as possible.