home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / FindOrderCustomer.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  9.2 KB  |  262 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.  * FindOrderCustomer implements the dialog for choosing a customer from the
  39.  * OrderEntryFrame. The CustomerFrame could not be used because a modal dialog
  40.  * is needed to get the customer ID for the Order record.
  41.  */
  42. public class FindOrderCustomer extends Dialog {
  43.   private static DataModule1 dm = DataModule1.getDataModule();
  44.   private QueryDataSet qdsCustomer;
  45.   private int result;
  46.   private int customerID;
  47.   Panel panel1 = new Panel();
  48.   BevelPanel pnlTop = new BevelPanel();
  49.   BevelPanel pnlButtons = new BevelPanel();
  50.   ButtonControl btnOK = new ButtonControl();
  51.   ButtonControl btnCancel = new ButtonControl();
  52.   LabelControl lblField = new LabelControl();
  53.   LabelControl lblValue = new LabelControl();
  54.   ChoiceControl cboField = new ChoiceControl();
  55.   LocatorControl locatorControl1 = new LocatorControl();
  56.   GridControl gridControl1 = new GridControl();
  57.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  58.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  59.   BorderLayout borderLayout1 = new BorderLayout();
  60.   BorderLayout borderLayout2 = new BorderLayout();
  61.   BevelPanel pnlLocate = new BevelPanel();
  62.  
  63.   // constants
  64.   static final int CANCEL = 0;
  65.   static final int OK = 1;
  66.   ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
  67.  
  68.   public FindOrderCustomer(Frame frame, String title, boolean modal) {
  69.     super(frame, title, modal);
  70.     try {
  71.       jbInit();
  72.       initData();
  73.       add(panel1);
  74.       pack();
  75.     }
  76.     catch (Exception e) {
  77.       e.printStackTrace();
  78.     }
  79.   }
  80.  
  81.   public FindOrderCustomer(Frame frame) {
  82.     this(frame, "", false);
  83.   }
  84.  
  85.   public FindOrderCustomer(Frame frame, boolean modal) {
  86.     this(frame, "", modal);
  87.   }
  88.  
  89.   public FindOrderCustomer(Frame frame, String title) {
  90.     this(frame, title, false);
  91.   }
  92.  
  93.   private void jbInit() throws Exception{
  94.     result = CANCEL;
  95.     customerID = 0;
  96.     pnlTop.setLayout(borderLayout2);
  97.     pnlButtons.setLayout(gridBagLayout1);
  98.     pnlLocate.setLayout(gridBagLayout2);
  99.     panel1.setSize(new Dimension(350, 250));
  100.     btnOK.setLabel(res.getString("FOC_OK"));
  101.     btnOK.addActionListener(new FindOrderCustomer_btnOK_actionAdapter(this));
  102.     btnCancel.setLabel(res.getString("FOC_Cancel"));
  103.     btnCancel.addActionListener(new FindOrderCustomer_btnCancel_actionAdapter(this));
  104.     lblField.setText(res.getString("FOC_Field"));
  105.     lblValue.setText(res.getString("FOC_Value"));
  106.     locatorControl1.setDataSet(dm.getCustomerDataSet());
  107.     cboField.addItemListener(new FindOrderCustomer_cboField_itemAdapter(this));
  108.     cboField.setItems(new String [] { res.getString("DM_CustomerDS_LASTNAME"), res.getString("DM_CustomerDS_FIRSTNAME"), res.getString("DM_CustomerDS_PHONE"), res.getString("DM_CustomerDS_ID") });
  109.     locatorControl1.addKeyListener(new FindOrderCustomer_locatorControl1_keyAdapter(this));
  110.     gridControl1.setDataSet(dm.getCustomerDataSet());
  111.     gridControl1.setReadOnly(true);
  112.     pnlLocate.setBevelInner(BevelPanel.FLAT);
  113.     pnlLocate.setMargins(new Insets(5, 5, 5, 5));
  114.     pnlButtons.setBevelInner(BevelPanel.FLAT);
  115.     pnlButtons.setMargins(new Insets(5, 5, 5, 5));
  116.     panel1.setLayout(borderLayout1);
  117.     panel1.add(pnlTop, BorderLayout.NORTH);
  118.     pnlTop.add(pnlLocate, BorderLayout.CENTER);
  119.     pnlTop.add(pnlButtons, BorderLayout.EAST);
  120.     pnlButtons.add(btnOK, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  121.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  122.     pnlButtons.add(btnCancel, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  123.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
  124.     pnlLocate.add(lblField, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  125.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  126.     pnlLocate.add(lblValue, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  127.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
  128.     pnlLocate.add(cboField, new GridBagConstraints2(1, 0, 3, 1, 1.0, 0.0
  129.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  130.     pnlLocate.add(locatorControl1, new GridBagConstraints2(1, 1, 3, 1, 1.0, 0.0
  131.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
  132.     panel1.add(gridControl1, BorderLayout.CENTER);
  133.   }
  134.  
  135.   private void initData() {
  136.     qdsCustomer = dm.getCustomerDataSet();
  137.   }
  138.  
  139.   /**
  140.    * Getter method for the result property
  141.    */
  142.   public int getResult() {
  143.     return this.result;
  144.   }
  145.  
  146.   /**
  147.    * Getter method for the customerID property
  148.    */
  149.   public int getCustomerID() {
  150.     return this.customerID;
  151.   }
  152.  
  153.  
  154.   /**
  155.    * When the OK button is clicked, set the customerID property of the dialog,
  156.    * set the result property of the dialog to OK, then close the dialog window.
  157.    */
  158.   void btnOK_actionPerformed(ActionEvent e) {
  159.     try {
  160.       customerID = qdsCustomer.getInt("ID");
  161.     }
  162.     catch (Exception ex) {
  163.       ex.printStackTrace();
  164.     }
  165.     result = OK;
  166.     setVisible(false);
  167.     dispose();
  168.   }
  169.  
  170.   /**
  171.    * When the Cancel button is clicked, cancel any unposted inserts or edits.
  172.    * Set the result property to CANCEL, then close the dialog window.
  173.    */
  174.   void btnCancel_actionPerformed(ActionEvent e) {
  175.     result = CANCEL;
  176.     setVisible(false);
  177.     dispose();
  178.   }
  179.   
  180.   /**
  181.    * The itemStateChanged event is triggered when the user selects a new
  182.    * item off the choiceControl's drop down list of possible fields to
  183.    * search on. Reset the text property of the locatorControl to be ready
  184.    * for a new search value.
  185.    */
  186.     void cboField_itemStateChanged(ItemEvent e) {
  187.     locatorControl1.setText("");
  188.   }
  189.  
  190.   /**
  191.    * When the user types in the locatorControl, make sure that the ColumnName
  192.    * property of the locatorControl is set to the column name selected in the
  193.    * ChoiceControl.
  194.    */
  195.   void locatorControl1_keyPressed(KeyEvent e) {
  196.     // Set the columnName property of the locatorControl
  197.     // if it is not set.
  198.     try {
  199.       if ((locatorControl1.getColumnName() == null) ||
  200.       (locatorControl1.getDataSet().getColumn(locatorControl1.getColumnName()).getCaption().compareTo(cboField.getSelectedItem()) != 0)) {
  201.     Column [] columns = locatorControl1.getDataSet().getColumns();
  202.     for (int index = 0; index < columns.length; index++) {
  203.       if (columns[index].getCaption().compareTo(cboField.getSelectedItem()) == 0) {
  204.         locatorControl1.setColumnName(columns[index].getColumnName());
  205.         break;
  206.       }
  207.     }
  208.       }
  209.     } catch (Exception ex) {
  210.       ex.printStackTrace();
  211.     }
  212.   }
  213. }
  214.  
  215. class FindOrderCustomer_btnOK_actionAdapter implements java.awt.event.ActionListener {
  216.   FindOrderCustomer adaptee;
  217.  
  218.   FindOrderCustomer_btnOK_actionAdapter(FindOrderCustomer adaptee) {
  219.     this.adaptee = adaptee;
  220.   }
  221.  
  222.   public void actionPerformed(ActionEvent e) {
  223.     adaptee.btnOK_actionPerformed(e);
  224.   }
  225. }
  226.  
  227. class FindOrderCustomer_btnCancel_actionAdapter implements java.awt.event.ActionListener {
  228.   FindOrderCustomer adaptee;
  229.  
  230.   FindOrderCustomer_btnCancel_actionAdapter(FindOrderCustomer adaptee) {
  231.     this.adaptee = adaptee;
  232.   }
  233.  
  234.   public void actionPerformed(ActionEvent e) {
  235.     adaptee.btnCancel_actionPerformed(e);
  236.   }
  237. }
  238.  
  239. class FindOrderCustomer_locatorControl1_keyAdapter extends java.awt.event.KeyAdapter {
  240.   FindOrderCustomer adaptee;
  241.  
  242.   FindOrderCustomer_locatorControl1_keyAdapter(FindOrderCustomer adaptee) {
  243.     this.adaptee = adaptee;
  244.   }
  245.  
  246.   public void keyPressed(KeyEvent e) {
  247.     adaptee.locatorControl1_keyPressed(e);
  248.   }
  249. }
  250.  
  251. class FindOrderCustomer_cboField_itemAdapter implements java.awt.event.ItemListener {
  252.   FindOrderCustomer adaptee;
  253.  
  254.   FindOrderCustomer_cboField_itemAdapter(FindOrderCustomer adaptee) {
  255.     this.adaptee = adaptee;
  256.   }
  257.  
  258.   public void itemStateChanged(ItemEvent e) {
  259.     adaptee.cboField_itemStateChanged(e);
  260.   }
  261. }
  262.