Client-Side Presentation Logic
605
// System.out.println("the region is " + tpDeal.getRegion());
if (currentRegionFilter == tpDeal.getRegion()) {
if (tpDeal.getCommission() >= minCommission) {
tripList.add(tpDeal.getDescription());
}
}
}
}
}
updateListData() is the method that actually makes the call to the server. It passes the result of the
call, containing all of the new trips available, in a disconnected XML dataset, into an instance of
DealsParser. This instance will parse the dataset and create a vector of TravelDeal instances.
We then add this new vector of TravelDeal instances to the curDeals vector thus expanding the
list of available deals:
private void updateListData() {
String dealsXML = locateDealsXML(curTripNumber);
DealsParser myParser = new DealsParser();
if (curTripNumber == 0) {
curDeals = myParser.parse(dealsXML);
} else { // curTripNumber != 0
Vector tpVec = myParser.parse(dealsXML);
for (int i = 0; i < tpVec.size(); i++) {
curDeals.addElement(tpVec.elementAt(i));
}
}
curTripNumber = myParser.getMaxTripNumber();
}
itemStateChanged() is called every time one of the radio buttons is selected or deselected. On a
selection, we change the value currentRegionFilter and we then refresh the filtered list:
public void itemStateChanged(ItemEvent evt) {
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
if (evt.getSource() == mexicoClick) {
currentRegionFilter = TravelDeal.MEXICO;
} else {
if (evt.getSource() == hawaiiClick) {
currentRegionFilter = TravelDeal.HAWAII;
} else {
if (evt.getSource() == caribClick) {
currentRegionFilter = TravelDeal.CARIBBEAN;
} else {
currentRegionFilter = 0;
}
}
}