public void saveUnit() { try { DefaultTableModel dtm = (DefaultTableModel) tblUnitList.getModel(); unitLists.clear(); unitNames.clear(); if (dtm.getRowCount() == 0) { this.dispose(); return; } for (int i = 0; i < dtm.getRowCount(); i++) { // if (((Number) dtm.getValueAt(i, 4)).intValue() == 0 || (userTask == // GlobalMode.RENEW)) { // RentalUnitBean rub = new RentalUnitBean(); // rub.setRentalDetailID((int) dtm.getValueAt(i, 4)); // UnitBean ub = new UnitBean(); // ub.setUnitID((int) dtm.getValueAt(i, 2)); // rub.setUnitBean(ub); // unitLists.add(rub); // } if (((Number) dtm.getValueAt(i, 4)).intValue() == 0) { RentalUnitBean rub = new RentalUnitBean(); rub.setRentalDetailID((int) dtm.getValueAt(i, 4)); UnitBean ub = new UnitBean(); ub.setUnitID((int) dtm.getValueAt(i, 2)); rub.setUnitBean(ub); unitLists.add(rub); } floor = dtm.getValueAt(i, 3).toString(); unitNames.add(dtm.getValueAt(i, 0).toString()); } KeyValue kv = (KeyValue) cboBuilding.getSelectedItem(); buildingID = (int) kv.getKey(); buildingCode = kv.getRow().toString(); bb.setBuildingID(buildingID); bb.setBuildingCode(buildingCode); bb.setBuildingName(cboBuilding.getSelectedItem().toString()); bb.setContractDraft(kv.getOtherRow().toString()); bb.setActualContract(kv.getOtherRow2().toString()); RentalEntry re = (RentalEntry) this.getParent(); re.setUnits(bb, unitNames, unitLists, floor, totalLeaseArea); this.dispose(); } catch (Exception e) { Message.showError(e.getMessage()); } }
public final void initialize() { try { model = (DefaultTableModel) tblUnitList.getModel(); loadBuildingCombo(); if (rentalID > 0) { rDB.getRentalUnit(rentalID, unitLists); for (int i = 0; i < cboBuilding.getItemCount(); i++) { KeyValue kv = (KeyValue) cboBuilding.getItemAt(i); if ((int) kv.getKey() == buildingID) { cboBuilding.setSelectedIndex(i); buildingCode = kv.getRow().toString(); break; } } for (RentalUnitBean arr : unitLists) { model.addRow( new Object[] { arr.getUnitBean().getUnitName(), arr.getUnitBean().getUnitArea(), arr.getUnitBean().getUnitID(), arr.getUnitBean().getFloor(), arr.getRentalDetailID() }); totalLeaseArea += arr.getUnitBean().getUnitArea(); } cboBuilding.setEnabled(false); } } catch (Exception e) { e.printStackTrace(); Message.showError(e.getMessage()); } tblUnitList.removeColumn(tblUnitList.getColumn("RentalDetailsID")); tblUnitList.removeColumn(tblUnitList.getColumn("UnitID")); tblUnitList.removeColumn(tblUnitList.getColumn("UnitFloor")); btnChooseUnit.requestFocus(); }