PageRenderTime 56ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/eclipse_SDK-3.7.1/plugins/org.eclipse.jdt.ui.source_3.7.1.r371_v20110824-0800/org/eclipse/jdt/internal/ui/preferences/JavaBuildConfigurationBlock.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 328 lines | 236 code | 71 blank | 21 comment | 19 complexity | f20debfe77c91e5b63651d8a2663fd5f MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2011 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.jdt.internal.ui.preferences;
  12. import org.eclipse.swt.SWT;
  13. import org.eclipse.swt.layout.GridData;
  14. import org.eclipse.swt.layout.GridLayout;
  15. import org.eclipse.swt.widgets.Composite;
  16. import org.eclipse.swt.widgets.Control;
  17. import org.eclipse.swt.widgets.Label;
  18. import org.eclipse.swt.widgets.Text;
  19. import org.eclipse.core.runtime.IStatus;
  20. import org.eclipse.core.resources.IProject;
  21. import org.eclipse.core.resources.IResource;
  22. import org.eclipse.core.resources.IWorkspace;
  23. import org.eclipse.core.resources.ResourcesPlugin;
  24. import org.eclipse.jface.dialogs.IDialogSettings;
  25. import org.eclipse.jface.layout.PixelConverter;
  26. import org.eclipse.ui.forms.widgets.ExpandableComposite;
  27. import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
  28. import org.eclipse.jdt.core.JavaCore;
  29. import org.eclipse.jdt.internal.corext.util.Messages;
  30. import org.eclipse.jdt.launching.JavaRuntime;
  31. import org.eclipse.jdt.internal.ui.JavaPlugin;
  32. import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
  33. import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
  34. import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
  35. public class JavaBuildConfigurationBlock extends OptionsConfigurationBlock {
  36. private static final String SETTINGS_SECTION_NAME= "JavaBuildConfigurationBlock"; //$NON-NLS-1$
  37. private static final Key PREF_PB_MAX_PER_UNIT= getJDTCoreKey(JavaCore.COMPILER_PB_MAX_PER_UNIT);
  38. private static final Key PREF_RESOURCE_FILTER= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
  39. private static final Key PREF_BUILD_INVALID_CLASSPATH= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH);
  40. private static final Key PREF_BUILD_CLEAN_OUTPUT_FOLDER= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
  41. private static final Key PREF_ENABLE_EXCLUSION_PATTERNS= getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
  42. private static final Key PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS= getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
  43. private static final Key PREF_PB_INCOMPLETE_BUILDPATH= getJDTCoreKey(JavaCore.CORE_INCOMPLETE_CLASSPATH);
  44. private static final Key PREF_PB_CIRCULAR_BUILDPATH= getJDTCoreKey(JavaCore.CORE_CIRCULAR_CLASSPATH);
  45. private static final Key PREF_PB_INCOMPATIBLE_JDK_LEVEL= getJDTCoreKey(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL);
  46. private static final Key PREF_PB_DUPLICATE_RESOURCE= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
  47. private static final Key PREF_RECREATE_MODIFIED_CLASS_FILES= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER);
  48. private static final Key PREF_PB_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE= getJDTLaunchingKey(JavaRuntime.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE);
  49. // values
  50. private static final String ERROR= JavaCore.ERROR;
  51. private static final String WARNING= JavaCore.WARNING;
  52. private static final String IGNORE= JavaCore.IGNORE;
  53. private static final String ABORT= JavaCore.ABORT;
  54. private static final String CLEAN= JavaCore.CLEAN;
  55. private static final String ENABLED= JavaCore.ENABLED;
  56. private static final String DISABLED= JavaCore.DISABLED;
  57. private PixelConverter fPixelConverter;
  58. private IStatus fMaxNumberProblemsStatus, fResourceFilterStatus;
  59. public JavaBuildConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) {
  60. super(context, project, getKeys(), container);
  61. fMaxNumberProblemsStatus= new StatusInfo();
  62. fResourceFilterStatus= new StatusInfo();
  63. }
  64. private static Key[] getKeys() {
  65. Key[] keys= new Key[] {
  66. PREF_PB_MAX_PER_UNIT, PREF_RESOURCE_FILTER, PREF_BUILD_INVALID_CLASSPATH, PREF_PB_INCOMPLETE_BUILDPATH, PREF_PB_CIRCULAR_BUILDPATH,
  67. PREF_BUILD_CLEAN_OUTPUT_FOLDER, PREF_PB_DUPLICATE_RESOURCE,
  68. PREF_PB_INCOMPATIBLE_JDK_LEVEL, PREF_ENABLE_EXCLUSION_PATTERNS, PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS, PREF_RECREATE_MODIFIED_CLASS_FILES,
  69. PREF_PB_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE
  70. };
  71. return keys;
  72. }
  73. /*
  74. * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
  75. */
  76. @Override
  77. protected Control createContents(Composite parent) {
  78. fPixelConverter= new PixelConverter(parent);
  79. setShell(parent.getShell());
  80. Composite mainComp= new Composite(parent, SWT.NONE);
  81. mainComp.setFont(parent.getFont());
  82. GridLayout layout= new GridLayout();
  83. layout.marginHeight= 0;
  84. layout.marginWidth= 0;
  85. mainComp.setLayout(layout);
  86. Composite othersComposite= createBuildPathTabContent(mainComp);
  87. GridData gridData= new GridData(GridData.FILL, GridData.FILL, true, true);
  88. gridData.heightHint= fPixelConverter.convertHeightInCharsToPixels(20);
  89. othersComposite.setLayoutData(gridData);
  90. validateSettings(null, null, null);
  91. return mainComp;
  92. }
  93. private Composite createBuildPathTabContent(Composite parent) {
  94. String[] abortIgnoreValues= new String[] { ABORT, IGNORE };
  95. String[] cleanIgnoreValues= new String[] { CLEAN, IGNORE };
  96. String[] enableDisableValues= new String[] { ENABLED, DISABLED };
  97. String[] enableIgnoreValues= new String[] { ENABLED, IGNORE };
  98. String[] errorWarning= new String[] { ERROR, WARNING };
  99. String[] errorWarningLabels= new String[] {
  100. PreferencesMessages.JavaBuildConfigurationBlock_error,
  101. PreferencesMessages.JavaBuildConfigurationBlock_warning
  102. };
  103. String[] errorWarningIgnore= new String[] { ERROR, WARNING, IGNORE };
  104. String[] errorWarningIgnoreLabels= new String[] {
  105. PreferencesMessages.JavaBuildConfigurationBlock_error,
  106. PreferencesMessages.JavaBuildConfigurationBlock_warning,
  107. PreferencesMessages.JavaBuildConfigurationBlock_ignore
  108. };
  109. int nColumns= 3;
  110. final ScrolledPageContent pageContent = new ScrolledPageContent(parent);
  111. GridLayout layout= new GridLayout();
  112. layout.numColumns= nColumns;
  113. layout.marginHeight= 0;
  114. layout.marginWidth= 0;
  115. Composite composite= pageContent.getBody();
  116. composite.setLayout(layout);
  117. String label= PreferencesMessages.JavaBuildConfigurationBlock_section_general;
  118. ExpandableComposite excomposite= createStyleSection(composite, label, nColumns);
  119. Composite othersComposite= new Composite(excomposite, SWT.NONE);
  120. excomposite.setClient(othersComposite);
  121. othersComposite.setLayout(new GridLayout(nColumns, false));
  122. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_max_per_unit_label;
  123. Text text= addTextField(othersComposite, label, PREF_PB_MAX_PER_UNIT, 0, 0);
  124. GridData gd= (GridData) text.getLayoutData();
  125. gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(8);
  126. gd.horizontalAlignment= GridData.END;
  127. text.setTextLimit(6);
  128. label= PreferencesMessages.JavaBuildConfigurationBlock_enable_exclusion_patterns_label;
  129. addCheckBox(othersComposite, label, PREF_ENABLE_EXCLUSION_PATTERNS, enableDisableValues, 0);
  130. label= PreferencesMessages.JavaBuildConfigurationBlock_enable_multiple_outputlocations_label;
  131. addCheckBox(othersComposite, label, PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS, enableDisableValues, 0);
  132. label= PreferencesMessages.JavaBuildConfigurationBlock_section_build_path_problems;
  133. excomposite= createStyleSection(composite, label, nColumns);
  134. othersComposite= new Composite(excomposite, SWT.NONE);
  135. excomposite.setClient(othersComposite);
  136. othersComposite.setLayout(new GridLayout(nColumns, false));
  137. label= PreferencesMessages.JavaBuildConfigurationBlock_build_invalid_classpath_label;
  138. addCheckBox(othersComposite, label, PREF_BUILD_INVALID_CLASSPATH, abortIgnoreValues, 0);
  139. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_incomplete_build_path_label;
  140. addComboBox(othersComposite, label, PREF_PB_INCOMPLETE_BUILDPATH, errorWarning, errorWarningLabels, 0);
  141. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_build_path_cycles_label;
  142. addComboBox(othersComposite, label, PREF_PB_CIRCULAR_BUILDPATH, errorWarning, errorWarningLabels, 0);
  143. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_check_prereq_binary_level_label;
  144. addComboBox(othersComposite, label, PREF_PB_INCOMPATIBLE_JDK_LEVEL, errorWarningIgnore, errorWarningIgnoreLabels, 0);
  145. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_strictly_compatible_jre_not_available_label;
  146. addComboBox(othersComposite, label, PREF_PB_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE, errorWarningIgnore, errorWarningIgnoreLabels, 0);
  147. label= PreferencesMessages.JavaBuildConfigurationBlock_section_output_folder;
  148. excomposite= createStyleSection(composite, label, nColumns);
  149. othersComposite= new Composite(excomposite, SWT.NONE);
  150. excomposite.setClient(othersComposite);
  151. othersComposite.setLayout(new GridLayout(nColumns, false));
  152. label= PreferencesMessages.JavaBuildConfigurationBlock_pb_duplicate_resources_label;
  153. addComboBox(othersComposite, label, PREF_PB_DUPLICATE_RESOURCE, errorWarning, errorWarningLabels, 0);
  154. label= PreferencesMessages.JavaBuildConfigurationBlock_build_clean_outputfolder_label;
  155. addCheckBox(othersComposite, label, PREF_BUILD_CLEAN_OUTPUT_FOLDER, cleanIgnoreValues, 0);
  156. label= PreferencesMessages.JavaBuildConfigurationBlock_build_recreate_modified;
  157. addCheckBox(othersComposite, label, PREF_RECREATE_MODIFIED_CLASS_FILES, enableIgnoreValues, 0);
  158. label= PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_label;
  159. text= addTextField(othersComposite, label, PREF_RESOURCE_FILTER, 0, 0);
  160. gd= (GridData) text.getLayoutData();
  161. gd.grabExcessHorizontalSpace= true;
  162. gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(10);
  163. Label description= new Label(othersComposite, SWT.WRAP);
  164. description.setText(PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_description);
  165. gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
  166. gd.horizontalSpan= nColumns;
  167. gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(60);
  168. description.setLayoutData(gd);
  169. IDialogSettings section= JavaPlugin.getDefault().getDialogSettings().getSection(SETTINGS_SECTION_NAME);
  170. restoreSectionExpansionStates(section);
  171. return pageContent;
  172. }
  173. /* (non-javadoc)
  174. * Update fields and validate.
  175. * @param changedKey Key that changed, or null, if all changed.
  176. */
  177. @Override
  178. protected void validateSettings(Key changedKey, String oldValue, String newValue) {
  179. if (!areSettingsEnabled()) {
  180. return;
  181. }
  182. if (changedKey != null) {
  183. if (PREF_PB_MAX_PER_UNIT.equals(changedKey)) {
  184. fMaxNumberProblemsStatus= validateMaxNumberProblems();
  185. } else if (PREF_RESOURCE_FILTER.equals(changedKey)) {
  186. fResourceFilterStatus= validateResourceFilters();
  187. } else {
  188. return;
  189. }
  190. } else {
  191. updateEnableStates();
  192. fMaxNumberProblemsStatus= validateMaxNumberProblems();
  193. fResourceFilterStatus= validateResourceFilters();
  194. }
  195. IStatus status= StatusUtil.getMostSevere(new IStatus[] { fMaxNumberProblemsStatus, fResourceFilterStatus });
  196. fContext.statusChanged(status);
  197. }
  198. private void updateEnableStates() {
  199. }
  200. @Override
  201. protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
  202. String title= PreferencesMessages.JavaBuildConfigurationBlock_needsbuild_title;
  203. String message;
  204. if (workspaceSettings) {
  205. message= PreferencesMessages.JavaBuildConfigurationBlock_needsfullbuild_message;
  206. } else {
  207. message= PreferencesMessages.JavaBuildConfigurationBlock_needsprojectbuild_message;
  208. }
  209. return new String[] { title, message };
  210. }
  211. private IStatus validateMaxNumberProblems() {
  212. String number= getValue(PREF_PB_MAX_PER_UNIT);
  213. StatusInfo status= new StatusInfo();
  214. if (number.length() == 0) {
  215. status.setError(PreferencesMessages.JavaBuildConfigurationBlock_empty_input);
  216. } else {
  217. try {
  218. int value= Integer.parseInt(number);
  219. if (value <= 0) {
  220. status.setError(Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_invalid_input, number));
  221. }
  222. } catch (NumberFormatException e) {
  223. status.setError(Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_invalid_input, number));
  224. }
  225. }
  226. return status;
  227. }
  228. private IStatus validateResourceFilters() {
  229. String text= getValue(PREF_RESOURCE_FILTER);
  230. IWorkspace workspace= ResourcesPlugin.getWorkspace();
  231. String[] filters= getTokens(text, ","); //$NON-NLS-1$
  232. for (int i= 0; i < filters.length; i++) {
  233. String fileName= filters[i].replace('*', 'x');
  234. int resourceType= IResource.FILE;
  235. int lastCharacter= fileName.length() - 1;
  236. if (lastCharacter >= 0 && fileName.charAt(lastCharacter) == '/') {
  237. fileName= fileName.substring(0, lastCharacter);
  238. resourceType= IResource.FOLDER;
  239. }
  240. IStatus status= workspace.validateName(fileName, resourceType);
  241. if (status.matches(IStatus.ERROR)) {
  242. String message= Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error, status.getMessage());
  243. return new StatusInfo(IStatus.ERROR, message);
  244. }
  245. }
  246. return new StatusInfo();
  247. }
  248. /* (non-Javadoc)
  249. * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#dispose()
  250. */
  251. @Override
  252. public void dispose() {
  253. IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings().addNewSection(SETTINGS_SECTION_NAME);
  254. storeSectionExpansionStates(settings);
  255. super.dispose();
  256. }
  257. }