home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JSAMPLES.Z / ProcedureSampleFrame.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  8.5 KB  |  219 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:        Stored Procedure Sample
  22. //Version:      2.0
  23. //Copyright:    Copyright (c) 1998
  24. //Company:      Borland Int'l
  25. //Description:  The Sample frame, consisting a TabsetPanel with 2 pages.
  26. //              The 'DDL' page executes sql statements when the lightning
  27. //              bulb is pressed. This should create tables and stored 
  28. //              procedures on the database. After that the second page 
  29. //              should appear with the actual test grids.
  30.  
  31.  
  32. package borland.samples.tutorial.dataset.storedprocedure;
  33.  
  34. import java.io.*;
  35. import java.awt.*;
  36. import java.awt.event.*;
  37. import borland.jbcl.layout.*;
  38. import borland.jbcl.control.*;
  39. import borland.jbcl.dataset.*;
  40. import borland.sql.dataset.*;
  41.  
  42. public class ProcedureSampleFrame extends DecoratedFrame {
  43.   TabsetPanel tabsetPanel1 = new TabsetPanel();
  44.   BorderLayout borderLayout1 = new BorderLayout();
  45.   BevelPanel bevelPanel1 = new BevelPanel();
  46.   ButtonControl buttonControl1 = new ButtonControl();
  47.   TextAreaControl textAreaControl1 = new TextAreaControl();
  48.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  49.   BevelPanel bevelPanel2 = new BevelPanel();
  50.   GridControl gridControl1 = new GridControl();
  51.   NavigatorControl navigatorControl2 = new NavigatorControl();
  52.   NavigatorControl navigatorControl1 = new NavigatorControl();
  53.   GridControl gridControl2 = new GridControl();
  54.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  55.   TextControl textControl1 = new TextControl();
  56.   TextControl textControl2 = new TextControl();
  57.   StoredProcedureDM dm = new StoredProcedureDM();
  58.   ButtonControl buttonControl2 = new ButtonControl();
  59.   boolean hasCreateDLL;
  60.  
  61.   public ProcedureSampleFrame() {
  62.     try {
  63.       jbInit();
  64.       initDDLtext();
  65.       initState();
  66.     }
  67.     catch (Exception e) {
  68.       e.printStackTrace();
  69.     }
  70.   }
  71.  
  72.   private void jbInit() throws Exception{
  73.     this.setSize(new Dimension(664, 420));
  74.     this.setTitle("Stored Procedure Sample");
  75.     this.addWindowListener(new ProcedureSampleFrame_this_windowAdapter(this));
  76.     tabsetPanel1.setClientBordered(false);
  77.     tabsetPanel1.setLabels(new String[] {"DDL", "Test Procedures"});
  78.     tabsetPanel1.setSelectedIndex(0);
  79.     bevelPanel1.setBevelInner(BevelPanel.FLAT);
  80.     bevelPanel1.setLayout(gridBagLayout1);
  81.     buttonControl1.setImageName("run.gif");
  82.     textAreaControl1.setFont(new Font("Monospaced", 0, 12));
  83.     buttonControl1.addActionListener(new ProcedureSampleFrame_buttonControl1_actionAdapter(this));
  84.     bevelPanel2.setBevelInner(BevelPanel.FLAT);
  85.     gridControl1.setDataSet(dm.getMasterQDS());
  86.     navigatorControl2.setDataSet(dm.getDetailPDS());
  87.     navigatorControl1.setDataSet(dm.getMasterQDS());
  88.     gridControl2.setDataSet(dm.getDetailPDS());
  89.     textControl1.setText("Master from Query :");
  90.     textControl2.setText("Detail from Procedure :");
  91.     buttonControl2.addActionListener(new ProcedureSampleFrame_buttonControl2_actionAdapter(this));
  92.     bevelPanel2.setLayout(gridBagLayout2);
  93.     this.setLayout(borderLayout1);
  94.     this.add(tabsetPanel1, BorderLayout.CENTER);
  95.     tabsetPanel1.add(bevelPanel1, "DDL");
  96.     bevelPanel1.add(buttonControl1, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
  97.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
  98.     bevelPanel1.add(textAreaControl1, new GridBagConstraints2(0, 0, 1, 3, 1.0, 1.0
  99.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  100.     bevelPanel1.add(buttonControl2, new GridBagConstraints2(2, 2, 1, 1, 0.0, 0.0
  101.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
  102.     tabsetPanel1.add(bevelPanel2, "Test Procedures");
  103.     bevelPanel2.add(gridControl1, new GridBagConstraints2(0, 1, 2, 1, 1.0, 1.0
  104.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  105.     bevelPanel2.add(navigatorControl2, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
  106.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
  107.     bevelPanel2.add(navigatorControl1, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  108.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  109.     bevelPanel2.add(gridControl2, new GridBagConstraints2(0, 3, 2, 1, 1.0, 1.0
  110.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  111.     bevelPanel2.add(textControl1, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
  112.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  113.     bevelPanel2.add(textControl2, new GridBagConstraints2(1, 2, 1, 1, 0.0, 0.0
  114.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  115.   }
  116.  
  117.   void initDDLtext() {
  118.     initDDLtext(dm.getDDLquery());
  119.     buttonControl2.setImageName("cleanup.gif");
  120.     hasCreateDLL = true;
  121.   }
  122.  
  123.   void initState() {
  124.     try {
  125.       dm.getMasterQDS().open();
  126.       dm.getDetailPDS().open();
  127.       dm.getMasterQDS().refresh();
  128.       dm.getDetailPDS().refresh();
  129.       tabsetPanel1.add(bevelPanel2, "Test Procedures");
  130.       tabsetPanel1.setSelectedIndex(1);
  131.     }
  132.     catch (Exception ex) {
  133.       tabsetPanel1.removeTab("Test Procedures");
  134.       tabsetPanel1.setSelectedIndex(0);
  135.     }                           
  136.   }
  137.   
  138.   void initDDLtext(String filename) {
  139.     try {
  140.       FileInputStream fs = new FileInputStream(filename);
  141.       byte[] stream = new byte[fs.available()];
  142.       fs.read(stream,0,stream.length);
  143.       String sql = new String(stream);
  144.       textAreaControl1.setText(sql);
  145.     }
  146.     catch (Exception ex) {
  147.       DataSetException.handleException(null, this, ex);
  148.     }
  149.   }  
  150.   
  151.   void buttonControl1_actionPerformed(ActionEvent e) {
  152.     try {
  153.       ExecuteStatements exec = new ExecuteStatements(dm.getCurrentDatabase()); 
  154.       exec.execute(textAreaControl1.getText(), dm.isAcceptCR(), dm.isKeepSemiColon());
  155.       initState();
  156.     }
  157.     catch (Exception ex) {
  158.       DataSetException.handleException(null, this, ex);
  159.     }
  160.   }
  161.  
  162.   void buttonControl2_actionPerformed(ActionEvent e) {
  163.     if (hasCreateDLL) {
  164.       initDDLtext(dm.getDropDDLquery());
  165.       buttonControl2.setImageName("create.gif");
  166.     }
  167.     else {
  168.       initDDLtext(dm.getDDLquery());
  169.       buttonControl2.setImageName("cleanup.gif");
  170.     }
  171.     hasCreateDLL = !hasCreateDLL;  
  172.   }
  173.  
  174.   // Always close the connections manually:
  175.   void this_windowClosing(WindowEvent e) {
  176.     try {
  177.       dm.getCurrentDatabase().closeConnection();
  178.     }
  179.     catch (Throwable ex) {
  180.     }
  181.   }
  182. }
  183.  
  184. class ProcedureSampleFrame_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
  185.   ProcedureSampleFrame adaptee;
  186.  
  187.   ProcedureSampleFrame_buttonControl1_actionAdapter(ProcedureSampleFrame adaptee) {
  188.     this.adaptee = adaptee;
  189.   }
  190.  
  191.   public void actionPerformed(ActionEvent e) {
  192.     adaptee.buttonControl1_actionPerformed(e);
  193.   }
  194. }
  195.  
  196. class ProcedureSampleFrame_buttonControl2_actionAdapter implements java.awt.event.ActionListener {
  197.   ProcedureSampleFrame adaptee;
  198.  
  199.   ProcedureSampleFrame_buttonControl2_actionAdapter(ProcedureSampleFrame adaptee) {
  200.     this.adaptee = adaptee;
  201.   }
  202.  
  203.   public void actionPerformed(ActionEvent e) {
  204.     adaptee.buttonControl2_actionPerformed(e);
  205.   }
  206. }
  207.  
  208. class ProcedureSampleFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
  209.   ProcedureSampleFrame adaptee;
  210.  
  211.   ProcedureSampleFrame_this_windowAdapter(ProcedureSampleFrame adaptee) {
  212.     this.adaptee = adaptee;
  213.   }
  214.  
  215.   public void windowClosing(WindowEvent e) {
  216.     adaptee.this_windowClosing(e);
  217.   }
  218. }
  219.