]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java
[XVSM] Solve bug which made the GUI send customers to always the same Pizzeria
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / pizzeria / gui / tablemodels / GroupsOverviewModel.java
1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
2
3 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
4 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
5 import at.ac.tuwien.sbc.valesriegler.types.Table;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 public class GroupsOverviewModel extends TableModel<GroupData> {
13     private static final Logger log = LoggerFactory.getLogger(GroupsOverviewModel.class);
14         private static final String ID = "ID";
15         private static final String SIZE = "Size";
16
17         private static final String[] COLUMNS = new String[] { ID, SIZE };
18
19         @Override
20         protected String[] getColumns() {
21                 return COLUMNS;
22         }
23         
24
25         @Override
26         public Object getValueAt(int rowIndex, int columnIndex) {
27                 List<GroupData> values = new ArrayList<>(items.values());
28
29                 GroupData group = values.get(rowIndex);
30                 String wantedColumn = COLUMNS[columnIndex];
31                 switch (wantedColumn) {
32                 case ID:
33                         return group.getId();
34                 case SIZE:
35                         return group.getSize();
36                 default:
37                         throw new RuntimeException(UNHANDLEDCOLUMN);
38                 }
39         }
40
41         public void removeGroup(int id) {
42                 items.remove(id);
43                 
44                 fireTableDataChanged();
45         }
46
47     public void removeGroupsFromTables(List<Table> tables) {
48         synchronized (items) {
49             for (Table table : tables) {
50                 final int groupId = table.getGroupId();
51                 items.remove(groupId);
52             }
53         }
54         fireTableDataChanged();
55     }
56 }