KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > SchemaComponentNodeChildren


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.nodes;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import org.netbeans.modules.xml.schema.model.SchemaComponent;
24 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Node;
27
28 /**
29  * A standard children object for schema component nodes. This class can be
30  * used directly by a node, in which case it will defer to its parent node
31  * to create nodes for child components. Or, this class can be used as a
32  * superclass, in which case the developer should override the
33  * <code>createChildNodes()</code> method to create new node children.
34  *
35  * @author Todd Fast, todd.fast@sun.com
36  */

37 public class SchemaComponentNodeChildren<T extends SchemaComponent>
38     extends RefreshableChildren
39 {
40     /**
41      *
42      *
43      */

44     public SchemaComponentNodeChildren(SchemaUIContext context,
45         SchemaComponentReference<T> reference)
46     {
47         super();
48         this.context=context;
49         this.reference=reference;
50     }
51
52
53     /**
54      *
55      *
56      */

57     public SchemaUIContext getContext()
58     {
59         return context;
60     }
61
62
63     /**
64      *
65      *
66      */

67     public SchemaComponentReference<T> getReference()
68     {
69         return reference;
70     }
71
72
73     /**
74      *
75      *
76      */

77     @Override JavaDoc
78     protected void addNotify()
79     {
80         super.addNotify();
81 // getModel().addPropertyChangeListener(this);
82
refreshChildren();
83     }
84
85
86     /**
87      *
88      *
89      */

90     @Override JavaDoc
91     protected void removeNotify()
92     {
93         super.removeNotify();
94         super.nodes.clear();
95         refresh();
96 // getModel().removePropertyChangeListener(this);
97
}
98
99
100     /**
101      *
102      *
103      */

104     @Override JavaDoc
105     public void refreshChildren()
106     {
107         T parentComponent=getReference().get();
108
109 // // Build a list of the children of the parent component
110
// List<SchemaComponentReference> references=
111
// new ArrayList<SchemaComponentReference>();
112
// for (SchemaComponent component: parentComponent.getChildren())
113
// references.add(SchemaComponentReference.create(component));
114
//
115
// setKeys(references);
116
setKeys(parentComponent.getChildren());
117     }
118
119
120     /**
121      *
122      *
123      */

124     @Override JavaDoc
125     protected Node[] createNodes(Object JavaDoc key)
126     {
127         Node[] result=null;
128
129         assert key==null || key instanceof SchemaComponent:
130             "Key was not a SchemaComponent (key = \""+
131             key+"\", class = "+key.getClass()+")";
132
133         if (key instanceof SchemaComponent)
134         {
135             Node node=createChildNode(SchemaComponent.class.cast(key));
136             if (node!=null)
137                 result=new Node[] { node };
138         }
139
140         return result;
141     }
142
143
144     /**
145      * Subclasses should override this method to create nodes for a given
146      * schema component
147      *
148      */

149     protected <C extends SchemaComponent> Node createChildNode(
150         SchemaComponent component)
151     {
152         Node result=getContext().getFactory().createNode(component);
153         return result;
154     }
155
156 // /**
157
// * Subclasses should override this method to create nodes for a given
158
// * schema component
159
// *
160
// */
161
// protected <C extends SchemaComponent> Node createChildNode(
162
// SchemaComponentReference<C> reference)
163
// {
164
// Node result=getContext().getFactory().createNode(getNode(),reference.get());
165
// return result;
166
// }
167
//
168

169 // /**
170
// *
171
// *
172
// */
173
// public Collection<SchemaComponent> getKeys()
174
// {
175
// return keys;
176
// }
177
//
178
//
179
// /**
180
// *
181
// *
182
// */
183
// public void setKeys(Collection<SchemaComponent> value)
184
// {
185
// keys=value;
186
// super.setKeys(value);
187
// }
188

189
190
191
192     ////////////////////////////////////////////////////////////////////////////
193
// Instance variables
194
////////////////////////////////////////////////////////////////////////////
195

196     private SchemaUIContext context;
197     private SchemaComponentReference<T> reference;
198 // private Collection<SchemaComponent> keys;
199
}
200
Popular Tags