1 package at.ac.tuwien.sbc.valesriegler.group.gui;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashMap;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import at.ac.tuwien.sbc.valesriegler.DEP_Table;
13 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
14 import at.ac.tuwien.sbc.valesriegler.common.Util;
15 import at.ac.tuwien.sbc.valesriegler.group.Group;
16 import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder;
17 import at.ac.tuwien.sbc.valesriegler.types.PizzaType;
19 public class GroupOverviewModel extends TableModel<Group> {
20 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
22 private static final String STATE = "State";
23 private static final String PIZZAS = "Pizzas";
24 private static final String SIZE = "Size";
25 private static final String ID = "ID";
26 private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE };
28 public GroupOverviewModel() {
30 // super.items.add(new Group()); // TODO: remove, debuggroup!
34 protected String[] getColumns() {
38 public List<Group> getItems() {
39 return new ArrayList<>(items.values());
42 public Group getGroupByID(int id) {
47 public Object getValueAt(int rowIndex, int columnIndex) {
48 List<Group> values = new ArrayList<>(items.values());
49 Group group = values.get(rowIndex);
50 String wantedColumn = COLUMNS[columnIndex];
51 switch (wantedColumn) {
53 int groupId = group.getGroupData().getId();
54 log.info("This is the group id : {}", groupId);
57 int groupSize = group.getGroupData().getSize();
58 log.info("This is the size : {}", groupSize);
61 if (group.getGroupData().getOrder() == null)
63 return pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas());
65 return group.getGroupData().getState();
67 throw new RuntimeException(UNHANDLEDCOLUMN);
73 * @return A display string for PizzaTypes.
75 * e.g. Cardinale, Cardinale, Margherita is displayed as
76 * "2xCARDINALE,1xMARGHERITA"
78 private String pizzaDisplay(List<PizzaOrder> list) {
79 HashMap<PizzaType, Integer> pizzaCount = new HashMap<PizzaType, Integer>();
80 for (PizzaOrder pizzaOrder : list) {
81 PizzaType pizzaType = pizzaOrder.getPizzaType();
82 if (pizzaCount.containsKey(pizzaType)) {
83 pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1);
85 pizzaCount.put(pizzaType, 1);
87 Set<PizzaType> pizzaTypes = pizzaCount.keySet();
88 StringBuilder sb = new StringBuilder();
90 boolean multiplePizzas = false;
91 for (PizzaType pizzaType : pizzaTypes) {
95 multiplePizzas = true;
97 sb.append(pizzaCount.get(pizzaType) + "x");
98 sb.append(pizzaType.toString());
101 return sb.toString();
105 public void addItems(List<Group> newItems) {
106 log.info("addItems()");
107 super.addItems(newItems);
108 for (Group g : newItems) {
109 if(Util.useJMS) g.goGrabSomeFood();