KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugin > java > reflect > SelectClassAction


1 /*====================================================================
2
3 Objectweb Browser Framework
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.plugin.java.reflect;
28
29 import java.io.File JavaDoc;
30 import java.util.jar.JarFile JavaDoc;
31
32 import javax.swing.JFileChooser JavaDoc;
33 import javax.swing.JOptionPane JavaDoc;
34
35 import org.objectweb.util.browser.api.MenuItem;
36 import org.objectweb.util.browser.api.MenuItemTreeView;
37 import org.objectweb.util.browser.api.TreeView;
38 import org.objectweb.util.browser.core.common.DynamicTree;
39 import org.objectweb.util.browser.gui.api.DialogAction;
40 import org.objectweb.util.browser.gui.api.DialogBox;
41 import org.objectweb.util.browser.gui.api.TreeChooserObserver;
42 import org.objectweb.util.browser.gui.api.TreeProvider;
43 import org.objectweb.util.browser.gui.lib.DefaultDialogBox;
44 import org.objectweb.util.browser.gui.lib.DefaultTreeProvider;
45 import org.objectweb.util.browser.gui.lib.FileChooserBox;
46 import org.objectweb.util.browser.gui.lib.TreeChooserBox;
47
48 /**
49  * Selects a jar and more precisly a Java class.
50  *
51  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
52  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
53  *
54  * @version 0.1
55  */

56 public class SelectClassAction
57     implements MenuItem, DialogAction, TreeChooserObserver {
58
59     //==================================================================
60
//
61
// Internal state.
62
//
63
//==================================================================
64

65     /** The FileChooserBox used to load a jar resource. */
66     protected FileChooserBox jarFile_;
67     
68     /** The TreeChooserBox used to browse the Jar file. */
69     protected TreeChooserBox classFile_;
70     
71     /** The JFileChooser used to load a jar resource. */
72     protected JFileChooser JavaDoc fileChooser_;
73     
74     /** The DynamicTree used to choose a file resource. */
75     protected DynamicTree tree_;
76
77     /** The associated TreeView. */
78     protected TreeView treeView_;
79
80     /** The TreeProvider used to create a DynamicTree */
81     protected TreeProvider treeProvider_;
82
83     /** The DialogBox to use. */
84     protected DialogBox action_;
85     
86     //==================================================================
87
//
88
// No constructor.
89
//
90
//==================================================================
91

92     //==================================================================
93
//
94
// No internal method.
95
//
96
//==================================================================
97

98     //==================================================================
99
//
100
// Public methods for MenuItem interface.
101
//
102
//==================================================================
103

104     public int getStatus(TreeView treeView) {
105         return MenuItem.ENABLED_STATUS;
106     }
107
108     public void actionPerformed(MenuItemTreeView treeView) throws Exception JavaDoc {
109         treeView_ = treeView;
110         treeProvider_ = new DefaultTreeProvider();
111         
112         action_ = new DefaultDialogBox("Choose a class");
113         fileChooser_ = new JFileChooser JavaDoc();
114         jarFile_ = new FileChooserBox("Jar file",fileChooser_,true,false);
115         action_.addElementBox(jarFile_);
116         
117         tree_ = treeProvider_.createDynamicTree(treeView_, false);
118         
119         classFile_ = new TreeChooserBox("Class File", tree_);
120         classFile_.setTreeChooserObserver(this);
121         action_.addElementBox(classFile_);
122
123         action_.setValidateAction(this);
124         action_.show();
125     }
126
127     //==================================================================
128
//
129
// Public methods for TreeChooserObserver interface.
130
//
131
//==================================================================
132

133     public DynamicTree refresh(){
134         File JavaDoc f = jarFile_.getFile();
135         if(f!=null) {
136             tree_ = treeProvider_.createDynamicTree(treeView_, false);
137             try {
138                 JarFile JavaDoc jf = new JarFile JavaDoc(f);
139                 tree_.addEntry(f.getName(), new JarFileStructure(jf,f.toURL()));
140             } catch (Exception JavaDoc e) {
141                 JOptionPane.showMessageDialog(null, "Jar file expected !", "Exception", JOptionPane.ERROR_MESSAGE);
142             }
143         }
144         return tree_;
145     }
146
147     //==================================================================
148
//
149
// Public methods for DialogAction interface.
150
//
151
//==================================================================
152

153     public void executeAction() throws Exception JavaDoc {
154         System.out.println("OK");
155     }
156
157 }
158
159
160     
Popular Tags