KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > jarloader > JarDataNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.jarloader;
21
22 import javax.swing.Action JavaDoc;
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 /**
34  * A node to represent a JAR file.
35  * @author Jesse Glick
36  */

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"); // NOI18N
47
}
48     
49     public Action JavaDoc getPreferredAction() {
50         return null;
51     }
52     
53     private static Children childrenFor(FileObject jar) {
54         if (!FileUtil.isArchiveFile(jar)) {
55             // Maybe corrupt, etc.
56
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     /**
67      * There is no nice way to lazy create delegating node's children.
68      * So, in order to fix #83595, here is a little hack that schedules
69      * replacement of this dummy children on addNotify call.
70      */

71     final static class DummyChildren extends Children implements Runnable JavaDoc {
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             // no-op
91
return false;
92         }
93
94         public boolean remove(final Node[] nodes) {
95             // no-op
96
return false;
97         }
98         
99     }
100     
101 }
102
Popular Tags