/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reiseverrechnung;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
/**
*
* @author Balti
*/
public class TableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
String[] headers = {};
//TableData [][] data; //Daten der Tabelle
ArrayList <TableData> list=new ArrayList <TableData>();
TableData data;
public TableModel() {
for (int i = 0; i < 17; i++) {
data=new TableData();
data.setTypefeeclaim(null);
data.setDistancetraveled(0);
data.setTravelcosts(0);
data.setDailyfee(0);
data.setOvernightcosts(0);
data.setOthercosts(0);
data.setSum(0);
list.add(data);
}
}
public int getRowCount() {
return 17;
}
public int getColumnCount() {
return 7;
}
@Override
public String getColumnName(int column){
String[] tab=new String []{"Art des Gebührenanspruches","Entfernung in Gesamt-km",
"Reisekosten", "Tagesgebühr", "Nächtigungsgebühr", "sonstige Nebenkosten", "Summe"};
return tab[column];
}
@Override
public boolean isCellEditable(int row, int column)
{
return true;
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return list.get(rowIndex).getTypefeeclaim();
case 1:
return list.get(rowIndex).getDistancetraveled();
case 2:
return list.get(rowIndex).getTravelcosts();
case 3:
return list.get(rowIndex).getDailyfee();
case 4:
return list.get(rowIndex).getOvernightcosts();
case 5:
return list.get(rowIndex).getOthercosts();
case 6:
return list.get(rowIndex).getSum();
default: return "Error";
}
}
@Override
public Class getColumnClass(int cI) {
if (cI == 0) {
return String.class;
} else {
if (cI == 1) {
return Integer.class;
} else {
if (cI == 2) {
return Integer.class;
} else {
if (cI == 3) {
return Integer.class;
} else {
if(cI==4){
return Integer.class;
} else {
if(cI==5){
return Integer.class;
}
else {
if(cI==6) {
return Integer.class;
}
}
}
return String.class;
}
}
}
}
}
@Override
public void setValueAt(Object aValue,int rowIndex, int columnIndex){
switch (columnIndex) {
case 0:
list.get(rowIndex).setTypefeeclaim(String.valueOf(aValue.toString()));
break;
case 1:
list.get(rowIndex).setDistancetraveled(Integer.valueOf(aValue.toString()));
break;
case 2:
list.get(rowIndex).setTravelcosts(Integer.valueOf(aValue.toString()));
break;
case 3:
list.get(rowIndex).setDailyfee(Integer.valueOf(aValue.toString()));
break;
case 4:
list.get(rowIndex).setOvernightcosts(Integer.valueOf(aValue.toString()));
break;
case 5:
list.get(rowIndex).setOthercosts(Integer.valueOf(aValue.toString()));
break;
case 6:
list.get(rowIndex).setSum(Integer.valueOf(aValue.toString()));
break;
}
fireTableDataChanged();
}
public ArrayList<TableData> getChanges(){
System.out.println(list);
return list;
}
}