KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > TypeRowModel


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

19
20 package org.netbeans.modules.websvc.registry.ui;
21
22 import org.netbeans.swing.outline.RowModel;
23 import org.openide.ErrorManager;
24
25
26 import com.sun.xml.rpc.processor.model.java.JavaType;
27 import com.sun.xml.rpc.processor.model.java.JavaSimpleType;
28 import com.sun.xml.rpc.processor.model.java.JavaEnumerationType;
29
30 import org.openide.util.NbBundle;
31 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
32
33 import java.net.URLClassLoader JavaDoc;
34
35 /**
36  *
37  * @author David Botterill
38  */

39 public class TypeRowModel implements RowModel {
40
41     private URLClassLoader JavaDoc urlClassLoader;
42     private String JavaDoc packageName;
43     
44     /** Creates a new instance of TypeRowModel */
45     public TypeRowModel(URLClassLoader JavaDoc inClassLoader, String JavaDoc inPackageName) {
46         urlClassLoader = inClassLoader;
47         packageName = inPackageName;
48     
49     }
50     
51     public Class JavaDoc getColumnClass(int column) {
52         switch(column) {
53          // case 0: return String.class;
54
case 0: return String JavaDoc.class;
55             case 1: return Object JavaDoc.class;
56             default: return String JavaDoc.class;
57         }
58     }
59     
60     public int getColumnCount() {
61         return 2;
62     }
63     
64     public String JavaDoc getColumnName(int column) {
65         switch(column) {
66            // case 0: return NbBundle.getMessage(this.getClass(), "PARAM_CLASS");
67
case 0: return NbBundle.getMessage(this.getClass(), "PARAM_NAME");
68             case 1: return NbBundle.getMessage(this.getClass(), "PARAM_VALUE");
69             default: return "";
70         }
71         
72     }
73     
74     public Object JavaDoc getValueFor(Object JavaDoc inNode, int column) {
75         if(null == inNode) return null;
76         DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)inNode;
77         if(null == node.getUserObject()) return null;
78         TypeNodeData data = (TypeNodeData)node.getUserObject();
79         switch(column) {
80        // case 0: return data.getParameterType().getRealName();
81
case 0: return data.getParameterName();
82             case 1: {
83                 Object JavaDoc val = data.getParameterValue();
84                 if (val instanceof java.util.Calendar JavaDoc)
85                     return java.text.DateFormat.getDateTimeInstance().format(((java.util.Calendar JavaDoc)val).getTime());
86                 return val;
87             }
88             default: return "";
89         }
90         
91     }
92     
93     public boolean isCellEditable(Object JavaDoc inNode, int column) {
94         if(null == inNode) return false;
95         DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)inNode;
96         if(null == node.getUserObject()) return false;
97         
98         TypeNodeData data = (TypeNodeData)node.getUserObject();
99         switch(column) {
100          // case 0: return false;
101
case 0: return false;
102             case 1: if(data.getParameterType() instanceof JavaSimpleType ||
103                        data.getParameterType() instanceof JavaEnumerationType) return true;
104                     else return false;
105             default: return false;
106         }
107         
108     }
109     
110     public void setValueFor(Object JavaDoc inNode, int column, Object JavaDoc value) {
111         if(null == inNode) return;
112         DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)inNode;
113         if(null == node.getUserObject()) return;
114         
115         TypeNodeData data = (TypeNodeData)node.getUserObject();
116         /**
117          * Make sure they are only trying to edit the value column
118          */

119         if(column != 1) {
120             return;
121         }
122         JavaType type = data.getParameterType();
123         Object JavaDoc newValue = null;
124         if(type instanceof JavaEnumerationType) {
125             try {
126                 newValue = ReflectionHelper.makeEnumerationType((JavaEnumerationType)type,urlClassLoader,packageName,value);
127             } catch(WebServiceReflectionException wsfe) {
128                 Throwable JavaDoc cause = wsfe.getCause();
129                 ErrorManager.getDefault().notify(cause);
130                 ErrorManager.getDefault().log(this.getClass().getName() +
131                 ": Error trying to create an Enumeration Type: " +
132                 type.getFormalName() + "ClassNWebServiceReflectionExceptionotFoundException=" + cause);
133                 return;
134             }
135             
136             
137         } else {
138             newValue = value;
139             
140         }
141         
142         data.setParameterValue(newValue);
143         /**
144          * If this node's parent is a JavaStructureType or JavaArrayType, update this value on the parent's
145          * value.
146          */

147         
148         DefaultMutableTreeNode JavaDoc parentNode = (DefaultMutableTreeNode JavaDoc) node.getParent();
149         if(null != parentNode && parentNode instanceof ArrayTypeTreeNode) {
150             ((ArrayTypeTreeNode)parentNode).updateValueOfChildren();
151         } else if(null != parentNode && parentNode instanceof StructureTypeTreeNode) {
152             /**
153              * This type should be a JavaStructureMember
154              */

155             ((StructureTypeTreeNode)parentNode).updateValueOfChild(data);
156         }
157         
158         
159         
160         
161     }
162     
163 }
164
Popular Tags