1 26 27 package org.objectweb.util.browser.plugin.java.reflect; 28 29 import java.io.File ; 30 import java.util.jar.JarFile ; 31 32 import javax.swing.JFileChooser ; 33 import javax.swing.JOptionPane ; 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 56 public class SelectClassAction 57 implements MenuItem, DialogAction, TreeChooserObserver { 58 59 65 66 protected FileChooserBox jarFile_; 67 68 69 protected TreeChooserBox classFile_; 70 71 72 protected JFileChooser fileChooser_; 73 74 75 protected DynamicTree tree_; 76 77 78 protected TreeView treeView_; 79 80 81 protected TreeProvider treeProvider_; 82 83 84 protected DialogBox action_; 85 86 92 98 104 public int getStatus(TreeView treeView) { 105 return MenuItem.ENABLED_STATUS; 106 } 107 108 public void actionPerformed(MenuItemTreeView treeView) throws Exception { 109 treeView_ = treeView; 110 treeProvider_ = new DefaultTreeProvider(); 111 112 action_ = new DefaultDialogBox("Choose a class"); 113 fileChooser_ = new JFileChooser (); 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 133 public DynamicTree refresh(){ 134 File f = jarFile_.getFile(); 135 if(f!=null) { 136 tree_ = treeProvider_.createDynamicTree(treeView_, false); 137 try { 138 JarFile jf = new JarFile (f); 139 tree_.addEntry(f.getName(), new JarFileStructure(jf,f.toURL())); 140 } catch (Exception e) { 141 JOptionPane.showMessageDialog(null, "Jar file expected !", "Exception", JOptionPane.ERROR_MESSAGE); 142 } 143 } 144 return tree_; 145 } 146 147 153 public void executeAction() throws Exception { 154 System.out.println("OK"); 155 } 156 157 } 158 159 160 | Popular Tags |