1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
3 import java.util.ArrayList;
6 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
7 import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table;
8 import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table.TableStatus;
10 public class TablesOverviewModel extends TableModel<Table> {
11 private static final String TABLE_ID = "ID";
12 private static final String STATUS = "Status";
13 private static final String GROUP_ID = "Group ID";
14 private static final String[] COLUMNS = new String[] {
15 TABLE_ID, STATUS, GROUP_ID
17 private int idCounter = 1;
19 public TablesOverviewModel(int numberOfTables) {
20 createFreeTables(numberOfTables);
25 protected String[] getColumns() {
30 public Object getValueAt(int rowIndex, int columnIndex) {
31 Table table = items.get(rowIndex);
32 String wantedColumn = COLUMNS[columnIndex];
33 switch(wantedColumn) {
34 case TABLE_ID : return table.getId();
35 case STATUS : return table.getStatus();
36 case GROUP_ID : return table.getGroupId();
37 default : throw new RuntimeException(UNHANDLEDCOLUMN);
41 public int getNumberOfFreeTables() {
43 for(Table table : items) {
44 if(table.getStatus() == TableStatus.FREE) {
52 private void createFreeTables(int numberOfTables) {
53 List<Table> tables = new ArrayList<Table>();
54 for(int i=0; i<numberOfTables; i++) {
55 Table table = createFreeTable();
61 private Table createFreeTable() {
62 Table table = new Table();
63 table.setId(idCounter);
64 idCounter = idCounter + 1;
65 table.setStatus(TableStatus.FREE);