1 package org.apache.ojb.tools.mapping.reversedb.gui; 2 3 17 18 import org.apache.ojb.tools.mapping.reversedb.gui.actions.*; 19 20 25 public class JFrmMainFrame extends javax.swing.JFrame 26 { 27 public static final String JDBC_DRIVER = "JDBCDriver"; 28 public static final String JDBC_URL = "JDBCURL"; 29 public static final String JDBC_USER = "JDBCUsername"; 30 public static final String JDBC_PASSWORD = "JDBCPassword"; 31 32 private java.util.HashMap hmPropertySheets = new java.util.HashMap (); 33 34 org.apache.ojb.tools.mapping.reversedb.DBMeta aDBMeta; 35 java.util.Properties schemeGeneratorProperties; 36 java.sql.Connection aConnection = null; 37 38 39 public JFrmMainFrame(java.util.Properties theProperties) 40 { 41 schemeGeneratorProperties = theProperties; 42 initComponents(); 43 } 44 45 public void setConnection(java.sql.Connection conn) 46 { 47 firePropertyChange("JDBCConnection", aConnection, conn); 48 aConnection = conn; 49 } 50 51 public String getProperty(String propertyName, String defaultValue) 52 { 53 return schemeGeneratorProperties.getProperty(propertyName, defaultValue); 54 } 55 56 public void setProperty(String propertyName, String 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 (System.getProperty("user.home") + 64 System.getProperty("file.separator") + "SchemeGenerator.properties"), ""); 65 } 66 catch (java.io.FileNotFoundException ex) 67 { 68 ex.printStackTrace(); 69 } 70 catch (java.io.IOException 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 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 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 (aDBMeta)); 93 } 94 catch (java.sql.SQLException sqlEx) 95 { 96 java.sql.SQLException 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 t) 105 { 106 t.printStackTrace(); 107 } 108 } 109 110 115 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 117 118 jToolBar1 = new javax.swing.JToolBar (); 119 jButton1 = new javax.swing.JButton (); 120 jButton2 = new javax.swing.JButton (); 121 jButton3 = new javax.swing.JButton (); 122 jButton4 = new javax.swing.JButton (); 123 jButton5 = new javax.swing.JButton (); 124 jButton6 = new javax.swing.JButton (); 125 jSplitPane1 = new javax.swing.JSplitPane (); 126 jScrollPane1 = new javax.swing.JScrollPane (); 127 jTree1 = new javax.swing.JTree (); 128 jScrollPane2 = new javax.swing.JScrollPane (); 129 jPanel1 = new javax.swing.JPanel (); 130 menuBar = new javax.swing.JMenuBar (); 131 fileMenu = new javax.swing.JMenu (); 132 mnuFileConnect = new javax.swing.JMenuItem (); 133 mnuFileReadSchema = new javax.swing.JMenuItem (); 134 exitMenuItem = new javax.swing.JMenuItem (); 135 136 getContentPane().setLayout(new java.awt.GridBagLayout ()); 137 138 setTitle("OJB Scheme Generator"); 139 addWindowListener(new java.awt.event.WindowAdapter () { 140 public void windowClosing(java.awt.event.WindowEvent 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 () { 150 public void actionPerformed(java.awt.event.ActionEvent 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 (); 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 () { 180 public void valueChanged(javax.swing.event.TreeSelectionEvent 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 (); 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 () { 203 public void actionPerformed(java.awt.event.ActionEvent evt) { 204 fileMenuActionPerformed(evt); 205 } 206 }); 207 208 mnuFileConnect.setAction(new DBConnPropertiesAction(this)); 209 mnuFileConnect.addActionListener(new java.awt.event.ActionListener () { 210 public void actionPerformed(java.awt.event.ActionEvent 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 () { 219 public void actionPerformed(java.awt.event.ActionEvent evt) { 220 mnuFileReadSchemaActionPerformed(evt); 221 } 222 }); 223 224 fileMenu.add(mnuFileReadSchema); 225 226 exitMenuItem.setText("Exit"); 227 exitMenuItem.addActionListener(new java.awt.event.ActionListener () { 228 public void actionPerformed(java.awt.event.ActionEvent evt) { 229 exitMenuItemActionPerformed(evt); 230 } 231 }); 232 233 fileMenu.add(exitMenuItem); 234 235 menuBar.add(fileMenu); 236 237 setJMenuBar(menuBar); 238 239 pack(); 240 } 242 private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) { javax.swing.tree.TreePath tp = evt.getPath(); 245 if (tp != null) 246 { 247 Object 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 ie) 260 { 261 ie.printStackTrace(); 263 } 264 catch (IllegalAccessException iae) 265 { 266 iae.printStackTrace(); 267 } 268 } 269 pv.setModel(p); 270 this.jScrollPane2.setViewportView((java.awt.Component )pv); 271 } 272 } 273 } 275 private void jButton2ActionPerformed (java.awt.event.ActionEvent evt) { this.analyzeSchema(); 278 } 280 private void mnuFileReadSchemaActionPerformed (java.awt.event.ActionEvent evt) { this.analyzeSchema(); 283 } 285 private void mnuFileConnectActionPerformed (java.awt.event.ActionEvent evt) { } 290 private void fileMenuActionPerformed (java.awt.event.ActionEvent evt) { } 295 private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) 296 { System.exit(0); 298 } 300 301 private void exitForm(java.awt.event.WindowEvent evt) 302 { System.exit(0); 304 } 306 309 public static void main(String args[]) 310 { 311 } 313 314 private javax.swing.JMenuItem exitMenuItem; 316 private javax.swing.JMenu fileMenu; 317 private javax.swing.JButton jButton1; 318 private javax.swing.JButton jButton2; 319 private javax.swing.JButton jButton3; 320 private javax.swing.JButton jButton4; 321 private javax.swing.JButton jButton5; 322 private javax.swing.JButton jButton6; 323 private javax.swing.JPanel jPanel1; 324 private javax.swing.JScrollPane jScrollPane1; 325 private javax.swing.JScrollPane jScrollPane2; 326 private javax.swing.JSplitPane jSplitPane1; 327 private javax.swing.JToolBar jToolBar1; 328 private javax.swing.JTree jTree1; 329 private javax.swing.JMenuBar menuBar; 330 private javax.swing.JMenuItem mnuFileConnect; 331 private javax.swing.JMenuItem mnuFileReadSchema; 332 334 } 335 336 422 | Popular Tags |