Java Reference
In-Depth Information
method would take the column and row indexes into account and evaluate whether or not a
cell was editable.
Listing 8-15. The TableModel's isCellEditable Method
public boolean isCellEditable (int row, int column) {
return false;
}
Note Unlike the other methods shown so far, isCellEditable is already implemented in
AbstractTableModel . As it happens, the AbstractTableModel implementation provides the same func-
tionality as our overridden method. We therefore did not need to override this method; however, doing so
makes it easier for you to experiment with this method.
Finally, our DVDTableModel class contains two methods beyond those required by the
TableModel interface. These extra methods are included as a matter of convenience. As men-
tioned earlier in this chapter, the DVD object, which is used by the rest of the system, is not the
same Model that is used by the View. In this case, the View object is a JTable and the Model
object is the DVDTableModel . The GUIController class must go through the process of convert-
ing a DVD object (or a collection of DVD objects) to a DVDTableModel object. To make this task
easier, the DVDTableModel implements the two methods in Listing 8-16.
Listing 8-16. Convenience Methods Within the DVDTableModel Class
public void addDVDRecord (String upc, String name, String director,
String leadActor, String supportingActor,
String composer, int numberOfCopies) {
String [] temp = {upc, name, director, leadActor, supportingActor,
composer, Integer.toString(numberOfCopies)};
this.dvdRecords.add(temp);
}
public void addDVDRecord (DVD dvd) {
addDVDRecord(dvd.getUPC(), dvd.getName(), dvd.getDirector(),
dvd.getLeadActor(), dvd.getSupportingActor(),
dvd.getComposer(), dvd.getCopy());
}
The methods in Listing 8-16 take in a DVD object (or the equivalent data) and append the
new row to the data set encapsulated within the DVDTableModel . The first method receives the
data contained in a DVD object as parts, whereas the second method simply requires a DVD
object. In order to add a DVD to the DVDTableModel , the GUIController will simply call one of
these two methods, thus avoiding a conversion process from within the GUIController each
time an alteration to the data view occurs.
Search WWH ::




Custom Search