/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.contract;
import beans.contract.entity.Contract;
import cli_fmw.main.ClipsException;
import clips.delegate.contract.ContractLocal;
import cli_fmw.utils.ErrorValue;
import clips.delegate.directory.complex.DirectoryEnterpriseItem;
import clips.delegate.directory.ro.DirectoryLpuItem;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;
/**
* модель для таблицы договоров клиента
* @author lacoste
*/
public class TableModelContractList extends AbstractTableModel {
private ArrayList<ContractLocal> contractList;
public static final int COLCOUNT = 6;
public static final int COL_INDEX = 0;
public static final int COL_ENTERPRICE = 1;
public static final int COL_TYPE = 2;
public static final int COL_BEGIN = 3;
public static final int COL_END = 4;
public static final int COL_LPU = 5;
public TableModelContractList(ArrayList<ContractLocal> contractList) {
this.contractList = contractList;
}
@Override
public String getColumnName(int c) {
String s = "";
switch (c) {
case COL_INDEX:
s = "Номер";
break;
case COL_ENTERPRICE:
s = "Предприятие";
break;
case COL_TYPE:
s = "Тип";
break;
case COL_BEGIN:
s = "Дата начала";
break;
case COL_END:
s = "Дата окончания";
break;
case COL_LPU:
s = "ЛПУ";
break;
default:
throw new IllegalArgumentException("Неверный номер столбца : " + c);
}
return s;
}
@Override
public boolean isCellEditable(int r, int c) {
return false;
}
@Override
public Class<?> getColumnClass(int col) {
if (col == COL_BEGIN || col == COL_END) {
return Date.class;
}
return super.getColumnClass(col);
}
@Override
public int getRowCount() {
if (contractList != null) {
return contractList.size();
} else {
return 0;
}
}
@Override
public int getColumnCount() {
return COLCOUNT;
}
@Override
public Object getValueAt(int r, int c) {
try {
ContractLocal contractLocal = contractList.get(r);
switch (c) {
case COL_INDEX: {
return contractLocal.getIndex();
}
case COL_ENTERPRICE: {
//предприятие
DirectoryEnterpriseItem enterprise = contractLocal.getEnterprise();
if (enterprise != null) {
return enterprise;
} else {
return null;
}
}
case COL_TYPE: {
//Тип договора
int i = contractLocal.getType();
return Contract.TYPES_ARRAY[i].toString();
}
case COL_BEGIN: {
//дата начала
return contractLocal.getBegin();
}
case COL_END: {
//дата окончания
return contractLocal.getEnd();
}
case COL_LPU: {
DirectoryLpuItem lpu = contractLocal.getLpu();
if (lpu == null || lpu.isNullItem()) {
return "все";
} else {
return lpu.getTitleShort();
}
}
default:
throw new IllegalArgumentException("Неверный номер столбца : " + c);
}
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}
public ContractLocal getRowValue(int row){
return contractList.get(row);
}
}