1 19 20 package org.netbeans.modules.junit; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.TreeSet ; 26 import java.awt.Image ; 27 import java.beans.*; 28 import org.openide.util.NbBundle; 29 import org.openide.util.Utilities; 30 31 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")); 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 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 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 propRootSuiteClassName 146 }; 147 } 148 catch (IntrospectionException ie) { 149 org.openide.ErrorManager.getDefault().notify(ie); 150 return null; 151 } 152 } 153 154 public Image 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"); } else { 158 return Utilities.loadImage("org/netbeans/modules/junit/resources/JUnitSettingsIcon32.gif"); } 160 } 161 162 public static class SortedListPropEd extends PropertyEditorSupport { 163 private List <String > displays = new LinkedList <String >(); 164 private List <String > values = new LinkedList <String >(); 165 private String defaultDisplay = NbBundle.getMessage(JUnitSettingsBeanInfo.class, "LBL_value_not_found"); 166 167 public String [] getTags () { 168 TreeSet <String > t = new TreeSet <String >(displays); 169 if (displays.size() > 0) { 170 return t.toArray(new String [displays.size() - 1]); 171 } else { 172 return new String [0]; 173 } 174 } 175 176 public String getAsText() { 177 String value = null; 178 String display = null; 179 Iterator <String > iD = displays.iterator(); 180 Iterator <String > 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 text) throws IllegalArgumentException { 192 String value = null; 193 String display = null; 194 Iterator <String > iD = displays.iterator(); 195 Iterator <String > 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 (); 205 } 206 207 protected void put(String display, String 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 |