1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import org.eclipse.core.resources.IProject; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.layout.GridData; 17 import org.eclipse.swt.layout.GridLayout; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Label; 21 22 import org.eclipse.jface.dialogs.ControlEnableState; 23 24 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 25 26 import org.eclipse.jdt.core.JavaCore; 27 28 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 29 import org.eclipse.jdt.internal.ui.util.PixelConverter; 30 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 31 32 34 public class JavadocProblemsConfigurationBlock extends OptionsConfigurationBlock { 35 36 private static final Key PREF_JAVADOC_SUPPORT= getJDTCoreKey(JavaCore.COMPILER_DOC_COMMENT_SUPPORT); 37 38 private static final Key PREF_PB_INVALID_JAVADOC= getJDTCoreKey(JavaCore.COMPILER_PB_INVALID_JAVADOC); 39 private static final Key PREF_PB_INVALID_JAVADOC_TAGS= getJDTCoreKey(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS); 40 private static final Key PREF_PB_INVALID_JAVADOC_TAGS_NOT_VISIBLE_REF= getJDTCoreKey(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__NOT_VISIBLE_REF); 41 private static final Key PREF_PB_INVALID_JAVADOC_TAGS_DEPRECATED_REF= getJDTCoreKey(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__DEPRECATED_REF); 42 private static final Key PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY= getJDTCoreKey(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS_VISIBILITY); 43 44 private static final Key PREF_PB_MISSING_JAVADOC_TAGS= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS); 45 private static final Key PREF_PB_MISSING_JAVADOC_TAGS_VISIBILITY= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_VISIBILITY); 46 private static final Key PREF_PB_MISSING_JAVADOC_TAGS_OVERRIDING= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_OVERRIDING); 47 48 private static final Key PREF_PB_MISSING_JAVADOC_COMMENTS= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS); 49 private static final Key PREF_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY); 50 private static final Key PREF_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING); 51 52 53 private static final String ERROR= JavaCore.ERROR; 55 private static final String WARNING= JavaCore.WARNING; 56 private static final String IGNORE= JavaCore.IGNORE; 57 58 private static final String ENABLED= JavaCore.ENABLED; 59 private static final String DISABLED= JavaCore.DISABLED; 60 61 private static final String PUBLIC= JavaCore.PUBLIC; 62 private static final String PROTECTED= JavaCore.PROTECTED; 63 private static final String DEFAULT= JavaCore.DEFAULT; 64 private static final String PRIVATE= JavaCore.PRIVATE; 65 66 private PixelConverter fPixelConverter; 67 private Composite fJavadocComposite; 68 69 private ControlEnableState fBlockEnableState; 70 71 72 public JavadocProblemsConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { 73 super(context, project, getKeys(), container); 74 fBlockEnableState= null; 75 } 76 77 private static Key[] getKeys() { 78 Key[] keys= new Key[] { 79 PREF_JAVADOC_SUPPORT, 80 PREF_PB_INVALID_JAVADOC, PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY, PREF_PB_INVALID_JAVADOC_TAGS, 81 PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY, 82 PREF_PB_INVALID_JAVADOC_TAGS_NOT_VISIBLE_REF, PREF_PB_INVALID_JAVADOC_TAGS_DEPRECATED_REF, 83 PREF_PB_MISSING_JAVADOC_TAGS, PREF_PB_MISSING_JAVADOC_TAGS_VISIBILITY, PREF_PB_MISSING_JAVADOC_TAGS_OVERRIDING, 84 PREF_PB_MISSING_JAVADOC_COMMENTS, PREF_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, PREF_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, 85 }; 86 return keys; 87 } 88 89 92 protected Control createContents(Composite parent) { 93 fPixelConverter= new PixelConverter(parent); 94 setShell(parent.getShell()); 95 96 Composite javadocComposite= createJavadocTabContent(parent); 97 98 validateSettings(null, null, null); 99 100 return javadocComposite; 101 } 102 103 104 private Composite createJavadocTabContent(Composite folder) { 105 String [] errorWarningIgnore= new String [] { ERROR, WARNING, IGNORE }; 106 107 String [] errorWarningIgnoreLabels= new String [] { 108 PreferencesMessages.JavadocProblemsConfigurationBlock_error, 109 PreferencesMessages.JavadocProblemsConfigurationBlock_warning, 110 PreferencesMessages.JavadocProblemsConfigurationBlock_ignore 111 }; 112 113 String [] enabledDisabled= new String [] { ENABLED, DISABLED }; 114 115 String [] visibilities= new String [] { PUBLIC, PROTECTED, DEFAULT, PRIVATE }; 116 117 String [] visibilitiesLabels= new String [] { 118 PreferencesMessages.JavadocProblemsConfigurationBlock_public, 119 PreferencesMessages.JavadocProblemsConfigurationBlock_protected, 120 PreferencesMessages.JavadocProblemsConfigurationBlock_default, 121 PreferencesMessages.JavadocProblemsConfigurationBlock_private 122 }; 123 int nColumns= 3; 124 125 126 final ScrolledPageContent sc1 = new ScrolledPageContent(folder); 127 128 Composite outer= sc1.getBody(); 129 130 GridLayout layout = new GridLayout(); 131 layout.numColumns= nColumns; 132 layout.marginHeight= 0; 133 layout.marginWidth= 0; 134 outer.setLayout(layout); 135 136 String label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_javadoc_support_label; 137 addCheckBox(outer, label, PREF_JAVADOC_SUPPORT, enabledDisabled, 0); 138 139 layout = new GridLayout(); 140 layout.numColumns= nColumns; 141 layout.marginHeight= 0; 142 144 Composite composite= new Composite(outer, SWT.NONE); 145 composite.setLayout(layout); 146 composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, true)); 147 148 fJavadocComposite= composite; 149 150 Label description= new Label(composite, SWT.WRAP); 151 description.setText(PreferencesMessages.JavadocProblemsConfigurationBlock_javadoc_description); 152 GridData gd= new GridData(); 153 gd.horizontalSpan= nColumns; 154 description.setLayoutData(gd); 156 157 int indent= fPixelConverter.convertWidthInCharsToPixels(2); 158 159 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_label; 160 addComboBox(composite, label, PREF_PB_INVALID_JAVADOC, errorWarningIgnore, errorWarningIgnoreLabels, 0); 161 162 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_tags_visibility_label; 163 addComboBox(composite, label, PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY, visibilities, visibilitiesLabels, indent); 164 165 label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_tags_label; 166 addCheckBox(composite, label, PREF_PB_INVALID_JAVADOC_TAGS, enabledDisabled, indent); 167 168 label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_tags_not_visible_ref_label; 169 addCheckBox(composite, label, PREF_PB_INVALID_JAVADOC_TAGS_NOT_VISIBLE_REF, enabledDisabled, indent); 170 171 label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_invalid_javadoc_tags_deprecated_label; 172 addCheckBox(composite, label, PREF_PB_INVALID_JAVADOC_TAGS_DEPRECATED_REF, enabledDisabled, indent); 173 174 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 175 gd.horizontalSpan= nColumns; 176 177 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_javadoc_label; 178 addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS, errorWarningIgnore, errorWarningIgnoreLabels, 0); 179 180 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_javadoc_tags_visibility_label; 181 addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS_VISIBILITY, visibilities, visibilitiesLabels, indent); 182 183 label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_javadoc_tags_overriding_label; 184 addCheckBox(composite, label, PREF_PB_MISSING_JAVADOC_TAGS_OVERRIDING, enabledDisabled, indent); 185 186 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 187 gd.horizontalSpan= nColumns; 188 189 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_comments_label; 190 addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS, errorWarningIgnore, errorWarningIgnoreLabels, 0); 191 192 label = PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_comments_visibility_label; 193 addComboBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, visibilities, visibilitiesLabels, indent); 194 195 label= PreferencesMessages.JavadocProblemsConfigurationBlock_pb_missing_comments_overriding_label; 196 addCheckBox(composite, label, PREF_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, enabledDisabled, indent); 197 198 return sc1; 199 } 200 201 205 protected void validateSettings(Key changedKey, String oldValue, String newValue) { 206 if (!areSettingsEnabled()) { 207 return; 208 } 209 210 if (changedKey != null) { 211 if (PREF_PB_INVALID_JAVADOC.equals(changedKey) || 212 PREF_PB_MISSING_JAVADOC_TAGS.equals(changedKey) || 213 PREF_PB_MISSING_JAVADOC_COMMENTS.equals(changedKey) || 214 PREF_JAVADOC_SUPPORT.equals(changedKey)) { 215 updateEnableStates(); 216 } else { 217 return; 218 } 219 } else { 220 updateEnableStates(); 221 } 222 fContext.statusChanged(new StatusInfo()); 223 } 224 225 private void updateEnableStates() { 226 boolean enableJavadoc= checkValue(PREF_JAVADOC_SUPPORT, ENABLED); 227 enableConfigControls(enableJavadoc); 228 229 if (enableJavadoc) { 230 boolean enableInvalidTagsErrors= !checkValue(PREF_PB_INVALID_JAVADOC, IGNORE); 231 getCheckBox(PREF_PB_INVALID_JAVADOC_TAGS).setEnabled(enableInvalidTagsErrors); 232 getCheckBox(PREF_PB_INVALID_JAVADOC_TAGS_NOT_VISIBLE_REF).setEnabled(enableInvalidTagsErrors); 233 getCheckBox(PREF_PB_INVALID_JAVADOC_TAGS_DEPRECATED_REF).setEnabled(enableInvalidTagsErrors); 234 setComboEnabled(PREF_PB_INVALID_JAVADOC_TAGS_VISIBILITY, enableInvalidTagsErrors); 235 236 boolean enableMissingTagsErrors= !checkValue(PREF_PB_MISSING_JAVADOC_TAGS, IGNORE); 237 getCheckBox(PREF_PB_MISSING_JAVADOC_TAGS_OVERRIDING).setEnabled(enableMissingTagsErrors); 238 setComboEnabled(PREF_PB_MISSING_JAVADOC_TAGS_VISIBILITY, enableMissingTagsErrors); 239 240 boolean enableMissingCommentsErrors= !checkValue(PREF_PB_MISSING_JAVADOC_COMMENTS, IGNORE); 241 getCheckBox(PREF_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING).setEnabled(enableMissingCommentsErrors); 242 setComboEnabled(PREF_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, enableMissingCommentsErrors); 243 } 244 } 245 246 protected void enableConfigControls(boolean enable) { 247 if (enable) { 248 if (fBlockEnableState != null) { 249 fBlockEnableState.restore(); 250 fBlockEnableState= null; 251 } 252 } else { 253 if (fBlockEnableState == null) { 254 fBlockEnableState= ControlEnableState.disable(fJavadocComposite); 255 } 256 } 257 } 258 259 260 protected String [] getFullBuildDialogStrings(boolean workspaceSettings) { 261 String title= PreferencesMessages.JavadocProblemsConfigurationBlock_needsbuild_title; 262 String message; 263 if (workspaceSettings) { 264 message= PreferencesMessages.JavadocProblemsConfigurationBlock_needsfullbuild_message; 265 } else { 266 message= PreferencesMessages.JavadocProblemsConfigurationBlock_needsprojectbuild_message; 267 } 268 return new String [] { title, message }; 269 } 270 271 } 272 | Popular Tags |