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