Removing an existing zookeeper
When you built the form for ZooKeeperPanel you included a Remove button. Before writing the code so that it removes the selected zookeeper (after asking for confirmation) you will change the status of the button so that it is only enabled (i.e., available to be clicked) when a zookeeper is actually selected in the list.
Open ZooKeeperPanel in Design mode and click the Remove button to select it. In the Properties window locate the enabled property (you may need to scroll to find it):
You will see that the check box for this attribute is checked, indicating that the button is enabled by default, so un-check this check box now. You will notice that the button becomes greyed out to indicate that it cannot be clicked.
Switch into Source mode and modify the valueChanged() method to enable the button whenever a zookeeper is selected, or disable it again when nothing is selected:
Now switch back to Design mode and double-click the Remove button to generate its removeButtonActionPerformed() method. This method needs to ask the user to confirm that they really do want to remove the zoo keeper and if so invoke the ZooAdministrator removeZooKeeper() method:
After the zookeeper is removed the editor is placed back into "add" mode by calling clearZooKeeper(). You should also now ensure nothing is selected in the list of zookeepers, so modify the zooKeeperRemovedEvent() of ZooKeeperList as follows:
- The
removeSelectionInterval()method de-selects all items in a list between the range of indexes specified in the arguments; - Also note that
removeSelectionInterval()automatically triggers aListSelectionEventso you will find the Remove button becomes disabled.