1 package at.ac.tuwien.sbc.valesriegler.group.gui;
3 import java.util.ArrayList;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
9 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
10 import at.ac.tuwien.sbc.valesriegler.common.Util;
11 import at.ac.tuwien.sbc.valesriegler.group.Group;
12 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
13 import at.ac.tuwien.sbc.valesriegler.types.GroupState;
14 import at.ac.tuwien.sbc.valesriegler.types.Table;
17 * Might not the nicest way to store global data, but this is an elemental
18 * Object, storing ALL the Group's data. Might consider splitting those two
24 public class GroupOverviewModel extends TableModel<Group> {
25 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
27 private static final String STATE = "State";
28 private static final String PIZZAS = "Pizzas";
29 private static final String SIZE = "Size";
30 private static final String ID = "ID";
31 private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE };
35 protected String[] getColumns() {
39 public List<Group> getItems() {
40 return new ArrayList<>(items.values());
43 public Group getGroupByID(int id) {
48 public Object getValueAt(int rowIndex, int columnIndex) {
49 List<Group> values = new ArrayList<>(items.values());
50 Group group = values.get(rowIndex);
51 String wantedColumn = COLUMNS[columnIndex];
52 switch (wantedColumn) {
54 int groupId = group.getGroupData().getId();
57 int groupSize = group.getGroupData().getSize();
60 if (group.getGroupData().getOrder() == null)
62 return Util.pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas());
64 return group.getGroupData().getState();
66 throw new RuntimeException(UNHANDLEDCOLUMN);
71 public void addItems(List<Group> newItems) {
72 log.info("addItems()");
73 super.addItems(newItems);
74 for (Group g : newItems) {
75 if(Util.useJMS) g.goGrabSomeFood();
81 * This is necessary as in the space version GroupData objects get written to the space. In order to
82 * translate from Group data to the actual group object the group object has to be looked up by the id.
84 * @param newItems the group data of the corresponding groups
87 public void addGroupData(List<GroupData> newItems) {
88 List<Group> groups = new ArrayList<>();
89 for (GroupData groupData : newItems) {
90 Group group = items.get(groupData.getId());
91 group.setGroupData(groupData);
94 super.addItems(groups);
97 public void setGroupEating(int groupId) {
98 // if(stateIs(groupId, GroupState.GONE) || stateIs(groupId, GroupState.PAY)) return;
99 changeStateOfGroup(groupId, GroupState.EATING);
101 fireTableDataChanged();
104 public void setGroupWantsToPay(int groupId) {
105 // if(stateIs(groupId, GroupState.GONE)) return;
106 changeStateOfGroup(groupId, GroupState.PAY);
108 fireTableDataChanged();
111 private boolean stateIs(int groupId, GroupState state) {
112 return items.get(groupId).getGroupData().getState() == state;
116 public void setGroupHasPaid(int groupId) {
117 changeStateOfGroup(groupId, GroupState.GONE);
119 fireTableDataChanged();
122 private void changeStateOfGroup(int groupId, GroupState state) {
123 items.get(groupId).getGroupData().setState(state);
126 public void setGroupsSitting(List<Table> tables) {
127 synchronized (items) {
128 for (Table table : tables) {
129 changeStateOfGroup(table.getGroupId(), GroupState.SITTING);
133 fireTableDataChanged();
136 public void setOrderTaken(GroupData group) {
137 changeStateOfGroup(group.getId(), GroupState.ORDERED);
139 fireTableDataChanged();