KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > JavaBuildConfigurationBlock


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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
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 /**
45   */

46 public class JavaBuildConfigurationBlock extends OptionsConfigurationBlock {
47     
48     private static final String JavaDoc SETTINGS_SECTION_NAME= "JavaBuildConfigurationBlock"; //$NON-NLS-1$
49

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     // values
66
private static final String JavaDoc ERROR= JavaCore.ERROR;
67     private static final String JavaDoc WARNING= JavaCore.WARNING;
68     private static final String JavaDoc IGNORE= JavaCore.IGNORE;
69
70     private static final String JavaDoc ABORT= JavaCore.ABORT;
71     private static final String JavaDoc CLEAN= JavaCore.CLEAN;
72
73     private static final String JavaDoc ENABLED= JavaCore.ENABLED;
74     private static final String JavaDoc 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     /*
97      * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
98      */

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 JavaDoc[] abortIgnoreValues= new String JavaDoc[] { ABORT, IGNORE };
123         String JavaDoc[] cleanIgnoreValues= new String JavaDoc[] { CLEAN, IGNORE };
124         String JavaDoc[] enableDisableValues= new String JavaDoc[] { ENABLED, DISABLED };
125         String JavaDoc[] enableIgnoreValues= new String JavaDoc[] { ENABLED, IGNORE };
126         
127         String JavaDoc[] errorWarning= new String JavaDoc[] { ERROR, WARNING };
128         
129         String JavaDoc[] errorWarningLabels= new String JavaDoc[] {
130             PreferencesMessages.JavaBuildConfigurationBlock_error,
131             PreferencesMessages.JavaBuildConfigurationBlock_warning
132         };
133         
134         String JavaDoc[] errorWarningIgnore= new String JavaDoc[] { ERROR, WARNING, IGNORE };
135         String JavaDoc[] errorWarningIgnoreLabels= new String JavaDoc[] {
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 JavaDoc 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     /* (non-javadoc)
228      * Update fields and validate.
229      * @param changedKey Key that changed, or null, if all changed.
230      */

231     protected void validateSettings(Key changedKey, String JavaDoc oldValue, String JavaDoc 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 JavaDoc[] getFullBuildDialogStrings(boolean workspaceSettings) {
257         String JavaDoc title= PreferencesMessages.JavaBuildConfigurationBlock_needsbuild_title;
258         String JavaDoc message;
259         if (workspaceSettings) {
260             message= PreferencesMessages.JavaBuildConfigurationBlock_needsfullbuild_message;
261         } else {
262             message= PreferencesMessages.JavaBuildConfigurationBlock_needsprojectbuild_message;
263         }
264         return new String JavaDoc[] { title, message };
265     }
266
267     private IStatus validateMaxNumberProblems() {
268         String JavaDoc 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 JavaDoc e) {
279                 status.setError(Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_invalid_input, number));
280             }
281         }
282         return status;
283     }
284
285     private IStatus validateResourceFilters() {
286         String JavaDoc text= getValue(PREF_RESOURCE_FILTER);
287         
288         IWorkspace workspace= ResourcesPlugin.getWorkspace();
289     
290         String JavaDoc[] filters= getTokens(text, ","); //$NON-NLS-1$
291
for (int i= 0; i < filters.length; i++) {
292             String JavaDoc 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 JavaDoc 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     /* (non-Javadoc)
309      * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#dispose()
310      */

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