KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb > gui > JFrmMainFrame


1 package org.apache.ojb.tools.mapping.reversedb.gui;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.tools.mapping.reversedb.gui.actions.*;
19
20 /**
21  *
22  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
23  * @version $Id: JFrmMainFrame.java,v 1.1.2.1 2005/12/21 22:32:02 tomdz Exp $
24  */

25 public class JFrmMainFrame extends javax.swing.JFrame JavaDoc
26 {
27     public static final String JavaDoc JDBC_DRIVER = "JDBCDriver";
28     public static final String JavaDoc JDBC_URL = "JDBCURL";
29     public static final String JavaDoc JDBC_USER = "JDBCUsername";
30     public static final String JavaDoc JDBC_PASSWORD = "JDBCPassword";
31     
32     private java.util.HashMap JavaDoc hmPropertySheets = new java.util.HashMap JavaDoc();
33     
34     org.apache.ojb.tools.mapping.reversedb.DBMeta aDBMeta;
35     java.util.Properties JavaDoc schemeGeneratorProperties;
36     java.sql.Connection JavaDoc aConnection = null;
37     
38     /** Creates new form JFrmMainFrame */
39     public JFrmMainFrame(java.util.Properties JavaDoc theProperties)
40     {
41         schemeGeneratorProperties = theProperties;
42         initComponents();
43     }
44     
45     public void setConnection(java.sql.Connection JavaDoc conn)
46     {
47         firePropertyChange("JDBCConnection", aConnection, conn);
48         aConnection = conn;
49     }
50     
51     public String JavaDoc getProperty(String JavaDoc propertyName, String JavaDoc defaultValue)
52     {
53         return schemeGeneratorProperties.getProperty(propertyName, defaultValue);
54     }
55     
56     public void setProperty(String JavaDoc propertyName, String JavaDoc value)
57     {
58         firePropertyChange(propertyName,
59         schemeGeneratorProperties.getProperty(propertyName), value);
60         schemeGeneratorProperties.setProperty(propertyName, value);
61         try
62         {
63             schemeGeneratorProperties.store(new java.io.FileOutputStream JavaDoc(System.getProperty("user.home") +
64             System.getProperty("file.separator") + "SchemeGenerator.properties"), "");
65         }
66         catch (java.io.FileNotFoundException JavaDoc ex)
67         {
68             ex.printStackTrace();
69         }
70         catch (java.io.IOException JavaDoc ioex)
71         {
72             ioex.printStackTrace();
73         }
74     }
75     
76     public org.apache.ojb.tools.mapping.reversedb.DBMeta getDBMeta()
77     {
78         return this.aDBMeta;
79     }
80     
81     public void analyzeSchema()
82     {
83         try
84         {
85             String JavaDoc strCatalogPattern = javax.swing.JOptionPane.showInputDialog(this, "Enter regular expression to filter catalogs (leave blank to get all catalogs, all catalogs will match the expression)");
86             String JavaDoc strSchemaPattern = javax.swing.JOptionPane.showInputDialog(this, "Enter regular expression to filter schemas (leave blank to get all schemas, all read schemas will match the expression)");
87             
88             aDBMeta = new org.apache.ojb.tools.mapping.reversedb.DBMeta(strCatalogPattern, strSchemaPattern, this.aConnection.getMetaData());
89             aDBMeta.read();
90             aDBMeta.generateReferences();
91             aDBMeta.debug();
92             this.jTree1.setModel(new javax.swing.tree.DefaultTreeModel JavaDoc(aDBMeta));
93         }
94         catch (java.sql.SQLException JavaDoc sqlEx)
95         {
96             java.sql.SQLException JavaDoc currentSqlEx = sqlEx;
97             while (currentSqlEx != null)
98             {
99                 System.out.println(sqlEx.getErrorCode() + ":" + sqlEx.getMessage());
100                 currentSqlEx = currentSqlEx.getNextException();
101             }
102             sqlEx.printStackTrace();
103         }
104         catch (Throwable JavaDoc t)
105         {
106             t.printStackTrace();
107         }
108     }
109     
110     /** This method is called from within the constructor to
111      * initialize the form.
112      * WARNING: Do NOT modify this code. The content of this method is
113      * always regenerated by the Form Editor.
114      */

115     private void initComponents() {//GEN-BEGIN:initComponents
116
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
117
118         jToolBar1 = new javax.swing.JToolBar JavaDoc();
119         jButton1 = new javax.swing.JButton JavaDoc();
120         jButton2 = new javax.swing.JButton JavaDoc();
121         jButton3 = new javax.swing.JButton JavaDoc();
122         jButton4 = new javax.swing.JButton JavaDoc();
123         jButton5 = new javax.swing.JButton JavaDoc();
124         jButton6 = new javax.swing.JButton JavaDoc();
125         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
126         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
127         jTree1 = new javax.swing.JTree JavaDoc();
128         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
129         jPanel1 = new javax.swing.JPanel JavaDoc();
130         menuBar = new javax.swing.JMenuBar JavaDoc();
131         fileMenu = new javax.swing.JMenu JavaDoc();
132         mnuFileConnect = new javax.swing.JMenuItem JavaDoc();
133         mnuFileReadSchema = new javax.swing.JMenuItem JavaDoc();
134         exitMenuItem = new javax.swing.JMenuItem JavaDoc();
135
136         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
137
138         setTitle("OJB Scheme Generator");
139         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
140             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
141                 exitForm(evt);
142             }
143         });
144
145         jButton1.setAction(new DBConnPropertiesAction(this));
146         jToolBar1.add(jButton1);
147
148         jButton2.setText("Read");
149         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
150             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
151                 jButton2ActionPerformed(evt);
152             }
153         });
154
155         jToolBar1.add(jButton2);
156
157         jButton3.setText("Save XML");
158         jButton3.setAction(new SaveXMLAction(this));
159         jToolBar1.add(jButton3);
160
161         jButton4.setAction(new GenerateJavaClassesAction(this));
162         jToolBar1.add(jButton4);
163
164         jButton5.setAction(new SetPackageAction(this));
165         jToolBar1.add(jButton5);
166
167         jButton6.setAction(new DisableClassesWithRegexAction(this));
168         jToolBar1.add(jButton6);
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 0;
172         gridBagConstraints.gridy = 0;
173         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
174         gridBagConstraints.weightx = 1.0;
175         getContentPane().add(jToolBar1, gridBagConstraints);
176
177         jSplitPane1.setDividerLocation(100);
178         jTree1.setModel(null);
179         jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc() {
180             public void valueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt) {
181                 jTree1ValueChanged(evt);
182             }
183         });
184
185         jScrollPane1.setViewportView(jTree1);
186
187         jSplitPane1.setLeftComponent(jScrollPane1);
188
189         jScrollPane2.setViewportView(jPanel1);
190
191         jSplitPane1.setRightComponent(jScrollPane2);
192
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 0;
195         gridBagConstraints.gridy = 1;
196         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197         gridBagConstraints.weightx = 1.0;
198         gridBagConstraints.weighty = 1.0;
199         getContentPane().add(jSplitPane1, gridBagConstraints);
200
201         fileMenu.setText("File");
202         fileMenu.addActionListener(new java.awt.event.ActionListener JavaDoc() {
203             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
204                 fileMenuActionPerformed(evt);
205             }
206         });
207
208         mnuFileConnect.setAction(new DBConnPropertiesAction(this));
209         mnuFileConnect.addActionListener(new java.awt.event.ActionListener JavaDoc() {
210             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
211                 mnuFileConnectActionPerformed(evt);
212             }
213         });
214
215         fileMenu.add(mnuFileConnect);
216
217         mnuFileReadSchema.setText("Read Schema");
218         mnuFileReadSchema.addActionListener(new java.awt.event.ActionListener JavaDoc() {
219             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
220                 mnuFileReadSchemaActionPerformed(evt);
221             }
222         });
223
224         fileMenu.add(mnuFileReadSchema);
225
226         exitMenuItem.setText("Exit");
227         exitMenuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
228             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
229                 exitMenuItemActionPerformed(evt);
230             }
231         });
232
233         fileMenu.add(exitMenuItem);
234
235         menuBar.add(fileMenu);
236
237         setJMenuBar(menuBar);
238
239         pack();
240     }//GEN-END:initComponents
241

242     private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt)//GEN-FIRST:event_jTree1ValueChanged
243
{//GEN-HEADEREND:event_jTree1ValueChanged
244
javax.swing.tree.TreePath JavaDoc tp = evt.getPath();
245         if (tp != null)
246         {
247             Object JavaDoc o = tp.getLastPathComponent();
248             if (o instanceof PropertySheetModel)
249             {
250                 PropertySheetModel p = (PropertySheetModel) o;
251                 PropertySheetView pv =
252                 (PropertySheetView)hmPropertySheets.get(p.getPropertySheetClass());
253                 if (pv == null)
254                 {
255                     try
256                     {
257                         pv = (PropertySheetView)p.getPropertySheetClass().newInstance();
258                     }
259                     catch (InstantiationException JavaDoc ie)
260                     {
261                         // What to do here?????
262
ie.printStackTrace();
263                     }
264                     catch (IllegalAccessException JavaDoc iae)
265                     {
266                         iae.printStackTrace();
267                     }
268                 }
269                 pv.setModel(p);
270                 this.jScrollPane2.setViewportView((java.awt.Component JavaDoc)pv);
271             }
272         }
273     }//GEN-LAST:event_jTree1ValueChanged
274

275   private void jButton2ActionPerformed (java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_jButton2ActionPerformed
276
{//GEN-HEADEREND:event_jButton2ActionPerformed
277
this.analyzeSchema();
278   }//GEN-LAST:event_jButton2ActionPerformed
279

280   private void mnuFileReadSchemaActionPerformed (java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_mnuFileReadSchemaActionPerformed
281
{//GEN-HEADEREND:event_mnuFileReadSchemaActionPerformed
282
this.analyzeSchema();
283   }//GEN-LAST:event_mnuFileReadSchemaActionPerformed
284

285   private void mnuFileConnectActionPerformed (java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_mnuFileConnectActionPerformed
286
{//GEN-HEADEREND:event_mnuFileConnectActionPerformed
287
// Add your handling code here:
288
}//GEN-LAST:event_mnuFileConnectActionPerformed
289

290   private void fileMenuActionPerformed (java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_fileMenuActionPerformed
291
{//GEN-HEADEREND:event_fileMenuActionPerformed
292
// Add your handling code here:
293
}//GEN-LAST:event_fileMenuActionPerformed
294

295   private void exitMenuItemActionPerformed(java.awt.event.ActionEvent JavaDoc evt)
296   {//GEN-FIRST:event_exitMenuItemActionPerformed
297
System.exit(0);
298   }//GEN-LAST:event_exitMenuItemActionPerformed
299

300   /** Exit the Application */
301   private void exitForm(java.awt.event.WindowEvent JavaDoc evt)
302   {//GEN-FIRST:event_exitForm
303
System.exit(0);
304   }//GEN-LAST:event_exitForm
305

306   /**
307    * @param args the command line arguments
308    */

309   public static void main(String JavaDoc args[])
310   {
311       // new JFrmMainFrame().show ();8
312
}
313   
314     // Variables declaration - do not modify//GEN-BEGIN:variables
315
private javax.swing.JMenuItem JavaDoc exitMenuItem;
316     private javax.swing.JMenu JavaDoc fileMenu;
317     private javax.swing.JButton JavaDoc jButton1;
318     private javax.swing.JButton JavaDoc jButton2;
319     private javax.swing.JButton JavaDoc jButton3;
320     private javax.swing.JButton JavaDoc jButton4;
321     private javax.swing.JButton JavaDoc jButton5;
322     private javax.swing.JButton JavaDoc jButton6;
323     private javax.swing.JPanel JavaDoc jPanel1;
324     private javax.swing.JScrollPane JavaDoc jScrollPane1;
325     private javax.swing.JScrollPane JavaDoc jScrollPane2;
326     private javax.swing.JSplitPane JavaDoc jSplitPane1;
327     private javax.swing.JToolBar JavaDoc jToolBar1;
328     private javax.swing.JTree JavaDoc jTree1;
329     private javax.swing.JMenuBar JavaDoc menuBar;
330     private javax.swing.JMenuItem JavaDoc mnuFileConnect;
331     private javax.swing.JMenuItem JavaDoc mnuFileReadSchema;
332     // End of variables declaration//GEN-END:variables
333

334 }
335
336 /***************************** Changelog *****************************
337  * // $Log: JFrmMainFrame.java,v $
338  * // Revision 1.1.2.1 2005/12/21 22:32:02 tomdz
339  * // Updated license
340  * //
341  * // Revision 1.1 2004/05/05 16:38:49 arminw
342  * // fix fault
343  * // wrong package structure used:
344  * // org.apache.ojb.tools.reversdb
345  * // org.apache.ojb.tools.reversdb2
346  * //
347  * // instead of
348  * // org.apache.ojb.tools.mapping.reversdb
349  * // org.apache.ojb.tools.mapping.reversdb2
350  * //
351  * // Revision 1.1 2004/05/04 13:44:59 arminw
352  * // move reverseDB stuff
353  * //
354  * // Revision 1.9 2004/04/04 23:53:42 brianm
355  * // Fixed initial copyright dates to match cvs repository
356  * //
357  * // Revision 1.8 2004/03/11 18:16:22 brianm
358  * // ASL 2.0
359  * //
360  * // Revision 1.7 2003/06/21 10:15:50 florianbruckner
361  * // start frame with a null treemodel (get rid of sample TreeModel on startup)
362  * //
363  * // Revision 1.6 2003/02/21 12:49:59 florianbruckner
364  * // remove duplicate license from header
365  * // Listen on the selection model for a changed selection instead of listening on mouse events
366  * //
367  * // Revision 1.5 2003/01/28 21:42:31 florianbruckner
368  * // add dialog for entering a schema and catalog regex pattern
369  * //
370  * // Revision 1.4 2003/01/28 19:59:35 florianbruckner
371  * // simple fix for error reporting
372  * //
373  * // Revision 1.3 2002/06/18 12:26:41 florianbruckner
374  * // changes in Netbeans Form definitions after move to jakarta.
375  * //
376  * // Revision 1.2 2002/06/17 19:34:34 jvanzyl
377  * // Correcting all the package references.
378  * // PR:
379  * // Obtained from:
380  * // Submitted by:
381  * // Reviewed by:
382  * //
383  * // Revision 1.1.1.1 2002/06/17 18:16:54 jvanzyl
384  * // Initial OJB import
385  * //
386  * // Revision 1.3 2002/05/18 19:13:33 mattbaird
387  * // Big Checkin includes:
388  *
389  * // - Fix for ODMG recursion bug, using registered for lock map.
390  *
391  * // - Do not create objects with no primary key that aren't using a key generator.
392  *
393  * // - Refactoring to allow OJB to use managed connections from an application server.
394  *
395  * // - addition of initial JCA implementation.
396  *
397  * // - addition of MBean code to integrate OJB into JBoss
398  * //
399  * // Revision 1.2 2002/05/16 11:47:09 florianbruckner
400  * // fix CR/LF issue, change license to ASL
401  * //
402  * // Revision 1.1 2002/04/18 11:44:16 mpoeschl
403  * //
404  * // move files to new location
405  * //
406  * // Revision 1.5 2002/04/07 09:05:17 thma
407  * // *** empty log message ***
408  * //
409  * // Revision 1.3 2002/03/11 18:40:26 florianbruckner
410  * // modify .form files so the use the correct package name
411  * //
412  * // Revision 1.2 2002/03/11 17:36:26 florianbruckner
413  * // fix line break issue for these files that were previously checked in with -kb
414  * //
415  * // Revision 1.1 2002/03/04 17:19:32 thma
416  * // initial checking for Florians Reverse engineering tool
417  * //
418  * // Revision 1.1.1.1 2002/02/20 13:35:25 Administrator
419  * // initial import
420  * //
421  * /***************************** Changelog *****************************/

422
Popular Tags