]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java
GUI fix for Tables OutOfBoundsException
[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                 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         synchronized (items) {
48             for (Table table : tables) {
49                 final int groupId = table.getGroupId();
50                 items.remove(groupId);
51             }
52         }
53         fireTableDataChanged();
54     }
55 }