From 13d01e0bdcc1e571c5cba0d6645cf75742079cb8 Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Mon, 27 May 2013 18:16:32 +0200 Subject: [PATCH] Create DeliveryGroup, DeliveryGroupData, DeliveryStatus. Add Deliveries overview table and model to Group GUI --- .../tuwien/sbc/valesriegler/common/Util.java | 61 +++++- .../sbc/valesriegler/group/DeliveryGroup.java | 31 +++ .../sbc/valesriegler/group/GroupAgent.java | 181 +++++++++--------- .../sbc/valesriegler/group/GroupGUI.java | 2 +- .../group/gui/DeliveryOverviewModel.java | 50 +++++ .../valesriegler/group/gui/GroupFrame.java | 39 ++-- .../group/gui/GroupOverviewModel.java | 42 +--- .../pizzeria/gui/PizzeriaFrame.java | 59 +----- .../valesriegler/types/DeliveryGroupData.java | 56 ++++++ .../valesriegler/types/DeliveryStatus.java | 8 + .../sbc/valesriegler/types/GroupData.java | 45 ++--- 11 files changed, 338 insertions(+), 236 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/DeliveryGroup.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.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 78939f5..fe2bc4f 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 @@ -1,12 +1,12 @@ package at.ac.tuwien.sbc.valesriegler.common; +import java.awt.*; import java.net.URI; -import java.util.Collections; -import java.util.HashMap; +import java.util.*; import java.util.List; -import java.util.Map; -import java.util.Random; +import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; +import at.ac.tuwien.sbc.valesriegler.types.PizzaType; import org.mozartspaces.capi3.Coordinator; import org.mozartspaces.core.Capi; import org.mozartspaces.core.ContainerReference; @@ -16,6 +16,9 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.swing.*; +import javax.swing.border.TitledBorder; + public abstract class Util { private static final Logger log = LoggerFactory.getLogger(Util.class); @@ -84,4 +87,54 @@ public abstract class Util { return parsedId; } + public static JTable createTableInTitledPanel(JPanel wrapperPanel, TableModel model, String title) { + JTable table = new JTable(model); + wrapperPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.weightx = 1; + c.weighty = 1; + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.BOTH; + JScrollPane scrollPane = new JScrollPane(table); + + wrapperPanel.setBorder(new TitledBorder(title)); + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + wrapperPanel.add(scrollPane, c); + + return table; + } + + /** + * + * @return A display string for PizzaTypes. + *

+ * e.g. Cardinale, Cardinale, Margherita is displayed as + * "2xCARDINALE,1xMARGHERITA" + */ + public static String pizzaDisplay(List list) { + HashMap pizzaCount = new HashMap(); + for (PizzaOrder pizzaOrder : list) { + PizzaType pizzaType = pizzaOrder.getPizzaType(); + if (pizzaCount.containsKey(pizzaType)) { + pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1); + } else + pizzaCount.put(pizzaType, 1); + } + Set pizzaTypes = pizzaCount.keySet(); + StringBuilder sb = new StringBuilder(); + + boolean multiplePizzas = false; + for (PizzaType pizzaType : pizzaTypes) { + if (multiplePizzas) + sb.append(", "); + else + multiplePizzas = true; + + sb.append(pizzaCount.get(pizzaType) + "x"); + sb.append(pizzaType.toString()); + } + + return sb.toString(); + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/DeliveryGroup.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/DeliveryGroup.java new file mode 100644 index 0000000..f2b726d --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/DeliveryGroup.java @@ -0,0 +1,31 @@ +package at.ac.tuwien.sbc.valesriegler.group; + + +import at.ac.tuwien.sbc.valesriegler.common.HasId; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeliveryGroup implements Runnable, HasId { + private static final Logger log = LoggerFactory.getLogger(DeliveryGroup.class); + + private DeliveryGroupData deliveryGroupData; + + public DeliveryGroup(int id) { + this.deliveryGroupData = new DeliveryGroupData(id); + } + + public DeliveryGroupData getDeliveryGroupData() { + return deliveryGroupData; + } + + @Override + public int getId() { + return deliveryGroupData.getId(); + } + + @Override + public void run() { + //@jan you can use that like in at.ac.tuwien.sbc.valesriegler.group.Group if you need to... + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java index 9266222..7cf297d 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java @@ -1,104 +1,109 @@ package at.ac.tuwien.sbc.valesriegler.group; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.SwingUtilities; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import at.ac.tuwien.sbc.valesriegler.common.Util; +import at.ac.tuwien.sbc.valesriegler.group.gui.DeliveryOverviewModel; import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel; import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector; import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; /** * The Main class of the Group component. - *

+ *

* Start the communication and the group GUI: - * + * * @author Gregor Riegler * @author jan - * */ public class GroupAgent { - private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">"; - - private static final Logger log = LoggerFactory.getLogger(GroupAgent.class); - private GroupOverviewModel groupModel; - private AbstractGroupConnector groupconn; - private GroupAgentXVSM xvsm; - - public static GroupAgent groupAgent; - - public static void main(String[] args) { - if (args.length != 1) { - throw new IllegalArgumentException(USAGE); - } - - String mw = args[0]; - log.info("Middleware: " + mw); - - if ("JMS".equalsIgnoreCase(mw)) { - groupAgent = new GroupAgent(new JMSGroupConnector()); - Util.useJMS = true; - } else if ("XVSM".equalsIgnoreCase(mw)) { - // TODO: XVSM Connector? - Util.useJMS = false; - groupAgent = new GroupAgent(null); - } else { - throw new IllegalArgumentException(USAGE); - } - - SwingUtilities.invokeLater(new GroupGUI()); - } - - public GroupAgent(AbstractGroupConnector groupconn) { - groupModel = new GroupOverviewModel(); - if (Util.useJMS) { - this.groupconn = groupconn; - groupconn.init(); - } else { - xvsm = new GroupAgentXVSM(); - - xvsm.listenForTableAssigned(); - xvsm.listenForOrdersTaken(); - xvsm.listenForDeliveredOrders(); - xvsm.listenForPaymentRequest(); - xvsm.listenForPaymentDone(); - } - } - - public static GroupAgent getInstance() { - return groupAgent; - } - - public AbstractGroupConnector getGroupcomm() { - return groupconn; - } - - public GroupOverviewModel getGroupModel() { - return groupModel; - } - - public void onGroupsCreated(List newGroups) { - if (!Util.useJMS) { - List groupData = new ArrayList<>(); - - for (Group group : newGroups) { - groupData.add(group.getGroupData()); - } - xvsm.sendNewGroupsToSpace(groupData); - - log.info("New Groups were sent to the space"); - - // start the space group in a new thread - for (GroupData group : groupData) { - new Thread(new SpaceGroup(group.getId())).start(); - } - } - - } + private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">"; + + private static final Logger log = LoggerFactory.getLogger(GroupAgent.class); + private GroupOverviewModel groupModel; + private AbstractGroupConnector groupconn; + private DeliveryOverviewModel deliveryOverviewModel; + private GroupAgentXVSM xvsm; + + public static GroupAgent groupAgent; + + public static void main(String[] args) { + if (args.length != 1) { + throw new IllegalArgumentException(USAGE); + } + + String mw = args[0]; + log.info("Middleware: " + mw); + + if ("JMS".equalsIgnoreCase(mw)) { + groupAgent = new GroupAgent(new JMSGroupConnector()); + Util.useJMS = true; + } else if ("XVSM".equalsIgnoreCase(mw)) { + // TODO: XVSM Connector? + Util.useJMS = false; + groupAgent = new GroupAgent(null); + } else { + throw new IllegalArgumentException(USAGE); + } + + SwingUtilities.invokeLater(new GroupGUI()); + } + + public GroupAgent(AbstractGroupConnector groupconn) { + groupModel = new GroupOverviewModel(); + if (Util.useJMS) { + this.groupconn = groupconn; + groupconn.init(); + } else { + xvsm = new GroupAgentXVSM(); + + xvsm.listenForTableAssigned(); + xvsm.listenForOrdersTaken(); + xvsm.listenForDeliveredOrders(); + xvsm.listenForPaymentRequest(); + xvsm.listenForPaymentDone(); + } + } + + public static GroupAgent getInstance() { + return groupAgent; + } + + public AbstractGroupConnector getGroupcomm() { + return groupconn; + } + + public GroupOverviewModel getGroupModel() { + return groupModel; + } + + public DeliveryOverviewModel getDeliveryModel() { + return deliveryOverviewModel; + } + + public void onGroupsCreated(List newGroups) { + if (!Util.useJMS) { + List groupData = new ArrayList<>(); + + for (Group group : newGroups) { + groupData.add(group.getGroupData()); + } + xvsm.sendNewGroupsToSpace(groupData); + + log.info("New Groups were sent to the space"); + + // start the space group in a new thread + for (GroupData group : groupData) { + new Thread(new SpaceGroup(group.getId())).start(); + } + } + + } + + } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java index f99a01d..c3df848 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java @@ -5,7 +5,7 @@ import at.ac.tuwien.sbc.valesriegler.group.gui.GroupFrame; class GroupGUI implements Runnable { @Override public void run() { - GroupFrame frame = new GroupFrame(GroupAgent.getInstance().getGroupModel()); + GroupFrame frame = new GroupFrame(GroupAgent.getInstance().getGroupModel(), GroupAgent.getInstance().getDeliveryModel()); frame.pack(); frame.setVisible(true); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java new file mode 100644 index 0000000..8db2932 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java @@ -0,0 +1,50 @@ +package at.ac.tuwien.sbc.valesriegler.group.gui; + + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.common.Util; +import at.ac.tuwien.sbc.valesriegler.group.DeliveryGroup; +import at.ac.tuwien.sbc.valesriegler.group.Group; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class DeliveryOverviewModel extends TableModel { + private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); + + private static final String STATE = "State"; + private static final String PIZZAS = "Pizzas"; + private static final String ADDRESS = "Address"; + private static final String ID = "ID"; + private static final String[] COLUMNS = new String[] { ID, ADDRESS, PIZZAS, STATE }; + + + @Override + protected String[] getColumns() { + return COLUMNS; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + List values = new ArrayList<>(items.values()); + DeliveryGroup group = values.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch (wantedColumn) { + case ID: + int groupId = group.getId(); + return groupId; + case ADDRESS: + return group.getDeliveryGroupData().getAddress(); + case PIZZAS: + if (group.getDeliveryGroupData().getOrder() == null) + return "none"; + return Util.pizzaDisplay(group.getDeliveryGroupData().getOrder().getOrderedPizzas()); + case STATE: + return group.getDeliveryGroupData().getDeliveryStatus(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); + } + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java index b752e5b..d77de18 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java @@ -20,6 +20,7 @@ import javax.swing.ScrollPaneConstants; import javax.swing.SpinnerNumberModel; import javax.swing.border.TitledBorder; +import at.ac.tuwien.sbc.valesriegler.common.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,10 +41,10 @@ import at.ac.tuwien.sbc.valesriegler.types.PizzaType; public class GroupFrame extends JFrame { private static final Logger log = LoggerFactory.getLogger(GroupFrame.class); - public GroupFrame(GroupOverviewModel groupModel) { + public GroupFrame(GroupOverviewModel groupModel, DeliveryOverviewModel deliveryModel) { super("Groups"); JPanel wrapper = new JPanel(); - GridLayout wrapperLayout = new GridLayout(2, 1); + GridLayout wrapperLayout = new GridLayout(3, 1); wrapper.setLayout(wrapperLayout); // Create Wizard-like panel for the creation of groups @@ -52,11 +53,16 @@ public class GroupFrame extends JFrame { // Create the panel for the group overview table initGroupOverview(wrapper, groupModel); - setContentPane(wrapper); + // Create the panel for the deliveries overview table + initDeliveriesOverview(wrapper, deliveryModel); + + setContentPane(wrapper); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } - private void initGroupCreation(JPanel wrapper) { + + + private void initGroupCreation(JPanel wrapper) { final JPanel creationPanel = new JPanel(); final JPanel chooseGroupSizePanel = new JPanel(); JLabel creationLabel = new JLabel("How many members should the group have?"); @@ -93,24 +99,17 @@ public class GroupFrame extends JFrame { } private void initGroupOverview(JPanel wrapper, GroupOverviewModel groupModel) { - JPanel overviewPanel = new JPanel(new GridBagLayout()); - - JTable overviewTable = new JTable(groupModel); - JScrollPane scrollPane = new JScrollPane(overviewTable); - - overviewPanel.setBorder(new TitledBorder("Group Overview")); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.weightx = 1; - c.weighty = 1; - c.insets = new Insets(10, 10, 10, 10); - c.fill = GridBagConstraints.BOTH; - overviewPanel.add(scrollPane, c); - wrapper.add(overviewPanel); + JPanel tablePanel = new JPanel(); + Util.createTableInTitledPanel(tablePanel, groupModel, "Group Overview"); + wrapper.add(tablePanel); } + private void initDeliveriesOverview(JPanel wrapper, DeliveryOverviewModel deliveryModel) { + JPanel tablePanel = new JPanel(); + Util.createTableInTitledPanel(tablePanel, deliveryModel, "Deliveries Overview"); + wrapper.add(tablePanel); + } + /** * Handles the Wizard-like creation of groups. *

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 2d3da5c..d52d883 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 @@ -1,9 +1,7 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,9 +11,6 @@ import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.GroupState; -import at.ac.tuwien.sbc.valesriegler.types.Order; -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; import at.ac.tuwien.sbc.valesriegler.types.Table; /** @@ -64,7 +59,7 @@ public class GroupOverviewModel extends TableModel { case PIZZAS: if (group.getGroupData().getOrder() == null) return "none"; - return pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas()); + return Util.pizzaDisplay(group.getGroupData().getOrder().getOrderedPizzas()); case STATE: return group.getGroupData().getState(); default: @@ -72,40 +67,7 @@ public class GroupOverviewModel extends TableModel { } } - /** - * - * @return A display string for PizzaTypes. - *

- * e.g. Cardinale, Cardinale, Margherita is displayed as - * "2xCARDINALE,1xMARGHERITA" - */ - private String pizzaDisplay(List list) { - HashMap pizzaCount = new HashMap(); - for (PizzaOrder pizzaOrder : list) { - PizzaType pizzaType = pizzaOrder.getPizzaType(); - if (pizzaCount.containsKey(pizzaType)) { - pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1); - } else - pizzaCount.put(pizzaType, 1); - } - Set pizzaTypes = pizzaCount.keySet(); - StringBuilder sb = new StringBuilder(); - - boolean multiplePizzas = false; - for (PizzaType pizzaType : pizzaTypes) { - if (multiplePizzas) - sb.append(", "); - else - multiplePizzas = true; - - sb.append(pizzaCount.get(pizzaType) + "x"); - sb.append(pizzaType.toString()); - } - - return sb.toString(); - } - - @Override + @Override public void addItems(List newItems) { log.info("addItems()"); super.addItems(newItems); 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 4541afa..c56f7be 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 @@ -3,7 +3,6 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; -import java.awt.Insets; import java.util.ArrayList; import java.util.List; @@ -11,20 +10,18 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; import javax.swing.border.TitledBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; +import at.ac.tuwien.sbc.valesriegler.common.Util; import org.slf4j.Logger; 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; @@ -98,7 +95,6 @@ public class PizzeriaFrame extends JFrame { return numberOfTables; } private void initModels() { -// List orders = getOrdersTestData(); PizzeriaAgent.getInstance().getOrdersModel().setItems(new ArrayList()); // When the tables get created in the first place, the handler is informed @@ -115,8 +111,8 @@ public class PizzeriaFrame extends JFrame { final JPanel waitersPanel = new JPanel(); final JPanel pizzasPanel = new JPanel(); - createTableInTitledPanel(waitersPanel, PizzeriaAgent.getInstance().getWaitersModel(), ""); - createTableInTitledPanel(pizzasPanel, PizzeriaAgent.getInstance().getPizzasModel(), ""); + Util.createTableInTitledPanel(waitersPanel, PizzeriaAgent.getInstance().getWaitersModel(), ""); + Util.createTableInTitledPanel(pizzasPanel, PizzeriaAgent.getInstance().getPizzasModel(), ""); /** * Update the displayed order in the waiter and pizza detail tables when an @@ -161,7 +157,7 @@ public class PizzeriaFrame extends JFrame { private JTable initOrdersOverview(JPanel wrapper) { JPanel tablePanel = new JPanel(); - JTable orderTable = createTableInTitledPanel(tablePanel, PizzeriaAgent.getInstance().getOrdersModel(), "Orders"); + JTable orderTable = Util.createTableInTitledPanel(tablePanel, PizzeriaAgent.getInstance().getOrdersModel(), "Orders"); wrapper.add(tablePanel); @@ -170,7 +166,7 @@ public class PizzeriaFrame extends JFrame { private void initWaitingGroupsOverview(JPanel wrapper) { JPanel tablePanel = new JPanel(); - createTableInTitledPanel(tablePanel, PizzeriaAgent.getInstance().getGroupModel(), "Waiting groups"); + Util.createTableInTitledPanel(tablePanel, PizzeriaAgent.getInstance().getGroupModel(), "Waiting groups"); wrapper.add(tablePanel); } @@ -179,7 +175,7 @@ public class PizzeriaFrame extends JFrame { JPanel scrollPanePanel = new JPanel(new GridBagLayout()); final JLabel freeTablesLabel = new JLabel(getNumberOfFreeTables()); scrollPanePanel.add(freeTablesLabel, new GridBagConstraints()); - createTableInTitledPanel(scrollPanePanel, PizzeriaAgent.getInstance().getTablesModel(), "Tables"); + Util.createTableInTitledPanel(scrollPanePanel, PizzeriaAgent.getInstance().getTablesModel(), "Tables"); PizzeriaAgent.getInstance().getTablesModel() .addTableModelListener(new TableModelListener() { @@ -197,49 +193,6 @@ public class PizzeriaFrame extends JFrame { wrapper.add(scrollPanePanel); } - private JTable createTableInTitledPanel(JPanel wrapperPanel, TableModel model, String title) { - JTable table = new JTable(model); - wrapperPanel.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.weightx = 1; - c.weighty = 1; - c.insets = new Insets(10, 10, 10, 10); - c.fill = GridBagConstraints.BOTH; - JScrollPane scrollPane = new JScrollPane(table); - - wrapperPanel.setBorder(new TitledBorder(title)); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - wrapperPanel.add(scrollPane, c); - - return table; - } - - /** - * not necessary in production - */ - private List getOrdersTestData() { // TODO: useful way to get data. - List orders = new ArrayList<>(); - // Order order1 = new Order(); - // 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); - // pizzas.add(pizzaOrder1); - // order1.setPizzaOrders(pizzas); - - // orders.add(order1); - // orders.add(order2); - // orders.add(order3); - // orders.add(order4); - return orders; - } private String getNumberOfFreeTables() { return String.format(FREE_TABLES, PizzeriaAgent.getInstance().getTablesModel().getNumberOfFreeTables()); 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 new file mode 100644 index 0000000..b5ef986 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java @@ -0,0 +1,56 @@ +package at.ac.tuwien.sbc.valesriegler.types; + +import at.ac.tuwien.sbc.valesriegler.common.HasId; +import at.ac.tuwien.sbc.valesriegler.common.Util; +import org.mozartspaces.capi3.Queryable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +@Queryable(autoindex = true) +public class DeliveryGroupData implements Serializable, HasId { + private static final Logger log = LoggerFactory.getLogger(GroupData.class); + + private Integer id; + private Order order; + private String address; + private DeliveryStatus deliveryStatus; + + public DeliveryGroupData(int id) { + this.id = id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public DeliveryStatus getDeliveryStatus() { + return deliveryStatus; + } + + public void setDeliveryStatus(DeliveryStatus deliveryStatus) { + this.deliveryStatus = deliveryStatus; + } + + @Override + public int getId() { + return Util.getIntSafe(id); + } +} 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 new file mode 100644 index 0000000..607c718 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryStatus.java @@ -0,0 +1,8 @@ +package at.ac.tuwien.sbc.valesriegler.types; + + +import java.io.Serializable; + +public enum DeliveryStatus implements Serializable { + ORDERED, DELIVERED, PAID; +} 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 76c68d3..29cfc32 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 @@ -34,9 +34,7 @@ public class GroupData implements Serializable, HasId { private Integer servingWaiter; private Integer payingWaiter; - @Deprecated - private List pizzas = new ArrayList(); - + public GroupData() { } @@ -65,16 +63,6 @@ public class GroupData implements Serializable, HasId { return Util.getIntSafe(payingWaiter); } - @Deprecated - public List getPizzas() { - return pizzas; - } - - @Deprecated - public int getPizzaWaiter() { - return servingWaiter; - } - public int getServingWaiter() { return Util.getIntSafe(servingWaiter); } @@ -96,7 +84,6 @@ public class GroupData implements Serializable, HasId { } public void setOrder(Order order) { -// order.setGroupId(Util.getIntSafe(id)); this.order = order; } @@ -108,16 +95,6 @@ public class GroupData implements Serializable, HasId { this.payingWaiter = payingWaiter; } - @Deprecated - public void setPizzas(List pizzas) { - this.pizzas = pizzas; - } - - @Deprecated - public void setPizzaWaiter(int pizzaWaiter) { - servingWaiter = pizzaWaiter; - } - public void setServingWaiter(int servingWaiter) { this.servingWaiter = servingWaiter; } @@ -138,10 +115,18 @@ public class GroupData implements Serializable, HasId { this.tableWaiter = tableWaiter; } - @Override - public String toString() { - return "GroupData [id=" + id + ", state=" + state + ", size=" + size + ", table=" + table + ", tableWaiter=" - + tableWaiter + ", order=" + order + ", orderWaiter=" + orderWaiter + ", servingWaiter=" + servingWaiter - + ", payingWaiter=" + payingWaiter + ", pizzas=" + pizzas + "]"; - } + @Override + public String toString() { + return "GroupData{" + + "id=" + id + + ", state=" + state + + ", size=" + size + + ", table=" + table + + ", tableWaiter=" + tableWaiter + + ", order=" + order + + ", orderWaiter=" + orderWaiter + + ", servingWaiter=" + servingWaiter + + ", payingWaiter=" + payingWaiter + + '}'; + } } -- 2.43.0