]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java
Change the pizzeria models so that they display (more) correct values
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / pizzeria / gui / tablemodels / OrdersOverviewModel.java
1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
7 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
8 import at.ac.tuwien.sbc.valesriegler.types.Order;
9
10 public class OrdersOverviewModel extends TableModel<GroupData> {
11         private static final String ID = "Order ID";
12         private static final String TABLE_ID = "Table ID";
13         private static final String GROUP_ID = "Group ID";
14         private static final String STATUS = "Status";
15
16         private static final String[] COLUMNS = new String[] { ID, TABLE_ID, GROUP_ID, STATUS };
17
18         @Override
19         public Object getValueAt(int rowIndex, int columnIndex) {
20                 List<GroupData> values = new ArrayList<>(items.values());
21                 GroupData group = values.get(rowIndex);
22                 Order order = group.getOrder();
23                 String wantedColumn = COLUMNS[columnIndex];
24                 switch (wantedColumn) {
25                 case ID:
26                         return order.getId();
27                 case TABLE_ID: 
28                         return group.getTable().getId() ;
29                 case GROUP_ID:
30                         return order.getGroupId();
31                 case STATUS:
32                         return order.getStatus();
33                 default:
34                         throw new RuntimeException(UNHANDLEDCOLUMN);
35                 }
36         }
37         
38         public GroupData getGroupOfRow(int rowIndex) {
39                 return new ArrayList<>(items.values()).get(rowIndex);
40         }
41
42         @Override
43         protected String[] getColumns() {
44                 return COLUMNS;
45         }
46
47 }