home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 9.2 KB | 262 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
-
- //Title: Cliffhanger Adventure Gear
- //Version:
- //Copyright: Copyright (c) 1997 Borland International, Inc.
- //Author: Application Methods, Inc.
- //Description: Cliffhanger Adventure Gear order entry system
-
- package borland.reference.cliffhanger;
-
- import java.awt.*;
- import java.awt.event.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.control.*;
- import borland.sql.dataset.*;
- import borland.jbcl.dataset.*;
- import java.util.*;
-
- /**
- * FindOrderCustomer implements the dialog for choosing a customer from the
- * OrderEntryFrame. The CustomerFrame could not be used because a modal dialog
- * is needed to get the customer ID for the Order record.
- */
- public class FindOrderCustomer extends Dialog {
- private static DataModule1 dm = DataModule1.getDataModule();
- private QueryDataSet qdsCustomer;
- private int result;
- private int customerID;
- Panel panel1 = new Panel();
- BevelPanel pnlTop = new BevelPanel();
- BevelPanel pnlButtons = new BevelPanel();
- ButtonControl btnOK = new ButtonControl();
- ButtonControl btnCancel = new ButtonControl();
- LabelControl lblField = new LabelControl();
- LabelControl lblValue = new LabelControl();
- ChoiceControl cboField = new ChoiceControl();
- LocatorControl locatorControl1 = new LocatorControl();
- GridControl gridControl1 = new GridControl();
- GridBagLayout gridBagLayout1 = new GridBagLayout();
- GridBagLayout gridBagLayout2 = new GridBagLayout();
- BorderLayout borderLayout1 = new BorderLayout();
- BorderLayout borderLayout2 = new BorderLayout();
- BevelPanel pnlLocate = new BevelPanel();
-
- // constants
- static final int CANCEL = 0;
- static final int OK = 1;
- ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
-
- public FindOrderCustomer(Frame frame, String title, boolean modal) {
- super(frame, title, modal);
- try {
- jbInit();
- initData();
- add(panel1);
- pack();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public FindOrderCustomer(Frame frame) {
- this(frame, "", false);
- }
-
- public FindOrderCustomer(Frame frame, boolean modal) {
- this(frame, "", modal);
- }
-
- public FindOrderCustomer(Frame frame, String title) {
- this(frame, title, false);
- }
-
- private void jbInit() throws Exception{
- result = CANCEL;
- customerID = 0;
- pnlTop.setLayout(borderLayout2);
- pnlButtons.setLayout(gridBagLayout1);
- pnlLocate.setLayout(gridBagLayout2);
- panel1.setSize(new Dimension(350, 250));
- btnOK.setLabel(res.getString("FOC_OK"));
- btnOK.addActionListener(new FindOrderCustomer_btnOK_actionAdapter(this));
- btnCancel.setLabel(res.getString("FOC_Cancel"));
- btnCancel.addActionListener(new FindOrderCustomer_btnCancel_actionAdapter(this));
- lblField.setText(res.getString("FOC_Field"));
- lblValue.setText(res.getString("FOC_Value"));
- locatorControl1.setDataSet(dm.getCustomerDataSet());
- cboField.addItemListener(new FindOrderCustomer_cboField_itemAdapter(this));
- cboField.setItems(new String [] { res.getString("DM_CustomerDS_LASTNAME"), res.getString("DM_CustomerDS_FIRSTNAME"), res.getString("DM_CustomerDS_PHONE"), res.getString("DM_CustomerDS_ID") });
- locatorControl1.addKeyListener(new FindOrderCustomer_locatorControl1_keyAdapter(this));
- gridControl1.setDataSet(dm.getCustomerDataSet());
- gridControl1.setReadOnly(true);
- pnlLocate.setBevelInner(BevelPanel.FLAT);
- pnlLocate.setMargins(new Insets(5, 5, 5, 5));
- pnlButtons.setBevelInner(BevelPanel.FLAT);
- pnlButtons.setMargins(new Insets(5, 5, 5, 5));
- panel1.setLayout(borderLayout1);
- panel1.add(pnlTop, BorderLayout.NORTH);
- pnlTop.add(pnlLocate, BorderLayout.CENTER);
- pnlTop.add(pnlButtons, BorderLayout.EAST);
- pnlButtons.add(btnOK, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
- pnlButtons.add(btnCancel, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
- pnlLocate.add(lblField, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
- pnlLocate.add(lblValue, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
- pnlLocate.add(cboField, new GridBagConstraints2(1, 0, 3, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
- pnlLocate.add(locatorControl1, new GridBagConstraints2(1, 1, 3, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
- panel1.add(gridControl1, BorderLayout.CENTER);
- }
-
- private void initData() {
- qdsCustomer = dm.getCustomerDataSet();
- }
-
- /**
- * Getter method for the result property
- */
- public int getResult() {
- return this.result;
- }
-
- /**
- * Getter method for the customerID property
- */
- public int getCustomerID() {
- return this.customerID;
- }
-
-
- /**
- * When the OK button is clicked, set the customerID property of the dialog,
- * set the result property of the dialog to OK, then close the dialog window.
- */
- void btnOK_actionPerformed(ActionEvent e) {
- try {
- customerID = qdsCustomer.getInt("ID");
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- result = OK;
- setVisible(false);
- dispose();
- }
-
- /**
- * When the Cancel button is clicked, cancel any unposted inserts or edits.
- * Set the result property to CANCEL, then close the dialog window.
- */
- void btnCancel_actionPerformed(ActionEvent e) {
- result = CANCEL;
- setVisible(false);
- dispose();
- }
-
- /**
- * The itemStateChanged event is triggered when the user selects a new
- * item off the choiceControl's drop down list of possible fields to
- * search on. Reset the text property of the locatorControl to be ready
- * for a new search value.
- */
- void cboField_itemStateChanged(ItemEvent e) {
- locatorControl1.setText("");
- }
-
- /**
- * When the user types in the locatorControl, make sure that the ColumnName
- * property of the locatorControl is set to the column name selected in the
- * ChoiceControl.
- */
- void locatorControl1_keyPressed(KeyEvent e) {
- // Set the columnName property of the locatorControl
- // if it is not set.
- try {
- if ((locatorControl1.getColumnName() == null) ||
- (locatorControl1.getDataSet().getColumn(locatorControl1.getColumnName()).getCaption().compareTo(cboField.getSelectedItem()) != 0)) {
- Column [] columns = locatorControl1.getDataSet().getColumns();
- for (int index = 0; index < columns.length; index++) {
- if (columns[index].getCaption().compareTo(cboField.getSelectedItem()) == 0) {
- locatorControl1.setColumnName(columns[index].getColumnName());
- break;
- }
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
-
- class FindOrderCustomer_btnOK_actionAdapter implements java.awt.event.ActionListener {
- FindOrderCustomer adaptee;
-
- FindOrderCustomer_btnOK_actionAdapter(FindOrderCustomer adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.btnOK_actionPerformed(e);
- }
- }
-
- class FindOrderCustomer_btnCancel_actionAdapter implements java.awt.event.ActionListener {
- FindOrderCustomer adaptee;
-
- FindOrderCustomer_btnCancel_actionAdapter(FindOrderCustomer adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.btnCancel_actionPerformed(e);
- }
- }
-
- class FindOrderCustomer_locatorControl1_keyAdapter extends java.awt.event.KeyAdapter {
- FindOrderCustomer adaptee;
-
- FindOrderCustomer_locatorControl1_keyAdapter(FindOrderCustomer adaptee) {
- this.adaptee = adaptee;
- }
-
- public void keyPressed(KeyEvent e) {
- adaptee.locatorControl1_keyPressed(e);
- }
- }
-
- class FindOrderCustomer_cboField_itemAdapter implements java.awt.event.ItemListener {
- FindOrderCustomer adaptee;
-
- FindOrderCustomer_cboField_itemAdapter(FindOrderCustomer adaptee) {
- this.adaptee = adaptee;
- }
-
- public void itemStateChanged(ItemEvent e) {
- adaptee.cboField_itemStateChanged(e);
- }
- }
-