~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to junit/src/org/netbeans/modules/junit/JUnitSettingsBeanInfo.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.junit;
 
43
 
 
44
import java.util.Iterator;
 
45
import java.util.LinkedList;
 
46
import java.util.List;
 
47
import java.util.TreeSet;
 
48
import java.awt.Image;
 
49
import java.beans.*;
 
50
import org.openide.util.NbBundle;
 
51
import org.openide.util.Utilities;
 
52
 
 
53
/**
 
54
 *
 
55
 * @author vstejskal
 
56
 * @author  Marian Petras
 
57
 */
 
58
public class JUnitSettingsBeanInfo extends SimpleBeanInfo {
 
59
    
 
60
    public BeanDescriptor getBeanDescriptor() {
 
61
        BeanDescriptor descr = new BeanDescriptor(JUnitSettings.class);
 
62
        descr.setDisplayName(
 
63
                NbBundle.getMessage(JUnitSettings.class,
 
64
                                    "SettingsNodeName"));               //NOI18N
 
65
        return descr;
 
66
    }
 
67
 
 
68
    public PropertyDescriptor[] getPropertyDescriptors () {
 
69
        try {
 
70
            PropertyDescriptor propMembersPublic = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PUBLIC, JUnitSettings.class);
 
71
            propMembersPublic.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_public"));
 
72
            propMembersPublic.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_public"));
 
73
 
 
74
            PropertyDescriptor propMembersProtected = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PROTECTED, JUnitSettings.class);
 
75
            propMembersProtected.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_protected"));
 
76
            propMembersProtected.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_protected"));
 
77
 
 
78
            PropertyDescriptor propMembersPackage = new PropertyDescriptor (JUnitSettings.PROP_MEMBERS_PACKAGE, JUnitSettings.class);
 
79
            propMembersPackage.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_members_package"));
 
80
            propMembersPackage.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_members_package"));
 
81
 
 
82
            PropertyDescriptor propBodyComments = new PropertyDescriptor (JUnitSettings.PROP_BODY_COMMENTS, JUnitSettings.class);
 
83
            propBodyComments.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_body_comments"));
 
84
            propBodyComments.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_body_comments"));
 
85
 
 
86
            PropertyDescriptor propBodyContent = new PropertyDescriptor (JUnitSettings.PROP_BODY_CONTENT, JUnitSettings.class);
 
87
            propBodyContent.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_body_content"));
 
88
            propBodyContent.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_body_content"));
 
89
 
 
90
            PropertyDescriptor propJavaDoc = new PropertyDescriptor (JUnitSettings.PROP_JAVADOC, JUnitSettings.class);
 
91
            propJavaDoc.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_javadoc"));
 
92
            propJavaDoc.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_javadoc"));
 
93
            
 
94
            PropertyDescriptor propGenerateExceptionClasses = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_EXCEPTION_CLASSES, JUnitSettings.class);
 
95
            propGenerateExceptionClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_exception_classes"));
 
96
            propGenerateExceptionClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_exception_classes"));
 
97
            
 
98
            PropertyDescriptor propGenerateAbstractImpl = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_ABSTRACT_IMPL, JUnitSettings.class);
 
99
            propGenerateAbstractImpl.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_abstract_impl"));
 
100
            propGenerateAbstractImpl.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_abstract_impl"));
 
101
 
 
102
            
 
103
            PropertyDescriptor propGenerateSuiteClasses = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_SUITE_CLASSES, JUnitSettings.class);
 
104
            propGenerateSuiteClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_suite_classes"));
 
105
            propGenerateSuiteClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_suite_classes"));
 
106
            
 
107
            PropertyDescriptor propIncludePackagePrivateClasses = new PropertyDescriptor (JUnitSettings.PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES, JUnitSettings.class);
 
108
            propIncludePackagePrivateClasses.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_include_package_private_classes"));
 
109
            propIncludePackagePrivateClasses.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_include_package_private_classes"));
 
110
            
 
111
            PropertyDescriptor propGenerateSetUp = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_SETUP, JUnitSettings.class);
 
112
            propGenerateSetUp.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_setUp"));
 
113
            propGenerateSetUp.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_setUp"));
 
114
            
 
115
            PropertyDescriptor propGenerateTearDown = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_TEARDOWN, JUnitSettings.class);
 
116
            propGenerateTearDown.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_tearDown"));
 
117
            propGenerateTearDown.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_tearDown"));
 
118
            
 
119
            PropertyDescriptor propGenerateClassSetUp = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_CLASS_SETUP, JUnitSettings.class);
 
120
            propGenerateClassSetUp.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_class_setUp"));
 
121
            propGenerateClassSetUp.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_class_setUp"));
 
122
            
 
123
            PropertyDescriptor propGenerateClassTearDown = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_CLASS_TEARDOWN, JUnitSettings.class);
 
124
            propGenerateClassTearDown.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_class_tearDown"));
 
125
            propGenerateClassTearDown.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_class_tearDown"));
 
126
            
 
127
            PropertyDescriptor propGenerator = new PropertyDescriptor (JUnitSettings.PROP_GENERATOR, JUnitSettings.class,
 
128
                                                                       "getGenerator", "setGenerator");
 
129
            propGenerator.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generator"));
 
130
            propGenerator.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generator"));
 
131
            propGenerator.setPropertyEditorClass(GeneratorsPropEditor.class);
 
132
            
 
133
            
 
134
            
 
135
            // expert properties
 
136
            PropertyDescriptor propGenerateMainMethod = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_MAIN_METHOD, JUnitSettings.class);
 
137
            propGenerateMainMethod.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_main_method"));
 
138
            propGenerateMainMethod.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_main_method"));
 
139
            propGenerateMainMethod.setExpert(true);
 
140
            
 
141
            PropertyDescriptor propGenerateMainMethodBody = new PropertyDescriptor (JUnitSettings.PROP_GENERATE_MAIN_METHOD_BODY, JUnitSettings.class);
 
142
            propGenerateMainMethodBody.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_generate_main_method_body"));
 
143
            propGenerateMainMethodBody.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_generate_main_method_body"));            
 
144
            propGenerateMainMethodBody.setExpert(true);
 
145
 
 
146
// XXX: is this really required to be customizable?
 
147
//            PropertyDescriptor propTestClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_PREFIX, JUnitSettings.class);
 
148
//            propTestClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_prefix"));
 
149
//            propTestClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_prefix"));
 
150
//            propTestClassNamePrefix.setExpert(true);
 
151
//
 
152
//            PropertyDescriptor propTestClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_TEST_CLASSNAME_SUFFIX, JUnitSettings.class);
 
153
//            propTestClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_test_classname_suffix"));
 
154
//            propTestClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_test_classname_suffix"));            
 
155
//            propTestClassNameSuffix.setExpert(true);
 
156
//            
 
157
//            PropertyDescriptor propSuiteClassNamePrefix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_PREFIX, JUnitSettings.class);
 
158
//            propSuiteClassNamePrefix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_prefix"));
 
159
//            propSuiteClassNamePrefix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_prefix"));
 
160
//            propSuiteClassNamePrefix.setExpert(true);
 
161
//
 
162
//            PropertyDescriptor propSuiteClassNameSuffix = new PropertyDescriptor (JUnitSettings.PROP_SUITE_CLASSNAME_SUFFIX, JUnitSettings.class);
 
163
//            propSuiteClassNameSuffix.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_suite_classname_suffix"));
 
164
//            propSuiteClassNameSuffix.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_suite_classname_suffix"));            
 
165
//            propSuiteClassNameSuffix.setExpert(true);
 
166
            
 
167
            PropertyDescriptor propRootSuiteClassName = new PropertyDescriptor (JUnitSettings.PROP_ROOT_SUITE_CLASSNAME, JUnitSettings.class);
 
168
            propRootSuiteClassName.setDisplayName (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "PROP_root_suite_classname"));
 
169
            propRootSuiteClassName.setShortDescription (NbBundle.getMessage (JUnitSettingsBeanInfo.class, "HINT_root_suite_classname"));            
 
170
            propRootSuiteClassName.setExpert(true);
 
171
                        
 
172
 
 
173
            return new PropertyDescriptor[] {
 
174
              propGenerator,
 
175
              propMembersPublic, propMembersProtected, propMembersPackage, propBodyComments, propBodyContent, 
 
176
              propJavaDoc,
 
177
              propGenerateExceptionClasses, propGenerateAbstractImpl, propIncludePackagePrivateClasses, 
 
178
              propGenerateSuiteClasses,
 
179
              propGenerateSetUp, propGenerateTearDown,
 
180
              propGenerateClassSetUp, propGenerateClassTearDown,
 
181
              propGenerateMainMethod, propGenerateMainMethodBody, 
 
182
              //propTestClassNamePrefix, propTestClassNameSuffix, propSuiteClassNamePrefix, propSuiteClassNameSuffix, 
 
183
              propRootSuiteClassName 
 
184
            };
 
185
        }
 
186
        catch (IntrospectionException ie) {
 
187
            org.openide.ErrorManager.getDefault().notify(ie);
 
188
            return null;
 
189
        }
 
190
    }
 
191
 
 
192
    public Image getIcon (int type) {
 
193
        if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
 
194
            return Utilities.loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon.gif");//NOI18N
 
195
        } else {
 
196
            return Utilities.loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon32.gif");//NOI18N
 
197
        }
 
198
    }
 
199
 
 
200
    static abstract class SortedListPropEd extends PropertyEditorSupport {
 
201
        private final String      defaultValue;
 
202
        private List<String>  displays = new LinkedList<String>();
 
203
        private List<String>  values = new LinkedList<String>();
 
204
        private String      defaultDisplay = NbBundle.getMessage(JUnitSettingsBeanInfo.class, "LBL_value_not_found");
 
205
        
 
206
        protected SortedListPropEd(String defValue) {
 
207
            defaultValue = defValue;
 
208
        }
 
209
 
 
210
        public String[] getTags () {
 
211
            TreeSet<String> t = new TreeSet<String>(displays);
 
212
            if (displays.size() > 0) {
 
213
                return t.toArray(new String[displays.size() - 1]);
 
214
            } else {
 
215
                return new String[0];
 
216
            }
 
217
        }
 
218
 
 
219
        public String getAsText() {
 
220
            String      value = null;
 
221
            String      display = null;
 
222
            Iterator<String> iD = displays.iterator();
 
223
            Iterator<String> iV = values.iterator();
 
224
            while (iV.hasNext()) {
 
225
                value = iV.next();
 
226
                display = iD.next();
 
227
                if (value.equals(getValue())) {
 
228
                    return display;
 
229
                }
 
230
            }
 
231
            return defaultDisplay;
 
232
        }
 
233
        
 
234
        public void setAsText(String text) throws IllegalArgumentException {
 
235
            String      value = null;
 
236
            String      display = null;
 
237
            Iterator<String> iD = displays.iterator();
 
238
            Iterator<String> iV = values.iterator();
 
239
            while (iD.hasNext()) {
 
240
                value = iV.next();
 
241
                display = iD.next();
 
242
                if (display.equals(text)) {
 
243
                    setValue(value);
 
244
                    return;
 
245
                }
 
246
            }
 
247
            throw new IllegalArgumentException ();
 
248
        }
 
249
 
 
250
        protected void put(String display, String value) {
 
251
            displays.add(display);
 
252
            values.add(value);
 
253
            
 
254
            if ((defaultDisplay == null) && value.equals(defaultValue)) {
 
255
                defaultDisplay = display;
 
256
            }
 
257
        }
 
258
        
 
259
    }
 
260
    
 
261
    public static final class GeneratorsPropEditor extends SortedListPropEd {
 
262
        
 
263
        public GeneratorsPropEditor() {
 
264
            super(JUnitSettings.DEFAULT_GENERATOR);
 
265
            put(NbBundle.getMessage(JUnitSettings.class,
 
266
                                    "LBL_JUnit3_generator"),            //NOI18N
 
267
                JUnitSettings.JUNIT3_GENERATOR);
 
268
            put(NbBundle.getMessage(JUnitSettings.class,
 
269
                                    "LBL_JUnit4_generator"),            //NOI18N
 
270
                JUnitSettings.JUNIT4_GENERATOR);
 
271
            put(NbBundle.getMessage(JUnitSettings.class,
 
272
                                    "LBL_JUnit_generator_ask_user"),    //NOI18N
 
273
                JUnitSettings.JUNIT_GENERATOR_ASK_USER);
 
274
        }
 
275
        
 
276
    }
 
277
 
 
278
}