home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 9.9 KB | 268 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 borland.jbcl.model.*;
- import java.util.*;
-
- /**
- * CategoryFrame implements the Category Form that is used to maintain
- * Product Category records. This form allows users to view or update
- * existing categories, or enter new product categories.
- *
- * <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
- * getCategoryFrame method.
- */
- public class CategoryFrame extends DecoratedFrame {
- private static CategoryFrame myCategoryFrame;
-
- private static DataModule1 dataModule = DataModule1.getDataModule();
-
- BevelPanel pnlToolbar = new BevelPanel();
- BevelPanel pnlMain = new BevelPanel();
- StatusBar statusBar1 = new StatusBar();
- GridControl gridControl1 = new GridControl();
- NavigatorControl navigatorControl1 = new NavigatorControl();
- BorderLayout borderLayout1 = new BorderLayout();
- BorderLayout borderLayout2 = new BorderLayout();
- ButtonControl btnClose = new ButtonControl();
- BevelPanel bevelPanel3 = new BevelPanel();
- ButtonControl btnNewProduct = new ButtonControl();
- FlowLayout flowLayout1 = new FlowLayout();
- ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
- ImageControl imageControl1 = new ImageControl();
- GridBagLayout gridBagLayout1 = new GridBagLayout();
-
- /**
- * The constructor is protected. Use the getCategoryFrame method to get
- * an instance of the class.
- */
- protected CategoryFrame() {
- try {
- jbInit(); // initialize frame's controls (JBuilder designer)
- }
- catch (Exception e) {
- e.printStackTrace();
- };
- }
-
- /**
- * Method generated and maintained by JBuilder designer to initialize
- * control properties.
- */
- private void jbInit() throws Exception{
- this.setSize(new Dimension(400, 350));
- this.setTitle(res.getString("CAF_Categories"));
- this.addWindowListener(new CategoryFrame_this_windowAdapter(this));
- this.setExitOnClose(false);
- pnlToolbar.setBevelInner(BevelPanel.FLAT);
- pnlMain.setBevelInner(BevelPanel.FLAT);
- statusBar1.setDataSet(dataModule.getCategoryDataSet());
- statusBar1.setBevelOuter(BevelPanel.LOWERED);
- statusBar1.setFont(new Font("Dialog", 0, 10));
- gridControl1.setDataSet(dataModule.getCategoryDataSet());
- navigatorControl1.setDataSet(dataModule.getCategoryDataSet());
- pnlToolbar.setLayout(gridBagLayout1);
- pnlMain.setLayout(borderLayout2);
- btnClose.setLabel(res.getString("CAF_Close"));
- btnClose.addActionListener(new CategoryFrame_btnClose_actionAdapter(this));
- bevelPanel3.setBevelInner(BevelPanel.FLAT);
- bevelPanel3.setLayout(flowLayout1);
- btnNewProduct.setLabel(res.getString("CAF_New_Product"));
- imageControl1.setAlignment(borland.jbcl.util.Alignment.LEFT | borland.jbcl.util.Alignment.TOP);
- imageControl1.setImageName(".\\graphics\\categoryBanner.jpg");
- btnNewProduct.addActionListener(new CategoryFrame_btnNewProduct_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, 42, 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(pnlMain, BorderLayout.CENTER);
- pnlMain.add(gridControl1, BorderLayout.CENTER);
- pnlMain.add(bevelPanel3, BorderLayout.SOUTH);
- bevelPanel3.add(btnNewProduct, null);
- this.add(statusBar1, BorderLayout.SOUTH);
- }
-
- /**
- * Class method to access the singleton instance of the class
- */
- public static CategoryFrame getCategoryFrame() {
- if (myCategoryFrame == null)
- myCategoryFrame = new CategoryFrame();
-
- return myCategoryFrame;
- }
-
- /**
- * 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 {
- QueryDataSet qdsCategory = dataModule.getCategoryDataSet();
- int status = qdsCategory.getStatus();
- if ( (qdsCategory.isEditing() || qdsCategory.isEditingNewRow()) ||
- ((status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0)
- ) {
- int answer = CliffhangerApplication.messageDlg(res.getString("CAF_Save_Pending_Changes"),
- res.getString("CAF_Save_pending_changes?"),
- Message.YES_NO_CANCEL);
- // Post changes and resolve them back to DB
- if (answer == Message.YES) {
- qdsCategory.post();
- // if there are pending changes to be resolved,
- // save the changes via the Database.saveChanges()
- // method. Then refresh the dataset.
- status = qdsCategory.getStatus();
- if ( (status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0) {
- qdsCategory.getDatabase().saveChanges(new DataSet[] {qdsCategory}, true);
- qdsCategory.refresh();
- }
- }
- // If user chooses no, then cancel any inserts or edits
- // and refresh the dataset.
- else if (answer == Message.NO) {
- qdsCategory.cancel();
- qdsCategory.refresh();
- }
- // If user cancels, just return
- else //if (answer == Message.CANCEL)
- return;
- }
-
- setVisible(false);
- dispose();
-
- }
- catch (Exception ex) {
- ex.printStackTrace();
- new ExceptionDialog(this, res.getString("CAF_Error"), ex, true).show();
- }
-
- }
-
- /**
- * 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));
- }
-
- /**
- * When New Product button is clicked, show the Product form
- * with a new product record inserted, default the category field to
- * the current category.
- */
- void btnNewProduct_actionPerformed(ActionEvent e) {
- try {
- // Get the ProductFrame and show centered in screen
- ProductFrame frame = ProductFrame.getProductFrame();
- CliffhangerApplication.showCenteredFrame(frame, false);
-
- // create a new Product, passing the Category String
- // to default the category of the new product
- // to this current category.
- frame.newProduct(dataModule.getCategoryDataSet().getString("Category"));
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- }
-
-
- class CategoryFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
- CategoryFrame adaptee;
-
- CategoryFrame_this_windowAdapter(CategoryFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void windowActivated(WindowEvent e) {
- adaptee.this_windowActivated(e);
- }
-
- public void windowClosing(WindowEvent e) {
- adaptee.this_windowClosing(e);
- }
- }
-
- class CategoryFrame_btnClose_actionAdapter implements java.awt.event.ActionListener {
- CategoryFrame adaptee;
-
- CategoryFrame_btnClose_actionAdapter(CategoryFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.btnClose_actionPerformed(e);
- }
- }
-
- class CategoryFrame_btnNewProduct_actionAdapter implements java.awt.event.ActionListener {
- CategoryFrame adaptee;
-
- CategoryFrame_btnNewProduct_actionAdapter(CategoryFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.btnNewProduct_actionPerformed(e);
- }
- }
-