/*
* Copyright (C) 2014 anonymous
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.yf.kp.design.kelas;
import com.yf.kp.model.Kelas;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
*
* @author anonymous
*/
public class KelasTableModel extends AbstractTableModel {
private List<Kelas> list = new ArrayList<>();
private final String[] header = {"Id", "Kelas"};
public void setList(List<Kelas> list) {
this.list = list;
}
public void save(Kelas kelas) {
list.add(kelas);
fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public void update(int index, Kelas kelas) {
list.set(index, kelas);
fireTableRowsUpdated(index, index);
}
public void delete(int index) {
list.remove(index);
fireTableRowsDeleted(index, index);
}
public Kelas getOne(int index) {
return list.get(index);
}
@Override
public int getRowCount() {
return list.size();
}
@Override
public int getColumnCount() {
return header.length;
}
@Override
public String getColumnName(int column) {
return header[column];
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Kelas kelas = list.get(rowIndex);
switch (columnIndex) {
case 0:
return kelas.getId();
case 1:
return kelas.getNama_kelas();
default:
return null;
}
}
}