1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
3 import java.util.ArrayList;
6 import at.ac.tuwien.sbc.valesriegler.DEP_GroupDataMin;
7 import at.ac.tuwien.sbc.valesriegler.DEP_Table;
8 import at.ac.tuwien.sbc.valesriegler.DEP_Table.TableStatus;
9 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
11 public class TablesOverviewModel extends TableModel<DEP_Table> {
12 private static final String TABLE_ID = "ID";
13 private static final String STATUS = "Status";
14 private static final String GROUP_ID = "Group ID";
15 private static final String[] COLUMNS = new String[] {
16 TABLE_ID, STATUS, GROUP_ID
18 private int idCounter = 1;
21 protected String[] getColumns() {
26 public Object getValueAt(int rowIndex, int columnIndex) {
27 List<DEP_Table> values = new ArrayList<>(items.values());
28 DEP_Table table = values.get(rowIndex);
29 String wantedColumn = COLUMNS[columnIndex];
30 switch(wantedColumn) {
31 case TABLE_ID : return table.getId();
32 case STATUS : return table.getStatus();
33 case GROUP_ID : return table.getGroupId();
34 default : throw new RuntimeException(UNHANDLEDCOLUMN);
38 public int getNumberOfFreeTables() {
39 return getIdsOfFreeTables().size();
42 public List<Integer> getIdsOfFreeTables() {
43 List<Integer> ids = new ArrayList<>();
46 for(DEP_Table table : items.values()) {
47 if(table.getStatus() == TableStatus.FREE) {
48 ids.add(table.getId());
56 public List<DEP_Table> createFreeTables(int numberOfTables) {
58 List<DEP_Table> tables = new ArrayList<DEP_Table>();
59 for(int i=0; i<numberOfTables; i++) {
60 DEP_Table table = createFreeTable();
68 private DEP_Table createFreeTable() {
69 DEP_Table table = new DEP_Table();
70 table.setId(idCounter);
71 idCounter = idCounter + 1;
72 table.setStatus(TableStatus.FREE);
76 public void mergeTables(List<DEP_Table> tables) {
77 for (DEP_Table table : tables) {
78 items.put(table.getId(), table);
80 fireTableDataChanged();