KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > ide > editors > TaggedEditor


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 /*
21  * TaggedEditor.java
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.ide.editors;
25 import java.beans.PropertyEditorSupport JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27
28 /**
29  *
30  * @author Administrator
31  */

32     public class TaggedEditor extends PropertyEditorSupport JavaDoc {
33         private Object JavaDoc curr_Sel;
34         private Class JavaDoc clazz;
35         private Method JavaDoc getValue;
36         private Method JavaDoc getChoices;
37         private String JavaDoc[] tags;
38
39         public TaggedEditor(Class JavaDoc clazz) {
40             this.clazz = clazz;
41             curr_Sel = null;
42
43             try {
44                 getValue = clazz.getMethod("getValue", // NOI18N
45
new Class JavaDoc[] { String JavaDoc.class });
46                 getChoices = clazz.getMethod("getChoices", null); // NOI18N
47
} catch (NoSuchMethodException JavaDoc e) {
48                                 // Should not happen
49
e.printStackTrace();
50             } // end of try-catch
51
}
52
53         public String JavaDoc getAsText() {
54             return curr_Sel.toString();
55         }
56
57         public void setAsText(String JavaDoc string)
58             throws IllegalArgumentException JavaDoc {
59             if ((string == null) || string.equals("")) { // NOI18N
60
throw new IllegalArgumentException JavaDoc();
61             }
62             else {
63                 try {
64                     curr_Sel = getValue.
65                         invoke(null, new Object JavaDoc[]{ string });
66                 } catch (Exception JavaDoc e) {
67                                 // Should not happen
68
} // end of try-catch
69
} // end of else
70

71             this.firePropertyChange();
72         }
73
74         public void setValue (Object JavaDoc val) {
75             if (!clazz.isInstance(val)) {
76                 throw new IllegalArgumentException JavaDoc();
77             }
78
79             curr_Sel = val;
80         }
81
82         public Object JavaDoc getValue() {
83             return curr_Sel;
84         }
85
86         public String JavaDoc getJavaInitializationString() {
87             return getAsText();
88         }
89
90         public String JavaDoc[] getTags() {
91             if (tags == null) {
92                 TaggedValue[] tagObjs = new TaggedValue[0];
93                 
94                 try {
95                     tagObjs =
96                         (TaggedValue[])getChoices.invoke(null, null);
97                 } catch (Exception JavaDoc e) {
98                     e.printStackTrace();
99                                 // Should not happen
100
} // end of try-catch
101

102                 tags = new String JavaDoc[tagObjs.length];
103             
104                 for (int i = 0; i < tagObjs.length; i++) {
105                     tags[i] = tagObjs[i].toString();
106                 } // end of for (int i = 0; i < tagObjs.length; i++)
107
} // end of if (tags == null)
108

109             return tags;
110         }
111     }
112
Popular Tags