001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.core.runtime.IStatus;
013:
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.core.resources.IWorkspace;
017: import org.eclipse.core.resources.ResourcesPlugin;
018:
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Control;
024: import org.eclipse.swt.widgets.Label;
025: import org.eclipse.swt.widgets.Text;
026:
027: import org.eclipse.jface.dialogs.IDialogSettings;
028:
029: import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
030:
031: import org.eclipse.ui.forms.widgets.ExpandableComposite;
032:
033: import org.eclipse.jdt.core.JavaCore;
034:
035: import org.eclipse.jdt.internal.corext.util.Messages;
036:
037: import org.eclipse.jdt.internal.ui.JavaPlugin;
038: import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
039: import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
040: import org.eclipse.jdt.internal.ui.util.PixelConverter;
041: import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
042:
043: /**
044: */
045: public class JavaBuildConfigurationBlock extends
046: OptionsConfigurationBlock {
047:
048: private static final String SETTINGS_SECTION_NAME = "JavaBuildConfigurationBlock"; //$NON-NLS-1$
049:
050: private static final Key PREF_PB_MAX_PER_UNIT = getJDTCoreKey(JavaCore.COMPILER_PB_MAX_PER_UNIT);
051:
052: private static final Key PREF_RESOURCE_FILTER = getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
053: private static final Key PREF_BUILD_INVALID_CLASSPATH = getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH);
054: private static final Key PREF_BUILD_CLEAN_OUTPUT_FOLDER = getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
055: private static final Key PREF_ENABLE_EXCLUSION_PATTERNS = getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
056: private static final Key PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS = getJDTCoreKey(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
057:
058: private static final Key PREF_PB_INCOMPLETE_BUILDPATH = getJDTCoreKey(JavaCore.CORE_INCOMPLETE_CLASSPATH);
059: private static final Key PREF_PB_CIRCULAR_BUILDPATH = getJDTCoreKey(JavaCore.CORE_CIRCULAR_CLASSPATH);
060: private static final Key PREF_PB_INCOMPATIBLE_JDK_LEVEL = getJDTCoreKey(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL);
061: private static final Key PREF_PB_DUPLICATE_RESOURCE = getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
062: private static final Key PREF_RECREATE_MODIFIED_CLASS_FILES = getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER);
063:
064: // values
065: private static final String ERROR = JavaCore.ERROR;
066: private static final String WARNING = JavaCore.WARNING;
067: private static final String IGNORE = JavaCore.IGNORE;
068:
069: private static final String ABORT = JavaCore.ABORT;
070: private static final String CLEAN = JavaCore.CLEAN;
071:
072: private static final String ENABLED = JavaCore.ENABLED;
073: private static final String DISABLED = JavaCore.DISABLED;
074:
075: private PixelConverter fPixelConverter;
076:
077: private IStatus fMaxNumberProblemsStatus, fResourceFilterStatus;
078:
079: public JavaBuildConfigurationBlock(IStatusChangeListener context,
080: IProject project, IWorkbenchPreferenceContainer container) {
081: super (context, project, getKeys(), container);
082: fMaxNumberProblemsStatus = new StatusInfo();
083: fResourceFilterStatus = new StatusInfo();
084: }
085:
086: private static Key[] getKeys() {
087: Key[] keys = new Key[] { PREF_PB_MAX_PER_UNIT,
088: PREF_RESOURCE_FILTER, PREF_BUILD_INVALID_CLASSPATH,
089: PREF_PB_INCOMPLETE_BUILDPATH,
090: PREF_PB_CIRCULAR_BUILDPATH,
091: PREF_BUILD_CLEAN_OUTPUT_FOLDER,
092: PREF_PB_DUPLICATE_RESOURCE,
093: PREF_PB_INCOMPATIBLE_JDK_LEVEL,
094: PREF_ENABLE_EXCLUSION_PATTERNS,
095: PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS,
096: PREF_RECREATE_MODIFIED_CLASS_FILES, };
097: return keys;
098: }
099:
100: /*
101: * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
102: */
103: protected Control createContents(Composite parent) {
104: fPixelConverter = new PixelConverter(parent);
105: setShell(parent.getShell());
106:
107: Composite mainComp = new Composite(parent, SWT.NONE);
108: mainComp.setFont(parent.getFont());
109: GridLayout layout = new GridLayout();
110: layout.marginHeight = 0;
111: layout.marginWidth = 0;
112: mainComp.setLayout(layout);
113:
114: Composite othersComposite = createBuildPathTabContent(mainComp);
115: GridData gridData = new GridData(GridData.FILL, GridData.FILL,
116: true, true);
117: gridData.heightHint = fPixelConverter
118: .convertHeightInCharsToPixels(20);
119: othersComposite.setLayoutData(gridData);
120:
121: validateSettings(null, null, null);
122:
123: return mainComp;
124: }
125:
126: private Composite createBuildPathTabContent(Composite parent) {
127: String[] abortIgnoreValues = new String[] { ABORT, IGNORE };
128: String[] cleanIgnoreValues = new String[] { CLEAN, IGNORE };
129: String[] enableDisableValues = new String[] { ENABLED, DISABLED };
130: String[] enableIgnoreValues = new String[] { ENABLED, IGNORE };
131:
132: String[] errorWarning = new String[] { ERROR, WARNING };
133:
134: String[] errorWarningLabels = new String[] {
135: PreferencesMessages.JavaBuildConfigurationBlock_error,
136: PreferencesMessages.JavaBuildConfigurationBlock_warning };
137:
138: String[] errorWarningIgnore = new String[] { ERROR, WARNING,
139: IGNORE };
140: String[] errorWarningIgnoreLabels = new String[] {
141: PreferencesMessages.JavaBuildConfigurationBlock_error,
142: PreferencesMessages.JavaBuildConfigurationBlock_warning,
143: PreferencesMessages.JavaBuildConfigurationBlock_ignore };
144:
145: int nColumns = 3;
146:
147: final ScrolledPageContent pageContent = new ScrolledPageContent(
148: parent);
149:
150: GridLayout layout = new GridLayout();
151: layout.numColumns = nColumns;
152: layout.marginHeight = 0;
153: layout.marginWidth = 0;
154:
155: Composite composite = pageContent.getBody();
156: composite.setLayout(layout);
157:
158: String label = PreferencesMessages.JavaBuildConfigurationBlock_section_general;
159: ExpandableComposite excomposite = createStyleSection(composite,
160: label, nColumns);
161:
162: Composite othersComposite = new Composite(excomposite, SWT.NONE);
163: excomposite.setClient(othersComposite);
164: othersComposite.setLayout(new GridLayout(nColumns, false));
165:
166: label = PreferencesMessages.JavaBuildConfigurationBlock_pb_max_per_unit_label;
167: Text text = addTextField(othersComposite, label,
168: PREF_PB_MAX_PER_UNIT, 0, 0);
169: GridData gd = (GridData) text.getLayoutData();
170: gd.widthHint = fPixelConverter.convertWidthInCharsToPixels(8);
171: gd.horizontalAlignment = GridData.END;
172: text.setTextLimit(6);
173:
174: label = PreferencesMessages.JavaBuildConfigurationBlock_enable_exclusion_patterns_label;
175: addCheckBox(othersComposite, label,
176: PREF_ENABLE_EXCLUSION_PATTERNS, enableDisableValues, 0);
177:
178: label = PreferencesMessages.JavaBuildConfigurationBlock_enable_multiple_outputlocations_label;
179: addCheckBox(othersComposite, label,
180: PREF_ENABLE_MULTIPLE_OUTPUT_LOCATIONS,
181: enableDisableValues, 0);
182:
183: label = PreferencesMessages.JavaBuildConfigurationBlock_section_build_path_problems;
184: excomposite = createStyleSection(composite, label, nColumns);
185:
186: othersComposite = new Composite(excomposite, SWT.NONE);
187: excomposite.setClient(othersComposite);
188: othersComposite.setLayout(new GridLayout(nColumns, false));
189:
190: label = PreferencesMessages.JavaBuildConfigurationBlock_build_invalid_classpath_label;
191: addCheckBox(othersComposite, label,
192: PREF_BUILD_INVALID_CLASSPATH, abortIgnoreValues, 0);
193:
194: label = PreferencesMessages.JavaBuildConfigurationBlock_pb_incomplete_build_path_label;
195: addComboBox(othersComposite, label,
196: PREF_PB_INCOMPLETE_BUILDPATH, errorWarning,
197: errorWarningLabels, 0);
198:
199: label = PreferencesMessages.JavaBuildConfigurationBlock_pb_build_path_cycles_label;
200: addComboBox(othersComposite, label, PREF_PB_CIRCULAR_BUILDPATH,
201: errorWarning, errorWarningLabels, 0);
202:
203: label = PreferencesMessages.JavaBuildConfigurationBlock_pb_check_prereq_binary_level_label;
204: addComboBox(othersComposite, label,
205: PREF_PB_INCOMPATIBLE_JDK_LEVEL, errorWarningIgnore,
206: errorWarningIgnoreLabels, 0);
207:
208: label = PreferencesMessages.JavaBuildConfigurationBlock_section_output_folder;
209: excomposite = createStyleSection(composite, label, nColumns);
210:
211: othersComposite = new Composite(excomposite, SWT.NONE);
212: excomposite.setClient(othersComposite);
213: othersComposite.setLayout(new GridLayout(nColumns, false));
214:
215: label = PreferencesMessages.JavaBuildConfigurationBlock_pb_duplicate_resources_label;
216: addComboBox(othersComposite, label, PREF_PB_DUPLICATE_RESOURCE,
217: errorWarning, errorWarningLabels, 0);
218:
219: label = PreferencesMessages.JavaBuildConfigurationBlock_build_clean_outputfolder_label;
220: addCheckBox(othersComposite, label,
221: PREF_BUILD_CLEAN_OUTPUT_FOLDER, cleanIgnoreValues, 0);
222:
223: label = PreferencesMessages.JavaBuildConfigurationBlock_build_recreate_modified;
224: addCheckBox(othersComposite, label,
225: PREF_RECREATE_MODIFIED_CLASS_FILES, enableIgnoreValues,
226: 0);
227:
228: label = PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_label;
229: text = addTextField(othersComposite, label,
230: PREF_RESOURCE_FILTER, 0, 0);
231: gd = (GridData) text.getLayoutData();
232: gd.grabExcessHorizontalSpace = true;
233: gd.widthHint = fPixelConverter.convertWidthInCharsToPixels(10);
234:
235: Label description = new Label(othersComposite, SWT.WRAP);
236: description
237: .setText(PreferencesMessages.JavaBuildConfigurationBlock_resource_filter_description);
238: gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
239: gd.horizontalSpan = nColumns;
240: gd.widthHint = fPixelConverter.convertWidthInCharsToPixels(60);
241: description.setLayoutData(gd);
242:
243: IDialogSettings section = JavaPlugin.getDefault()
244: .getDialogSettings().getSection(SETTINGS_SECTION_NAME);
245: restoreSectionExpansionStates(section);
246:
247: return pageContent;
248: }
249:
250: /* (non-javadoc)
251: * Update fields and validate.
252: * @param changedKey Key that changed, or null, if all changed.
253: */
254: protected void validateSettings(Key changedKey, String oldValue,
255: String newValue) {
256: if (!areSettingsEnabled()) {
257: return;
258: }
259:
260: if (changedKey != null) {
261: if (PREF_PB_MAX_PER_UNIT.equals(changedKey)) {
262: fMaxNumberProblemsStatus = validateMaxNumberProblems();
263: } else if (PREF_RESOURCE_FILTER.equals(changedKey)) {
264: fResourceFilterStatus = validateResourceFilters();
265: } else {
266: return;
267: }
268: } else {
269: updateEnableStates();
270: fMaxNumberProblemsStatus = validateMaxNumberProblems();
271: fResourceFilterStatus = validateResourceFilters();
272: }
273: IStatus status = StatusUtil.getMostSevere(new IStatus[] {
274: fMaxNumberProblemsStatus, fResourceFilterStatus });
275: fContext.statusChanged(status);
276: }
277:
278: private void updateEnableStates() {
279: }
280:
281: protected String[] getFullBuildDialogStrings(
282: boolean workspaceSettings) {
283: String title = PreferencesMessages.JavaBuildConfigurationBlock_needsbuild_title;
284: String message;
285: if (workspaceSettings) {
286: message = PreferencesMessages.JavaBuildConfigurationBlock_needsfullbuild_message;
287: } else {
288: message = PreferencesMessages.JavaBuildConfigurationBlock_needsprojectbuild_message;
289: }
290: return new String[] { title, message };
291: }
292:
293: private IStatus validateMaxNumberProblems() {
294: String number = getValue(PREF_PB_MAX_PER_UNIT);
295: StatusInfo status = new StatusInfo();
296: if (number.length() == 0) {
297: status
298: .setError(PreferencesMessages.JavaBuildConfigurationBlock_empty_input);
299: } else {
300: try {
301: int value = Integer.parseInt(number);
302: if (value <= 0) {
303: status
304: .setError(Messages
305: .format(
306: PreferencesMessages.JavaBuildConfigurationBlock_invalid_input,
307: number));
308: }
309: } catch (NumberFormatException e) {
310: status
311: .setError(Messages
312: .format(
313: PreferencesMessages.JavaBuildConfigurationBlock_invalid_input,
314: number));
315: }
316: }
317: return status;
318: }
319:
320: private IStatus validateResourceFilters() {
321: String text = getValue(PREF_RESOURCE_FILTER);
322:
323: IWorkspace workspace = ResourcesPlugin.getWorkspace();
324:
325: String[] filters = getTokens(text, ","); //$NON-NLS-1$
326: for (int i = 0; i < filters.length; i++) {
327: String fileName = filters[i].replace('*', 'x');
328: int resourceType = IResource.FILE;
329: int lastCharacter = fileName.length() - 1;
330: if (lastCharacter >= 0
331: && fileName.charAt(lastCharacter) == '/') {
332: fileName = fileName.substring(0, lastCharacter);
333: resourceType = IResource.FOLDER;
334: }
335: IStatus status = workspace.validateName(fileName,
336: resourceType);
337: if (status.matches(IStatus.ERROR)) {
338: String message = Messages
339: .format(
340: PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error,
341: status.getMessage());
342: return new StatusInfo(IStatus.ERROR, message);
343: }
344: }
345: return new StatusInfo();
346: }
347:
348: /* (non-Javadoc)
349: * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#dispose()
350: */
351: public void dispose() {
352: IDialogSettings settings = JavaPlugin.getDefault()
353: .getDialogSettings().addNewSection(
354: SETTINGS_SECTION_NAME);
355: storeSectionExpansionStates(settings);
356: super.dispose();
357: }
358:
359: }
|