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-2007 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.junit;
043:
044: import java.util.Iterator;
045: import java.util.LinkedList;
046: import java.util.List;
047: import java.util.TreeSet;
048: import java.awt.Image;
049: import java.beans.*;
050: import org.openide.util.NbBundle;
051: import org.openide.util.Utilities;
052:
053: /**
054: *
055: * @author vstejskal
056: * @author Marian Petras
057: */
058: public class JUnitSettingsBeanInfo extends SimpleBeanInfo {
059:
060: public BeanDescriptor getBeanDescriptor() {
061: BeanDescriptor descr = new BeanDescriptor(JUnitSettings.class);
062: descr.setDisplayName(NbBundle.getMessage(JUnitSettings.class,
063: "SettingsNodeName")); //NOI18N
064: return descr;
065: }
066:
067: public PropertyDescriptor[] getPropertyDescriptors() {
068: try {
069: PropertyDescriptor propMembersPublic = new PropertyDescriptor(
070: JUnitSettings.PROP_MEMBERS_PUBLIC,
071: JUnitSettings.class);
072: propMembersPublic
073: .setDisplayName(NbBundle.getMessage(
074: JUnitSettingsBeanInfo.class,
075: "PROP_members_public"));
076: propMembersPublic
077: .setShortDescription(NbBundle.getMessage(
078: JUnitSettingsBeanInfo.class,
079: "HINT_members_public"));
080:
081: PropertyDescriptor propMembersProtected = new PropertyDescriptor(
082: JUnitSettings.PROP_MEMBERS_PROTECTED,
083: JUnitSettings.class);
084: propMembersProtected.setDisplayName(NbBundle.getMessage(
085: JUnitSettingsBeanInfo.class,
086: "PROP_members_protected"));
087: propMembersProtected.setShortDescription(NbBundle
088: .getMessage(JUnitSettingsBeanInfo.class,
089: "HINT_members_protected"));
090:
091: PropertyDescriptor propMembersPackage = new PropertyDescriptor(
092: JUnitSettings.PROP_MEMBERS_PACKAGE,
093: JUnitSettings.class);
094: propMembersPackage.setDisplayName(NbBundle
095: .getMessage(JUnitSettingsBeanInfo.class,
096: "PROP_members_package"));
097: propMembersPackage.setShortDescription(NbBundle
098: .getMessage(JUnitSettingsBeanInfo.class,
099: "HINT_members_package"));
100:
101: PropertyDescriptor propBodyComments = new PropertyDescriptor(
102: JUnitSettings.PROP_BODY_COMMENTS,
103: JUnitSettings.class);
104: propBodyComments.setDisplayName(NbBundle.getMessage(
105: JUnitSettingsBeanInfo.class, "PROP_body_comments"));
106: propBodyComments.setShortDescription(NbBundle.getMessage(
107: JUnitSettingsBeanInfo.class, "HINT_body_comments"));
108:
109: PropertyDescriptor propBodyContent = new PropertyDescriptor(
110: JUnitSettings.PROP_BODY_CONTENT,
111: JUnitSettings.class);
112: propBodyContent.setDisplayName(NbBundle.getMessage(
113: JUnitSettingsBeanInfo.class, "PROP_body_content"));
114: propBodyContent.setShortDescription(NbBundle.getMessage(
115: JUnitSettingsBeanInfo.class, "HINT_body_content"));
116:
117: PropertyDescriptor propJavaDoc = new PropertyDescriptor(
118: JUnitSettings.PROP_JAVADOC, JUnitSettings.class);
119: propJavaDoc.setDisplayName(NbBundle.getMessage(
120: JUnitSettingsBeanInfo.class, "PROP_javadoc"));
121: propJavaDoc.setShortDescription(NbBundle.getMessage(
122: JUnitSettingsBeanInfo.class, "HINT_javadoc"));
123:
124: PropertyDescriptor propGenerateExceptionClasses = new PropertyDescriptor(
125: JUnitSettings.PROP_GENERATE_EXCEPTION_CLASSES,
126: JUnitSettings.class);
127: propGenerateExceptionClasses.setDisplayName(NbBundle
128: .getMessage(JUnitSettingsBeanInfo.class,
129: "PROP_generate_exception_classes"));
130: propGenerateExceptionClasses.setShortDescription(NbBundle
131: .getMessage(JUnitSettingsBeanInfo.class,
132: "HINT_generate_exception_classes"));
133:
134: PropertyDescriptor propGenerateAbstractImpl = new PropertyDescriptor(
135: JUnitSettings.PROP_GENERATE_ABSTRACT_IMPL,
136: JUnitSettings.class);
137: propGenerateAbstractImpl.setDisplayName(NbBundle
138: .getMessage(JUnitSettingsBeanInfo.class,
139: "PROP_generate_abstract_impl"));
140: propGenerateAbstractImpl.setShortDescription(NbBundle
141: .getMessage(JUnitSettingsBeanInfo.class,
142: "HINT_generate_abstract_impl"));
143:
144: PropertyDescriptor propGenerateSuiteClasses = new PropertyDescriptor(
145: JUnitSettings.PROP_GENERATE_SUITE_CLASSES,
146: JUnitSettings.class);
147: propGenerateSuiteClasses.setDisplayName(NbBundle
148: .getMessage(JUnitSettingsBeanInfo.class,
149: "PROP_generate_suite_classes"));
150: propGenerateSuiteClasses.setShortDescription(NbBundle
151: .getMessage(JUnitSettingsBeanInfo.class,
152: "HINT_generate_suite_classes"));
153:
154: PropertyDescriptor propIncludePackagePrivateClasses = new PropertyDescriptor(
155: JUnitSettings.PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES,
156: JUnitSettings.class);
157: propIncludePackagePrivateClasses.setDisplayName(NbBundle
158: .getMessage(JUnitSettingsBeanInfo.class,
159: "PROP_include_package_private_classes"));
160: propIncludePackagePrivateClasses
161: .setShortDescription(NbBundle.getMessage(
162: JUnitSettingsBeanInfo.class,
163: "HINT_include_package_private_classes"));
164:
165: PropertyDescriptor propGenerateSetUp = new PropertyDescriptor(
166: JUnitSettings.PROP_GENERATE_SETUP,
167: JUnitSettings.class);
168: propGenerateSetUp
169: .setDisplayName(NbBundle.getMessage(
170: JUnitSettingsBeanInfo.class,
171: "PROP_generate_setUp"));
172: propGenerateSetUp
173: .setShortDescription(NbBundle.getMessage(
174: JUnitSettingsBeanInfo.class,
175: "HINT_generate_setUp"));
176:
177: PropertyDescriptor propGenerateTearDown = new PropertyDescriptor(
178: JUnitSettings.PROP_GENERATE_TEARDOWN,
179: JUnitSettings.class);
180: propGenerateTearDown.setDisplayName(NbBundle.getMessage(
181: JUnitSettingsBeanInfo.class,
182: "PROP_generate_tearDown"));
183: propGenerateTearDown.setShortDescription(NbBundle
184: .getMessage(JUnitSettingsBeanInfo.class,
185: "HINT_generate_tearDown"));
186:
187: PropertyDescriptor propGenerateClassSetUp = new PropertyDescriptor(
188: JUnitSettings.PROP_GENERATE_CLASS_SETUP,
189: JUnitSettings.class);
190: propGenerateClassSetUp.setDisplayName(NbBundle.getMessage(
191: JUnitSettingsBeanInfo.class,
192: "PROP_generate_class_setUp"));
193: propGenerateClassSetUp.setShortDescription(NbBundle
194: .getMessage(JUnitSettingsBeanInfo.class,
195: "HINT_generate_class_setUp"));
196:
197: PropertyDescriptor propGenerateClassTearDown = new PropertyDescriptor(
198: JUnitSettings.PROP_GENERATE_CLASS_TEARDOWN,
199: JUnitSettings.class);
200: propGenerateClassTearDown.setDisplayName(NbBundle
201: .getMessage(JUnitSettingsBeanInfo.class,
202: "PROP_generate_class_tearDown"));
203: propGenerateClassTearDown.setShortDescription(NbBundle
204: .getMessage(JUnitSettingsBeanInfo.class,
205: "HINT_generate_class_tearDown"));
206:
207: PropertyDescriptor propGenerator = new PropertyDescriptor(
208: JUnitSettings.PROP_GENERATOR, JUnitSettings.class,
209: "getGenerator", "setGenerator");
210: propGenerator.setDisplayName(NbBundle.getMessage(
211: JUnitSettingsBeanInfo.class, "PROP_generator"));
212: propGenerator.setShortDescription(NbBundle.getMessage(
213: JUnitSettingsBeanInfo.class, "HINT_generator"));
214: propGenerator
215: .setPropertyEditorClass(GeneratorsPropEditor.class);
216:
217: // expert properties
218: PropertyDescriptor propGenerateMainMethod = new PropertyDescriptor(
219: JUnitSettings.PROP_GENERATE_MAIN_METHOD,
220: JUnitSettings.class);
221: propGenerateMainMethod.setDisplayName(NbBundle.getMessage(
222: JUnitSettingsBeanInfo.class,
223: "PROP_generate_main_method"));
224: propGenerateMainMethod.setShortDescription(NbBundle
225: .getMessage(JUnitSettingsBeanInfo.class,
226: "HINT_generate_main_method"));
227: propGenerateMainMethod.setExpert(true);
228:
229: PropertyDescriptor propGenerateMainMethodBody = new PropertyDescriptor(
230: JUnitSettings.PROP_GENERATE_MAIN_METHOD_BODY,
231: JUnitSettings.class);
232: propGenerateMainMethodBody.setDisplayName(NbBundle
233: .getMessage(JUnitSettingsBeanInfo.class,
234: "PROP_generate_main_method_body"));
235: propGenerateMainMethodBody.setShortDescription(NbBundle
236: .getMessage(JUnitSettingsBeanInfo.class,
237: "HINT_generate_main_method_body"));
238: propGenerateMainMethodBody.setExpert(true);
239:
240: // XXX: is this really required to be customizable?
241: // PropertyDescriptor propTestClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_PREFIX, JUnitSettings.class);
242: // propTestClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_prefix"));
243: // propTestClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_prefix"));
244: // propTestClassNamePrefix.setExpert(true);
245: //
246: // PropertyDescriptor propTestClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_SUFFIX, JUnitSettings.class);
247: // propTestClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_suffix"));
248: // propTestClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_suffix"));
249: // propTestClassNameSuffix.setExpert(true);
250: //
251: // PropertyDescriptor propSuiteClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_PREFIX, JUnitSettings.class);
252: // propSuiteClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_prefix"));
253: // propSuiteClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_prefix"));
254: // propSuiteClassNamePrefix.setExpert(true);
255: //
256: // PropertyDescriptor propSuiteClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_SUFFIX, JUnitSettings.class);
257: // propSuiteClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_suffix"));
258: // propSuiteClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_suffix"));
259: // propSuiteClassNameSuffix.setExpert(true);
260:
261: PropertyDescriptor propRootSuiteClassName = new PropertyDescriptor(
262: JUnitSettings.PROP_ROOT_SUITE_CLASSNAME,
263: JUnitSettings.class);
264: propRootSuiteClassName.setDisplayName(NbBundle.getMessage(
265: JUnitSettingsBeanInfo.class,
266: "PROP_root_suite_classname"));
267: propRootSuiteClassName.setShortDescription(NbBundle
268: .getMessage(JUnitSettingsBeanInfo.class,
269: "HINT_root_suite_classname"));
270: propRootSuiteClassName.setExpert(true);
271:
272: return new PropertyDescriptor[] { propGenerator,
273: propMembersPublic, propMembersProtected,
274: propMembersPackage, propBodyComments,
275: propBodyContent, propJavaDoc,
276: propGenerateExceptionClasses,
277: propGenerateAbstractImpl,
278: propIncludePackagePrivateClasses,
279: propGenerateSuiteClasses, propGenerateSetUp,
280: propGenerateTearDown, propGenerateClassSetUp,
281: propGenerateClassTearDown, propGenerateMainMethod,
282: propGenerateMainMethodBody,
283: //propTestClassNamePrefix, propTestClassNameSuffix, propSuiteClassNamePrefix, propSuiteClassNameSuffix,
284: propRootSuiteClassName };
285: } catch (IntrospectionException ie) {
286: org.openide.ErrorManager.getDefault().notify(ie);
287: return null;
288: }
289: }
290:
291: public Image getIcon(int type) {
292: if (type == BeanInfo.ICON_COLOR_16x16
293: || type == BeanInfo.ICON_MONO_16x16) {
294: return Utilities
295: .loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon.gif");//NOI18N
296: } else {
297: return Utilities
298: .loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon32.gif");//NOI18N
299: }
300: }
301:
302: static abstract class SortedListPropEd extends
303: PropertyEditorSupport {
304: private final String defaultValue;
305: private List<String> displays = new LinkedList<String>();
306: private List<String> values = new LinkedList<String>();
307: private String defaultDisplay = NbBundle.getMessage(
308: JUnitSettingsBeanInfo.class, "LBL_value_not_found");
309:
310: protected SortedListPropEd(String defValue) {
311: defaultValue = defValue;
312: }
313:
314: public String[] getTags() {
315: TreeSet<String> t = new TreeSet<String>(displays);
316: if (displays.size() > 0) {
317: return t.toArray(new String[displays.size() - 1]);
318: } else {
319: return new String[0];
320: }
321: }
322:
323: public String getAsText() {
324: String value = null;
325: String display = null;
326: Iterator<String> iD = displays.iterator();
327: Iterator<String> iV = values.iterator();
328: while (iV.hasNext()) {
329: value = iV.next();
330: display = iD.next();
331: if (value.equals(getValue())) {
332: return display;
333: }
334: }
335: return defaultDisplay;
336: }
337:
338: public void setAsText(String text)
339: throws IllegalArgumentException {
340: String value = null;
341: String display = null;
342: Iterator<String> iD = displays.iterator();
343: Iterator<String> iV = values.iterator();
344: while (iD.hasNext()) {
345: value = iV.next();
346: display = iD.next();
347: if (display.equals(text)) {
348: setValue(value);
349: return;
350: }
351: }
352: throw new IllegalArgumentException();
353: }
354:
355: protected void put(String display, String value) {
356: displays.add(display);
357: values.add(value);
358:
359: if ((defaultDisplay == null) && value.equals(defaultValue)) {
360: defaultDisplay = display;
361: }
362: }
363:
364: }
365:
366: public static final class GeneratorsPropEditor extends
367: SortedListPropEd {
368:
369: public GeneratorsPropEditor() {
370: super (JUnitSettings.DEFAULT_GENERATOR);
371: put(NbBundle.getMessage(JUnitSettings.class,
372: "LBL_JUnit3_generator"), //NOI18N
373: JUnitSettings.JUNIT3_GENERATOR);
374: put(NbBundle.getMessage(JUnitSettings.class,
375: "LBL_JUnit4_generator"), //NOI18N
376: JUnitSettings.JUNIT4_GENERATOR);
377: put(NbBundle.getMessage(JUnitSettings.class,
378: "LBL_JUnit_generator_ask_user"), //NOI18N
379: JUnitSettings.JUNIT_GENERATOR_ASK_USER);
380: }
381:
382: }
383:
384: }
|