KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > beanbrowser > TopComponentsNode


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.apisupport.beanbrowser;
21
22 import java.beans.IntrospectionException JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.util.Collections JavaDoc;
26 import org.openide.nodes.AbstractNode;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.windows.TopComponent;
30
31 /**
32  * Shows open windows.
33  * @author Jesse Glick
34  */

35 class TopComponentsNode extends AbstractNode {
36
37     public TopComponentsNode(TopComponent.Registry r) {
38         super(new TopComponentsChildren(r));
39         setName("TopComponentsNode");
40         setDisplayName("Open Windows");
41         setIconBaseWithExtension("org/netbeans/modules/apisupport/beanbrowser/BeanBrowserIcon.gif");
42     }
43     
44     private static final class TopComponentsChildren extends Children.Keys implements PropertyChangeListener JavaDoc {
45
46         private final TopComponent.Registry r;
47         
48         TopComponentsChildren(TopComponent.Registry r) {
49             this.r = r;
50         }
51
52         protected void addNotify() {
53             super.addNotify();
54             setKeys(r.getOpened());
55             r.addPropertyChangeListener(this);
56         }
57         
58         protected void removeNotify() {
59             r.removePropertyChangeListener(this);
60             setKeys(Collections.EMPTY_SET);
61             super.removeNotify();
62         }
63
64         protected Node[] createNodes(Object JavaDoc key) {
65             TopComponent c = (TopComponent) key;
66             Node n;
67             try {
68                 n = Wrapper.make(new RefinedBeanNode(c));
69             } catch (IntrospectionException JavaDoc ex) {
70                 ex.printStackTrace();
71                 return null;
72             }
73             n.setName(c.getName());
74             n.setDisplayName(c.getDisplayName());
75             n.setShortDescription(c.toString());
76             return new Node[] {n};
77         }
78
79         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
80             setKeys(r.getOpened());
81         }
82
83     }
84     
85 }
86
Popular Tags