1 package at.ac.tuwien.sbc.valesriegler.group.gui;
3 import java.util.HashMap;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
11 import at.ac.tuwien.sbc.valesriegler.group.Group;
12 import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder;
13 import at.ac.tuwien.sbc.valesriegler.types.PizzaType;
16 * Might not the nicest way to store global data, but this is an elemental
17 * Object, storing ALL the Group's data. Might consider splitting those two
23 public class GroupOverviewModel extends TableModel<Group> {
24 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
26 private static final String STATE = "State";
27 private static final String PIZZAS = "Pizzas";
28 private static final String SIZE = "Size";
29 private static final String ID = "ID";
30 private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE };
32 public GroupOverviewModel() {
34 super.items.add(new Group()); // TODO: remove, debuggroup!
38 protected String[] getColumns() {
42 public List<Group> getItems() {
46 public Group getGroupByID(int id) {
47 for (Group group : items) {
48 if (group.getGroupData().getId() == id)
55 public Object getValueAt(int rowIndex, int columnIndex) {
56 Group group = items.get(rowIndex);
57 String wantedColumn = COLUMNS[columnIndex];
58 switch (wantedColumn) {
60 int groupId = group.getGroupData().getId();
61 log.info("This is the group id : {}", groupId);
64 int groupSize = group.getGroupData().getSize();
65 log.info("This is the size : {}", groupSize);
68 if (group.getGroupData().getOrder() == null)
70 return pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas());
72 return group.getGroupData().getState();
74 throw new RuntimeException(UNHANDLEDCOLUMN);
80 * @return A display string for PizzaTypes.
82 * e.g. Cardinale, Cardinale, Margherita is displayed as
83 * "2xCARDINALE,1xMARGHERITA"
85 private String pizzaDisplay(List<PizzaOrder> list) {
86 HashMap<PizzaType, Integer> pizzaCount = new HashMap<PizzaType, Integer>();
87 for (PizzaOrder pizzaOrder : list) {
88 PizzaType pizzaType = pizzaOrder.getPizzaType();
89 if (pizzaCount.containsKey(pizzaType)) {
90 pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1);
92 pizzaCount.put(pizzaType, 1);
94 Set<PizzaType> pizzaTypes = pizzaCount.keySet();
95 StringBuilder sb = new StringBuilder();
97 boolean multiplePizzas = false;
98 for (PizzaType pizzaType : pizzaTypes) {
102 multiplePizzas = true;
104 sb.append(pizzaCount.get(pizzaType) + "x");
105 sb.append(pizzaType.toString());
108 return sb.toString();
112 public void addItems(List<Group> newItems) {
113 log.info("addItems()");
114 super.addItems(newItems);
115 for (Group g : newItems) {