001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.schema.ui.nodes;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import org.netbeans.modules.xml.schema.model.SchemaComponent;
047: import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
048: import org.openide.nodes.Children;
049: import org.openide.nodes.Node;
050:
051: /**
052: * A standard children object for schema component nodes. This class can be
053: * used directly by a node, in which case it will defer to its parent node
054: * to create nodes for child components. Or, this class can be used as a
055: * superclass, in which case the developer should override the
056: * <code>createChildNodes()</code> method to create new node children.
057: *
058: * @author Todd Fast, todd.fast@sun.com
059: */
060: public class SchemaComponentNodeChildren<T extends SchemaComponent>
061: extends RefreshableChildren {
062: /**
063: *
064: *
065: */
066: public SchemaComponentNodeChildren(SchemaUIContext context,
067: SchemaComponentReference<T> reference) {
068: super ();
069: this .context = context;
070: this .reference = reference;
071: }
072:
073: /**
074: *
075: *
076: */
077: public SchemaUIContext getContext() {
078: return context;
079: }
080:
081: /**
082: *
083: *
084: */
085: public SchemaComponentReference<T> getReference() {
086: return reference;
087: }
088:
089: /**
090: *
091: *
092: */
093: @Override
094: protected void addNotify() {
095: super .addNotify();
096: // getModel().addPropertyChangeListener(this);
097: refreshChildren();
098: }
099:
100: /**
101: *
102: *
103: */
104: @Override
105: protected void removeNotify() {
106: super .removeNotify();
107: super .nodes.clear();
108: refresh();
109: // getModel().removePropertyChangeListener(this);
110: }
111:
112: /**
113: *
114: *
115: */
116: @Override
117: public void refreshChildren() {
118: T parentComponent = getReference().get();
119:
120: // // Build a list of the children of the parent component
121: // List<SchemaComponentReference> references=
122: // new ArrayList<SchemaComponentReference>();
123: // for (SchemaComponent component: parentComponent.getChildren())
124: // references.add(SchemaComponentReference.create(component));
125: //
126: // setKeys(references);
127: setKeys(parentComponent.getChildren());
128: }
129:
130: /**
131: *
132: *
133: */
134: @Override
135: protected Node[] createNodes(Object key) {
136: Node[] result = null;
137:
138: assert key == null || key instanceof SchemaComponent : "Key was not a SchemaComponent (key = \""
139: + key + "\", class = " + key.getClass() + ")";
140:
141: if (key instanceof SchemaComponent) {
142: Node node = createChildNode(SchemaComponent.class.cast(key));
143: if (node != null)
144: result = new Node[] { node };
145: }
146:
147: return result;
148: }
149:
150: /**
151: * Subclasses should override this method to create nodes for a given
152: * schema component
153: *
154: */
155: protected <C extends SchemaComponent> Node createChildNode(
156: SchemaComponent component) {
157: Node result = getContext().getFactory().createNode(component);
158: return result;
159: }
160:
161: // /**
162: // * Subclasses should override this method to create nodes for a given
163: // * schema component
164: // *
165: // */
166: // protected <C extends SchemaComponent> Node createChildNode(
167: // SchemaComponentReference<C> reference)
168: // {
169: // Node result=getContext().getFactory().createNode(getNode(),reference.get());
170: // return result;
171: // }
172: //
173:
174: // /**
175: // *
176: // *
177: // */
178: // public Collection<SchemaComponent> getKeys()
179: // {
180: // return keys;
181: // }
182: //
183: //
184: // /**
185: // *
186: // *
187: // */
188: // public void setKeys(Collection<SchemaComponent> value)
189: // {
190: // keys=value;
191: // super.setKeys(value);
192: // }
193:
194: ////////////////////////////////////////////////////////////////////////////
195: // Instance variables
196: ////////////////////////////////////////////////////////////////////////////
197:
198: private SchemaUIContext context;
199: private SchemaComponentReference<T> reference;
200: // private Collection<SchemaComponent> keys;
201: }
|