1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
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;
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.Comparator;
12 import java.util.List;
14 public class GroupsOverviewModel extends TableModel<GroupData> {
15 private static final Logger log = LoggerFactory.getLogger(GroupsOverviewModel.class);
16 private static final String ID = "ID";
17 private static final String SIZE = "Size";
19 private static final String[] COLUMNS = new String[] { ID, SIZE };
22 protected String[] getColumns() {
28 public Object getValueAt(int rowIndex, int columnIndex) {
29 List<GroupData> values = new ArrayList<>(items.values());
31 // TODO: make sure that is necessary
32 Collections.sort(values, new Comparator<GroupData>() {
34 public int compare(GroupData o1, GroupData o2) {
35 final int o1Id = o1.getOrder().getId();
36 final int o2Id = o2.getOrder().getId();
38 if (o2Id > 0) return 1;
41 if (o1Id > 0) return 1;
43 if (o1Id < o2Id) return -1;
44 else if (o1Id > o2Id) return 1;
48 GroupData group = values.get(rowIndex);
49 String wantedColumn = COLUMNS[columnIndex];
50 switch (wantedColumn) {
54 return group.getSize();
56 throw new RuntimeException(UNHANDLEDCOLUMN);
60 public void removeGroup(int id) {
63 fireTableDataChanged();
66 public void removeGroupsFromTables(List<Table> tables) {
67 synchronized (items) {
68 for (Table table : tables) {
69 final int groupId = table.getGroupId();
70 items.remove(groupId);
73 fireTableDataChanged();