com.starbucks.apps.StarbucksBarista.java Source code

Java tutorial

Introduction

Here is the source code for com.starbucks.apps.StarbucksBarista.java

Source

/*
 *  Copyright 2012 WSO2
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.starbucks.apps;

import java.io.IOException;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.text.DefaultCaret;
import org.apache.http.HttpResponse;

/**
 * Starbucks barista view
 */
public class StarbucksBarista extends javax.swing.JFrame {

    private static final int STATE_READY = 0;
    private static final int STATE_ITEM_PREPARED = 1;
    private static final int STATE_PAYMENT_RECEIVED = 2;

    private String url;
    private int state = STATE_READY;

    /** Creates new form StarbucksBarista */
    public StarbucksBarista(String host, int port) {
        this.url = "http://" + host + ":" + port;
        System.out.println("Using ESB URL: " + url);

        initComponents();
        ((DefaultCaret) statusArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
        ((DefaultCaret) requestView.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
        ((DefaultCaret) responseView.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
        setApplicationState(STATE_READY);
    }

    private void setApplicationState(int state) {
        this.state = state;

        switch (state) {
        case STATE_READY:
            customerField.setText("");
            amountField.setText("");
            cardField.setText("");
            orderIdField.setText("");
            statusArea.setText("");
            requestView.setText("");
            responseView.setText("");
            findButton.setEnabled(true);
            prepareButton.setEnabled(false);
            viewButton.setEnabled(false);
            verifyButton.setEnabled(false);
            deliverButton.setEnabled(false);
            resetButton.setEnabled(false);
            ordersList.setModel(new DefaultListModel());
            ordersList.setEnabled(true);
            break;

        case STATE_ITEM_PREPARED:
            findButton.setEnabled(false);
            prepareButton.setEnabled(false);
            viewButton.setEnabled(false);
            verifyButton.setEnabled(true);
            deliverButton.setEnabled(false);
            ordersList.setEnabled(false);
            resetButton.setEnabled(false);
            break;

        case STATE_PAYMENT_RECEIVED:
            findButton.setEnabled(false);
            prepareButton.setEnabled(false);
            viewButton.setEnabled(false);
            verifyButton.setEnabled(false);
            deliverButton.setEnabled(true);
            ordersList.setEnabled(false);
            resetButton.setEnabled(false);
            break;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ordersList = new javax.swing.JList();
        findButton = new javax.swing.JButton();
        prepareButton = new javax.swing.JButton();
        viewButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        orderIdField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        customerField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        amountField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cardField = new javax.swing.JTextField();
        verifyButton = new javax.swing.JButton();
        deliverButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        statusArea = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        requestView = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        responseView = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Starbucks Barista");
        setResizable(false);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Pending Orders"));
        jLabel1.setText("Orders");

        ordersList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                ordersListValueChanged(evt);
            }
        });

        jScrollPane1.setViewportView(ordersList);

        findButton.setText("Find");
        findButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findButtonActionPerformed(evt);
            }
        });

        prepareButton.setText("Make");
        prepareButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prepareButtonActionPerformed(evt);
            }
        });

        viewButton.setText("View");
        viewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225,
                                        Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(viewButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(prepareButton, javax.swing.GroupLayout.Alignment.TRAILING, 0,
                                                0, Short.MAX_VALUE)
                                        .addComponent(findButton, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)))
                        .addComponent(jLabel1)).addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(findButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(prepareButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(viewButton))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 105,
                                        Short.MAX_VALUE))
                        .addContainerGap()));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Order Delivery"));
        jLabel2.setText("Order");

        orderIdField.setEditable(false);

        jLabel3.setText("Customer");

        customerField.setEditable(false);

        jLabel4.setText("Amount");

        amountField.setEditable(false);

        jLabel5.setText("Card No");

        cardField.setEditable(false);

        verifyButton.setText("Verify");
        verifyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verifyButtonActionPerformed(evt);
            }
        });

        deliverButton.setText("Deliver");
        deliverButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deliverButtonActionPerformed(evt);
            }
        });

        resetButton.setText("Reset");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout
                .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                                        jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel4).addComponent(jLabel3).addComponent(jLabel2))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel2Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                                .addComponent(amountField,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(jLabel5)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(cardField,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 172,
                                                                        Short.MAX_VALUE))
                                                        .addComponent(customerField,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 316,
                                                                Short.MAX_VALUE)
                                                        .addComponent(orderIdField,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 316,
                                                                Short.MAX_VALUE))
                                                .addContainerGap())
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(verifyButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(deliverButton, javax.swing.GroupLayout.DEFAULT_SIZE, 78,
                                                Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(resetButton).addGap(173, 173, 173)))));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(orderIdField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(customerField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(amountField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5).addComponent(cardField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(verifyButton).addComponent(deliverButton).addComponent(resetButton))
                        .addContainerGap()));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Status"));
        statusArea.setColumns(20);
        statusArea.setEditable(false);
        statusArea.setRows(5);
        jScrollPane2.setViewportView(statusArea);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                        .addContainerGap()));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Message Tracer"));
        requestView.setColumns(20);
        requestView.setEditable(false);
        requestView.setRows(5);
        jScrollPane3.setViewportView(requestView);

        responseView.setColumns(20);
        responseView.setEditable(false);
        responseView.setRows(5);
        jScrollPane4.setViewportView(responseView);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 407,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE))
                        .addContainerGap()));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/starbucks/apps/starbucks.png")));
        jLabel6.setText("jLabel6");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 86,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        setApplicationState(STATE_READY);
    }//GEN-LAST:event_resetButtonActionPerformed

    private void deliverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deliverButtonActionPerformed
        Order order = (Order) ordersList.getSelectedValue();
        if (order != null) {
            try {
                HttpInvocationContext context = HttpUtils
                        .doDelete(this.url + "/barista/order/" + order.getOrderId());
                requestView.setText(context.getRequestData());
                responseView.setText(context.getResponseData());
                if (context.getHttpResponse().getStatusLine().getStatusCode() == 200) {
                    statusArea.setText("Order removed successfully");
                    deliverButton.setEnabled(false);
                    resetButton.setEnabled(true);
                } else {
                    statusArea.setText("Order removal operation failed");
                }
            } catch (IOException e) {
                handleError("Error while deleting order", e);
            }
        }
    }//GEN-LAST:event_deliverButtonActionPerformed

    private void verifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verifyButtonActionPerformed
        Order order = (Order) ordersList.getSelectedValue();
        if (order != null) {
            try {
                HttpInvocationContext context = HttpUtils.doGet(this.url + "/payment/order/" + order.getOrderId());
                HttpResponse response = context.getHttpResponse();
                requestView.setText(context.getRequestData());
                responseView.setText(context.getResponseData());
                if (response.getStatusLine().getStatusCode() == 200) {
                    Payment payment = new Payment(order.getOrderId(), context.getResponsePayload());
                    customerField.setText(payment.getName());
                    amountField.setText("$ " + payment.getAmount());
                    cardField.setText(payment.getCardNo());
                    statusArea.setText("Payment details retrieved\n" + payment);
                    setApplicationState(STATE_PAYMENT_RECEIVED);
                } else {
                    statusArea.setText("Order still not paid for");
                }
            } catch (IOException e) {
                handleError("Error while retrieving order details", e);
            }
        }
    }//GEN-LAST:event_verifyButtonActionPerformed

    private void prepareButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prepareButtonActionPerformed
        Order order = (Order) ordersList.getSelectedValue();
        if (order != null) {
            StringBuilder payloadBuilder = new StringBuilder("<entry>")
                    .append("<order xmlns=\"http://starbucks.example.org\">").append("<drink>")
                    .append(order.getDrink()).append("</drink>");
            if (order.getAdditions() != null) {
                payloadBuilder.append("<additions>" + order.getAdditions() + "</additions>");
            }
            payloadBuilder.append("<cost>").append(order.getCost()).append("</cost>")
                    .append("<status>preparing</status>").append("</order>")
                    .append("<link type=\"application/atom+xml\" rel=\"edit\" href=\"" + this.url
                            + "/barista/order/" + order.getOrderId() + "\" />")
                    .append("</entry>");
            String payload = XmlUtils.prettyPrint(payloadBuilder.toString());

            try {
                HttpInvocationContext context = HttpUtils.doPut(payload, "application/atom+xml",
                        url + "/barista/order/" + order.getOrderId());
                requestView.setText(context.getRequestData());
                responseView.setText(context.getResponseData());
                statusArea.setText("Drink prepared");
                setApplicationState(STATE_ITEM_PREPARED);
                orderIdField.setText(order.getOrderId());
            } catch (IOException e) {
                handleError("Error while preparing the drink", e);
            }
        }
    }//GEN-LAST:event_prepareButtonActionPerformed

    private void viewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewButtonActionPerformed
        Order order = (Order) ordersList.getSelectedValue();
        if (order != null) {
            try {
                HttpInvocationContext context = HttpUtils.doGet(this.url + "/order/" + order.getOrderId());
                requestView.setText(context.getRequestData());
                responseView.setText(context.getResponseData());
                Order orderReview = new Order(order.getOrderId(), context.getResponsePayload());
                statusArea.setText("Order details retrieved\n" + orderReview);
            } catch (IOException e) {
                handleError("Error while retrieving order details", e);
            }
        }
    }//GEN-LAST:event_viewButtonActionPerformed

    private void ordersListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ordersListValueChanged
        JList list = (JList) evt.getSource();
        Order order = (Order) list.getSelectedValue();
        if (order != null) {
            viewButton.setEnabled(true);
            prepareButton.setEnabled(true);
        }
    }//GEN-LAST:event_ordersListValueChanged

    private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
        setApplicationState(STATE_READY);
        try {
            HttpInvocationContext context = HttpUtils.doGet(this.url + "/orders");
            requestView.setText(context.getRequestData());
            responseView.setText(context.getResponseData());
            Feed feed = new Feed(context.getResponsePayload());
            if (feed.getOrders() != null) {
                for (Order order : feed.getOrders()) {
                    ((DefaultListModel) ordersList.getModel()).addElement(order);
                }
            }
            statusArea.setText("Pending order list retreived\n" + feed);
        } catch (IOException e) {
            handleError("Error while retrieving pending order list", e);
        }

    }//GEN-LAST:event_findButtonActionPerformed

    private void handleError(String msg, Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField amountField;
    private javax.swing.JTextField cardField;
    private javax.swing.JTextField customerField;
    private javax.swing.JButton deliverButton;
    private javax.swing.JButton findButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField orderIdField;
    private javax.swing.JList ordersList;
    private javax.swing.JButton prepareButton;
    private javax.swing.JTextArea requestView;
    private javax.swing.JButton resetButton;
    private javax.swing.JTextArea responseView;
    private javax.swing.JTextArea statusArea;
    private javax.swing.JButton verifyButton;
    private javax.swing.JButton viewButton;
    // End of variables declaration//GEN-END:variables

}