/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.contract.info.polis;
import beans.contract.entity.PolisDetails;
import cli_fmw.delegate.lists.DataChunk;
import clips.delegate.client.ClientLocal;
import cli_fmw.main.ClipsException;
import clips.delegate.contract.PolisData;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import clips.delegate.contract.ContractLocal;
import clips.delegate.directory.simple.insurer.DirectoryInsurerItem;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCodeItem;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
* Модель таблицы списка членов договора, в модель передается ContractLocal
* @author lacoste
*/
public class TableModelPolisView extends AbstractTableModel {
private List<PolisData> polisList;
private ContractLocal contract;
public static final int COLCOUNT = 10;
public static final int COL_INSURER = 0;
public static final int COL_INSURER_REGION = 1;
public static final int COL_SERIES = 2;
public static final int COL_NUMBER = 3;
public static final int COL_FIO = 4;
public static final int COL_BIRTHDAY = 5;
public static final int COL_MEMBER = 6;
public static final int COL_FROMDATE = 7;
public static final int COL_TILLDATE = 8;
public static final int COL_ADDRESS = 9;
public TableModelPolisView(List<PolisData> polisList, ContractLocal contract_) {
this.polisList = polisList;
contract = contract_;
}
@Override
public boolean isCellEditable(int r, int c) {
if (c == COL_FIO || c == COL_BIRTHDAY || c == COL_ADDRESS) {
return false;
}
return true;
}
@Override
public int getRowCount() {
if (polisList != null) {
return polisList.size();
} else {
return 0;
}
}
@Override
public int getColumnCount() {
return COLCOUNT;
}
@Override
public String getColumnName(int c) {
String s = "";
switch (c) {
case COL_INSURER:
s = "Страх. компания";
break;
case COL_INSURER_REGION:
s = "Код региона";
break;
case COL_FIO:
s = "ФИО";
break;
case COL_BIRTHDAY:
s = "Дата рождения";
break;
case COL_SERIES:
s = "Серия";
break;
case COL_NUMBER:
s = "№ полиса";
break;
case COL_MEMBER:
s = "Участник";
break;
case COL_FROMDATE:
s = "Действителен от";
break;
case COL_TILLDATE:
s = "Действителен до";
break;
case COL_ADDRESS:
s = "Адрес";
break;
default:
s = "Не сработал switch-case";
}
return s;
}
@Override
public Class getColumnClass(int columnIndex) {
if (columnIndex == COL_MEMBER) {
return Boolean.class;
}
else if (columnIndex == COL_TILLDATE || columnIndex == COL_FROMDATE){
return Date.class;
}
else if (columnIndex == COL_BIRTHDAY){
return Date.class;
}
return super.getColumnClass(columnIndex);
}
@Override
public void setValueAt(Object obj, int row, int col) {
try {
PolisData polis = polisList.get(row);
PolisData old = (PolisData) polis.clone();
if (col == COL_INSURER) {
polis.setInsurer((DirectoryInsurerItem) obj);
}
if (col == COL_SERIES) {
polis.setSeries(obj.toString());
}
if (col == COL_NUMBER) {
polis.setNumber(obj.toString());
}
else if (col == COL_MEMBER) {
polis.setMember((Boolean) obj);
}
else if (col == COL_FROMDATE) {
polis.setFromDate((Date) obj);
}
else if (col == COL_TILLDATE) {
polis.setTillDate((Date) obj);
}
else if (col == COL_INSURER_REGION) {
polis.setRegionCode((DirectoryRegionIdCodeItem) obj);
}
fireTableCellUpdated(row, col);
if (!old.equals(polis)) {
contract.savePolisData(polis);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public Object getValueAt(int r, int c) {
try {
PolisData polisData = polisList.get(r);
switch (c) {
case COL_INSURER: {
//страховая компания
DirectoryInsurerItem insurer = polisData.getInsurer();
if (insurer != null) {
return insurer;
} else {
return "";
}
}
case COL_INSURER_REGION: {
//код региона страховой компании
DirectoryRegionIdCodeItem region = polisData.getRegionCode();
if (region != null) {
return region;
} else {
return "";
}
}
case COL_FIO: {
//ФИО
ClientLocal cl = polisData.getClient();
if (cl != null) {
return cl.toString();
} else {
return "";
}
}
case COL_BIRTHDAY: {
//Дата рождения
Date date = polisData.getClient().getBorn();
return date;
}
case COL_SERIES: {
//Серия полиса
return polisData.getSeries();
}
case COL_NUMBER: {
//№ полиса
return polisData.getNumber();
}
case COL_MEMBER: {
//непосредственный участник договора
return polisData.isMember();
}
case COL_FROMDATE: {
//дата начала срока действия полиса
return polisData.getFromDate();
}
case COL_TILLDATE: {
//дата окончания срока действия полиса
return polisData.getTillDate();
}
case COL_ADDRESS: {
//адрес в полисе
return polisData.getAddress().toStringShort();
}
default:
return null;
}
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}
}