home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 8.5 KB | 219 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: Stored Procedure Sample
- //Version: 2.0
- //Copyright: Copyright (c) 1998
- //Company: Borland Int'l
- //Description: The Sample frame, consisting a TabsetPanel with 2 pages.
- // The 'DDL' page executes sql statements when the lightning
- // bulb is pressed. This should create tables and stored
- // procedures on the database. After that the second page
- // should appear with the actual test grids.
-
-
- package borland.samples.tutorial.dataset.storedprocedure;
-
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.control.*;
- import borland.jbcl.dataset.*;
- import borland.sql.dataset.*;
-
- public class ProcedureSampleFrame extends DecoratedFrame {
- TabsetPanel tabsetPanel1 = new TabsetPanel();
- BorderLayout borderLayout1 = new BorderLayout();
- BevelPanel bevelPanel1 = new BevelPanel();
- ButtonControl buttonControl1 = new ButtonControl();
- TextAreaControl textAreaControl1 = new TextAreaControl();
- GridBagLayout gridBagLayout1 = new GridBagLayout();
- BevelPanel bevelPanel2 = new BevelPanel();
- GridControl gridControl1 = new GridControl();
- NavigatorControl navigatorControl2 = new NavigatorControl();
- NavigatorControl navigatorControl1 = new NavigatorControl();
- GridControl gridControl2 = new GridControl();
- GridBagLayout gridBagLayout2 = new GridBagLayout();
- TextControl textControl1 = new TextControl();
- TextControl textControl2 = new TextControl();
- StoredProcedureDM dm = new StoredProcedureDM();
- ButtonControl buttonControl2 = new ButtonControl();
- boolean hasCreateDLL;
-
- public ProcedureSampleFrame() {
- try {
- jbInit();
- initDDLtext();
- initState();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void jbInit() throws Exception{
- this.setSize(new Dimension(664, 420));
- this.setTitle("Stored Procedure Sample");
- this.addWindowListener(new ProcedureSampleFrame_this_windowAdapter(this));
- tabsetPanel1.setClientBordered(false);
- tabsetPanel1.setLabels(new String[] {"DDL", "Test Procedures"});
- tabsetPanel1.setSelectedIndex(0);
- bevelPanel1.setBevelInner(BevelPanel.FLAT);
- bevelPanel1.setLayout(gridBagLayout1);
- buttonControl1.setImageName("run.gif");
- textAreaControl1.setFont(new Font("Monospaced", 0, 12));
- buttonControl1.addActionListener(new ProcedureSampleFrame_buttonControl1_actionAdapter(this));
- bevelPanel2.setBevelInner(BevelPanel.FLAT);
- gridControl1.setDataSet(dm.getMasterQDS());
- navigatorControl2.setDataSet(dm.getDetailPDS());
- navigatorControl1.setDataSet(dm.getMasterQDS());
- gridControl2.setDataSet(dm.getDetailPDS());
- textControl1.setText("Master from Query :");
- textControl2.setText("Detail from Procedure :");
- buttonControl2.addActionListener(new ProcedureSampleFrame_buttonControl2_actionAdapter(this));
- bevelPanel2.setLayout(gridBagLayout2);
- this.setLayout(borderLayout1);
- this.add(tabsetPanel1, BorderLayout.CENTER);
- tabsetPanel1.add(bevelPanel1, "DDL");
- bevelPanel1.add(buttonControl1, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
- ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
- bevelPanel1.add(textAreaControl1, new GridBagConstraints2(0, 0, 1, 3, 1.0, 1.0
- ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- bevelPanel1.add(buttonControl2, new GridBagConstraints2(2, 2, 1, 1, 0.0, 0.0
- ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
- tabsetPanel1.add(bevelPanel2, "Test Procedures");
- bevelPanel2.add(gridControl1, new GridBagConstraints2(0, 1, 2, 1, 1.0, 1.0
- ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- bevelPanel2.add(navigatorControl2, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
- ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
- bevelPanel2.add(navigatorControl1, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
- ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
- bevelPanel2.add(gridControl2, new GridBagConstraints2(0, 3, 2, 1, 1.0, 1.0
- ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- bevelPanel2.add(textControl1, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
- bevelPanel2.add(textControl2, new GridBagConstraints2(1, 2, 1, 1, 0.0, 0.0
- ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
- }
-
- void initDDLtext() {
- initDDLtext(dm.getDDLquery());
- buttonControl2.setImageName("cleanup.gif");
- hasCreateDLL = true;
- }
-
- void initState() {
- try {
- dm.getMasterQDS().open();
- dm.getDetailPDS().open();
- dm.getMasterQDS().refresh();
- dm.getDetailPDS().refresh();
- tabsetPanel1.add(bevelPanel2, "Test Procedures");
- tabsetPanel1.setSelectedIndex(1);
- }
- catch (Exception ex) {
- tabsetPanel1.removeTab("Test Procedures");
- tabsetPanel1.setSelectedIndex(0);
- }
- }
-
- void initDDLtext(String filename) {
- try {
- FileInputStream fs = new FileInputStream(filename);
- byte[] stream = new byte[fs.available()];
- fs.read(stream,0,stream.length);
- String sql = new String(stream);
- textAreaControl1.setText(sql);
- }
- catch (Exception ex) {
- DataSetException.handleException(null, this, ex);
- }
- }
-
- void buttonControl1_actionPerformed(ActionEvent e) {
- try {
- ExecuteStatements exec = new ExecuteStatements(dm.getCurrentDatabase());
- exec.execute(textAreaControl1.getText(), dm.isAcceptCR(), dm.isKeepSemiColon());
- initState();
- }
- catch (Exception ex) {
- DataSetException.handleException(null, this, ex);
- }
- }
-
- void buttonControl2_actionPerformed(ActionEvent e) {
- if (hasCreateDLL) {
- initDDLtext(dm.getDropDDLquery());
- buttonControl2.setImageName("create.gif");
- }
- else {
- initDDLtext(dm.getDDLquery());
- buttonControl2.setImageName("cleanup.gif");
- }
- hasCreateDLL = !hasCreateDLL;
- }
-
- // Always close the connections manually:
- void this_windowClosing(WindowEvent e) {
- try {
- dm.getCurrentDatabase().closeConnection();
- }
- catch (Throwable ex) {
- }
- }
- }
-
- class ProcedureSampleFrame_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
- ProcedureSampleFrame adaptee;
-
- ProcedureSampleFrame_buttonControl1_actionAdapter(ProcedureSampleFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.buttonControl1_actionPerformed(e);
- }
- }
-
- class ProcedureSampleFrame_buttonControl2_actionAdapter implements java.awt.event.ActionListener {
- ProcedureSampleFrame adaptee;
-
- ProcedureSampleFrame_buttonControl2_actionAdapter(ProcedureSampleFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.buttonControl2_actionPerformed(e);
- }
- }
-
- class ProcedureSampleFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
- ProcedureSampleFrame adaptee;
-
- ProcedureSampleFrame_this_windowAdapter(ProcedureSampleFrame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void windowClosing(WindowEvent e) {
- adaptee.this_windowClosing(e);
- }
- }
-