1 package at.ac.tuwien.sbc.valesriegler.group.gui;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
12 import at.ac.tuwien.sbc.valesriegler.common.Util;
13 import at.ac.tuwien.sbc.valesriegler.group.Group;
14 import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder;
15 import at.ac.tuwien.sbc.valesriegler.types.PizzaType;
18 * Might not the nicest way to store global data, but this is an elemental
19 * Object, storing ALL the Group's data. Might consider splitting those two
25 public class GroupOverviewModel extends TableModel<Group> {
26 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
28 private static final String STATE = "State";
29 private static final String PIZZAS = "Pizzas";
30 private static final String SIZE = "Size";
31 private static final String ID = "ID";
32 private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE };
36 protected String[] getColumns() {
40 public List<Group> getItems() {
41 return new ArrayList<>(items.values());
44 public Group getGroupByID(int id) {
49 public Object getValueAt(int rowIndex, int columnIndex) {
50 List<Group> values = new ArrayList<>(items.values());
51 Group group = values.get(rowIndex);
52 String wantedColumn = COLUMNS[columnIndex];
53 switch (wantedColumn) {
55 int groupId = group.getGroupData().getId();
56 log.info("This is the group id : {}", groupId);
59 int groupSize = group.getGroupData().getSize();
60 log.info("This is the size : {}", groupSize);
63 if (group.getGroupData().getOrder() == null)
65 return pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas());
67 return group.getGroupData().getState();
69 throw new RuntimeException(UNHANDLEDCOLUMN);
75 * @return A display string for PizzaTypes.
77 * e.g. Cardinale, Cardinale, Margherita is displayed as
78 * "2xCARDINALE,1xMARGHERITA"
80 private String pizzaDisplay(List<PizzaOrder> list) {
81 HashMap<PizzaType, Integer> pizzaCount = new HashMap<PizzaType, Integer>();
82 for (PizzaOrder pizzaOrder : list) {
83 PizzaType pizzaType = pizzaOrder.getPizzaType();
84 if (pizzaCount.containsKey(pizzaType)) {
85 pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1);
87 pizzaCount.put(pizzaType, 1);
89 Set<PizzaType> pizzaTypes = pizzaCount.keySet();
90 StringBuilder sb = new StringBuilder();
92 boolean multiplePizzas = false;
93 for (PizzaType pizzaType : pizzaTypes) {
97 multiplePizzas = true;
99 sb.append(pizzaCount.get(pizzaType) + "x");
100 sb.append(pizzaType.toString());
103 return sb.toString();
107 public void addItems(List<Group> newItems) {
108 log.info("addItems()");
109 super.addItems(newItems);
110 for (Group g : newItems) {
111 if(Util.useJMS) g.goGrabSomeFood();