]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java
Pizzeria GUI implemented
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / pizzeria / gui / tablemodels / TablesOverviewModel.java
1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
2
3 import java.util.List;
4
5 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
6 import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table;
7 import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table.TableStatus;
8
9 public class TablesOverviewModel extends TableModel<Table> {
10         private static final String TABLE_ID = "ID";
11         private static final String STATUS = "Status";
12         private static final String GROUP_ID = "Group ID";
13         private static final String[] COLUMNS = new String[] {
14                 TABLE_ID, STATUS, GROUP_ID
15         };
16         
17         public TablesOverviewModel(List<Table> tables) {
18                 setItems(tables);
19         }
20         
21         @Override
22         protected String[] getColumns() {
23                 return COLUMNS;
24         }
25
26         @Override
27         public Object getValueAt(int rowIndex, int columnIndex) {
28                 Table table = items.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); 
35                 }
36         }
37
38         public int getNumberOfFreeTables() {
39                 int i=0;
40                 for(Table table : items) {
41                         if(table.getStatus() == TableStatus.FREE) {
42                                 i = i+1;
43                         }
44                 }
45                 return i;
46         }
47
48 }