From 6512b1bff4e97b2cfda407ad53fbaee35ab92f81 Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Mon, 6 May 2013 16:19:17 +0200 Subject: [PATCH] Change the pizzeria models so that they display (more) correct values --- .../tuwien/sbc/valesriegler/common/Util.java | 2 +- .../pizzeria/gui/PizzeriaFrame.java | 19 +++++++------- .../gui/tablemodels/OrdersOverviewModel.java | 14 +++++----- .../tablemodels/TableModelOfSingleOrder.java | 19 -------------- .../gui/tablemodels/WaitersOfOrderModel.java | 26 +++++++++++++++---- .../sbc/valesriegler/xvsm/XVSMConnector.java | 1 + 6 files changed, 41 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java index 8f214ec..1f0a1bc 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java @@ -12,7 +12,7 @@ import org.mozartspaces.core.MzsCoreException; public abstract class Util { // TODO: solve the switch between mom by command-line arguments - public static final boolean useJMS = true; + public static final boolean useJMS = false; public static final String TABLES_CONTAINER = "tables"; public static final String GROUPS_CONTAINER = "groups"; 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 0b01906..4ae943c 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 @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.TableModel; 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; @@ -97,8 +98,8 @@ public class PizzeriaFrame extends JFrame { return numberOfTables; } private void initModels() { - List orders = getOrdersTestData(); - PizzeriaAgent.getInstance().getOrdersModel().setItems(orders); +// List orders = getOrdersTestData(); + PizzeriaAgent.getInstance().getOrdersModel().setItems(new ArrayList()); // When the tables get created in the first place, the handler is informed int numberOfTables = getNumberOfTables(); @@ -127,11 +128,11 @@ public class PizzeriaFrame extends JFrame { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int minIndex = lsm.getMinSelectionIndex(); - Order currentOrder = PizzeriaAgent.getInstance().getOrdersModel().getOrderOfRow(minIndex); - waitersPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION, currentOrder.getId()))); - pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION, currentOrder.getId()))); - PizzeriaAgent.getInstance().getWaitersModel().setCurrentOrder(currentOrder); - PizzeriaAgent.getInstance().getPizzasModel().setCurrentOrder(currentOrder); + GroupData currentGroup = PizzeriaAgent.getInstance().getOrdersModel().getGroupOfRow(minIndex); + waitersPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION, currentGroup.getId()))); + pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION, currentGroup.getId()))); + PizzeriaAgent.getInstance().getWaitersModel().setCurrentGroup(currentGroup); + PizzeriaAgent.getInstance().getPizzasModel().setCurrentOrder(currentGroup.getOrder()); waitersPanel.setVisible(true); pizzasPanel.setVisible(true); @@ -213,10 +214,10 @@ public class PizzeriaFrame extends JFrame { // Order order2 = new Order(); // Order order3 = new Order(); // Order order4 = new Order(); - // + // order1.setWaiterIdOfOrder(4); // order2.setWaiterIdOfServing(2); - // + // List pizzas = new ArrayList<>(); // PizzaOrder pizzaOrder1 = new PizzaOrder(PizzaType.CARDINALE); // pizzaOrder1.setStatus(PizzaOrderStatus.DONE); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java index 60e3285..96e6729 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java @@ -4,9 +4,10 @@ import java.util.ArrayList; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.Order; -public class OrdersOverviewModel extends TableModel { +public class OrdersOverviewModel extends TableModel { private static final String ID = "Order ID"; private static final String TABLE_ID = "Table ID"; private static final String GROUP_ID = "Group ID"; @@ -16,14 +17,15 @@ public class OrdersOverviewModel extends TableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - List values = new ArrayList<>(items.values()); - Order order = values.get(rowIndex); + List values = new ArrayList<>(items.values()); + GroupData group = values.get(rowIndex); + Order order = group.getOrder(); String wantedColumn = COLUMNS[columnIndex]; switch (wantedColumn) { case ID: return order.getId(); - case TABLE_ID: // FIXME: tableid! - return new Integer(0); + case TABLE_ID: + return group.getTable().getId() ; case GROUP_ID: return order.getGroupId(); case STATUS: @@ -33,7 +35,7 @@ public class OrdersOverviewModel extends TableModel { } } - public Order getOrderOfRow(int rowIndex) { + public GroupData getGroupOfRow(int rowIndex) { return new ArrayList<>(items.values()).get(rowIndex); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java deleted file mode 100644 index 9f436c1..0000000 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java +++ /dev/null @@ -1,19 +0,0 @@ -package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; - -import at.ac.tuwien.sbc.valesriegler.common.TableModel; -import at.ac.tuwien.sbc.valesriegler.types.Order; - -public abstract class TableModelOfSingleOrder extends TableModel { - protected Order currentOrder; - - public void setCurrentOrder(Order currentOrder) { - this.currentOrder = currentOrder; - - fireTableDataChanged(); - } - - @Override - public int getRowCount() { - return currentOrder == null ? 0 : 1; - } -} 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 f8d16c5..779cc9c 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 @@ -1,13 +1,29 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; -public class WaitersOfOrderModel extends TableModelOfSingleOrder { + +public class WaitersOfOrderModel extends TableModel { private static final String TABLE_ASSIGNMENT = "Table Assignment"; private static final String ORDER = "Order"; private static final String SERVING = "Serving"; private static final String PAYMENT = "Payment"; private static final String[] COLUMNS = new String[] { TABLE_ASSIGNMENT, ORDER, SERVING, PAYMENT }; + protected GroupData groupData; + + public void setCurrentGroup(GroupData 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) @@ -21,13 +37,13 @@ public class WaitersOfOrderModel extends TableModelOfSingleOrder { // case SERVING : return currentOrder.getWaiterIdOfServing(); // case PAYMENT : return currentOrder.getWaiterIdOfPayment(); case TABLE_ASSIGNMENT: - return new Integer(-2); + return groupData.getTableWaiter(); case ORDER: - return new Integer(-2); + return groupData.getOrderWaiter(); case SERVING: - return new Integer(-2); + return groupData.getServingWaiter(); case PAYMENT: - return new Integer(-2); + return groupData.getPayingWaiter(); default: throw new RuntimeException(UNHANDLEDCOLUMN); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java index 6f76348..6c4bab5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java @@ -84,6 +84,7 @@ public class XVSMConnector { private void handleSpaceErrorAndTerminate(Exception e) { log.error(e.getMessage()); + e.printStackTrace(); System.exit(1); } -- 2.43.0