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.websvc.saas.ui.wizards;
043:
044: import java.util.Collection;
045: import javax.swing.tree.*;
046: import java.util.Iterator;
047:
048: import java.net.URLClassLoader;
049:
050: /**
051: * Node for Collection and List types
052: *
053: * @author quynguyen
054: */
055: public class ListTypeTreeNode extends AbstractParameterTreeNode {
056: private URLClassLoader urlClassLoader;
057:
058: public ListTypeTreeNode(TypeNodeData userObject,
059: URLClassLoader inClassLoader) {
060: super (userObject);
061: urlClassLoader = inClassLoader;
062:
063: }
064:
065: public void updateValueFromChildren(TypeNodeData inData) {
066: /**
067: * create a new ArrayList from all of the child values.
068: */
069: TypeNodeData data = (TypeNodeData) this .getUserObject();
070:
071: Collection c = (Collection) data.getTypeValue();
072: if (c == null)
073: return;
074:
075: c.clear();
076: for (int ii = 0; ii < this .getChildCount(); ii++) {
077: DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) this
078: .getChildAt(ii);
079: TypeNodeData childData = (TypeNodeData) childNode
080: .getUserObject();
081: if (null != childData.getTypeValue()) {
082: c.add(childData.getTypeValue());
083: }
084: }
085:
086: DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) this
087: .getParent();
088: if (parentNode != null
089: && parentNode instanceof ParameterTreeNode) {
090: ((ParameterTreeNode) parentNode)
091: .updateValueFromChildren(data);
092: }
093: }
094:
095: /**
096: * Update the child nodes based on the value of this UserObject.
097: * Fix for Bug: 5059732
098: * - David Botterill 8/12/2004
099: *
100: */
101: public void updateChildren() {
102: TypeNodeData this Data = (TypeNodeData) this .getUserObject();
103: /**
104: * First get the Collection for this node.
105: */
106: Collection childCollection = (Collection) this Data
107: .getTypeValue();
108: /**
109: * Next we need to delete all of the child nodes
110: */
111: this .removeAllChildren();
112: /**
113: * For each entry in the array, make a child node
114: */
115: String structureType = this Data.getGenericType();
116: if (structureType == null || structureType.length() == 0) {
117: structureType = "java.lang.Object"; // NOI18N
118: }
119:
120: Iterator iter = childCollection.iterator();
121: for (int i = 0; iter.hasNext(); i++) {
122: TypeNodeData data = ReflectionHelper.createTypeData(
123: structureType, "[" + i + "]", iter.next());
124: data.setAssignable(this Data.isAssignable());
125: if (ReflectionHelper.isComplexType(data.getTypeClass(),
126: urlClassLoader)) {
127: StructureTypeTreeNode childNode = new StructureTypeTreeNode(
128: data, urlClassLoader);
129: childNode.updateChildren();
130: this .add(childNode);
131: } else if (ReflectionHelper.isCollection(data
132: .getTypeClass(), urlClassLoader)) {
133: ListTypeTreeNode childNode = new ListTypeTreeNode(data,
134: urlClassLoader);
135: childNode.updateChildren();
136: this .add(childNode);
137: } else {
138: DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
139: data);
140: this.add(childNode);
141: }
142: }
143: }
144:
145: }
|