KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > devgui > ConfigFilePanel


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/devgui/ConfigFilePanel.java,v 1.12 2004/08/18 13:11:57 hkollmann Exp $
3  * $Revision: 1.12 $
4  * $Date: 2004/08/18 13:11:57 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.devgui;
25
26 import java.awt.*;
27 import java.awt.event.*;
28
29 import java.io.*;
30
31 import java.sql.*;
32
33 import java.util.Vector JavaDoc;
34
35 import javax.swing.*;
36
37
38
39 /**
40  * DOCUMENT ME!
41  *
42  * @author $author$
43  * @version $Revision: 1.12 $
44  */

45 public class ConfigFilePanel extends PropertyPanel implements ActionListener {
46    private javax.swing.ButtonGroup JavaDoc catalogButtonGroup;
47    private javax.swing.ButtonGroup JavaDoc forkeyButtonGroup;
48    private javax.swing.ButtonGroup JavaDoc schemaButtonGroup;
49    private javax.swing.ButtonGroup JavaDoc tableButtonGroup;
50
51    /* changes 2002-03-04 dikr:
52    * - gui part of this panel is totally new, new functionality:
53    * - radiobuttons for selecting all catalogs/schemas/tables or entering a filter value
54    * - names of catalogs and schemas can be loaded into a combobox
55    * - catalog and schemanames can be included in table names written to dbforms
56    * config file. added checkboxes for this feature
57    * - option to let creation of config file run in transaction mode. this is a workaround
58    * for current Ingres II
59    * - let user free select if to examine tables, views, system tables via checkboxes
60    * - new options and properties needed changes in several parts of program
61    */

62    private DevGui parent;
63    private EditorPanel panel_editor;
64    private javax.swing.JButton JavaDoc b_browse;
65    private javax.swing.JButton JavaDoc b_generate;
66    private javax.swing.JButton JavaDoc b_loadLists;
67    private javax.swing.JCheckBox JavaDoc cb_autocommit;
68    private javax.swing.JCheckBox JavaDoc cb_examine_systabs;
69    private javax.swing.JCheckBox JavaDoc cb_examine_tables;
70    private javax.swing.JCheckBox JavaDoc cb_examine_views;
71    private javax.swing.JCheckBox JavaDoc cb_include_catalogname;
72    private javax.swing.JCheckBox JavaDoc cb_include_schemaname;
73    private javax.swing.JCheckBox JavaDoc cb_stdTypeNames;
74    private javax.swing.JComboBox JavaDoc catalogList;
75    private javax.swing.JComboBox JavaDoc dateFormat;
76    private javax.swing.JComboBox JavaDoc schemaList;
77    private javax.swing.JLabel JavaDoc jLabel1;
78    private javax.swing.JLabel JavaDoc jLabel2;
79    private javax.swing.JLabel JavaDoc jLabel3;
80    private javax.swing.JLabel JavaDoc jLabel4;
81    private javax.swing.JLabel JavaDoc jLabel5;
82    private javax.swing.JLabel JavaDoc jLabel6;
83    private javax.swing.JLabel JavaDoc jLabel7;
84    private javax.swing.JPanel JavaDoc jPanel1;
85    private javax.swing.JPanel JavaDoc jPanel2;
86    private javax.swing.JPanel JavaDoc jPanel3;
87    private javax.swing.JPanel JavaDoc jPanel4;
88    private javax.swing.JPanel JavaDoc jPanel5;
89    private javax.swing.JPanel JavaDoc jPanel6;
90    private javax.swing.JPanel JavaDoc panel_top;
91    private javax.swing.JRadioButton JavaDoc rb_catalog_all;
92    private javax.swing.JRadioButton JavaDoc rb_catalog_combobox;
93    private javax.swing.JRadioButton JavaDoc rb_forkey_deactivated;
94    private javax.swing.JRadioButton JavaDoc rb_forkey_getCrossReferences;
95    private javax.swing.JRadioButton JavaDoc rb_forkey_getImportedKeys;
96    private javax.swing.JRadioButton JavaDoc rb_schema_all;
97    private javax.swing.JRadioButton JavaDoc rb_schema_combobox;
98    private javax.swing.JRadioButton JavaDoc rb_table_all;
99    private javax.swing.JRadioButton JavaDoc rb_table_textfield;
100    private javax.swing.JSeparator JavaDoc jSeparator1;
101
102    // Variables declaration - do not modify//GEN-BEGIN:variables
103
private javax.swing.JSeparator JavaDoc jSeparator2;
104    private javax.swing.JSeparator JavaDoc jSeparator3;
105    private javax.swing.JSeparator JavaDoc jSeparator4;
106    private javax.swing.JSeparator JavaDoc jSeparator5;
107    private javax.swing.JSeparator JavaDoc jSeparator6;
108    private javax.swing.JSeparator JavaDoc jSeparator7;
109    private javax.swing.JSeparator JavaDoc jSeparator8;
110    private javax.swing.JTextField JavaDoc tf_configFile;
111    private javax.swing.JTextField JavaDoc tf_tableNamePattern;
112    private String JavaDoc[] dateFormats = {
113                                                    "",
114                                                    "yyyy-MM-dd",
115                                                    "yyyy_MM_dd",
116                                                    "yyyy/MM/dd",
117                                                    "yyyy.MM.dd",
118                                                    "dd-MMM-yyyy",
119                                                    "dd.MM.yyyy",
120                                                    "dd/MM/yyyyy",
121                                                    "MM-dd-yyyy"
122                                                 };
123
124    /**
125     * Creates new form WebAppPanel
126     *
127     * @param parent DOCUMENT ME!
128     */

129    public ConfigFilePanel(DevGui parent) {
130       super(parent.getProjectData());
131       this.parent = parent;
132       initComponents(); // this method is automatically generated by
133

134       // ndetbeans GUI builder
135
initComponents2(); // this method is written by a human
136
doLayout();
137    }
138
139    //GEN-LAST:event_loadCatalogAndSchemaNames
140

141    /**
142     * DOCUMENT ME!
143     *
144     * @param projectData DOCUMENT ME!
145     */

146    public void setNewProjectData(ProjectData projectData) {
147       this.projectData = projectData;
148
149       String JavaDoc webAppRoot = projectData.getProperty("webAppRoot");
150       String JavaDoc configFile = projectData.getProperty(CONFIG_FILE);
151
152       tf_configFile.setText("");
153
154       if (!"".equals(configFile)) {
155          tf_configFile.setText(configFile);
156
157          File f = new File(configFile);
158
159          if (f.exists() && f.isFile()) {
160             panel_editor.setFile(f);
161          }
162       } else {
163          if (!"".equals(webAppRoot)) {
164             tf_configFile.setText(FileNameTool.normalize(webAppRoot)
165                                   + "WEB-INF" + parent.getFileSeparator());
166          }
167       }
168
169       initializeCatalogAndSchemaList();
170
171       // set radioButtons for foreign key detection:
172
String JavaDoc forKeyDetection = projectData.getProperty(FOREIGNKEY_DETECTION);
173
174       if (DEACTIVATED.equalsIgnoreCase(forKeyDetection)) {
175          rb_forkey_deactivated.setSelected(true);
176       } else if (USE_GETCROSSREFERENCES.equalsIgnoreCase(forKeyDetection)) {
177          rb_forkey_getCrossReferences.setSelected(true);
178       } else {
179          rb_forkey_getImportedKeys.setSelected(true);
180       }
181
182       // set radioButtons for catalog, schema and tablenamepattern selection:
183
if (ALL.equalsIgnoreCase(projectData.getProperty(CATALOG_SELECTION))) {
184          rb_catalog_all.setSelected(true);
185       } else {
186          rb_catalog_combobox.setSelected(true);
187       }
188
189       if (ALL.equalsIgnoreCase(projectData.getProperty(SCHEMA_SELECTION))) {
190          rb_schema_all.setSelected(true);
191       } else {
192          rb_schema_combobox.setSelected(true);
193       }
194
195       if (ALL.equalsIgnoreCase(projectData.getProperty(TABLE_SELECTION))) {
196          rb_table_all.setSelected(true);
197       } else {
198          rb_table_textfield.setSelected(true);
199       }
200
201       // set checkboxes for including catalog or schemaname and for
202
// autocommit mode:
203
cb_include_catalogname.setSelected(TRUESTRING.equalsIgnoreCase(projectData
204                                                                      .getProperty(INCLUDE_CATALOGNAME)));
205       cb_include_schemaname.setSelected(TRUESTRING.equalsIgnoreCase(projectData
206                                                                     .getProperty(INCLUDE_SCHEMANAME)));
207       cb_autocommit.setSelected(TRUESTRING.equalsIgnoreCase(projectData
208                                                             .getProperty(AUTOCOMMIT_MODE)));
209
210       cb_stdTypeNames.setSelected(TRUESTRING.equalsIgnoreCase(projectData
211                                                               .getProperty(WRITE_STD_TYPENAMES)));
212
213       // set checkboxes for examination of tables, views and system tables:
214
cb_examine_tables.setSelected(TRUESTRING.equalsIgnoreCase(projectData
215                                                                 .getProperty(EXAMINE_TABLES)));
216       cb_examine_views.setSelected(TRUESTRING.equalsIgnoreCase(projectData
217                                                                .getProperty(EXAMINE_VIEWS)));
218       cb_examine_systabs.setSelected(TRUESTRING.equalsIgnoreCase(projectData
219                                                                  .getProperty(EXAMINE_SYSTABS)));
220
221       // set value for comboboxes for catalog and schema:
222
catalogList.setSelectedItem(projectData.getProperty(CATALOG));
223       schemaList.setSelectedItem(projectData.getProperty(SCHEMA));
224
225       // set textfield for tablename pattern:
226
tf_tableNamePattern.setText(projectData.getProperty(TABLE_NAME_PATTERN));
227
228       // set date format, if found:
229
if (projectData.getProperty(DATE_FORMAT) != null) {
230          dateFormat.setSelectedItem(projectData.getProperty(DATE_FORMAT));
231       }
232    }
233
234
235    /**
236     * DOCUMENT ME!
237     *
238     * @param ev DOCUMENT ME!
239     */

240    public void actionPerformed(ActionEvent ev) {
241       if (ev.getSource() == b_generate) {
242          String JavaDoc configFile = projectData.getProperty(CONFIG_FILE);
243
244          if (!"".equals(configFile)) {
245             File f = new File(configFile);
246
247             try {
248                String JavaDoc result = XMLConfigGenerator.createXMLOutput(projectData,
249                                                                   true);
250
251                FileOutputStream os = new FileOutputStream(f);
252                ByteArrayInputStream is = new ByteArrayInputStream(result.getBytes());
253
254                byte[] b = new byte[1024];
255                int read;
256
257                while ((read = is.read(b)) != -1) {
258                   os.write(b, 0, read);
259                }
260
261                panel_editor.setFile(f);
262             } catch (IOException ioe) {
263                showExceptionDialog(ioe);
264             } catch (Exception JavaDoc e) {
265                showExceptionDialog(e);
266             }
267          } else {
268             JOptionPane.showMessageDialog(this,
269                                           "Please enter name of config file");
270          }
271       } else if (ev.getSource() == b_browse) {
272          String JavaDoc configFile = projectData.getProperty(CONFIG_FILE);
273
274          System.out.println("configFile=" + configFile + "!");
275
276          File dlgFile;
277
278          System.out.println("ps2");
279
280          if (!"".equals(configFile)) {
281             System.out.println("ps3");
282             dlgFile = new File(configFile);
283             System.out.println("ps4");
284          } else {
285             System.out.println("ps5");
286
287             String JavaDoc webAppRoot = projectData.getProperty("webAppRoot");
288             System.out.println("ps6");
289
290             if (!"".equals(webAppRoot)) {
291                System.out.println("ps7");
292                dlgFile = new File(webAppRoot);
293                System.out.println("ps8");
294             } else {
295                System.out.println("ps9");
296                dlgFile = null;
297                System.out.println("ps10");
298             }
299          }
300
301          if ((dlgFile != null) && dlgFile.exists()) {
302             dlgFile = null;
303          }
304
305          JFileChooser dlg_fileChooser = new JFileChooser(dlgFile);
306          dlg_fileChooser.setVisible(true);
307
308          int returnVal = dlg_fileChooser.showOpenDialog(this);
309
310          if (returnVal == JFileChooser.APPROVE_OPTION) {
311             File selectedFile = dlg_fileChooser.getSelectedFile();
312             tf_configFile.setText(selectedFile.getAbsolutePath());
313             tf_configFile.grabFocus();
314             panel_editor.setFile(selectedFile);
315          }
316       }
317    }
318
319
320    /**
321     * DOCUMENT ME!
322     *
323     * @param cb DOCUMENT ME!
324     * @param propertyName DOCUMENT ME!
325     */

326    protected void addCheckBoxItemListener(final JCheckBox cb,
327                                           final String JavaDoc propertyName) {
328       cb.addItemListener(new java.awt.event.ItemListener JavaDoc() {
329             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
330                projectData.setProperty(propertyName,
331                                        cb.isSelected() ? TRUESTRING
332                                                        : FALSESTRING);
333             }
334          });
335    }
336
337
338    /**
339     * DOCUMENT ME!
340     *
341     * @param cb DOCUMENT ME!
342     * @param p DOCUMENT ME!
343     */

344    protected void addComboBoxItemListener(final JComboBox cb,
345                                           final String JavaDoc p) {
346       cb.addItemListener(new java.awt.event.ItemListener JavaDoc() {
347             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
348                projectData.setProperty(p, (String JavaDoc) cb.getSelectedItem());
349             }
350          });
351    }
352
353
354    /**
355     * DOCUMENT ME!
356     *
357     * @param rb DOCUMENT ME!
358     * @param propertyName DOCUMENT ME!
359     * @param propertyValue DOCUMENT ME!
360     */

361    protected void addJRadioButtonActionListener(final JRadioButton rb,
362                                                 final String JavaDoc propertyName,
363                                                 final String JavaDoc propertyValue) {
364       rb.addActionListener(new java.awt.event.ActionListener JavaDoc() {
365             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
366                projectData.setProperty(propertyName, propertyValue);
367             }
368          });
369    }
370
371
372    /**
373     * This method is called from within the constructor to initialize the form.
374     * WARNING: Do NOT modify this code. The content of this method is always
375     * regenerated by the Form Editor.
376     */

377    private void initComponents() { //GEN-BEGIN:initComponents
378

379       java.awt.GridBagConstraints JavaDoc gridBagConstraints;
380
381       catalogButtonGroup = new javax.swing.ButtonGroup JavaDoc();
382       schemaButtonGroup = new javax.swing.ButtonGroup JavaDoc();
383       tableButtonGroup = new javax.swing.ButtonGroup JavaDoc();
384       forkeyButtonGroup = new javax.swing.ButtonGroup JavaDoc();
385       panel_top = new javax.swing.JPanel JavaDoc();
386       tf_tableNamePattern = new javax.swing.JTextField JavaDoc();
387       jPanel2 = new javax.swing.JPanel JavaDoc();
388       jLabel1 = new javax.swing.JLabel JavaDoc();
389       tf_configFile = new javax.swing.JTextField JavaDoc();
390       b_browse = new javax.swing.JButton JavaDoc();
391       rb_catalog_all = new javax.swing.JRadioButton JavaDoc();
392       rb_schema_all = new javax.swing.JRadioButton JavaDoc();
393       rb_table_all = new javax.swing.JRadioButton JavaDoc();
394       rb_table_textfield = new javax.swing.JRadioButton JavaDoc();
395       jSeparator1 = new javax.swing.JSeparator JavaDoc();
396       jSeparator2 = new javax.swing.JSeparator JavaDoc();
397       jSeparator3 = new javax.swing.JSeparator JavaDoc();
398       jSeparator4 = new javax.swing.JSeparator JavaDoc();
399       rb_catalog_combobox = new javax.swing.JRadioButton JavaDoc();
400       jPanel1 = new javax.swing.JPanel JavaDoc();
401       b_generate = new javax.swing.JButton JavaDoc();
402       rb_schema_combobox = new javax.swing.JRadioButton JavaDoc();
403       cb_autocommit = new javax.swing.JCheckBox JavaDoc();
404       jPanel3 = new javax.swing.JPanel JavaDoc();
405       jLabel3 = new javax.swing.JLabel JavaDoc();
406       cb_include_catalogname = new javax.swing.JCheckBox JavaDoc();
407       jLabel4 = new javax.swing.JLabel JavaDoc();
408       cb_include_schemaname = new javax.swing.JCheckBox JavaDoc();
409       jLabel5 = new javax.swing.JLabel JavaDoc();
410       jPanel4 = new javax.swing.JPanel JavaDoc();
411       jLabel6 = new javax.swing.JLabel JavaDoc();
412       cb_examine_tables = new javax.swing.JCheckBox JavaDoc();
413       cb_examine_views = new javax.swing.JCheckBox JavaDoc();
414       cb_examine_systabs = new javax.swing.JCheckBox JavaDoc();
415       jSeparator5 = new javax.swing.JSeparator JavaDoc();
416       catalogList = new javax.swing.JComboBox JavaDoc();
417       schemaList = new javax.swing.JComboBox JavaDoc();
418       b_loadLists = new javax.swing.JButton JavaDoc();
419       cb_stdTypeNames = new javax.swing.JCheckBox JavaDoc();
420       jSeparator6 = new javax.swing.JSeparator JavaDoc();
421       jPanel5 = new javax.swing.JPanel JavaDoc();
422       jLabel2 = new javax.swing.JLabel JavaDoc();
423       dateFormat = new javax.swing.JComboBox JavaDoc();
424       jSeparator7 = new javax.swing.JSeparator JavaDoc();
425       jPanel6 = new javax.swing.JPanel JavaDoc();
426       jLabel7 = new javax.swing.JLabel JavaDoc();
427       rb_forkey_getImportedKeys = new javax.swing.JRadioButton JavaDoc();
428       rb_forkey_getCrossReferences = new javax.swing.JRadioButton JavaDoc();
429       rb_forkey_deactivated = new javax.swing.JRadioButton JavaDoc();
430       jSeparator8 = new javax.swing.JSeparator JavaDoc();
431
432       setLayout(new java.awt.BorderLayout JavaDoc());
433
434       panel_top.setLayout(new java.awt.GridBagLayout JavaDoc());
435
436       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
437       gridBagConstraints.gridx = 2;
438       gridBagConstraints.gridy = 7;
439       gridBagConstraints.gridwidth = 2;
440       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
441       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
442       gridBagConstraints.weightx = 1.0;
443       panel_top.add(tf_tableNamePattern, gridBagConstraints);
444
445       jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
446
447       jLabel1.setText("DbForms-Config File: ");
448       jPanel2.add(jLabel1, new java.awt.GridBagConstraints JavaDoc());
449
450       tf_configFile.setMinimumSize(new java.awt.Dimension JavaDoc(50, 24));
451       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
452       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
453       gridBagConstraints.weightx = 1.0;
454       jPanel2.add(tf_configFile, gridBagConstraints);
455
456       b_browse.setText("browse...");
457       jPanel2.add(b_browse, new java.awt.GridBagConstraints JavaDoc());
458
459       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
460       gridBagConstraints.gridwidth = 4;
461       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
462       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
463       gridBagConstraints.weightx = 1.0;
464       panel_top.add(jPanel2, gridBagConstraints);
465
466       rb_catalog_all.setSelected(true);
467       rb_catalog_all.setText("in all catalogs");
468       catalogButtonGroup.add(rb_catalog_all);
469       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
470       gridBagConstraints.gridx = 0;
471       gridBagConstraints.gridy = 5;
472       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
473       panel_top.add(rb_catalog_all, gridBagConstraints);
474
475       rb_schema_all.setSelected(true);
476       rb_schema_all.setText("in all schemas");
477       schemaButtonGroup.add(rb_schema_all);
478       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
479       gridBagConstraints.gridx = 0;
480       gridBagConstraints.gridy = 6;
481       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
482       panel_top.add(rb_schema_all, gridBagConstraints);
483
484       rb_table_all.setSelected(true);
485       rb_table_all.setText("with arbitrary names");
486       tableButtonGroup.add(rb_table_all);
487       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
488       gridBagConstraints.gridx = 0;
489       gridBagConstraints.gridy = 7;
490       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
491       panel_top.add(rb_table_all, gridBagConstraints);
492
493       rb_table_textfield.setText("with table name pattern:");
494       tableButtonGroup.add(rb_table_textfield);
495       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
496       gridBagConstraints.gridx = 1;
497       gridBagConstraints.gridy = 7;
498       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
499       panel_top.add(rb_table_textfield, gridBagConstraints);
500
501       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
502       gridBagConstraints.gridx = 0;
503       gridBagConstraints.gridy = 1;
504       gridBagConstraints.gridwidth = 4;
505       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
506       panel_top.add(jSeparator1, gridBagConstraints);
507
508       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
509       gridBagConstraints.gridx = 0;
510       gridBagConstraints.gridy = 16;
511       gridBagConstraints.gridwidth = 4;
512       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
513       panel_top.add(jSeparator2, gridBagConstraints);
514
515       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
516       gridBagConstraints.gridx = 0;
517       gridBagConstraints.gridy = 8;
518       gridBagConstraints.gridwidth = 4;
519       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
520       panel_top.add(jSeparator3, gridBagConstraints);
521
522       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
523       gridBagConstraints.gridx = 0;
524       gridBagConstraints.gridy = 10;
525       gridBagConstraints.gridwidth = 4;
526       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
527       panel_top.add(jSeparator4, gridBagConstraints);
528
529       rb_catalog_combobox.setText("in catalog with name:");
530       catalogButtonGroup.add(rb_catalog_combobox);
531       rb_catalog_combobox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
532             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
533                rb_catalog_comboboxActionPerformed(evt);
534             }
535          });
536
537       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
538       gridBagConstraints.gridx = 1;
539       gridBagConstraints.gridy = 5;
540       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
541       panel_top.add(rb_catalog_combobox, gridBagConstraints);
542
543       b_generate.setText("Generate XML!");
544       jPanel1.add(b_generate);
545
546       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
547       gridBagConstraints.gridx = 0;
548       gridBagConstraints.gridy = 19;
549       gridBagConstraints.gridwidth = 4;
550       panel_top.add(jPanel1, gridBagConstraints);
551
552       rb_schema_combobox.setText("in schema with name pattern:");
553       schemaButtonGroup.add(rb_schema_combobox);
554       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
555       gridBagConstraints.gridx = 1;
556       gridBagConstraints.gridy = 6;
557       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
558       panel_top.add(rb_schema_combobox, gridBagConstraints);
559
560       cb_autocommit.setSelected(true);
561       cb_autocommit.setText("Use autocommit mode while reading metadata (recommended).");
562       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
563       gridBagConstraints.gridx = 0;
564       gridBagConstraints.gridy = 9;
565       gridBagConstraints.gridwidth = 4;
566       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
567       panel_top.add(cb_autocommit, gridBagConstraints);
568
569       jLabel3.setText("Include");
570       jPanel3.add(jLabel3);
571
572       cb_include_catalogname.setText("catalog name");
573       jPanel3.add(cb_include_catalogname);
574
575       jLabel4.setText(" ");
576       jPanel3.add(jLabel4);
577
578       cb_include_schemaname.setText("schema name");
579       jPanel3.add(cb_include_schemaname);
580
581       jLabel5.setText("in table name.");
582       jPanel3.add(jLabel5);
583
584       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
585       gridBagConstraints.gridx = 0;
586       gridBagConstraints.gridy = 15;
587       gridBagConstraints.gridwidth = 4;
588       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
589       panel_top.add(jPanel3, gridBagConstraints);
590
591       jPanel4.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
592
593       jLabel6.setText("Examine");
594       jPanel4.add(jLabel6);
595
596       cb_examine_tables.setSelected(true);
597       cb_examine_tables.setText("Tables");
598       jPanel4.add(cb_examine_tables);
599
600       cb_examine_views.setSelected(true);
601       cb_examine_views.setText("Views");
602       jPanel4.add(cb_examine_views);
603
604       cb_examine_systabs.setText("System Tables");
605       jPanel4.add(cb_examine_systabs);
606
607       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
608       gridBagConstraints.gridx = 0;
609       gridBagConstraints.gridy = 3;
610       gridBagConstraints.gridwidth = 4;
611       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
612       panel_top.add(jPanel4, gridBagConstraints);
613
614       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
615       gridBagConstraints.gridx = 0;
616       gridBagConstraints.gridy = 4;
617       gridBagConstraints.gridwidth = 4;
618       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
619       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
620       panel_top.add(jSeparator5, gridBagConstraints);
621
622       catalogList.setEditable(true);
623       catalogList.setMinimumSize(new java.awt.Dimension JavaDoc(124, 24));
624       catalogList.setPreferredSize(new java.awt.Dimension JavaDoc(128, 24));
625       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
626       gridBagConstraints.gridx = 2;
627       gridBagConstraints.gridy = 5;
628       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
629       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
630       gridBagConstraints.weightx = 1.0;
631       panel_top.add(catalogList, gridBagConstraints);
632
633       schemaList.setEditable(true);
634       schemaList.setMinimumSize(new java.awt.Dimension JavaDoc(124, 24));
635       schemaList.setPreferredSize(new java.awt.Dimension JavaDoc(128, 24));
636       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
637       gridBagConstraints.gridx = 2;
638       gridBagConstraints.gridy = 6;
639       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
640       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
641       gridBagConstraints.weightx = 1.0;
642       panel_top.add(schemaList, gridBagConstraints);
643
644       b_loadLists.setText("Load");
645       b_loadLists.setToolTipText("Load catalog and schema names from database");
646       b_loadLists.addActionListener(new java.awt.event.ActionListener JavaDoc() {
647             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
648                loadCatalogAndSchemaNames(evt);
649             }
650          });
651
652       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
653       gridBagConstraints.gridx = 3;
654       gridBagConstraints.gridy = 5;
655       gridBagConstraints.gridheight = 2;
656       gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
657       gridBagConstraints.weighty = 0.5;
658       panel_top.add(b_loadLists, gridBagConstraints);
659
660       cb_stdTypeNames.setText("Try to write standard type names for unknown field types into xml config file.");
661       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
662       gridBagConstraints.gridx = 0;
663       gridBagConstraints.gridy = 11;
664       gridBagConstraints.gridwidth = 4;
665       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
666       panel_top.add(cb_stdTypeNames, gridBagConstraints);
667
668       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
669       gridBagConstraints.gridx = 0;
670       gridBagConstraints.gridy = 14;
671       gridBagConstraints.gridwidth = 4;
672       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
673       gridBagConstraints.weightx = 1.0;
674       panel_top.add(jSeparator6, gridBagConstraints);
675
676       jLabel2.setText("Set date format to: ");
677       jPanel5.add(jLabel2);
678
679       dateFormat.setEditable(true);
680       jPanel5.add(dateFormat);
681
682       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
683       gridBagConstraints.gridx = 0;
684       gridBagConstraints.gridy = 17;
685       gridBagConstraints.gridwidth = 4;
686       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
687       panel_top.add(jPanel5, gridBagConstraints);
688
689       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
690       gridBagConstraints.gridx = 0;
691       gridBagConstraints.gridy = 18;
692       gridBagConstraints.gridwidth = 4;
693       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
694       panel_top.add(jSeparator7, gridBagConstraints);
695
696       jPanel6.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
697
698       jLabel7.setText("Foreign Key Detection:");
699       jPanel6.add(jLabel7);
700
701       rb_forkey_getImportedKeys.setSelected(true);
702       rb_forkey_getImportedKeys.setText("getImportedKeys( )");
703       forkeyButtonGroup.add(rb_forkey_getImportedKeys);
704       jPanel6.add(rb_forkey_getImportedKeys);
705
706       rb_forkey_getCrossReferences.setText("getCrossReferences( )");
707       rb_forkey_getCrossReferences.setToolTipText("null");
708       forkeyButtonGroup.add(rb_forkey_getCrossReferences);
709       jPanel6.add(rb_forkey_getCrossReferences);
710
711       rb_forkey_deactivated.setText("deactivated");
712       forkeyButtonGroup.add(rb_forkey_deactivated);
713       jPanel6.add(rb_forkey_deactivated);
714
715       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
716       gridBagConstraints.gridx = 0;
717       gridBagConstraints.gridy = 13;
718       gridBagConstraints.gridwidth = 4;
719       gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 1, 0, 1);
720       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
721       panel_top.add(jPanel6, gridBagConstraints);
722
723       gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
724       gridBagConstraints.gridx = 0;
725       gridBagConstraints.gridy = 12;
726       gridBagConstraints.gridwidth = 4;
727       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
728       gridBagConstraints.weightx = 1.0;
729       panel_top.add(jSeparator8, gridBagConstraints);
730
731       add(panel_top, java.awt.BorderLayout.NORTH);
732    }
733
734
735    private void initComponents2() {
736       b_browse.addActionListener(this);
737
738       // first listener => for global property / Project data
739
addAFocusListener(tf_configFile, CONFIG_FILE);
740
741       // second listener => for notification of texteditor
742
tf_configFile.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
743             public void focusLost(java.awt.event.FocusEvent JavaDoc e) {
744                File f = new File(tf_configFile.getText());
745
746                if (f.exists() && f.isFile() && f.canRead()) {
747                   panel_editor.setFile(f);
748                }
749             }
750          });
751
752       b_browse.setToolTipText("default: webAppRoot" + parent.getFileSeparator()
753                               + "WEB-INF" + parent.getFileSeparator()
754                               + "dbforms-config.xml\nNon-default values must be configured in web.xml!");
755
756       b_generate.addActionListener(this);
757       b_generate.setToolTipText("Generate raw content of config-file by quering the database you defined in tab \"Database properties\".");
758
759       panel_editor = new EditorPanel();
760       add(BorderLayout.CENTER, panel_editor);
761
762       // we will now register several event listeners that will automatically
763
// change property values in case corresponding gui elements are
764
// changed:
765
// register event listener that sets property in case
766
// value of table name pettern textfield is changed:
767
addAFocusListener(tf_tableNamePattern, TABLE_NAME_PATTERN);
768
769       // register event listeners for radio buttons...
770
// example: if rb_catalog_all is activated, then property
771
// CATALOG_SELECTION will be set to value ALL
772
addJRadioButtonActionListener(rb_catalog_all, CATALOG_SELECTION, ALL);
773       addJRadioButtonActionListener(rb_catalog_combobox, CATALOG_SELECTION,
774                                     SELECTION);
775
776       addJRadioButtonActionListener(rb_schema_all, SCHEMA_SELECTION, ALL);
777       addJRadioButtonActionListener(rb_schema_combobox, SCHEMA_SELECTION,
778                                     SELECTION);
779
780       addJRadioButtonActionListener(rb_table_all, TABLE_SELECTION, ALL);
781       addJRadioButtonActionListener(rb_table_textfield, TABLE_SELECTION,
782                                     SELECTION);
783
784       addJRadioButtonActionListener(rb_forkey_getImportedKeys,
785                                     FOREIGNKEY_DETECTION, USE_GETIMPORTEDKEYS);
786       addJRadioButtonActionListener(rb_forkey_getCrossReferences,
787                                     FOREIGNKEY_DETECTION, USE_GETCROSSREFERENCES);
788       addJRadioButtonActionListener(rb_forkey_deactivated,
789                                     FOREIGNKEY_DETECTION, DEACTIVATED);
790
791       // register event listeners for checkboxes...
792
// example: cb_include_catalogname is bound to
793
// property INCLUDE_CATALOGNAME
794
addCheckBoxItemListener(cb_include_catalogname, INCLUDE_CATALOGNAME);
795       addCheckBoxItemListener(cb_include_schemaname, INCLUDE_SCHEMANAME);
796       addCheckBoxItemListener(cb_autocommit, AUTOCOMMIT_MODE);
797       addCheckBoxItemListener(cb_examine_tables, EXAMINE_TABLES);
798       addCheckBoxItemListener(cb_examine_views, EXAMINE_VIEWS);
799       addCheckBoxItemListener(cb_examine_systabs, EXAMINE_SYSTABS);
800       addCheckBoxItemListener(cb_stdTypeNames, WRITE_STD_TYPENAMES);
801
802       initializeCatalogAndSchemaList();
803
804       // register event listeners to automatically set
805
// properties for catalog name and schema name:
806
addComboBoxItemListener(catalogList, CATALOG);
807       addComboBoxItemListener(schemaList, SCHEMA);
808
809       // initialize combo box with date formats:
810
for (int i = 0; i < dateFormats.length; i++) {
811          dateFormat.addItem(dateFormats[i]);
812       }
813
814       // register event Listener for date format combo box:
815
addComboBoxItemListener(dateFormat, DATE_FORMAT);
816    }
817
818
819    private void initializeCatalogAndSchemaList() {
820       // create initial values for selection lists used in
821
// combo boxes for catalog and schema names:
822
Vector JavaDoc catalogs = new Vector JavaDoc();
823       catalogs.add("--- no catalogs loaded ---");
824       catalogList.setModel(new DefaultComboBoxModel(catalogs));
825
826       // catalogList.setSelectedIndex(0);
827
// projectData.setProperty(CATALOG,(String)catalogList.getItemAt(0));
828
Vector JavaDoc schemas = new Vector JavaDoc();
829       schemas.add("--- no schemas loaded ---");
830       schemaList.setModel(new DefaultComboBoxModel(schemas));
831
832       // schemaList.setSelectedIndex(0);
833
// projectData.setProperty(SCHEMA,(String)schemaList.getItemAt(0));
834
}
835
836
837    //GEN-LAST:event_rb_catalog_comboboxActionPerformed
838

839    /*
840      try to read catalog and schema names from database and fill corresponding combo boxes
841      */

842    private void loadCatalogAndSchemaNames(java.awt.event.ActionEvent JavaDoc evt) { //GEN-FIRST:event_loadCatalogAndSchemaNames
843

844       String JavaDoc jdbcDriver = projectData.getProperty("jdbcDriver");
845       String JavaDoc jdbcURL = projectData.getProperty("jdbcURL");
846       String JavaDoc username = projectData.getProperty("username");
847       String JavaDoc password = projectData.getProperty("password");
848
849       try {
850          try {
851             Class.forName(jdbcDriver)
852                  .newInstance();
853          } catch (ClassNotFoundException JavaDoc ex) {
854             String JavaDoc message = "Could not find JDBC driver class " + jdbcDriver
855                              + "\n"
856                              + "Please check database properties and classpath!";
857
858             if (jdbcDriver.equalsIgnoreCase("")) {
859                message = "JDBC driver class in database properties not set!\n"
860                          + "Please check database properties!";
861             }
862
863             JOptionPane.showMessageDialog(this, message);
864
865             return;
866          }
867
868          Connection con = DriverManager.getConnection(jdbcURL, username,
869                                                       password);
870
871          DatabaseMetaData dbmd = con.getMetaData();
872
873          // try to read list of catalogs, in case of error
874
// continue with schemas....
875
Vector JavaDoc catalogs = new Vector JavaDoc();
876
877          try {
878             ResultSet catalogRs = dbmd.getCatalogs();
879
880             while (catalogRs.next()) {
881                catalogs.add(catalogRs.getString(1));
882             }
883          } catch (SQLException ignored) {
884             ;
885          }
886
887          if (catalogs.size() == 0) {
888             catalogs.add(" --- no catalogs found ---");
889          }
890
891          catalogList.setModel(new DefaultComboBoxModel(catalogs));
892          catalogList.setSelectedIndex(0);
893          projectData.setProperty(CATALOG, (String JavaDoc) catalogList.getItemAt(0));
894
895          // try to read list of schemas
896
Vector JavaDoc schemas = new Vector JavaDoc();
897          ResultSet schemaRs = dbmd.getSchemas();
898
899          while (schemaRs.next()) {
900             schemas.add(schemaRs.getString(1));
901          }
902
903          if (schemas.size() == 0) {
904             schemas.add("--- no schemas found ---");
905          }
906
907          schemaList.setModel(new DefaultComboBoxModel(schemas));
908          schemaList.setSelectedIndex(0);
909          projectData.setProperty(SCHEMA, (String JavaDoc) schemaList.getItemAt(0));
910       } catch (Exception JavaDoc ex) {
911          showExceptionDialog(ex);
912       }
913    }
914
915
916    //GEN-END:initComponents
917
private void rb_catalog_comboboxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
918       //GEN-FIRST:event_rb_catalog_comboboxActionPerformed
919
// Add your handling code here:
920
}
921
922    // End of variables declaration//GEN-END:variables
923
}
924
Popular Tags