@Override public void tableChanged(TableModelEvent e) { int r = e.getFirstRow(); int c = e.getColumn(); if (e.getType() == TableModelEvent.UPDATE) { TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(r, c); DbManager.editAttribute(r, c, data, DbManager.VOLUNTEERS); } }
/** * Removes volunteer(row) from table and database * * @param rowNum */ public void removeVolunteer(int rowNum) { DbManager.remove(rowNum, DbManager.VOLUNTEERS); data.remove(rowNum - 1); fireTableRowsDeleted(rowNum - 1, rowNum - 1); // shift ID for (int i = rowNum - 1; i < data.size(); i++) { data.get(i).setAttribute(0, Integer.parseInt(data.get(i).getAttribute(0).toString()) - 1); fireTableCellUpdated(i, 0); } }
/** * Adds volunteer to table and database * * @param s */ public void addVolunteer(Volunteer v) { DbManager.addVolunteer(v); data.add(v); fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); }
public VolunteerTableModel() { data = DbManager.getVolunteers(); colNames = Volunteer.fields; addTableModelListener(this); }