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 };
34 public GroupOverviewModel() {
36 // super.items.add(new Group()); // TODO: remove, debuggroup!
40 protected String[] getColumns() {
44 public List<Group> getItems() {
45 return new ArrayList<>(items.values());
48 public Group getGroupByID(int id) {
53 public Object getValueAt(int rowIndex, int columnIndex) {
54 List<Group> values = new ArrayList<>(items.values());
55 Group group = values.get(rowIndex);
56 String wantedColumn = COLUMNS[columnIndex];
57 switch (wantedColumn) {
59 int groupId = group.getGroupData().getId();
60 log.info("This is the group id : {}", groupId);
63 int groupSize = group.getGroupData().getSize();
64 log.info("This is the size : {}", groupSize);
67 if (group.getGroupData().getOrder() == null)
69 return pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas());
71 return group.getGroupData().getState();
73 throw new RuntimeException(UNHANDLEDCOLUMN);
79 * @return A display string for PizzaTypes.
81 * e.g. Cardinale, Cardinale, Margherita is displayed as
82 * "2xCARDINALE,1xMARGHERITA"
84 private String pizzaDisplay(List<PizzaOrder> list) {
85 HashMap<PizzaType, Integer> pizzaCount = new HashMap<PizzaType, Integer>();
86 for (PizzaOrder pizzaOrder : list) {
87 PizzaType pizzaType = pizzaOrder.getPizzaType();
88 if (pizzaCount.containsKey(pizzaType)) {
89 pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1);
91 pizzaCount.put(pizzaType, 1);
93 Set<PizzaType> pizzaTypes = pizzaCount.keySet();
94 StringBuilder sb = new StringBuilder();
96 boolean multiplePizzas = false;
97 for (PizzaType pizzaType : pizzaTypes) {
101 multiplePizzas = true;
103 sb.append(pizzaCount.get(pizzaType) + "x");
104 sb.append(pizzaType.toString());
107 return sb.toString();
111 public void addItems(List<Group> newItems) {
112 log.info("addItems()");
113 super.addItems(newItems);
114 for (Group g : newItems) {
115 if(Util.useJMS) g.goGrabSomeFood();