From e0478a4da4acc5d75bd785e9982f8d2837a99dd8 Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Wed, 29 May 2013 18:27:09 +0200 Subject: [PATCH] Adjust Pizzeria GUI to display delivery orders. Show pizzeria identifier in Group GUI. --- .../group/gui/GroupCreationHandler.java | 1 - .../group/gui/GroupOverviewModel.java | 5 +- .../valesriegler/pizzeria/PizzeriaAgent.java | 34 ++++++--- .../pizzeria/gui/PizzeriaFrame.java | 75 +++++++++++++++++-- .../gui/tablemodels/DeliveryDetailsModel.java | 46 ++++++++++++ .../gui/tablemodels/DeliveryOrdersModel.java | 49 ++++++++++++ .../gui/tablemodels/WaitersOfOrderModel.java | 5 -- .../valesriegler/types/DeliveryGroupData.java | 53 +++++++++++-- .../valesriegler/types/DeliveryStatus.java | 2 +- .../sbc/valesriegler/types/GroupData.java | 11 ++- 10 files changed, 247 insertions(+), 34 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryDetailsModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryOrdersModel.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java index fcbfe20..f3864f1 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java @@ -38,7 +38,6 @@ class GroupCreationHandler { chooseGroupSizePanel.setVisible(true); creationPanel.remove(groupCreationPanel); creationPanel.repaint(); - createGroups(gc); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java index d52d883..e750ef4 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java @@ -28,7 +28,8 @@ public class GroupOverviewModel extends TableModel { private static final String PIZZAS = "Pizzas"; private static final String SIZE = "Size"; private static final String ID = "ID"; - private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE }; + private static final String PIZZERIA = "Pizzeria"; + private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE, PIZZERIA }; @Override @@ -62,6 +63,8 @@ public class GroupOverviewModel extends TableModel { return Util.pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas()); case STATE: return group.getGroupData().getState(); + case PIZZERIA: + return group.getGroupData().getPizzeriaId(); default: throw new RuntimeException(UNHANDLEDCOLUMN); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java index 0988a86..6e3c6d7 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java @@ -4,17 +4,13 @@ import java.util.List; import javax.swing.SwingUtilities; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.pizzeria.actions.TableNew; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.TablesOverviewModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.WaitersOfOrderModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.jms.JMSPizzeriaConnector; import at.ac.tuwien.sbc.valesriegler.types.Table; import at.ac.tuwien.sbc.valesriegler.xvsm.PizzeriaAgentXVSM; @@ -37,9 +33,12 @@ public class PizzeriaAgent { private GroupsOverviewModel groupModel; private TablesOverviewModel tablesModel; private WaitersOfOrderModel waitersModel; - private PizzasOfOrderModel pizzasModel; + private PizzasOfOrderModel pizzasOfOrderModel; + private DeliveryDetailsModel deliveryDetailsModel; + private PizzasOfOrderModel pizzasOfDeliveryModel; + private DeliveryOrdersModel deliveryOrdersModel; - private PizzeriaAgentXVSM xvsm; + private PizzeriaAgentXVSM xvsm; private JMSPizzeriaConnector jmspc; public static void main(String[] args) { @@ -119,7 +118,10 @@ public class PizzeriaAgent { groupModel = new GroupsOverviewModel(); tablesModel = new TablesOverviewModel(); waitersModel = new WaitersOfOrderModel(); - pizzasModel = new PizzasOfOrderModel(); + pizzasOfOrderModel = new PizzasOfOrderModel(); + deliveryOrdersModel = new DeliveryOrdersModel(); + deliveryDetailsModel = new DeliveryDetailsModel(); + pizzasOfDeliveryModel = new PizzasOfOrderModel(); } public static PizzeriaAgent getInstance() { @@ -130,6 +132,18 @@ public class PizzeriaAgent { return ordersModel; } + public DeliveryOrdersModel getDeliveryOrdersModel() { + return deliveryOrdersModel; + } + + public DeliveryDetailsModel getDeliveryDetailsModel() { + return deliveryDetailsModel; + } + + public PizzasOfOrderModel getPizzasOfDeliveryModel() { + return pizzasOfDeliveryModel; + } + public GroupsOverviewModel getGroupModel() { return groupModel; } @@ -142,8 +156,8 @@ public class PizzeriaAgent { return waitersModel; } - public PizzasOfOrderModel getPizzasModel() { - return pizzasModel; + public PizzasOfOrderModel getPizzasOfOrderModel() { + return pizzasOfOrderModel; } public interface TablesCreatedHandler { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java index c56f7be..8ef5880 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java @@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent.TablesCreatedHandler; import at.ac.tuwien.sbc.valesriegler.types.GroupData; -import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.Table; /** @@ -54,7 +53,7 @@ public class PizzeriaFrame extends JFrame { JPanel wrapper = new JPanel(); - GridLayout wrapperLayout = new GridLayout(2, 2); + GridLayout wrapperLayout = new GridLayout(3, 2); wrapper.setLayout(wrapperLayout); // Create the tables overview @@ -63,6 +62,12 @@ public class PizzeriaFrame extends JFrame { // Create the waiting groups table overview initWaitingGroupsOverview(wrapper); + // Create the overview table of deliveries + JTable deliveryTable = initDeliveryOverview(wrapper); + + // Create the details table for the deliveries containing the pizza, waiter and driver information + initDeliveryDetails(wrapper, deliveryTable); + // Create the overview table of the orders JTable ordersTable = initOrdersOverview(wrapper); @@ -104,6 +109,57 @@ public class PizzeriaFrame extends JFrame { } + private void initDeliveryDetails(JPanel wrapper, JTable deliveryTable) { + JPanel detailWrapper = new JPanel(); + GridLayout wrapperLayout = new GridLayout(2, 1); + detailWrapper.setLayout(wrapperLayout); + + final JPanel detailsPanel = new JPanel(); + final JPanel pizzasPanel = new JPanel(); + Util.createTableInTitledPanel(detailsPanel, PizzeriaAgent.getInstance().getDeliveryDetailsModel(), ""); + Util.createTableInTitledPanel(pizzasPanel, PizzeriaAgent.getInstance().getPizzasOfDeliveryModel(), ""); + + /** + * Update the displayed order in the waiter and pizza detail tables when an + * order gets selected in the orders table + */ + deliveryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + ListSelectionModel lsm = (ListSelectionModel) e.getSource(); + int minIndex = lsm.getMinSelectionIndex(); + if (minIndex < 0) return; + + GroupData currentGroup = PizzeriaAgent.getInstance().getOrdersModel().getGroupOfRow(minIndex); + detailsPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION, currentGroup.getOrder().getId()))); + pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION, currentGroup.getOrder().getId()))); + PizzeriaAgent.getInstance().getWaitersModel().setCurrentGroup(currentGroup); + PizzeriaAgent.getInstance().getPizzasOfOrderModel().setCurrentOrder(currentGroup.getOrder()); + + detailsPanel.setVisible(true); + pizzasPanel.setVisible(true); + } + }); + + /* The PizzaModel and WaitersModel and their tables only show the selected entry in the orders table + When the table model of the orders model changes the PizzaModel and WaitersModel have to update, too */ + PizzeriaAgent.getInstance().getOrdersModel().addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + PizzeriaAgent.getInstance().getPizzasOfOrderModel().fireTableDataChanged(); + PizzeriaAgent.getInstance().getWaitersModel().fireTableDataChanged(); + } + }); + + detailWrapper.add(detailsPanel); + detailWrapper.add(pizzasPanel); + detailsPanel.setVisible(false); + pizzasPanel.setVisible(false); + + wrapper.add(detailWrapper); + + } + private void initOrdersDetails(JPanel wrapper, JTable ordersTable) { JPanel detailWrapper = new JPanel(); GridLayout wrapperLayout = new GridLayout(2, 1); @@ -112,7 +168,7 @@ public class PizzeriaFrame extends JFrame { final JPanel waitersPanel = new JPanel(); final JPanel pizzasPanel = new JPanel(); Util.createTableInTitledPanel(waitersPanel, PizzeriaAgent.getInstance().getWaitersModel(), ""); - Util.createTableInTitledPanel(pizzasPanel, PizzeriaAgent.getInstance().getPizzasModel(), ""); + Util.createTableInTitledPanel(pizzasPanel, PizzeriaAgent.getInstance().getPizzasOfOrderModel(), ""); /** * Update the displayed order in the waiter and pizza detail tables when an @@ -129,7 +185,7 @@ public class PizzeriaFrame extends JFrame { waitersPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION, currentGroup.getOrder().getId()))); pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION, currentGroup.getOrder().getId()))); PizzeriaAgent.getInstance().getWaitersModel().setCurrentGroup(currentGroup); - PizzeriaAgent.getInstance().getPizzasModel().setCurrentOrder(currentGroup.getOrder()); + PizzeriaAgent.getInstance().getPizzasOfOrderModel().setCurrentOrder(currentGroup.getOrder()); waitersPanel.setVisible(true); pizzasPanel.setVisible(true); @@ -141,7 +197,7 @@ public class PizzeriaFrame extends JFrame { PizzeriaAgent.getInstance().getOrdersModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { - PizzeriaAgent.getInstance().getPizzasModel().fireTableDataChanged(); + PizzeriaAgent.getInstance().getPizzasOfOrderModel().fireTableDataChanged(); PizzeriaAgent.getInstance().getWaitersModel().fireTableDataChanged(); } }); @@ -164,6 +220,15 @@ public class PizzeriaFrame extends JFrame { return orderTable; } + private JTable initDeliveryOverview(JPanel wrapper) { + JPanel deliveryPanel = new JPanel(); + JTable deliveryTable = Util.createTableInTitledPanel(deliveryPanel, PizzeriaAgent.getInstance().getDeliveryOrdersModel(), "Delivery Orders"); + + wrapper.add(deliveryPanel); + + return deliveryTable; + } + private void initWaitingGroupsOverview(JPanel wrapper) { JPanel tablePanel = new JPanel(); Util.createTableInTitledPanel(tablePanel, PizzeriaAgent.getInstance().getGroupModel(), "Waiting groups"); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryDetailsModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryDetailsModel.java new file mode 100644 index 0000000..bbc33ce --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryDetailsModel.java @@ -0,0 +1,46 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.common.Util; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; + +public class DeliveryDetailsModel extends TableModel { + private static final String WAITER_ID = "Waiter ID"; + private static final String DRIVER_ID = "Driver ID"; + private static final String[] COLUMNS = new String[] {WAITER_ID, DRIVER_ID}; + + protected DeliveryGroupData groupData; + + public void setCurrentDelivery(DeliveryGroupData groupData) { + this.groupData = groupData; + + fireTableDataChanged(); + } + + @Override + public int getRowCount() { + return groupData == null ? 0 : 1; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + if (rowIndex > 0) + return null; + + String wantedColumn = COLUMNS[columnIndex]; + switch (wantedColumn) { + case WAITER_ID: + return Util.getId(groupData.getWaiterIdOfOrder()); + case DRIVER_ID: + return Util.getId(groupData.getDriverId()); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + + @Override + protected String[] getColumns() { + return COLUMNS; + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryOrdersModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryOrdersModel.java new file mode 100644 index 0000000..fedbe7d --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryOrdersModel.java @@ -0,0 +1,49 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; +import at.ac.tuwien.sbc.valesriegler.types.Order; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class DeliveryOrdersModel extends TableModel { + private static final Logger log = LoggerFactory.getLogger(DeliveryOrdersModel.class); + + private static final String ID = "Delivery ID"; + private static final String DELIVERY_ADDRESS = "Address"; + private static final String STATUS = "Status"; + private static final String LOAD_BALANCER_ID = "Moved by"; + private static final String ORIGINAL_PIZZERIA = "Moved from"; + + private static final String[] COLUMNS = new String[] { ID, DELIVERY_ADDRESS, STATUS, LOAD_BALANCER_ID, ORIGINAL_PIZZERIA }; + + @Override + protected String[] getColumns() { + return COLUMNS; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + List values = new ArrayList<>(items.values()); + DeliveryGroupData group = values.get(rowIndex); + Order order = group.getOrder(); + String wantedColumn = COLUMNS[columnIndex]; + switch (wantedColumn) { + case ID: + return order.getId(); + case DELIVERY_ADDRESS: + return group.getAddress(); + case STATUS: + return group.getDeliveryStatus(); + case LOAD_BALANCER_ID: + return group.getLoadBalancerId(); + case ORIGINAL_PIZZERIA: + return group.getOriginalPizzeriaId(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); + } + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java index 2c17b8a..983c1c0 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java @@ -32,11 +32,6 @@ public class WaitersOfOrderModel extends TableModel { String wantedColumn = COLUMNS[columnIndex]; switch (wantedColumn) { - // case TABLE_ASSIGNMENT : return - // currentOrder.getWaiterIdOfTableAssignment(); - // case ORDER : return currentOrder.getWaiterIdOfOrder(); - // case SERVING : return currentOrder.getWaiterIdOfServing(); - // case PAYMENT : return currentOrder.getWaiterIdOfPayment(); case TABLE_ASSIGNMENT: return Util.getId(groupData.getTableWaiter()); case ORDER: diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java index a6965e2..1ad794b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java @@ -15,9 +15,17 @@ public class DeliveryGroupData implements Serializable, HasId { private Integer id; private Order order; private String address; - private DeliveryStatus deliveryStatus; - private Integer pizzeriaId; + private DeliveryStatus deliveryStatus = DeliveryStatus.START; + private String pizzeriaId; + private Integer waiterIdOfOrder; + private Integer driverId; + + /** + * These fields are set only when the delivery order was shifted by a load balancer from one pizzeria to another + */ + private Integer loadBalancerId; + private String originalPizzeriaId; public DeliveryGroupData(int id) { this.id = id; @@ -39,6 +47,32 @@ public class DeliveryGroupData implements Serializable, HasId { return address; } + public String getOriginalPizzeriaId() { + return originalPizzeriaId; + } + + public Integer getDriverId() { + return driverId; + } + + public void setDriverId(Integer driverId) { + this.driverId = driverId; + } + + public Integer getWaiterIdOfOrder() { + return waiterIdOfOrder; + } + + public void setWaiterIdOfOrder(Integer waiterIdOfOrder) { + this.waiterIdOfOrder = waiterIdOfOrder; + } + + + public void setOriginalPizzeriaId(String originalPizzeriaId) { + this.originalPizzeriaId = originalPizzeriaId; + } + + public void setAddress(String address) { this.address = address; } @@ -51,11 +85,20 @@ public class DeliveryGroupData implements Serializable, HasId { this.deliveryStatus = deliveryStatus; } - public int getPizzeriaId() { - return Util.getIntSafe(pizzeriaId); + public int getLoadBalancerId() { + return Util.getIntSafe(loadBalancerId); + } + + public void setLoadBalancerId(Integer loadBalancerId) { + this.loadBalancerId = loadBalancerId; + } + + + public String getPizzeriaId() { + return pizzeriaId; } - public void setPizzeriaId(Integer pizzeriaId) { + public void setPizzeriaId(String pizzeriaId) { this.pizzeriaId = pizzeriaId; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.java index 607c718..5348feb 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.java @@ -4,5 +4,5 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; public enum DeliveryStatus implements Serializable { - ORDERED, DELIVERED, PAID; + ORDERED, IS_DELIVERED, DELIVERED, PAID, DELIVERY_FAILED, START; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java index ac6f039..27f40b0 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java @@ -33,10 +33,9 @@ public class GroupData implements Serializable, HasId { private Integer orderWaiter; private Integer servingWaiter; private Integer payingWaiter; - private Integer pizzeriaId; + private String pizzeriaId; - - public GroupData() { + public GroupData() { } @@ -68,11 +67,11 @@ public class GroupData implements Serializable, HasId { return Util.getIntSafe(servingWaiter); } - public int getPizzeriaId() { - return Util.getIntSafe(pizzeriaId); + public String getPizzeriaId() { + return pizzeriaId; } - public void setPizzeriaId(Integer pizzeriaId) { + public void setPizzeriaId(String pizzeriaId) { this.pizzeriaId = pizzeriaId; } -- 2.43.0