KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > actions > ActionOpenOJBRepository


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

22
23 /**
24  * Opens a new JIFrmOBJRepository in the specified frame.
25  * @author Administrator
26  */

27 public class ActionOpenOJBRepository extends javax.swing.AbstractAction JavaDoc
28 {
29     private javax.swing.JFrame JavaDoc containingFrame;
30     /** Creates a new instance of ActionOpenOJBRepository */
31     public ActionOpenOJBRepository(javax.swing.JFrame JavaDoc pcontainingFrame)
32     {
33         this.containingFrame = pcontainingFrame;
34         putValue(NAME, "Open OJB Repository");
35         putValue(MNEMONIC_KEY, new Integer JavaDoc(java.awt.event.KeyEvent.VK_O));
36     }
37
38     public void actionPerformed (java.awt.event.ActionEvent JavaDoc actionEvent)
39     {
40         String JavaDoc lastPath = Main.getProperties().getProperty("lastFileChooserPosition");
41         javax.swing.JFileChooser JavaDoc fileChooser = new javax.swing.JFileChooser JavaDoc (lastPath);
42         if (fileChooser.showOpenDialog(containingFrame)==JFileChooser.APPROVE_OPTION)
43         {
44             final java.io.File JavaDoc selectedFile = fileChooser.getSelectedFile();
45             Main.getProperties().setProperty("lastFileChooserPosition", selectedFile.getParentFile().getAbsolutePath());
46             Main.getProperties().storeProperties("");
47             javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc()
48             {
49                 public void run()
50                 {
51                     try
52                     {
53                         RepositoryPersistor persistor = new RepositoryPersistor ();
54                         DescriptorRepository repository = persistor.readDescriptorRepository(selectedFile.getCanonicalPath());
55                         JIFrmOJBRepository frm = new JIFrmOJBRepository(repository);
56                         containingFrame.getContentPane().add(frm);
57                         frm.setVisible(true);
58                     }
59                     catch (Throwable JavaDoc t)
60                     {
61                         t.printStackTrace();
62                     }
63                 }
64             });
65         }
66     }
67 }
68
Popular Tags