01: package org.apache.ojb.tools.mapping.reversedb2.actions;
02:
03: import javax.swing.JFileChooser;
04:
05: import org.apache.ojb.broker.metadata.DescriptorRepository;
06: import org.apache.ojb.broker.metadata.RepositoryPersistor;
07: import org.apache.ojb.tools.mapping.reversedb2.Main;
08: import org.apache.ojb.tools.mapping.reversedb2.gui.JIFrmOJBRepository;
09:
10: /* Copyright 2002-2005 The Apache Software Foundation
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License");
13: * you may not use this file except in compliance with the License.
14: * You may obtain a copy of the License at
15: *
16: * http://www.apache.org/licenses/LICENSE-2.0
17: *
18: * Unless required by applicable law or agreed to in writing, software
19: * distributed under the License is distributed on an "AS IS" BASIS,
20: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21: * See the License for the specific language governing permissions and
22: * limitations under the License.
23: */
24:
25: /**
26: * Opens a new JIFrmOBJRepository in the specified frame.
27: * @author Administrator
28: */
29: public class ActionOpenOJBRepository extends javax.swing.AbstractAction {
30: private javax.swing.JFrame containingFrame;
31:
32: /** Creates a new instance of ActionOpenOJBRepository */
33: public ActionOpenOJBRepository(javax.swing.JFrame pcontainingFrame) {
34: this .containingFrame = pcontainingFrame;
35: putValue(NAME, "Open OJB Repository");
36: putValue(MNEMONIC_KEY,
37: new Integer(java.awt.event.KeyEvent.VK_O));
38: }
39:
40: public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
41: String lastPath = Main.getProperties().getProperty(
42: "lastFileChooserPosition");
43: javax.swing.JFileChooser fileChooser = new javax.swing.JFileChooser(
44: lastPath);
45: if (fileChooser.showOpenDialog(containingFrame) == JFileChooser.APPROVE_OPTION) {
46: final java.io.File selectedFile = fileChooser
47: .getSelectedFile();
48: Main.getProperties().setProperty("lastFileChooserPosition",
49: selectedFile.getParentFile().getAbsolutePath());
50: Main.getProperties().storeProperties("");
51: javax.swing.SwingUtilities.invokeLater(new Runnable() {
52: public void run() {
53: try {
54: RepositoryPersistor persistor = new RepositoryPersistor();
55: DescriptorRepository repository = persistor
56: .readDescriptorRepository(selectedFile
57: .getCanonicalPath());
58: JIFrmOJBRepository frm = new JIFrmOJBRepository(
59: repository);
60: containingFrame.getContentPane().add(frm);
61: frm.setVisible(true);
62: } catch (Throwable t) {
63: t.printStackTrace();
64: }
65: }
66: });
67: }
68: }
69: }
|