Database Reference
In-Depth Information
We get the selected value from the available proxies table and add that as an item in a new Vector ,
itemVector . Then we test to see whether an identical itemVector (proxy) already exists in the users list. If
not, we add the new itemVector to the list.
There are a couple things to observe here. We get a reference to the current dataVector from the
userProxiesTM table model. We do not replace it with a new Vector at any point. Then at the end we set
the data Vector for userProxiesTM back to the dataVector we got.
Was that necessary? Couldn't we have just added the new itemVector to the existing dataVector
without getting a local reference? And couldn't we avoid calling userProxiesTM.setDataVector() with the
local reference?
The answer to the first question is no, it is not necessary. The answer to the second question is yes,
we could have referred to the existing dataVector in place in the table model without creating a local
reference, but that would have made for longer references and more code after all. The answer to the
third question is probably, but we are counting on a side effect of the setDataVector() method—it also
updates the GUI display with the new data. There are other ways to update the displayed table data, but
none is so concise.
Listing 12-39. Add Proxy to User's List
Vector dataVector = userProxiesTM.getDataVector ();
String value = (String) availableProxiesTM.getValueAt (
availableProxiesTable.getSelectedRow(), 0);
Vector itemVector = new Vector();
itemVector.add(value) ;
if (!dataVector.contains(itemVector)) {
dataVector.add(itemVector);
userProxiesTM.setDataVector(dataVector, columnIdentifiers) ;
}
Removing a Proxy from the User's List
When the Remove Selected button is pressed, the operation for removing an item from the user's proxies
table is relatively simple. The code is shown in Listing 12-40. Just call the remove() method on
dataVector . Once again, we call the table model setDataVector() method to assure the GUI display is
updated.
Listing 12-40. Remove Proxy from User's List
Vector dataVector = userProxiesTM.getDataVector() ;
String value = (String)userProxiesTM.getValueAt(
userProxiesTable.getSelectedRow(), 0);
Vector itemVector = new Vector();
itemVector.add(value);
dataVector.remove(itemVector) ;
userProxiesTM.setDataVector(dataVector, columnIdentifiers) ;
Saving Updates to the User's Proxies
When the Save Updates button is pressed, the saveButton_actionPerformed() method will be run. The
significant code for this method is shown in Listing 12-41. This comes from the delayed thread run()
method that is defined there.
 
Search WWH ::




Custom Search