/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package systole.view.crud.tableModels;
import java.util.Date;
import java.util.List;
import systole.domain.persons.Medic;
import systole.domain.persons.identityCard.IdentityCard;
import systole.domain.persons.identityCard.IdentityCardType;
/**
*
* @author jmj
*/
public class MedicTableModel extends SystoleTableModel<Medic> {
private String[] columnNames = {"Apellido", "Nombre", "Tipo Documento",
"Documento", "Fecha Nacimiento"};
private static final int NAME_INDEX = 1;
private static final int SURNAME_INDEX = 0;
private static final int KIND_IDENTITY_INDEX = 2;
private static final int IDENTITY_NUMBER_INDEX = 3;
private static final int BIRTHDATE_INDEX = 4;
/**
* @param medics
*/
public MedicTableModel(List<Medic> medics) {
super(medics);
}
public int getColumnCount() {
return this.columnNames.length;
}
public String getColumnName(int column) {
return this.columnNames[column];
}
public Class<?> getColumnClass(int column) {
switch (column) {
case BIRTHDATE_INDEX:
return Date.class;
case IDENTITY_NUMBER_INDEX:
return Integer.class;
case KIND_IDENTITY_INDEX:
return IdentityCardType.class;
case NAME_INDEX:
return String.class;
case SURNAME_INDEX:
return String.class;
}
return null;
}
public Object getValueAt(int row, int column) {
switch (column) {
case BIRTHDATE_INDEX:
return this.entities.get(row).getBirthdate();
case IDENTITY_NUMBER_INDEX:
return (this.entities.get(row).getIdentityCard() != null ? this.entities.get(row).getIdentityCard().getNumber() : null);
case KIND_IDENTITY_INDEX:
return (this.entities.get(row).getIdentityCard() != null ? this.entities.get(row).getIdentityCard().getCardType() : null);
case NAME_INDEX:
return this.entities.get(row).getName();
case SURNAME_INDEX:
return this.entities.get(row).getSurname();
}
return null;
}
public void setValueAt(Object value, int row, int column) {
switch (column) {
case BIRTHDATE_INDEX:
this.entities.get(row).setBirthdate((Date) value);
break;
case IDENTITY_NUMBER_INDEX:
if (this.entities.get(row).getIdentityCard() == null) {
this.entities.get(row).setIdentityCard(new IdentityCard());
}
this.entities.get(row).getIdentityCard().setNumber((Integer) value);
break;
case KIND_IDENTITY_INDEX:
if (this.entities.get(row).getIdentityCard() == null) {
this.entities.get(row).setIdentityCard(new IdentityCard());
}
this.entities.get(row).getIdentityCard().setCardType((IdentityCardType) value);
break;
case NAME_INDEX:
this.entities.get(row).setName((String) value);
break;
case SURNAME_INDEX:
this.entities.get(row).setSurname((String) value);
break;
}
}
}