KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 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): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.explorer.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.fractal.api.Component;
36 import org.objectweb.util.explorer.api.MenuItem;
37 import org.objectweb.util.explorer.api.MenuItemTreeView;
38 import org.objectweb.util.explorer.api.Tree;
39 import org.objectweb.util.explorer.api.TreeView;
40 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
41 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
42 import org.objectweb.util.explorer.swing.gui.api.TreeChooserObserver;
43 import org.objectweb.util.explorer.swing.gui.api.TreeProvider;
44 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
45 import org.objectweb.util.explorer.swing.gui.lib.FileChooserBox;
46 import org.objectweb.util.explorer.swing.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
//
62
// Internal state.
63
//
64
//==================================================================
65

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

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

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

105     /* (non-Javadoc)
106      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
107      */

108     public int getStatus(TreeView treeView) {
109         return MenuItem.ENABLED_STATUS;
110     }
111
112     /* (non-Javadoc)
113      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
114      */

115     public void actionPerformed(MenuItemTreeView treeView) throws Exception JavaDoc {
116         treeView_ = treeView;
117         
118         action_ = new DefaultDialogBox("Choose a class");
119         fileChooser_ = new JFileChooser JavaDoc();
120         jarFile_ = new FileChooserBox("Jar file",fileChooser_,true,false);
121         action_.addElementBox(jarFile_);
122         
123         Component treeCpt = treeView.getTree().duplicate(false);
124         tree_ = (Tree)treeCpt.getFcInterface(Tree.TREE);
125         
126         classFile_ = new TreeChooserBox("Class File", treeCpt);
127         classFile_.setTreeChooserObserver(this);
128         action_.addElementBox(classFile_);
129
130         action_.setValidateAction(this);
131         action_.show();
132     }
133
134     //==================================================================
135
//
136
// Public methods for TreeChooserObserver interface.
137
//
138
//==================================================================
139

140     /* (non-Javadoc)
141      * @see org.objectweb.util.explorer.swing.gui.api.TreeChooserObserver#refresh()
142      */

143     public Component refresh(){
144         Component treeCpt = null;
145         File JavaDoc f = jarFile_.getFile();
146         if(f!=null) {
147             treeCpt = treeView_.getTree().duplicate(false);
148             try {
149                 Tree treeItf = (Tree)treeCpt.getFcInterface(Tree.TREE);
150                 JarFile JavaDoc jf = new JarFile JavaDoc(f);
151                 tree_.addEntry(f.getName(), new JarFileStructure(jf,f.toURL()));
152             } catch (Exception JavaDoc e) {
153                 JOptionPane.showMessageDialog(null, "Jar file expected !", "Exception", JOptionPane.ERROR_MESSAGE);
154             }
155         }
156         return treeCpt;
157     }
158
159     //==================================================================
160
//
161
// Public methods for DialogAction interface.
162
//
163
//==================================================================
164

165     /* (non-Javadoc)
166      * @see org.objectweb.util.explorer.swing.gui.api.DialogAction#executeAction()
167      */

168     public void executeAction() throws Exception JavaDoc {
169         System.out.println("OK");
170     }
171
172 }
173
174
175     
Popular Tags