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-2006 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.registry.ui;
043:
044: import org.netbeans.swing.outline.RowModel;
045: import org.openide.ErrorManager;
046:
047: import com.sun.xml.rpc.processor.model.java.JavaType;
048: import com.sun.xml.rpc.processor.model.java.JavaSimpleType;
049: import com.sun.xml.rpc.processor.model.java.JavaEnumerationType;
050:
051: import org.openide.util.NbBundle;
052: import javax.swing.tree.DefaultMutableTreeNode;
053:
054: import java.net.URLClassLoader;
055:
056: /**
057: *
058: * @author David Botterill
059: */
060: public class TypeRowModel implements RowModel {
061:
062: private URLClassLoader urlClassLoader;
063: private String packageName;
064:
065: /** Creates a new instance of TypeRowModel */
066: public TypeRowModel(URLClassLoader inClassLoader,
067: String inPackageName) {
068: urlClassLoader = inClassLoader;
069: packageName = inPackageName;
070:
071: }
072:
073: public Class getColumnClass(int column) {
074: switch (column) {
075: // case 0: return String.class;
076: case 0:
077: return String.class;
078: case 1:
079: return Object.class;
080: default:
081: return String.class;
082: }
083: }
084:
085: public int getColumnCount() {
086: return 2;
087: }
088:
089: public String getColumnName(int column) {
090: switch (column) {
091: // case 0: return NbBundle.getMessage(TypeRowModel.class, "PARAM_CLASS");
092: case 0:
093: return NbBundle
094: .getMessage(TypeRowModel.class, "PARAM_NAME");
095: case 1:
096: return NbBundle.getMessage(TypeRowModel.class,
097: "PARAM_VALUE");
098: default:
099: return "";
100: }
101:
102: }
103:
104: public Object getValueFor(Object inNode, int column) {
105: if (null == inNode)
106: return null;
107: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
108: if (null == node.getUserObject())
109: return null;
110: TypeNodeData data = (TypeNodeData) node.getUserObject();
111: switch (column) {
112: // case 0: return data.getParameterType().getRealName();
113: case 0:
114: return data.getParameterName();
115: case 1: {
116: Object val = data.getParameterValue();
117: if (val instanceof java.util.Calendar)
118: return java.text.DateFormat.getDateTimeInstance()
119: .format(((java.util.Calendar) val).getTime());
120: return val;
121: }
122: default:
123: return "";
124: }
125:
126: }
127:
128: public boolean isCellEditable(Object inNode, int column) {
129: if (null == inNode)
130: return false;
131: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
132: if (null == node.getUserObject())
133: return false;
134:
135: TypeNodeData data = (TypeNodeData) node.getUserObject();
136: switch (column) {
137: // case 0: return false;
138: case 0:
139: return false;
140: case 1:
141: if (data.getParameterType() instanceof JavaSimpleType
142: || data.getParameterType() instanceof JavaEnumerationType)
143: return true;
144: else
145: return false;
146: default:
147: return false;
148: }
149:
150: }
151:
152: public void setValueFor(Object inNode, int column, Object value) {
153: if (null == inNode)
154: return;
155: DefaultMutableTreeNode node = (DefaultMutableTreeNode) inNode;
156: if (null == node.getUserObject())
157: return;
158:
159: TypeNodeData data = (TypeNodeData) node.getUserObject();
160: /**
161: * Make sure they are only trying to edit the value column
162: */
163: if (column != 1) {
164: return;
165: }
166: JavaType type = data.getParameterType();
167: Object newValue = null;
168: if (type instanceof JavaEnumerationType) {
169: try {
170: newValue = ReflectionHelper.makeEnumerationType(
171: (JavaEnumerationType) type, urlClassLoader,
172: packageName, value);
173: } catch (WebServiceReflectionException wsfe) {
174: Throwable cause = wsfe.getCause();
175: ErrorManager.getDefault().notify(cause);
176: ErrorManager
177: .getDefault()
178: .log(
179: TypeRowModel.class.getName()
180: + ": Error trying to create an Enumeration Type: "
181: + type.getFormalName()
182: + "ClassNWebServiceReflectionExceptionotFoundException="
183: + cause);
184: return;
185: }
186:
187: } else {
188: newValue = value;
189:
190: }
191:
192: data.setParameterValue(newValue);
193: /**
194: * If this node's parent is a JavaStructureType or JavaArrayType, update this value on the parent's
195: * value.
196: */
197:
198: DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node
199: .getParent();
200: if (null != parentNode
201: && parentNode instanceof ArrayTypeTreeNode) {
202: ((ArrayTypeTreeNode) parentNode).updateValueOfChildren();
203: } else if (null != parentNode
204: && parentNode instanceof StructureTypeTreeNode) {
205: /**
206: * This type should be a JavaStructureMember
207: */
208: ((StructureTypeTreeNode) parentNode)
209: .updateValueOfChild(data);
210: }
211:
212: }
213:
214: }
|