public void removeRow() { try { if (tblUnitList.getSelectedRow() < 0) { Message.showWarning("Please select in the table"); return; } // if (((Number) model.getValueAt(0, 2)).intValue() > 0) { // deleteUnitList.add((Integer) model.getValueAt(tblUnitList.getSelectedRow(), // 4)); // } if (userTask >= GlobalMode.EDIT && (int) model.getValueAt(tblUnitList.getSelectedRow(), 4) > 0) { if (JOptionPane.showConfirmDialog( this, "This unit is already in use. This will be permanently delete to the database. Do you still want to continue?", "WARNING", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { totalLeaseArea -= ((Number) model.getValueAt(tblUnitList.getSelectedRow(), 1)).doubleValue(); rDB.deleteRentalDetailID( ((Number) model.getValueAt(tblUnitList.getSelectedRow(), 4)).intValue(), totalLeaseArea); model.removeRow(tblUnitList.getSelectedRow()); } } else { totalLeaseArea -= ((Number) model.getValueAt(tblUnitList.getSelectedRow(), 1)).doubleValue(); model.removeRow(tblUnitList.getSelectedRow()); } } 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(); }