home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / CustomerFrame.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  22.2 KB  |  500 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20.  
  21. //Title:        Cliffhanger Adventure Gear
  22. //Version:      
  23. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  24. //Author:       Application Methods, Inc.
  25. //Description:  Cliffhanger Adventure Gear order entry system
  26.  
  27. package borland.reference.cliffhanger;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import borland.jbcl.layout.*;
  32. import borland.jbcl.control.*;
  33. import borland.sql.dataset.*;
  34. import borland.jbcl.dataset.*;
  35. import java.util.*;
  36.  
  37. /**
  38.  * CustomerFrame implements the Customer Form that is used to maintain
  39.  * Customer records. This form allows users to view or update
  40.  * existing customers, or enter new customers. A standard navigation control
  41.  * is used to allow for record browsing. A master-detail relationship between
  42.  * customers and orders is used to display a list of orders placed by each
  43.  * customer.
  44.  *
  45.  * <P>
  46.  * This class employs the Singleton pattern to ensure that the class has only
  47.  * one instance. You can access the singleton instance by calling the
  48.  * getCustomerFrame method.
  49.  */
  50. public class CustomerFrame extends DecoratedFrame {
  51.   private static DataModule1 dm = DataModule1.getDataModule();
  52.  
  53.   private static CustomerFrame myCustomerFrame;
  54.   private QueryDataSet qdsCustomer;
  55.   private QueryDataSet qdsCustOrder;
  56.   BevelPanel pnlCustomerInfo = new BevelPanel();
  57.   BevelPanel pnlOrders = new BevelPanel();
  58.   BevelPanel pnlToolBar = new BevelPanel();
  59.   BevelPanel pnlMain = new BevelPanel();
  60.   BorderLayout borderLayout1 = new BorderLayout();
  61.   BorderLayout borderLayout2 = new BorderLayout();
  62.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  63.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  64.   NavigatorControl navigatorControl1 = new NavigatorControl();
  65.   GridControl gridControl1 = new GridControl();
  66.   FieldControl txtFirstName = new FieldControl();
  67.   FieldControl txtMI = new FieldControl();
  68.   FieldControl txtLastName = new FieldControl();
  69.   FieldControl txtAddr1 = new FieldControl();
  70.   FieldControl txtAddr2 = new FieldControl();
  71.   FieldControl txtCity = new FieldControl();
  72.   FieldControl txtState = new FieldControl();
  73.   FieldControl txtPostalCode = new FieldControl();
  74.   FieldControl txtCountry = new FieldControl();
  75.   FieldControl txtPhone = new FieldControl();
  76.   FieldControl txtFax = new FieldControl();
  77.   FieldControl txtEmail = new FieldControl();
  78.   LabelControl lblCustomerID = new LabelControl();
  79.   LabelControl labelControl1 = new LabelControl();
  80.   LabelControl labelControl2 = new LabelControl();
  81.   LabelControl labelControl3 = new LabelControl();
  82.   LabelControl labelControl4 = new LabelControl();
  83.   LabelControl labelControl5 = new LabelControl();
  84.   LabelControl labelControl6 = new LabelControl();
  85.   LabelControl labelControl7 = new LabelControl();
  86.   LabelControl labelControl8 = new LabelControl();
  87.   LabelControl labelControl9 = new LabelControl();
  88.   LabelControl labelControl10 = new LabelControl();
  89.   LabelControl labelControl11 = new LabelControl();
  90.   LabelControl labelControl12 = new LabelControl();
  91.   LabelControl lblOrders = new LabelControl();
  92.   StatusBar statusBar1 = new StatusBar();
  93.   ButtonControl btnViewOrder = new ButtonControl();
  94.   ButtonControl btnClose = new ButtonControl();
  95.   ButtonControl btnNewOrder = new ButtonControl();
  96.   BevelPanel pnlOrderButtons = new BevelPanel();
  97.   FlowLayout flowLayout1 = new FlowLayout();
  98.   ImageControl imageControl1 = new ImageControl();
  99.   GridBagLayout gridBagLayout3 = new GridBagLayout();
  100.   ResourceBundle res = java.util.ResourceBundle.getBundle("borland.reference.cliffhanger.Res");
  101.  
  102.   /**
  103.    * The constructor is protected. Use the getCustomerFrame method to get an
  104.    * instance of this class.
  105.    */
  106.   protected CustomerFrame() {
  107.     try {
  108.       jbInit();   // initialize frame's controls (JBuilder designer)
  109.       initData(); // initialize dataset and data-aware components.
  110.     }
  111.     catch (Exception e) {
  112.       e.printStackTrace();
  113.     };
  114.   }
  115.  
  116.   /**
  117.    * Method generated and maintained by JBuilder designer to initialize
  118.    * control properties.
  119.    */
  120.   private void jbInit() throws Exception{
  121.     this.setSize(new Dimension(420, 520));
  122.     this.setTitle(res.getString("CF_Customers"));
  123.     this.addWindowListener(new CustomerFrame_this_windowAdapter(this));
  124.     this.setExitOnClose(false);
  125.     this.setLayout(borderLayout2);
  126.     pnlCustomerInfo.setBevelInner(BevelPanel.FLAT);
  127.     pnlCustomerInfo.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  128.     pnlOrders.setBevelInner(BevelPanel.FLAT);
  129.     pnlOrders.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  130.     pnlMain.setBevelInner(BevelPanel.FLAT);
  131.     pnlMain.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  132.     navigatorControl1.setDataSet(dm.getCustomerDataSet());
  133.     gridControl1.setDataSet(dm.getCustOrderDataSet());
  134.     gridControl1.setDefaultColumnWidth(80);
  135.     gridControl1.setFont(new Font("Dialog", 0, 12));
  136.     gridControl1.setSelectRow(true);
  137.     txtFirstName.setColumnName("FIRSTNAME");
  138.     txtFirstName.setDataSet(dm.getCustomerDataSet());
  139.     txtMI.setColumnName("MI");
  140.     txtMI.setDataSet(dm.getCustomerDataSet());
  141.     txtLastName.setColumnName("LASTNAME");
  142.     txtLastName.setDataSet(dm.getCustomerDataSet());
  143.     txtAddr1.setColumnName("ADDR1");
  144.     txtAddr1.setDataSet(dm.getCustomerDataSet());
  145.     txtAddr2.setColumnName("ADDR2");
  146.     txtAddr2.setDataSet(dm.getCustomerDataSet());
  147.     txtCity.setColumnName("CITY");
  148.     txtCity.setDataSet(dm.getCustomerDataSet());
  149.     txtState.setColumnName("STATE");
  150.     txtState.setDataSet(dm.getCustomerDataSet());
  151.     txtPostalCode.setColumnName("POSTALCODE");
  152.     txtPostalCode.setDataSet(dm.getCustomerDataSet());
  153.     txtCountry.setColumnName("COUNTRY");
  154.     txtCountry.setDataSet(dm.getCustomerDataSet());
  155.     txtPhone.setColumnName("PHONE");
  156.     txtPhone.setDataSet(dm.getCustomerDataSet());
  157.     txtFax.setColumnName("FAX");
  158.     txtFax.setDataSet(dm.getCustomerDataSet());
  159.     txtEmail.setColumnName("EMAIL");
  160.     txtEmail.setDataSet(dm.getCustomerDataSet());
  161.     pnlCustomerInfo.setLayout(gridBagLayout1);
  162.     pnlOrders.setLayout(borderLayout1);
  163.     pnlToolBar.setLayout(gridBagLayout3);
  164.     pnlMain.setLayout(gridBagLayout2);
  165.     lblCustomerID.setColumnName("ID");
  166.     lblCustomerID.setDataSet(dm.getCustomerDataSet());
  167.     lblCustomerID.setFont(new Font("Dialog", 1, 12));
  168.     lblCustomerID.setForeground(Color.red);
  169.     labelControl1.setText(res.getString("CF_Name"));
  170.     labelControl2.setText(res.getString("CF_Address_1"));
  171.     labelControl3.setText(res.getString("CF_City_StateProv"));
  172.     labelControl4.setText(res.getString("CF_Phone"));
  173.     labelControl5.setText(res.getString("CF_EMail"));
  174.     labelControl6.setText(res.getString("CF_Fax"));
  175.     labelControl7.setText(res.getString("CF_Address_2"));
  176.     labelControl8.setText(res.getString("CF_Country"));
  177.     labelControl9.setText(res.getString("CF_First"));
  178.     labelControl10.setAlignment(Label.CENTER);
  179.     labelControl10.setText(res.getString("CF_MI"));
  180.     labelControl11.setText(res.getString("CF_Last"));
  181.     labelControl12.setText(res.getString("CF_Postal_Code"));
  182.     statusBar1.setDataSet(dm.getCustomerDataSet());
  183.     statusBar1.setBevelOuter(BevelPanel.LOWERED);
  184.     statusBar1.setFont(new Font("Dialog", 0, 10));
  185.     btnViewOrder.setLabel(res.getString("CF_View_Order"));
  186.     btnViewOrder.addActionListener(new CustomerFrame_btnViewOrder_actionAdapter(this));
  187.     lblOrders.setText(res.getString("CF_Orders_placed_by_this"));
  188.     btnClose.setLabel(res.getString("CF_Close"));
  189.     btnClose.addActionListener(new CustomerFrame_btnClose_actionAdapter(this));
  190.     pnlOrderButtons.setLayout(flowLayout1);
  191.     btnNewOrder.setLabel(res.getString("CF_New_Order"));
  192.     imageControl1.setAlignment(borland.jbcl.util.Alignment.LEFT | borland.jbcl.util.Alignment.TOP);
  193.     imageControl1.setBackground(SystemColor.control);
  194.     imageControl1.setImageName(".\\graphics\\customerBanner.jpg");
  195.     labelControl6.setAlignment(Label.CENTER);
  196.     btnNewOrder.addActionListener(new CustomerFrame_btnNewOrder_actionAdapter(this));
  197.     this.add(pnlToolBar, BorderLayout.NORTH);
  198.     this.add(pnlMain, BorderLayout.CENTER);
  199.     this.add(statusBar1, BorderLayout.SOUTH);
  200.     pnlMain.add(pnlCustomerInfo, new GridBagConstraints2(0, 0, 1, 1, 100.0, 0.0
  201.             ,GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  202.     pnlCustomerInfo.add(txtFirstName, new GridBagConstraints2(6, 1, 2, 1, 1.0, 0.0
  203.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 112, 0));
  204.     pnlCustomerInfo.add(txtMI, new GridBagConstraints2(8, 1, 2, 1, 0.0, 0.0
  205.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), -60, 0));
  206.     pnlCustomerInfo.add(txtLastName, new GridBagConstraints2(10, 1, 3, 1, 1.0, 0.0
  207.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 4), 107, 0));
  208.     pnlCustomerInfo.add(txtAddr1, new GridBagConstraints2(6, 2, 6, 1, 1.0, 0.0
  209.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 4), 224, 0));
  210.     pnlCustomerInfo.add(txtAddr2, new GridBagConstraints2(6, 3, 6, 1, 1.0, 0.0
  211.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 4), 224, 0));
  212.     pnlCustomerInfo.add(txtCity, new GridBagConstraints2(6, 4, 2, 1, 1.0, 0.0
  213.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
  214.     pnlCustomerInfo.add(txtState, new GridBagConstraints2(8, 4, 4, 1, 0.0, 0.0
  215.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 18, 0));
  216.     pnlCustomerInfo.add(txtPostalCode, new GridBagConstraints2(6, 5, 2, 1, 1.0, 0.0
  217.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
  218.     pnlCustomerInfo.add(txtCountry, new GridBagConstraints2(6, 6, 2, 1, 1.0, 0.0
  219.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 107, 0));
  220.     pnlCustomerInfo.add(txtPhone, new GridBagConstraints2(6, 7, 2, 1, 1.0, 0.0
  221.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 0), 106, 0));
  222.     pnlCustomerInfo.add(txtFax, new GridBagConstraints2(10, 7, 2, 1, 1.0, 0.0
  223.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 4), 65, 0));
  224.     pnlCustomerInfo.add(txtEmail, new GridBagConstraints2(6, 9, 6, 1, 1.0, 0.0
  225.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 10, 4), 223, 0));
  226.     pnlCustomerInfo.add(labelControl1, new GridBagConstraints2(0, 1, 6, 1, 0.0, 0.0
  227.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 27, 0));
  228.     pnlCustomerInfo.add(labelControl2, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
  229.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
  230.     pnlCustomerInfo.add(labelControl3, new GridBagConstraints2(0, 4, 1, 1, 0.0, 0.0
  231.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  232.     pnlCustomerInfo.add(labelControl4, new GridBagConstraints2(0, 7, 3, 2, 0.0, 0.0
  233.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
  234.     pnlCustomerInfo.add(labelControl5, new GridBagConstraints2(0, 9, 2, 1, 0.0, 0.0
  235.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 10, 0), 0, 0));
  236.     pnlCustomerInfo.add(labelControl6, new GridBagConstraints2(8, 7, 1, 1, 0.0, 0.0
  237.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
  238.     pnlCustomerInfo.add(labelControl7, new GridBagConstraints2(0, 3, 5, 1, 0.0, 0.0
  239.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  240.     pnlCustomerInfo.add(labelControl8, new GridBagConstraints2(0, 6, 4, 1, 0.0, 0.0
  241.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  242.     pnlCustomerInfo.add(labelControl9, new GridBagConstraints2(6, 0, 1, 1, 0.0, 0.0
  243.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 12, 0, 0), 9, 0));
  244.     pnlCustomerInfo.add(labelControl10, new GridBagConstraints2(8, 0, 1, 1, 0.0, 0.0
  245.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0));
  246.     pnlCustomerInfo.add(labelControl11, new GridBagConstraints2(10, 0, 1, 1, 0.0, 0.0
  247.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 9, 0, 0), 0, 0));
  248.     pnlCustomerInfo.add(lblCustomerID, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  249.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  250.     pnlCustomerInfo.add(labelControl12, new GridBagConstraints2(0, 5, 4, 1, 0.0, 0.0
  251.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  252.     pnlMain.add(pnlOrders, new GridBagConstraints2(0, 1, 1, 1, 100.0, 100.0
  253.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  254.     pnlOrders.add(gridControl1, BorderLayout.CENTER);
  255.     pnlOrders.add(lblOrders, BorderLayout.NORTH);
  256.     pnlOrders.add(pnlOrderButtons, BorderLayout.SOUTH);
  257.     pnlOrderButtons.add(btnViewOrder, null);
  258.     pnlOrderButtons.add(btnNewOrder, null);
  259.     pnlToolBar.add(navigatorControl1, new GridBagConstraints2(0, 1, 1, 1, 1.0, 0.0
  260.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
  261.     pnlToolBar.add(btnClose, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0
  262.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 60, 2, 2), 0, 7));
  263.     pnlToolBar.add(imageControl1, new GridBagConstraints2(0, 0, 2, 1, 1.0, 1.0
  264.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, -57));
  265.   }
  266.  
  267.   /**
  268.    * We created this method to separate code to initialize database and
  269.    * data-aware controls, which otherwise would go in the jbInit() method.
  270.    * Note that by doing so, the properties set here are not visible to the
  271.    * property inspector. And setting any properties via the inspector will
  272.    * add code to jbInit() instead of here.
  273.    */
  274.   private void initData() throws Exception {
  275.     qdsCustomer = dm.getCustomerDataSet();
  276.     qdsCustomer.open();
  277.     qdsCustOrder = dm.getCustOrderDataSet();
  278.   }
  279.  
  280.   /**
  281.    * Class method to access the singleton instance of the class.
  282.    */
  283.   public static CustomerFrame getCustomerFrame() {
  284.     if (myCustomerFrame == null)
  285.       myCustomerFrame = new CustomerFrame();
  286.  
  287.     return myCustomerFrame;
  288.   }
  289.  
  290.   /**
  291.    * Method to insert a new customer record.
  292.    * Useful for inserting records from other forms in the application.
  293.    */
  294.   public void newCustomer() {
  295.     try {
  296.       // Open the dataset if not already opened.
  297.       qdsCustomer.open();
  298.       // Insert a new Customer record at the end of the
  299.       // dataset
  300.       qdsCustomer.insertRow(false);
  301.     }
  302.     catch (Exception e) {
  303.       e.printStackTrace();
  304.     }
  305.   }
  306.  
  307.   /**
  308.    * Initialize form controls when the form is activated.
  309.    */
  310.   void this_windowActivated(WindowEvent e) {
  311.     // determine which navigator buttons to enable
  312.  
  313.     // Note that we set the buttons here instead of in
  314.     // windowOpened because when the NavigatorControl rebuilds
  315.     // itself, the Save and Refresh buttons get re-enabled
  316.     int[] enabledFlags = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0};
  317.     for (int i = 0; i < enabledFlags.length; i++)
  318.       navigatorControl1.setButtonEnabled(i, enabledFlags[i] == 1);
  319.   }
  320.  
  321.   /**
  322.    * Before closing the window, check for any pending changes,
  323.    * and prompt user if there are changes pending.
  324.    * Note that we need to both check if there is anything to Post,
  325.    * and to check if there is anything to resolve.
  326.    */
  327.   void this_windowClosing(WindowEvent e) {
  328.     try {
  329.       int status = qdsCustomer.getStatus();
  330.       if ( (qdsCustomer.isEditing() || qdsCustomer.isEditingNewRow()) ||
  331.            ((status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0)
  332.          ) {
  333.         int answer = CliffhangerApplication.messageDlg(res.getString("CF_Save_Pending_Changes"),
  334.                                                        res.getString("CF_Save_pending_changes?"),
  335.                                                        Message.YES_NO_CANCEL);
  336.         // Post changes and resolve them back to DB
  337.         if (answer == Message.YES) {
  338.           qdsCustomer.post();
  339.  
  340.           // if there are pending changes to be resolved,
  341.           // save the changes via the Database.saveChanges()
  342.           // method. Then refresh the dataset.
  343.           status = qdsCustomer.getStatus();
  344.           if ( (status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0) {
  345.             qdsCustomer.getDatabase().saveChanges(new DataSet[] {qdsCustomer}, true);
  346.           }
  347.         }
  348.         // If user chooses no, then cancel any inserts or edits
  349.         // and refresh the dataset.
  350.         else if (answer == Message.NO) {
  351.           qdsCustomer.cancel();
  352.         }
  353.         // If user cancels, just return
  354.         else //if (answer == Message.CANCEL)
  355.           return;
  356.       }
  357.  
  358.       // Refresh the dataset to ensure that we have updated data
  359.       qdsCustomer.refresh();
  360.       setVisible(false);
  361.       dispose();
  362.  
  363.     }
  364.     catch (Exception ex) {
  365.       ex.printStackTrace();
  366.       new ExceptionDialog(this, res.getString("CF_Error"), ex, true).show();
  367.     }
  368.   }
  369.  
  370.   /**
  371.    * When View Order button is clicked, show the Order Entry form
  372.    * with the selected order as the current record.
  373.    */
  374.   void btnViewOrder_actionPerformed(ActionEvent e) {
  375.     try {
  376.       // make sure it is a valid order
  377.       int orderID = qdsCustOrder.getInt("ID");
  378.       if (orderID <= 0) {
  379.         CliffhangerApplication.messageDlg(CliffhangerApplication.MESSAGE_TITLE,
  380.                                           res.getString("CF_No_order_selected"),
  381.                                           Message.OK);
  382.         return;
  383.       }
  384.  
  385.       // Get the OrderEntryFrame, and locate the selected order
  386.       OrderEntryFrame frame = OrderEntryFrame.getOrderEntryFrame();
  387.       if (frame.locateOrder(orderID)) {
  388.         // Show the frame centered in the screen
  389.         CliffhangerApplication.showCenteredFrame(frame, false);
  390.       }
  391.       else {
  392.         CliffhangerApplication.messageDlg(res.getString("CF_Error"),
  393.                                           res.getString("CF_Order_not_found"),
  394.                                           Message.OK);
  395.       }
  396.     }
  397.     catch (Exception ex) {
  398.       ex.printStackTrace();
  399.     }
  400.   }
  401.  
  402.   /**
  403.    * When New Order button is clicked, show the Order Entry form
  404.    * with a new order inserted, default the customer for the order
  405.    * to the current customer record.
  406.    */
  407.   void btnNewOrder_actionPerformed(ActionEvent e) {
  408.     try {
  409.       // post any changes first
  410.       if (qdsCustomer.isEditing() || qdsCustomer.isEditingNewRow()) {
  411.         qdsCustomer.post();
  412.       }
  413.  
  414.       // make sure it is a valid order
  415.       int customerID = qdsCustomer.getInt("ID");
  416.       if (customerID <= 0) {
  417.         CliffhangerApplication.messageDlg(CliffhangerApplication.MESSAGE_TITLE,
  418.                                           res.getString("CF_No_customer_selected"),
  419.                                           Message.OK);
  420.         return;
  421.       }
  422.  
  423.       // Get the OrderEntryFrame and show the frame centered in the screen
  424.       OrderEntryFrame frame = OrderEntryFrame.getOrderEntryFrame();
  425.       CliffhangerApplication.showCenteredFrame(frame, false);
  426.  
  427.       // create a new order, passing the customer ID
  428.       // to default the customer of the new order
  429.       // to this current customer.
  430.       frame.newOrder(customerID);
  431.     }
  432.     catch (Exception ex) {
  433.       ex.printStackTrace();
  434.     }
  435.   }
  436.  
  437.   /**
  438.    * When Close button is clicked, call this frame's windowClosing
  439.    * event handler to properly handle all dataset pending updates.
  440.    */
  441.   void btnClose_actionPerformed(ActionEvent e) {
  442.     // close this Window
  443.     this.this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  444.   }
  445.  
  446. }
  447.  
  448. class CustomerFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
  449.   CustomerFrame adaptee;
  450.  
  451.   CustomerFrame_this_windowAdapter(CustomerFrame adaptee) {
  452.     this.adaptee = adaptee;
  453.   }
  454.  
  455.   public void windowClosing(WindowEvent e) {
  456.     adaptee.this_windowClosing(e);
  457.   }
  458.  
  459.   public void windowActivated(WindowEvent e) {
  460.     adaptee.this_windowActivated(e);
  461.   }
  462.  
  463. }
  464.  
  465. class CustomerFrame_btnViewOrder_actionAdapter implements java.awt.event.ActionListener{
  466.   CustomerFrame adaptee;
  467.  
  468.   CustomerFrame_btnViewOrder_actionAdapter(CustomerFrame adaptee) {
  469.     this.adaptee = adaptee;
  470.   }
  471.  
  472.   public void actionPerformed(ActionEvent e) {
  473.     adaptee.btnViewOrder_actionPerformed(e);
  474.   }
  475. }
  476.  
  477. class CustomerFrame_btnClose_actionAdapter implements java.awt.event.ActionListener {
  478.   CustomerFrame adaptee;
  479.  
  480.   CustomerFrame_btnClose_actionAdapter(CustomerFrame adaptee) {
  481.     this.adaptee = adaptee;
  482.   }
  483.  
  484.   public void actionPerformed(ActionEvent e) {
  485.     adaptee.btnClose_actionPerformed(e);
  486.   }
  487. }
  488.  
  489. class CustomerFrame_btnNewOrder_actionAdapter implements java.awt.event.ActionListener {
  490.   CustomerFrame adaptee;
  491.  
  492.   CustomerFrame_btnNewOrder_actionAdapter(CustomerFrame adaptee) {
  493.     this.adaptee = adaptee;
  494.   }
  495.  
  496.   public void actionPerformed(ActionEvent e) {
  497.     adaptee.btnNewOrder_actionPerformed(e);
  498.   }
  499. }
  500.