KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > nodes > WS70ManagedObjectBase


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.j2ee.sun.ws7.nodes;
21
22
23 import org.netbeans.modules.j2ee.sun.ws7.Constants;
24 import org.netbeans.modules.j2ee.sun.ws7.ui.Util;
25 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue;
26 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedEditor;
27 import java.awt.Component JavaDoc;
28 import java.beans.PropertyDescriptor JavaDoc;
29 import java.beans.PropertyEditor JavaDoc;
30 import java.beans.PropertyEditorSupport JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import java.rmi.RemoteException JavaDoc;
33 import java.text.MessageFormat JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Set JavaDoc;
38
39 import javax.swing.AbstractAction JavaDoc;
40
41
42 import org.openide.nodes.Node;
43 import org.openide.nodes.PropertySupport;
44 import org.openide.nodes.Sheet;
45 import org.openide.util.HelpCtx;
46 import org.openide.util.NbBundle;
47
48 /**
49  * Base class for the manged objects.
50  */

51 public abstract class WS70ManagedObjectBase implements Node.Cookie, Constants {
52    
53     public abstract String JavaDoc getDisplayName();
54     public abstract Attribute setAttribute(String JavaDoc attribute, Object JavaDoc value) throws Exception JavaDoc;
55     public abstract Sheet updateSheet(Sheet sheet);
56     static Map JavaDoc primitivesMap = new HashMap JavaDoc();
57     static {
58         primitivesMap.put("short", Short JavaDoc.class); // NOI18N
59
primitivesMap.put("long", Long JavaDoc.class); // NOI18N
60
primitivesMap.put("int", Integer JavaDoc.class); // NOI18N
61
primitivesMap.put("boolean", Boolean JavaDoc.class); // NOI18N
62
primitivesMap.put("float", Float JavaDoc.class); // NOI18N
63
primitivesMap.put("double", Double JavaDoc.class); // NOI18N
64
primitivesMap.put("byte", Byte JavaDoc.class); // NOI18N
65
primitivesMap.put("char", String JavaDoc.class); // NOI18N
66
};
67     
68     protected static Class JavaDoc getSupportedType(String JavaDoc type) {
69         try {
70             Class JavaDoc c = (Class JavaDoc) primitivesMap.get(type);
71             
72             if (c == null) {
73                 c = Class.forName(type);
74             }
75         
76             if (c == null) {
77                 throw new ClassNotFoundException JavaDoc(type);
78             }
79             
80             if (!String JavaDoc.class.isAssignableFrom(c) &&
81                 !Number JavaDoc.class.isAssignableFrom(c) &&
82                 !TaggedValue.class.isAssignableFrom(c)) {
83                 return null;
84             }
85             
86             return c;
87         } catch (ClassNotFoundException JavaDoc cnfe) {
88             return null;
89         }
90     }
91     private static String JavaDoc getLocString(String JavaDoc key) {
92         return NbBundle.getMessage(WS70ManagedObjectBase.class, key);
93     }
94     
95     
96     
97
98     PropertySupport getStringArrayEditor(final Attribute a,
99                                          final AttributeInfo attr,
100                                          final String JavaDoc shortDescription,
101                                          final Class JavaDoc type,
102                                          boolean writable) {
103         PropertySupport strArrayEditor = null;
104
105         if (writable) {
106             strArrayEditor = createStringArrayWritableProperty(a, attr,
107                                                                shortDescription,
108                                                                type);
109         }
110         else {
111             strArrayEditor = createStringArrayReadOnlyProperty(a, attr,
112                                                                shortDescription,
113                                                                type);
114         } // end of else
115

116         strArrayEditor.setValue("helpID", "AS_RTT_StringArrayEditor"); // NOI18N
117

118         return strArrayEditor;
119     }
120
121     String JavaDoc getShortDescription(AttributeInfo attr) {
122         String JavaDoc shortDescription = attr.getDescription();
123
124         if (shortDescription == null ||
125             shortDescription.trim().equals("")) { // NOI18N
126
/* try {
127                 shortDescription = getLocString("DSC_" + attr.getName()); // NOI18N
128             } catch (Exception ex) {
129                                 // IN case bundle key is missing
130                 shortDescription = MessageFormat.format(getLocString("Msg_Value"), // NOI18N
131                                                         new Object[]{ attr.getName()});
132             }
133  
134  */

135             shortDescription = attr.getName();
136         }
137
138         return shortDescription;
139     }
140  
141  /* void setHelpId(Sheet.Set ps) {
142         String propSheetHelp = getPropertiesHelpID();
143
144         if (propSheetHelp != null) {
145             ps.setValue("helpID", propSheetHelp); // NOI18N
146         }
147     }
148  */

149     PropertySupport createReadOnlyProperty(final Attribute a,
150                                            final AttributeInfo attributeInfo,
151                                            final String JavaDoc shortDescription) {
152         return new PropertySupport.ReadOnly(attributeInfo.getName(),
153                                             String JavaDoc.class,
154                                             attributeInfo.getName(),
155                                             shortDescription) {
156                 Attribute attribute = a;
157
158                 public Object JavaDoc getValue() {
159                     Object JavaDoc value = null;
160
161                     try {
162                         value = attribute.getValue();
163
164                         if (value != null && !(value instanceof String JavaDoc)) {
165                             value = value.toString();
166                         }
167                     } catch (Exception JavaDoc e) {}
168
169                     return (value == null) ? "" : value; // NOI18N
170
}
171             };
172     }
173
174     PropertySupport createWritableProperty(final Attribute a,
175                                            final AttributeInfo attr,
176                                            final String JavaDoc shortDescription,
177                                            final Class JavaDoc type) {
178         return new PropertySupport.ReadWrite(attr.getName(),
179                                              type,
180                                              attr.getName(),
181                                              shortDescription) {
182                 Attribute attribute = a;
183
184                 public Object JavaDoc getValue() {
185                     return attribute.getValue();
186                 }
187
188                 public void setValue(Object JavaDoc value) {
189                     try {
190                         String JavaDoc attributeName = getName();
191                         attribute = setAttribute(getName(),
192                                                  value);
193                     } catch (Exception JavaDoc e) {
194                         Util.showError(e.getLocalizedMessage());
195                     }
196                 }
197             };
198     }
199     
200     PropertySupport createStringArrayWritableProperty(final Attribute a,
201                                                       final AttributeInfo attr,
202                                                       final String JavaDoc shortDescription,
203                                                       final Class JavaDoc type) {
204         return new PropertySupport.ReadWrite(attr.getName(),
205                                              type,
206                                              attr.getName(),
207                                              shortDescription) {
208                 Attribute attribute = a;
209
210                 public Object JavaDoc getValue() {
211                     return attribute.getValue();
212                 }
213
214                 public void setValue(Object JavaDoc value) {
215                     try {
216                         attribute = setAttribute(getName(),
217                                                  value);
218                     } catch (Exception JavaDoc e) {
219                         Util.showError(e.getLocalizedMessage());
220                     }
221                 }
222             };
223     }
224     
225     PropertySupport createStringArrayReadOnlyProperty(final Attribute a,
226                                                       final AttributeInfo attr,
227                                                       final String JavaDoc shortDescription,
228                                                       final Class JavaDoc type) {
229         return new PropertySupport.ReadOnly(attr.getName(),
230                                             type,
231                                             attr.getName(),
232                                             shortDescription) {
233                 Attribute attribute = a;
234
235                 public Object JavaDoc getValue() {
236                     return attribute.getValue();
237                 }
238             };
239     }
240     
241     
242     PropertySupport createTaggedProperty(final Attribute a,
243                                          final AttributeInfo attr,
244                                          final String JavaDoc shortDescription,
245                                          final Class JavaDoc type) {
246         return new PropertySupport.ReadWrite(attr.getName(),
247                                              type,
248                                              attr.getName(),
249                                              shortDescription) {
250                 Attribute attribute = a;
251
252                 public Object JavaDoc getValue() {
253                     return attribute.getValue();
254                 }
255
256                 public void setValue(Object JavaDoc value) {
257                     try {
258                         attribute = setAttribute(getName(), value);
259                     } catch (Exception JavaDoc e) {
260                         Util.showError(e.getLocalizedMessage());
261                     }
262                 }
263
264                 public PropertyEditor JavaDoc getPropertyEditor() {
265                     return new TaggedEditor(attribute.getValue().getClass());
266                 }
267             };
268     }
269     public static class Boolean extends TaggedValue {
270         private boolean value;
271         
272         private Boolean(boolean value) {
273             this.value = value;
274         }
275         
276         private static final Boolean JavaDoc TRUE =
277             new Boolean JavaDoc(true);
278         private static final Boolean JavaDoc FALSE =
279             new Boolean JavaDoc(false);
280         private static final Boolean JavaDoc[] values =
281             new Boolean JavaDoc[]{ TRUE, FALSE };
282         
283         public static TaggedValue getValue(String JavaDoc s) {
284             if ("true".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s)) { // NOI18N
285
return TRUE;
286             } // end of if ("true".equalsIgnoreCase(s) ||
287
// "on".equalsIgnoreCase(s))
288

289             return FALSE;
290         }
291        public static TaggedValue getValue(java.lang.Boolean JavaDoc b) {
292             if (b.toString().equals("true")|| b.toString().equals("on")) { // NOI18N
293
return TRUE;
294             }
295
296             return FALSE;
297         }
298         public static TaggedValue[] getChoices() {
299             return values;
300         }
301         
302         public boolean booleanValue() {
303             return value;
304         }
305
306         public String JavaDoc toString() {
307             if (value) {
308                 return "true"; // NOI18N
309
} // end of if (value)
310

311             return "false"; // NOI18N
312
}
313     }
314 }
315
Popular Tags