KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.ojb.tools.mapping.reversedb.gui.actions;
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 javax.swing.JOptionPane JavaDoc;
19 /**
20  *
21  * @author Florian Bruckner
22  * @version $Revision: 1.1.2.1 $
23  */

24 public class GenerateJavaClassesAction extends javax.swing.AbstractAction JavaDoc
25 {
26   org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame mainFrame;
27   /** Creates a new instance of GenerateJavaClassesAction */
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 JavaDoc actionEvent)
36   {
37     // 1. Open a Filechooser dialog to get the directory for the java Files
38
javax.swing.JFileChooser JavaDoc fileChooser = new javax.swing.JFileChooser JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc ioex)
68       {
69           ioex.printStackTrace();
70           JOptionPane.showMessageDialog(mainFrame, "I/O Error:\n" + ioex.getMessage(), "Generate Java", JOptionPane.ERROR_MESSAGE);
71       }
72       catch (Throwable JavaDoc 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 /***************************** Changelog *****************************
83 // $Log: GenerateJavaClassesAction.java,v $
84 // Revision 1.1.2.1 2005/12/21 22:32:06 tomdz
85 // Updated license
86 //
87 // Revision 1.1 2004/05/05 16:38:25 arminw
88 // fix fault
89 // wrong package structure used:
90 // org.apache.ojb.tools.reversdb
91 // org.apache.ojb.tools.reversdb2
92 //
93 // instead of
94 // org.apache.ojb.tools.mapping.reversdb
95 // org.apache.ojb.tools.mapping.reversdb2
96 //
97 // Revision 1.1 2004/05/04 13:44:59 arminw
98 // move reverseDB stuff
99 //
100 // Revision 1.6 2004/04/04 23:53:42 brianm
101 // Fixed initial copyright dates to match cvs repository
102 //
103 // Revision 1.5 2004/03/11 18:16:23 brianm
104 // ASL 2.0
105 //
106 // Revision 1.4 2003/06/21 10:39:13 florianbruckner
107 // improve error reporting; use writeXML(PrintWriter) instead of getXML()
108 //
109 // Revision 1.3 2002/11/08 13:47:38 brj
110 // corrected some compiler warnings
111 //
112 // Revision 1.2 2002/06/17 19:34:34 jvanzyl
113 // Correcting all the package references.
114 // PR:
115 // Obtained from:
116 // Submitted by:
117 // Reviewed by:
118 //
119 // Revision 1.1.1.1 2002/06/17 18:16:54 jvanzyl
120 // Initial OJB import
121 //
122 // Revision 1.2 2002/05/16 11:47:09 florianbruckner
123 // fix CR/LF issue, change license to ASL
124 //
125 // Revision 1.1 2002/04/18 11:44:16 mpoeschl
126 //
127 // move files to new location
128 //
129 // Revision 1.2 2002/04/07 09:05:17 thma
130 // *** empty log message ***
131 //
132 // Revision 1.1.1.1 2002/02/20 13:35:25 Administrator
133 // initial import
134 //
135 /***************************** Changelog *****************************/

136  
137
Popular Tags