1 19 20 package org.netbeans.modules.java.jarloader; 21 22 import javax.swing.Action ; 23 import org.openide.filesystems.FileObject; 24 import org.openide.filesystems.FileUtil; 25 import org.openide.loaders.DataFilter; 26 import org.openide.loaders.DataFolder; 27 import org.openide.loaders.DataNode; 28 import org.openide.nodes.Children; 29 import org.openide.nodes.Node; 30 import org.openide.util.RequestProcessor; 31 32 33 37 final class JarDataNode extends DataNode { 38 39 public JarDataNode(JarDataObject obj) { 40 this(obj, new DummyChildren()); 41 } 42 43 private JarDataNode(JarDataObject obj, DummyChildren c) { 44 super(obj, c); 45 c.attachJarNode(this); 46 setIconBaseWithExtension("org/netbeans/modules/java/jarloader/jar.gif"); } 48 49 public Action getPreferredAction() { 50 return null; 51 } 52 53 private static Children childrenFor(FileObject jar) { 54 if (!FileUtil.isArchiveFile(jar)) { 55 return Children.LEAF; 57 } 58 FileObject root = FileUtil.getArchiveRoot(jar); 59 if (root != null) { 60 return DataFolder.findFolder(root).createNodeChildren(DataFilter.ALL); 61 } else { 62 return Children.LEAF; 63 } 64 } 65 66 71 final static class DummyChildren extends Children implements Runnable { 72 73 private JarDataNode node; 74 75 protected void addNotify() { 76 super.addNotify(); 77 assert node != null; 78 RequestProcessor.getDefault().post(this); 79 } 80 81 private void attachJarNode(JarDataNode jarDataNode) { 82 this.node = jarDataNode; 83 } 84 85 public void run() { 86 node.setChildren(childrenFor(node.getDataObject().getPrimaryFile())); 87 } 88 89 public boolean add(final Node[] nodes) { 90 return false; 92 } 93 94 public boolean remove(final Node[] nodes) { 95 return false; 97 } 98 99 } 100 101 } 102 | Popular Tags |