/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.doctor.followup;
import clips.delegate.doctor.DiseaseLocal;
import clips.delegate.doctor.followup.FollowupEventData;
import clips.delegate.doctor.followup.FollowupLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.SelectorEditable;
import java.util.Date;
import javax.swing.table.AbstractTableModel;
import framework.utils.Converter;
/**
*
* @author lacoste
*/
public class TableModelFollowUpEvents extends AbstractTableModel {
private final SelectorEditable<FollowupEventData> eventList;
private FollowupLocal followupLocal;
public static final int COLCOUNT = 4;
public static final int COL_DATE = 0;
public static final int COL_ORDERED = 1;
public static final int COL_CANCELLED = 2;
public static final int COL_CALLED = 3;
public TableModelFollowUpEvents(FollowupLocal followupLocal) throws ClipsException {
this.followupLocal = followupLocal;
this.eventList = followupLocal.getFollowupEventList();
}
@Override
public int getRowCount() {
return eventList.size();
}
@Override
public int getColumnCount() {
return COLCOUNT;
}
@Override
public Object getValueAt(int r, int c) {
FollowupEventData event = eventList.get(r);
switch (c) {
case COL_DATE: {
return event.getDate();
}
case COL_ORDERED: {
try {
DiseaseLocal disease = event.getDisease();
return disease != null ? disease.getCreated() : null;
} catch (ClipsException ex) {
ex.printStackTrace();
return false;
}
}
case COL_CANCELLED: {
return event.isCancelled();
}
case COL_CALLED: {
return event.isCalled();
}
default: return null;
}
}
@Override
public Class getColumnClass(int col) {
if (col == COL_ORDERED || col == COL_DATE){
return Date.class;
}
if (col == COL_CANCELLED || col == COL_CALLED) {
return Boolean.class;
}
return super.getColumnClass(col);
}
@Override
public boolean isCellEditable(int row, int col) {
try {
FollowupEventData event = eventList.get(row);
if (col == COL_DATE) {
return false;
}
if (followupLocal.isDown()) {
return false;
}
if (event.isNewlyCreated() || event.isOrdered()){
return false;
}
if (col == COL_ORDERED){
return !eventList.get(row).isCancelled();
}
return true;
} catch (ClipsException ex) {
MessageBox.showException(ex);
return false;
}
}
@Override
public String getColumnName(int col) {
switch (col) {
case COL_DATE: return "Должен явиться";
case COL_ORDERED: return "Явился";
case COL_CANCELLED: return "Отменено";
case COL_CALLED: return "Оповещен";
default: return null;
}
}
@Override
public void setValueAt(Object obj, int row, int col) {
FollowupEventData event;
event = eventList.get(row);
if (col == COL_DATE) {
event.setDate((Date) obj);
}
if (col == COL_CANCELLED) {
event.setCancelled((Boolean) obj);
}
if (col == COL_CALLED) {
event.setCalled((Boolean) obj);
}
fireTableCellUpdated(row, col);
}
}