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());
   }
 }
 private void initialize() {
   try {
     tblBuildingList.getColumnModel().getColumn(3).setCellRenderer(new DecimalFormatRenderer());
     tblBuildingList.getColumnModel().getColumn(4).setCellRenderer(new DecimalFormatRenderer());
     model = (DefaultTableModel) tblBuildingList.getModel();
   } catch (Exception e) {
     Message.showError(e.getMessage());
   }
 }
  // METHODS for SEARCHING / RELOADING THE SEARCH VALUE
  public void loadTable() {
    try {
      model.getDataVector().removeAllElements();
      model.fireTableDataChanged();

      b.searchBuildingList(txtSearch.getText().trim().replaceAll("'", ""), buildingList);
      if (buildingList.isEmpty()) {
        Message.showWarning("Record not Found");
        txtSearch.requestFocus();
        return;
      }
      for (Object[] obj : buildingList) {
        model.addRow(obj);
      }
      if (model.getRowCount() > 0) {
        tblBuildingList.requestFocus();
        tblBuildingList.setRowSelectionInterval(0, 0);
      }
    } catch (Exception e) {
      Message.showError(e.getMessage());
    }
  }
  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 void addUnitToTable(Object[] obj) {
    //        if (model == null) {
    //            model = (DefaultTableModel) tblUnitList.getModel();
    //        }

    for (int i = 0; i < model.getRowCount(); i++) {
      if (((Number) model.getValueAt(i, 2)).intValue() == (int) obj[2]) {
        Message.showWarning("UNIT Already Exist");
        return;
      }
    }
    model.addRow(obj);
    totalLeaseArea += ((Number) obj[1]).doubleValue();
    tblUnitList.requestFocus();
    tblUnitList.setRowSelectionInterval(0, 0);
    btnChooseUnit.requestFocus();
  }
  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();
  }