1 package at.ac.tuwien.sbc.valesriegler.group.gui;
4 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
5 import at.ac.tuwien.sbc.valesriegler.common.Util;
6 import at.ac.tuwien.sbc.valesriegler.group.DeliveryGroup;
7 import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData;
8 import at.ac.tuwien.sbc.valesriegler.types.DeliveryStatus;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import java.util.ArrayList;
13 import java.util.List;
15 public class DeliveryOverviewModel extends TableModel<DeliveryGroup> {
16 private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class);
18 private static final String STATE = "State";
19 private static final String PIZZAS = "Pizzas";
20 private static final String ADDRESS = "Address";
21 private static final String ID = "ID";
22 private static final String PIZZERIA = "Pizzeria";
23 private static final String[] COLUMNS = new String[]{ID, ADDRESS, PIZZAS, STATE, PIZZERIA};
27 protected String[] getColumns() {
32 public Object getValueAt(int rowIndex, int columnIndex) {
33 List<DeliveryGroup> values = new ArrayList<>(items.values());
34 DeliveryGroup group = values.get(rowIndex);
35 String wantedColumn = COLUMNS[columnIndex];
36 switch (wantedColumn) {
38 int groupId = group.getId();
41 return group.getDeliveryGroupData().getAddress();
43 if (group.getDeliveryGroupData().getOrder() == null)
45 return Util.pizzaDisplay(group.getDeliveryGroupData().getOrder().getOrderedPizzas());
47 return group.getDeliveryGroupData().getDeliveryStatus();
49 return group.getDeliveryGroupData().getPizzeriaId();
51 throw new RuntimeException(UNHANDLEDCOLUMN);
55 public void setOrdersTaken(List<DeliveryGroupData> groups) {
56 for (DeliveryGroupData group : groups) {
57 changeStateOfGroup(group.getId(), DeliveryStatus.ORDERED);
60 fireTableDataChanged();
63 private void changeStateOfGroup(int groupId, DeliveryStatus state) {
64 items.get(groupId).getDeliveryGroupData().setDeliveryStatus(state);
67 public void setOrdersDelivered(List<DeliveryGroupData> groups) {
68 for (DeliveryGroupData group : groups) {
69 changeStateOfGroup(group.getId(), group.getDeliveryStatus());
72 fireTableDataChanged();
75 public void addDeliveries(List<DeliveryGroupData> groups) {
76 synchronized (items) {
77 for (DeliveryGroupData group : groups) {
78 final DeliveryGroup deliveryGroup = items.get(group.getId());
79 if(deliveryGroup==null) {
80 log.error("Delivery group not found!!!");
82 deliveryGroup.setDeliveryGroupData(group);
85 fireTableDataChanged();