1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import org.eclipse.core.runtime.IStatus; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspace; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.layout.GridLayout; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.swt.widgets.Text; 27 28 import org.eclipse.jface.dialogs.IDialogSettings; 29 30 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 31 32 import org.eclipse.ui.forms.widgets.ExpandableComposite; 33 34 import org.eclipse.jdt.core.JavaCore; 35 36 import org.eclipse.jdt.internal.corext.util.Messages; 37 38 import org.eclipse.jdt.internal.ui.JavaPlugin; 39 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 40 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 41 import org.eclipse.jdt.internal.ui.util.PixelConverter; 42 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 43 44 46 public class JavaBuildConfigurationBlock extends OptionsConfigurationBlock { 47 48 private static final String SETTINGS_SECTION_NAME= "JavaBuildConfigurationBlock"; 50 private static final Key PREF_PB_MAX_PER_UNIT= getJDTCoreKey(JavaCore.COMPILER_PB_MAX_PER_UNIT); 51 52 private static final Key PREF_RESOURCE_FILTER= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER); 53 private static final Key PREF_BUILD_INVALID_CLASSPATH= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH); 54 private static final Key PREF_BUILD_CLEAN_OUTPUT_FOLDER= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER); 55 private static final Key PREF_ENABLE_EXCLUSION_PATTERNS= getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS); 56 private static final Key PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS= getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS); 57 58 private static final Key PREF_PB_INCOMPLETE_BUILDPATH= getJDTCoreKey(JavaCore.CORE_INCOMPLETE_CLASSPATH); 59 private static final Key PREF_PB_CIRCULAR_BUILDPATH= getJDTCoreKey(JavaCore.CORE_CIRCULAR_CLASSPATH); 60 private static final Key PREF_PB_INCOMPATIBLE_JDK_LEVEL= getJDTCoreKey(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL); 61 private static final Key PREF_PB_DUPLICATE_RESOURCE= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE); 62 private static final Key PREF_RECREATE_MODIFIED_CLASS_FILES= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER); 63 64 65 private static final String ERROR= JavaCore.ERROR; 67 private static final String WARNING= JavaCore.WARNING; 68 private static final String IGNORE= JavaCore.IGNORE; 69 70 private static final String ABORT= JavaCore.ABORT; 71 private static final String CLEAN= JavaCore.CLEAN; 72 73 private static final String ENABLED= JavaCore.ENABLED; 74 private static final String DISABLED= JavaCore.DISABLED; 75 76 private PixelConverter fPixelConverter; 77 78 private IStatus fMaxNumberProblemsStatus, fResourceFilterStatus; 79 80 public JavaBuildConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { 81 super(context, project, getKeys(), container); 82 fMaxNumberProblemsStatus= new StatusInfo(); 83 fResourceFilterStatus= new StatusInfo(); 84 } 85 86 private static Key[] getKeys() { 87 Key[] keys= new Key[] { 88 PREF_PB_MAX_PER_UNIT, PREF_RESOURCE_FILTER, PREF_BUILD_INVALID_CLASSPATH, PREF_PB_INCOMPLETE_BUILDPATH, PREF_PB_CIRCULAR_BUILDPATH, 89 PREF_BUILD_CLEAN_OUTPUT_FOLDER, PREF_PB_DUPLICATE_RESOURCE, 90 PREF_PB_INCOMPATIBLE_JDK_LEVEL, PREF_ENABLE_EXCLUSION_PATTERNS, PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS, PREF_RECREATE_MODIFIED_CLASS_FILES, 91 }; 92 return keys; 93 } 94 95 96 99 protected Control createContents(Composite parent) { 100 fPixelConverter= new PixelConverter(parent); 101 setShell(parent.getShell()); 102 103 Composite mainComp= new Composite(parent, SWT.NONE); 104 mainComp.setFont(parent.getFont()); 105 GridLayout layout= new GridLayout(); 106 layout.marginHeight= 0; 107 layout.marginWidth= 0; 108 mainComp.setLayout(layout); 109 110 Composite othersComposite= createBuildPathTabContent(mainComp); 111 GridData gridData= new GridData(GridData.FILL, GridData.FILL, true, true); 112 gridData.heightHint= fPixelConverter.convertHeightInCharsToPixels(20); 113 othersComposite.setLayoutData(gridData); 114 115 validateSettings(null, null, null); 116 117 return mainComp; 118 } 119 120 121 private Composite createBuildPathTabContent(Composite parent) { 122 String [] abortIgnoreValues= new String [] { ABORT, IGNORE }; 123 String [] cleanIgnoreValues= new String [] { CLEAN, IGNORE }; 124 String [] enableDisableValues= new String [] { ENABLED, DISABLED }; 125 String [] enableIgnoreValues= new String [] { ENABLED, IGNORE }; 126 127 String [] errorWarning= new String [] { ERROR, WARNING }; 128 129 String [] errorWarningLabels= new String [] { 130 PreferencesMessages.JavaBuildConfigurationBlock_error, 131 PreferencesMessages.JavaBuildConfigurationBlock_warning 132 }; 133 134 String [] errorWarningIgnore= new String [] { ERROR, WARNING, IGNORE }; 135 String [] errorWarningIgnoreLabels= new String [] { 136 PreferencesMessages.JavaBuildConfigurationBlock_error, 137 PreferencesMessages.JavaBuildConfigurationBlock_warning, 138 PreferencesMessages.JavaBuildConfigurationBlock_ignore 139 }; 140 141 int nColumns= 3; 142 143 final ScrolledPageContent pageContent = new ScrolledPageContent(parent); 144 145 GridLayout layout= new GridLayout(); 146 layout.numColumns= nColumns; 147 layout.marginHeight= 0; 148 layout.marginWidth= 0; 149 150 Composite composite= pageContent.getBody(); 151 composite.setLayout(layout); 152 153 String label= PreferencesMessages.JavaBuildConfigurationBlock_section_general; 154 ExpandableComposite excomposite= createStyleSection(composite, label, nColumns); 155 156 Composite othersComposite= new Composite(excomposite, SWT.NONE); 157 excomposite.setClient(othersComposite); 158 othersComposite.setLayout(new GridLayout(nColumns, false)); 159 160 label= PreferencesMessages.JavaBuildConfigurationBlock_pb_max_per_unit_label; 161 Text text= addTextField(othersComposite, label, PREF_PB_MAX_PER_UNIT, 0, 0); 162 GridData gd= (GridData) text.getLayoutData(); 163 gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(8); 164 gd.horizontalAlignment= GridData.END; 165 text.setTextLimit(6); 166 167 label= PreferencesMessages.JavaBuildConfigurationBlock_enable_exclusion_patterns_label; 168 addCheckBox(othersComposite, label, PREF_ENABLE_EXCLUSION_PATTERNS, enableDisableValues, 0); 169 170 label= PreferencesMessages.JavaBuildConfigurationBlock_enable_multiple_outputlocations_label; 171 addCheckBox(othersComposite, label, PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS, enableDisableValues, 0); 172 173 label= PreferencesMessages.JavaBuildConfigurationBlock_section_build_path_problems; 174 excomposite= createStyleSection(composite, label, nColumns); 175 176 othersComposite= new Composite(excomposite, SWT.NONE); 177 excomposite.setClient(othersComposite); 178 othersComposite.setLayout(new GridLayout(nColumns, false)); 179 180 label= PreferencesMessages.JavaBuildConfigurationBlock_build_invalid_classpath_label; 181 addCheckBox(othersComposite, label, PREF_BUILD_INVALID_CLASSPATH, abortIgnoreValues, 0); 182 183 label= PreferencesMessages.JavaBuildConfigurationBlock_pb_incomplete_build_path_label; 184 addComboBox(othersComposite, label, PREF_PB_INCOMPLETE_BUILDPATH, errorWarning, errorWarningLabels, 0); 185 186 label= PreferencesMessages.JavaBuildConfigurationBlock_pb_build_path_cycles_label; 187 addComboBox(othersComposite, label, PREF_PB_CIRCULAR_BUILDPATH, errorWarning, errorWarningLabels, 0); 188 189 label= PreferencesMessages.JavaBuildConfigurationBlock_pb_check_prereq_binary_level_label; 190 addComboBox(othersComposite, label, PREF_PB_INCOMPATIBLE_JDK_LEVEL, errorWarningIgnore, errorWarningIgnoreLabels, 0); 191 192 label= PreferencesMessages.JavaBuildConfigurationBlock_section_output_folder; 193 excomposite= createStyleSection(composite, label, nColumns); 194 195 othersComposite= new Composite(excomposite, SWT.NONE); 196 excomposite.setClient(othersComposite); 197 othersComposite.setLayout(new GridLayout(nColumns, false)); 198 199 label= PreferencesMessages.JavaBuildConfigurationBlock_pb_duplicate_resources_label; 200 addComboBox(othersComposite, label, PREF_PB_DUPLICATE_RESOURCE, errorWarning, errorWarningLabels, 0); 201 202 label= PreferencesMessages.JavaBuildConfigurationBlock_build_clean_outputfolder_label; 203 addCheckBox(othersComposite, label, PREF_BUILD_CLEAN_OUTPUT_FOLDER, cleanIgnoreValues, 0); 204 205 label= PreferencesMessages.JavaBuildConfigurationBlock_build_recreate_modified; 206 addCheckBox(othersComposite, label, PREF_RECREATE_MODIFIED_CLASS_FILES, enableIgnoreValues, 0); 207 208 label= PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_label; 209 text= addTextField(othersComposite, label, PREF_RESOURCE_FILTER, 0, 0); 210 gd= (GridData) text.getLayoutData(); 211 gd.grabExcessHorizontalSpace= true; 212 gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(10); 213 214 Label description= new Label(othersComposite, SWT.WRAP); 215 description.setText(PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_description); 216 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 217 gd.horizontalSpan= nColumns; 218 gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(60); 219 description.setLayoutData(gd); 220 221 IDialogSettings section= JavaPlugin.getDefault().getDialogSettings().getSection(SETTINGS_SECTION_NAME); 222 restoreSectionExpansionStates(section); 223 224 return pageContent; 225 } 226 227 231 protected void validateSettings(Key changedKey, String oldValue, String newValue) { 232 if (!areSettingsEnabled()) { 233 return; 234 } 235 236 if (changedKey != null) { 237 if (PREF_PB_MAX_PER_UNIT.equals(changedKey)) { 238 fMaxNumberProblemsStatus= validateMaxNumberProblems(); 239 } else if (PREF_RESOURCE_FILTER.equals(changedKey)) { 240 fResourceFilterStatus= validateResourceFilters(); 241 } else { 242 return; 243 } 244 } else { 245 updateEnableStates(); 246 fMaxNumberProblemsStatus= validateMaxNumberProblems(); 247 fResourceFilterStatus= validateResourceFilters(); 248 } 249 IStatus status= StatusUtil.getMostSevere(new IStatus[] { fMaxNumberProblemsStatus, fResourceFilterStatus }); 250 fContext.statusChanged(status); 251 } 252 253 private void updateEnableStates() { 254 } 255 256 protected String [] getFullBuildDialogStrings(boolean workspaceSettings) { 257 String title= PreferencesMessages.JavaBuildConfigurationBlock_needsbuild_title; 258 String message; 259 if (workspaceSettings) { 260 message= PreferencesMessages.JavaBuildConfigurationBlock_needsfullbuild_message; 261 } else { 262 message= PreferencesMessages.JavaBuildConfigurationBlock_needsprojectbuild_message; 263 } 264 return new String [] { title, message }; 265 } 266 267 private IStatus validateMaxNumberProblems() { 268 String number= getValue(PREF_PB_MAX_PER_UNIT); 269 StatusInfo status= new StatusInfo(); 270 if (number.length() == 0) { 271 status.setError(PreferencesMessages.JavaBuildConfigurationBlock_empty_input); 272 } else { 273 try { 274 int value= Integer.parseInt(number); 275 if (value <= 0) { 276 status.setError(Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_invalid_input, number)); 277 } 278 } catch (NumberFormatException e) { 279 status.setError(Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_invalid_input, number)); 280 } 281 } 282 return status; 283 } 284 285 private IStatus validateResourceFilters() { 286 String text= getValue(PREF_RESOURCE_FILTER); 287 288 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 289 290 String [] filters= getTokens(text, ","); for (int i= 0; i < filters.length; i++) { 292 String fileName= filters[i].replace('*', 'x'); 293 int resourceType= IResource.FILE; 294 int lastCharacter= fileName.length() - 1; 295 if (lastCharacter >= 0 && fileName.charAt(lastCharacter) == '/') { 296 fileName= fileName.substring(0, lastCharacter); 297 resourceType= IResource.FOLDER; 298 } 299 IStatus status= workspace.validateName(fileName, resourceType); 300 if (status.matches(IStatus.ERROR)) { 301 String message= Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error, status.getMessage()); 302 return new StatusInfo(IStatus.ERROR, message); 303 } 304 } 305 return new StatusInfo(); 306 } 307 308 311 public void dispose() { 312 IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings().addNewSection(SETTINGS_SECTION_NAME); 313 storeSectionExpansionStates(settings); 314 super.dispose(); 315 } 316 317 318 } 319 | Popular Tags |