home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 14.7 KB | 352 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.lang.Exception;
- import java.util.*;
-
- /**
- * ProductFrame implements the Product Form that is used to maintain
- * Product records. This form allows users to view or update
- * existing products, or enter new products. A standard navigation control
- * is used to allow for record browsing.
- *
- * <P>
- * This class employs the Singleton pattern to ensure that the class has only
- * one instance. You can access the singleton instance by calling the
- * getProductFrame method.
- */
- public class ProductFrame extends DecoratedFrame {
- private static DataModule1 dm = DataModule1.getDataModule();
- private static ProductFrame myProductFrame;
- private QueryDataSet qdsProduct;
- private QueryDataSet qdsCategory;
- BevelPanel pnlToolbar = new BevelPanel();
- BevelPanel pnlProductInfo = new BevelPanel();
- FieldControl txtProductID = new FieldControl();
- FieldControl txtName = new FieldControl();
- ChoiceControl cboCategory = new ChoiceControl();
- FieldControl txtBasePrice = new FieldControl();
- FieldControl txtDiscountPct = new FieldControl();
- FieldControl txtStockQty = new FieldControl();
- FieldControl txtMinReorderQty = new FieldControl();
- CheckboxControl chkIsActive = new CheckboxControl();
- LabelControl lblName = new LabelControl();
- LabelControl lblCategory = new LabelControl();
- LabelControl lblBasePrice = new LabelControl();
- LabelControl lblDiscountPct = new LabelControl();
- LabelControl lblStockQty = new LabelControl();
- LabelControl lblMinReorderQty = new LabelControl();
- LabelControl lblProductID = new LabelControl();
- BorderLayout borderLayout1 = new BorderLayout();
- GridBagLayout gridBagLayout1 = new GridBagLayout();
- NavigatorControl navigatorControl1 = new NavigatorControl();
- StatusBar statusBar1 = new StatusBar();
- ButtonControl btnClose = new ButtonControl();
- ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
- ImageControl imageControl1 = new ImageControl();
- GridBagLayout gridBagLayout2 = new GridBagLayout();
-
- /**
- * The constructor is protected. Use the getProductFrame method to get an
- * instance of this class.
- */
- protected ProductFrame() {
- try {
- initData(); // initialize dataset and data-aware components.
- jbInit(); // initialize frame's controls (JBuilder designer)
- }
- catch (Exception e) {
- e.printStackTrace();
- };
- }
-
- /**
- * Method generated and maintained by JBuilder designer to initialize
- * control properties.
- */
- void jbInit() throws Exception{
- this.setSize(new Dimension(400, 350));
- this.setTitle(res.getString("PF_Products"));
- this.addWindowListener(new ProductFrame_this_windowAdapter(this));
- this.setExitOnClose(false);
- pnlProductInfo.setBevelInner(BevelPanel.FLAT);
- chkIsActive.setColumnName("ISACTIVE");
- chkIsActive.setDataSet(dm.getProductDataSet());
- chkIsActive.setLabel(res.getString("PF_Active"));
- txtProductID.setColumnName("ID");
- txtProductID.setBackground(SystemColor.control);
- txtProductID.setDataSet(dm.getProductDataSet());
- txtProductID.setPostOnEndEdit(false);
- txtProductID.setPostOnFocusLost(false);
- txtProductID.setReadOnly(true);
- txtName.setColumnName("NAME");
- txtName.setDataSet(dm.getProductDataSet());
- cboCategory.setColumnName("CATEGORY");
- cboCategory.setDataSet(dm.getProductDataSet());
- txtBasePrice.setColumnName("BASEPRICE");
- txtBasePrice.setDataSet(dm.getProductDataSet());
- txtDiscountPct.setColumnName("DISCOUNTPCT");
- txtDiscountPct.setDataSet(dm.getProductDataSet());
- txtStockQty.setColumnName("STOCKQTY");
- txtStockQty.setDataSet(dm.getProductDataSet());
- txtMinReorderQty.setColumnName("MINREORDERQTY");
- txtMinReorderQty.setDataSet(dm.getProductDataSet());
- pnlToolbar.setLayout(gridBagLayout2);
- pnlProductInfo.setLayout(gridBagLayout1);
- lblName.setText(res.getString("PF_Name"));
- lblCategory.setText(res.getString("PF_Category"));
- lblBasePrice.setText(res.getString("PF_Base_Price"));
- lblDiscountPct.setText(res.getString("PF_Discount_%"));
- lblStockQty.setText(res.getString("PF_Stock_Qty"));
- lblMinReorderQty.setText(res.getString("PF_Min_Reorder_Qty"));
- lblProductID.setText(res.getString("PF_Product_ID"));
- navigatorControl1.setDataSet(dm.getProductDataSet());
- statusBar1.setDataSet(dm.getProductDataSet());
- statusBar1.setBevelOuter(BevelPanel.LOWERED);
- statusBar1.setFont(new Font("Dialog", 0, 10));
- btnClose.setLabel(res.getString("PF_Close"));
- imageControl1.setBackground(SystemColor.control);
- imageControl1.setAlignment(borland.jbcl.util.Alignment.LEFT | borland.jbcl.util.Alignment.TOP);
- imageControl1.setImageName(".\\graphics\\productBanner.jpg");
- btnClose.addActionListener(new ProductFrame_btnClose_actionAdapter(this));
- this.setLayout(borderLayout1);
- this.add(pnlToolbar, BorderLayout.NORTH);
- pnlToolbar.add(navigatorControl1, new GridBagConstraints2(0, 1, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
- pnlToolbar.add(btnClose, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0
- ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 40, 2, 2), 0, 7));
- pnlToolbar.add(imageControl1, new GridBagConstraints2(0, 0, 2, 1, 1.0, 1.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, -57));
- this.add(pnlProductInfo, BorderLayout.CENTER);
- pnlProductInfo.add(txtProductID, new GridBagConstraints2(4, 0, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 0, 0, 0), 46, 0));
- pnlProductInfo.add(txtName, new GridBagConstraints2(4, 1, 2, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 15), 223, 0));
- pnlProductInfo.add(cboCategory, new GridBagConstraints2(4, 2, 2, 1, 1.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 15), 218, 0));
- pnlProductInfo.add(txtBasePrice, new GridBagConstraints2(4, 3, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 46, 0));
- pnlProductInfo.add(txtDiscountPct, new GridBagConstraints2(4, 4, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 46, 0));
- pnlProductInfo.add(txtStockQty, new GridBagConstraints2(4, 5, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 46, 0));
- pnlProductInfo.add(txtMinReorderQty, new GridBagConstraints2(4, 6, 1, 1, 1.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 7, 0), 46, 0));
- pnlProductInfo.add(lblName, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 15, 0, 0), 2, 2));
- pnlProductInfo.add(lblCategory, new GridBagConstraints2(0, 2, 2, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 0), -3, 0));
- pnlProductInfo.add(lblBasePrice, new GridBagConstraints2(0, 3, 3, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 0), 0, 0));
- pnlProductInfo.add(lblDiscountPct, new GridBagConstraints2(0, 4, 3, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 0), 0, 0));
- pnlProductInfo.add(lblStockQty, new GridBagConstraints2(0, 5, 2, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 0), 0, 0));
- pnlProductInfo.add(lblMinReorderQty, new GridBagConstraints2(0, 6, 4, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 7, 0), 0, 0));
- pnlProductInfo.add(chkIsActive, new GridBagConstraints2(5, 6, 1, 1, 0.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 110, 7, 15), 4, 0));
- pnlProductInfo.add(lblProductID, new GridBagConstraints2(0, 0, 3, 1, 0.0, 0.0
- ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 15, 0, 0), 1, 0));
- this.add(statusBar1, BorderLayout.SOUTH);
- }
-
- /**
- * We created this method to separate code to initialize database and
- * data-aware controls, which otherwise would go in the jbInit() method.
- * Note that by doing so, the properties set here are not visible to the
- * property inspector. And setting any properties via the inspector will
- * add code to jbInit() instead of here.
- */
- private void initData() throws Exception {
- qdsProduct = dm.getProductDataSet();
- qdsCategory = dm.getCategoryDataSet();
-
- qdsProduct.open();
- qdsCategory.open();
-
- cboCategory.setItems(qdsCategory, "CATEGORY");
- }
-
- /**
- * Class method to access the singleton instance of the class.
- */
- public static ProductFrame getProductFrame() {
- if (myProductFrame == null)
- myProductFrame = new ProductFrame();
-
- return myProductFrame;
- }
-
- /**
- * Initialize form controls when the form is activated.
- */
- void this_windowActivated(WindowEvent e) {
- // determine which navigator buttons to enable
-
- // Note that we set the buttons here instead of in
- // windowOpened because when the NavigatorControl rebuilds
- // itself, the Save and Refresh buttons get re-enabled
- int[] enabledFlags = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0};
- for (int i = 0; i < enabledFlags.length; i++)
- navigatorControl1.setButtonEnabled(i, enabledFlags[i] == 1);
- }
-
- /**
- * Before closing the window, check for any pending changes,
- * and prompt user if there are changes pending.
- * Note that we need to both check if there is anything to Post,
- * and to check if there is anything to resolve.
- */
- void this_windowClosing(WindowEvent e) {
- try {
- int status = qdsCategory.getStatus();
- if ( (qdsProduct.isEditing() || qdsProduct.isEditingNewRow()) ||
- ((status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0)
- ) {
- int answer = CliffhangerApplication.messageDlg(res.getString("PF_Save_Pending_Changes"),
- res.getString("PF_Save_pending_changes?"),
- Message.YES_NO_CANCEL);
- // Post changes and resolve them back to DB
- if (answer == Message.YES) {
- qdsProduct.post();
- // if there are pending changes to be resolved,
- // save the changes via the Database.saveChanges()
- // method. Then refresh the dataset.
- status = qdsProduct.getStatus();
- if ( (status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0) {
- qdsProduct.getDatabase().saveChanges(new DataSet[] {qdsProduct}, true);
- }
- }
- // If user chooses no, then cancel any inserts or edits
- // and refresh the dataset.
- else if (answer == Message.NO) {
- qdsProduct.cancel();
- }
- // If user cancels, just return
- else //if (answer == Message.CANCEL)
- return;
- }
-
- // Refresh the dataset to ensure that we have updated data
- qdsProduct.refresh();
- setVisible(false);
- dispose();
-
- }
- catch (Exception ex) {
- ex.printStackTrace();
- new ExceptionDialog(this, res.getString("PF_Error"), ex, true).show();
- }
- }
-
- /**
- * Method to insert a new product order record.
- * Useful for inserting a new product from other forms in
- * the application.
- */
- public void newProduct() {
- try {
- // Open the dataset if not already opened.
- qdsProduct.open();
- // Insert a new Product record at the end of the
- // dataset
- qdsProduct.insertRow(false);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Method to insert a new product record
- * and setting the category that is passed as
- * the parameter category.
- */
- public void newProduct(String category) {
- try {
- // Open the dataset if not already opened.
- qdsProduct.open();
- // Insert a new Product record at the end of the
- // dataset
- qdsProduct.insertRow(false);
- qdsProduct.setString("CATEGORY", category);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * When Close button is clicked, call this frame's windowClosing
- * event handler to properly handle all dataset pending updates.
- */
- void btnClose_actionPerformed(ActionEvent e) {
- // close this Window
- this.this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
- }
-
- }
-
-
- class ProductFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
- ProductFrame adaptee;
-
- ProductFrame_this_windowAdapter(ProductFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void windowClosing(WindowEvent e) {
- adaptee.this_windowClosing(e);
- }
-
- public void windowActivated(WindowEvent e) {
- adaptee.this_windowActivated(e);
- }
- }
-
- class ProductFrame_btnClose_actionAdapter implements java.awt.event.ActionListener {
- ProductFrame adaptee;
-
- ProductFrame_btnClose_actionAdapter(ProductFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.btnClose_actionPerformed(e);
- }
- }
-
-