1 package org.apache.ojb.tools.mapping.reversedb.gui.actions; 2 3 17 18 import javax.swing.JOptionPane ; 19 24 public class GenerateJavaClassesAction extends javax.swing.AbstractAction 25 { 26 org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame mainFrame; 27 28 public GenerateJavaClassesAction (org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame pmainFrame) 29 { 30 super(); 31 mainFrame = pmainFrame; 32 this.putValue(NAME, "Generate Java"); 33 } 34 35 public void actionPerformed (java.awt.event.ActionEvent actionEvent) 36 { 37 javax.swing.JFileChooser fileChooser = new javax.swing.JFileChooser (); 39 fileChooser.setDialogTitle("Select Directory for Java generation"); 40 fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); 41 int rc = fileChooser.showSaveDialog(mainFrame); 42 if (rc == javax.swing.JFileChooser.APPROVE_OPTION) 43 { 44 java.io.File f = fileChooser.getSelectedFile(); 45 try 46 { 47 if (!f.isDirectory()) 48 { 49 JOptionPane.showMessageDialog(mainFrame, "Selected item is not a directory", "Generate Java", JOptionPane.ERROR_MESSAGE); 50 return; 51 } 52 if (f.canWrite()) 53 { 54 mainFrame.getDBMeta().generateJava(f, "", ""); 55 } 56 else 57 { 58 JOptionPane.showMessageDialog(mainFrame, "Cannot write to selected directory", "Generate Java", JOptionPane.ERROR_MESSAGE); 59 return; 60 } 61 } 62 catch (java.io.FileNotFoundException fnfe) 63 { 64 fnfe.printStackTrace(); 65 JOptionPane.showMessageDialog(mainFrame, "File not found:\n" + fnfe.getMessage(), "Generate Java", JOptionPane.ERROR_MESSAGE); 66 } 67 catch (java.io.IOException ioex) 68 { 69 ioex.printStackTrace(); 70 JOptionPane.showMessageDialog(mainFrame, "I/O Error:\n" + ioex.getMessage(), "Generate Java", JOptionPane.ERROR_MESSAGE); 71 } 72 catch (Throwable t) 73 { 74 t.printStackTrace(); 75 JOptionPane.showMessageDialog(mainFrame, "Error:\n" + t.getMessage(), "Generate Java", JOptionPane.ERROR_MESSAGE); 76 } 77 } 78 } 79 80 } 81 82 136 137 | Popular Tags |