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 org.netbeans.swing.outline.RowModel;
045: import org.openide.util.NbBundle;
046: import javax.swing.tree.DefaultMutableTreeNode;
047:
048: /**
049: *
050: * @author David Botterill
051: */
052: public class TypeRowModel implements RowModel {
053: private ClassLoader classLoader;
054:
055: /** Creates a new instance of TypeRowModel */
056: public TypeRowModel(ClassLoader loader) {
057: this .classLoader = loader;
058: }
059:
060: public Class getColumnClass(int column) {
061: switch (column) {
062: // case 0: return String.class;
063: case 0:
064: return String.class;
065: case 1:
066: return Object.class;
067: default:
068: return String.class;
069: }
070: }
071:
072: public int getColumnCount() {
073: return 2;
074: }
075:
076: public String getColumnName(int column) {
077: switch (column) {
078: // case 0: return NbBundle.getMessage(this.getClass(), "PARAM_CLASS");
079: case 0:
080: return NbBundle.getMessage(this .getClass(), "PARAM_NAME");
081: case 1:
082: return NbBundle.getMessage(this .getClass(), "PARAM_VALUE");
083: default:
084: return "";
085: }
086:
087: }
088:
089: public Object getValueFor(Object inNode, int column) {
090: if (null == inNode)
091: return null;
092: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
093: if (null == node.getUserObject())
094: return null;
095: TypeNodeData data = (TypeNodeData) node.getUserObject();
096: switch (column) {
097: case 0:
098: return data.getTypeName();
099: case 1:
100: return data.getTypeValue();
101: default:
102: return "";
103: }
104:
105: }
106:
107: public boolean isCellEditable(Object inNode, int column) {
108: if (null == inNode)
109: return false;
110: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
111: if (null == node.getUserObject())
112: return false;
113:
114: TypeNodeData data = (TypeNodeData) node.getUserObject();
115: switch (column) {
116: case 0:
117: return false;
118: case 1:
119: if (!data.isAssignable()) {
120: return false;
121: }
122:
123: String typeClass = data.getTypeClass();
124: if (ReflectionHelper.isSimpleType(typeClass, classLoader)) {
125: if (typeClass.equalsIgnoreCase("java.util.Calendar")) { // NOI18N
126: return false;
127: } else {
128: return true;
129: }
130: } else if (ReflectionHelper.isEnumeration(typeClass,
131: classLoader)) {
132: return true;
133: } else {
134: return false;
135: }
136: default:
137: return false;
138: }
139:
140: }
141:
142: public void setValueFor(Object inNode, int column, Object value) {
143: if (null == inNode)
144: return;
145: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
146: if (null == node.getUserObject())
147: return;
148:
149: TypeNodeData data = (TypeNodeData) node.getUserObject();
150: /**
151: * Make sure they are only trying to edit the value column
152: */
153: if (column != 1) {
154: return;
155: }
156:
157: data.setTypeValue(value);
158: /**
159: * If this node's parent is a ArrayTypeTreeNode, StructureTypeTreeNode, or HolderTypeTreeNode,
160: * update this value on the parent's
161: * value.
162: */
163:
164: DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node
165: .getParent();
166: if (null != parentNode
167: && parentNode instanceof ListTypeTreeNode) {
168: ((ListTypeTreeNode) parentNode)
169: .updateValueFromChildren(data);
170: } else if (null != parentNode
171: && parentNode instanceof StructureTypeTreeNode) {
172: /**
173: * This type should be a JavaStructureMember
174: */
175: ((StructureTypeTreeNode) parentNode)
176: .updateValueFromChildren(data);
177: } else if (null != parentNode
178: && parentNode instanceof HolderTypeTreeNode) {
179:
180: ((HolderTypeTreeNode) parentNode)
181: .updateValueFromChildren(data);
182: }
183:
184: }
185:
186: }
|