KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > JUnitSettingsBeanInfo


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

19
20 package org.netbeans.modules.junit;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.TreeSet JavaDoc;
26 import java.awt.Image JavaDoc;
27 import java.beans.*;
28 import org.openide.util.NbBundle;
29 import org.openide.util.Utilities;
30
31 /**
32  *
33  * @author vstejskal
34  * @author Marian Petras
35  */

36 public class JUnitSettingsBeanInfo extends SimpleBeanInfo {
37     
38     public BeanDescriptor getBeanDescriptor() {
39         BeanDescriptor descr = new BeanDescriptor(JUnitSettings.class);
40         descr.setDisplayName(
41                 NbBundle.getMessage(JUnitSettings.class,
42                                     "SettingsNodeName")); //NOI18N
43
return descr;
44     }
45
46     public PropertyDescriptor[] getPropertyDescriptors () {
47         try {
48             PropertyDescriptor propMembersPublic = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PUBLIC, JUnitSettings.class);
49             propMembersPublic.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_public"));
50             propMembersPublic.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_public"));
51
52             PropertyDescriptor propMembersProtected = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PROTECTED, JUnitSettings.class);
53             propMembersProtected.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_protected"));
54             propMembersProtected.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_protected"));
55
56             PropertyDescriptor propMembersPackage = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PACKAGE, JUnitSettings.class);
57             propMembersPackage.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_package"));
58             propMembersPackage.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_package"));
59
60             PropertyDescriptor propBodyComments = new PropertyDescriptor (JUnitSettings.PROP_BODY_COMMENTS, JUnitSettings.class);
61             propBodyComments.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_body_comments"));
62             propBodyComments.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_body_comments"));
63
64             PropertyDescriptor propBodyContent = new PropertyDescriptor (JUnitSettings.PROP_BODY_CONTENT, JUnitSettings.class);
65             propBodyContent.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_body_content"));
66             propBodyContent.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_body_content"));
67
68             PropertyDescriptor propJavaDoc = new PropertyDescriptor (JUnitSettings.PROP_JAVADOC, JUnitSettings.class);
69             propJavaDoc.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_javadoc"));
70             propJavaDoc.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_javadoc"));
71             
72             PropertyDescriptor propGenerateExceptionClasses = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_EXCEPTION_CLASSES, JUnitSettings.class);
73             propGenerateExceptionClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_exception_classes"));
74             propGenerateExceptionClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_exception_classes"));
75             
76             PropertyDescriptor propGenerateAbstractImpl = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_ABSTRACT_IMPL, JUnitSettings.class);
77             propGenerateAbstractImpl.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_abstract_impl"));
78             propGenerateAbstractImpl.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_abstract_impl"));
79
80             
81             PropertyDescriptor propGenerateSuiteClasses = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_SUITE_CLASSES, JUnitSettings.class);
82             propGenerateSuiteClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_suite_classes"));
83             propGenerateSuiteClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_suite_classes"));
84             
85             PropertyDescriptor propIncludePackagePrivateClasses = new PropertyDescriptor (JUnitSettings.PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES, JUnitSettings.class);
86             propIncludePackagePrivateClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_include_package_private_classes"));
87             propIncludePackagePrivateClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_include_package_private_classes"));
88             
89             PropertyDescriptor propGenerateSetUp = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_SETUP, JUnitSettings.class);
90             propGenerateSetUp.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_setUp"));
91             propGenerateSetUp.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_setUp"));
92             
93             PropertyDescriptor propGenerateTearDown = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_TEARDOWN, JUnitSettings.class);
94             propGenerateTearDown.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_tearDown"));
95             propGenerateTearDown.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_tearDown"));
96             
97
98             
99             // expert properties
100
PropertyDescriptor propGenerateMainMethod = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_MAIN_METHOD, JUnitSettings.class);
101             propGenerateMainMethod.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_main_method"));
102             propGenerateMainMethod.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_main_method"));
103             propGenerateMainMethod.setExpert(true);
104             
105             PropertyDescriptor propGenerateMainMethodBody = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_MAIN_METHOD_BODY, JUnitSettings.class);
106             propGenerateMainMethodBody.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_main_method_body"));
107             propGenerateMainMethodBody.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_main_method_body"));
108             propGenerateMainMethodBody.setExpert(true);
109
110 // XXX: is this really required to be customizable?
111
// PropertyDescriptor propTestClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_PREFIX, JUnitSettings.class);
112
// propTestClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_prefix"));
113
// propTestClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_prefix"));
114
// propTestClassNamePrefix.setExpert(true);
115
//
116
// PropertyDescriptor propTestClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_SUFFIX, JUnitSettings.class);
117
// propTestClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_suffix"));
118
// propTestClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_suffix"));
119
// propTestClassNameSuffix.setExpert(true);
120
//
121
// PropertyDescriptor propSuiteClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_PREFIX, JUnitSettings.class);
122
// propSuiteClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_prefix"));
123
// propSuiteClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_prefix"));
124
// propSuiteClassNamePrefix.setExpert(true);
125
//
126
// PropertyDescriptor propSuiteClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_SUFFIX, JUnitSettings.class);
127
// propSuiteClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_suffix"));
128
// propSuiteClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_suffix"));
129
// propSuiteClassNameSuffix.setExpert(true);
130

131             PropertyDescriptor propRootSuiteClassName = new PropertyDescriptor (JUnitSettings.PROP_ROOT_SUITE_CLASSNAME, JUnitSettings.class);
132             propRootSuiteClassName.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_root_suite_classname"));
133             propRootSuiteClassName.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_root_suite_classname"));
134             propRootSuiteClassName.setExpert(true);
135                         
136
137             return new PropertyDescriptor[] {
138               propMembersPublic, propMembersProtected, propMembersPackage, propBodyComments, propBodyContent,
139               propJavaDoc,
140               propGenerateExceptionClasses, propGenerateAbstractImpl, propIncludePackagePrivateClasses,
141               propGenerateSuiteClasses,
142               propGenerateSetUp, propGenerateTearDown,
143               propGenerateMainMethod, propGenerateMainMethodBody,
144               //propTestClassNamePrefix, propTestClassNameSuffix, propSuiteClassNamePrefix, propSuiteClassNameSuffix,
145
propRootSuiteClassName
146             };
147         }
148         catch (IntrospectionException ie) {
149             org.openide.ErrorManager.getDefault().notify(ie);
150             return null;
151         }
152     }
153
154     public Image JavaDoc getIcon (int type) {
155         if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
156             return Utilities.loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon.gif");//NOI18N
157
} else {
158             return Utilities.loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon32.gif");//NOI18N
159
}
160     }
161
162     public static class SortedListPropEd extends PropertyEditorSupport {
163         private List JavaDoc<String JavaDoc> displays = new LinkedList JavaDoc<String JavaDoc>();
164         private List JavaDoc<String JavaDoc> values = new LinkedList JavaDoc<String JavaDoc>();
165         private String JavaDoc defaultDisplay = NbBundle.getMessage(JUnitSettingsBeanInfo.class, "LBL_value_not_found");
166
167         public String JavaDoc[] getTags () {
168             TreeSet JavaDoc<String JavaDoc> t = new TreeSet JavaDoc<String JavaDoc>(displays);
169             if (displays.size() > 0) {
170                 return t.toArray(new String JavaDoc[displays.size() - 1]);
171             } else {
172                 return new String JavaDoc[0];
173             }
174         }
175
176         public String JavaDoc getAsText() {
177             String JavaDoc value = null;
178             String JavaDoc display = null;
179             Iterator JavaDoc<String JavaDoc> iD = displays.iterator();
180             Iterator JavaDoc<String JavaDoc> iV = values.iterator();
181             while (iV.hasNext()) {
182                 value = iV.next();
183                 display = iD.next();
184                 if (value.equals(getValue())) {
185                     return display;
186                 }
187             }
188             return defaultDisplay;
189         }
190         
191         public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
192             String JavaDoc value = null;
193             String JavaDoc display = null;
194             Iterator JavaDoc<String JavaDoc> iD = displays.iterator();
195             Iterator JavaDoc<String JavaDoc> iV = values.iterator();
196             while (iD.hasNext()) {
197                 value = iV.next();
198                 display = iD.next();
199                 if (display.equals(text)) {
200                     setValue(value);
201                     return;
202                 }
203             }
204             throw new IllegalArgumentException JavaDoc ();
205         }
206
207         protected void put(String JavaDoc display, String JavaDoc value, int type) {
208             if (SHOW_IN_LIST == (type & SHOW_IN_LIST)) {
209                 displays.add(display);
210                 values.add(value);
211             }
212             if (IS_DEFAULT == (type & IS_DEFAULT)) {
213                 defaultDisplay = display;
214             }
215         }
216         
217         protected static int SHOW_IN_LIST = 1;
218         protected static int IS_DEFAULT = 2;
219     }
220
221 }
222
Popular Tags