/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.service.newSerRen;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import clips.delegate.service.discount.DiscountCardLocal;
import framework.utils.Converter;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
*
* @author vip
*/
public class TableModelDiscountList extends AbstractTableModel{
public static final int COL_COUNT = 4;
public static final int COL_TYPE = 0;
public static final int COL_CODE = 1;
public static final int COL_DATE = 2;
public static final int COL_BLOCKED = 3;
List<DiscountCardLocal> list;
public TableModelDiscountList(List<DiscountCardLocal> list) {
this.list = list;
}
@Override
public int getRowCount() {
return list.size() + 1;
}
@Override
public int getColumnCount() {
return COL_COUNT;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
@Override
public Class<?> getColumnClass(int col) {
if (col == COL_BLOCKED) {
return Boolean.class;
} else {
return super.getColumnClass(col);
}
}
@Override
public String getColumnName(int col) {
switch (col) {
case COL_TYPE: return "Тип карты";
case COL_CODE: return "Код";
case COL_DATE: return "Срок действия";
case COL_BLOCKED: return "Заблокирована";
default: throw new UnsupportedOperationException("Not supported yet.");
}
}
@Override
public Object getValueAt(int row, int col) {
if (row == 0) {
if (col == COL_TYPE) {
return "Без дисконтной карты";
} else if (col == COL_BLOCKED) {
return false;
} else {
return "";
}
}
DiscountCardLocal card = list.get(row - 1);
try {
switch (col) {
case COL_TYPE: return card.getCardType();
case COL_CODE: return card.getCode();
case COL_DATE: return Converter.dateToString(card.getExpiredDate());
case COL_BLOCKED: {
boolean expired = card.isExpired();
System.out.println(expired);
return expired;
}
default: throw new UnsupportedOperationException("Not supported yet.");
}
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}
public boolean isExpired(int row) {
try {
if (row < 0) {
return true;
}
if (row == 0) {
return false;
}
return list.get(row - 1).isExpired();
} catch (ClipsException ex) {
return true;
}
}
}