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.PizzaType;
14 public class GroupOverviewModel extends TableModel<Group> {
15 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
17 private static final String STATE = "State";
18 private static final String PIZZAS = "Pizzas";
19 private static final String SIZE = "Size";
20 private static final String ID = "ID";
21 private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE };
23 public GroupOverviewModel() {
25 super.items.add(new Group()); // TODO: remove, debuggroup!
29 protected String[] getColumns() {
33 public List<Group> getItems() {
37 public Group getGroupByID(int id) {
38 for (Group group : items) {
39 if (group.getGroupData().getId() == id)
46 public Object getValueAt(int rowIndex, int columnIndex) {
47 Group group = items.get(rowIndex);
48 String wantedColumn = COLUMNS[columnIndex];
49 switch (wantedColumn) {
51 int groupId = group.getGroupData().getId();
52 log.info("This is the group id : {}", groupId);
55 int groupSize = group.getGroupData().getSize();
56 log.info("This is the size : {}", groupSize);
59 return pizzaDisplay(group.getGroupData().getPizzas());
61 return group.getGroupData().getState();
63 throw new RuntimeException(UNHANDLEDCOLUMN);
69 * @return A display string for PizzaTypes.
71 * e.g. Cardinale, Cardinale, Margherita is displayed as
72 * "2xCARDINALE,1xMARGHERITA"
74 private String pizzaDisplay(List<PizzaType> pizzas) {
75 HashMap<PizzaType, Integer> pizzaCount = new HashMap<PizzaType, Integer>();
76 for (PizzaType pizzaType : pizzas) {
77 if (pizzaCount.containsKey(pizzaType)) {
78 pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1);
80 pizzaCount.put(pizzaType, 1);
82 Set<PizzaType> pizzaTypes = pizzaCount.keySet();
83 StringBuilder sb = new StringBuilder();
85 boolean multiplePizzas = false;
86 for (PizzaType pizzaType : pizzaTypes) {
90 multiplePizzas = true;
92 sb.append(pizzaCount.get(pizzaType) + "x");
93 sb.append(pizzaType.toString());
100 public void addItems(List<Group> newItems) {
101 log.info("addItems()");
102 super.addItems(newItems);
103 for (Group g : newItems) {