KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > AntEditorPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ant.internal.ui.preferences;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.ant.internal.ui.AntSourceViewerConfiguration;
20 import org.eclipse.ant.internal.ui.AntUIPlugin;
21 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
22 import org.eclipse.ant.internal.ui.editor.text.AntDocumentSetupParticipant;
23 import org.eclipse.ant.internal.ui.editor.text.IAntEditorColorConstants;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.preference.PreferenceConverter;
26 import org.eclipse.jface.resource.JFaceResources;
27 import org.eclipse.jface.text.Document;
28 import org.eclipse.jface.text.IDocument;
29 import org.eclipse.jface.text.source.SourceViewer;
30 import org.eclipse.jface.viewers.IColorProvider;
31 import org.eclipse.jface.viewers.ISelectionChangedListener;
32 import org.eclipse.jface.viewers.IStructuredContentProvider;
33 import org.eclipse.jface.viewers.IStructuredSelection;
34 import org.eclipse.jface.viewers.LabelProvider;
35 import org.eclipse.jface.viewers.SelectionChangedEvent;
36 import org.eclipse.jface.viewers.StructuredSelection;
37 import org.eclipse.jface.viewers.TableViewer;
38 import org.eclipse.jface.viewers.Viewer;
39 import org.eclipse.swt.SWT;
40 import org.eclipse.swt.events.SelectionAdapter;
41 import org.eclipse.swt.events.SelectionEvent;
42 import org.eclipse.swt.events.SelectionListener;
43 import org.eclipse.swt.graphics.Color;
44 import org.eclipse.swt.graphics.Font;
45 import org.eclipse.swt.graphics.RGB;
46 import org.eclipse.swt.layout.GridData;
47 import org.eclipse.swt.layout.GridLayout;
48 import org.eclipse.swt.widgets.Button;
49 import org.eclipse.swt.widgets.Combo;
50 import org.eclipse.swt.widgets.Composite;
51 import org.eclipse.swt.widgets.Control;
52 import org.eclipse.swt.widgets.Label;
53 import org.eclipse.swt.widgets.Link;
54 import org.eclipse.swt.widgets.TabFolder;
55 import org.eclipse.swt.widgets.TabItem;
56 import org.eclipse.swt.widgets.Text;
57 import org.eclipse.swt.widgets.Widget;
58 import org.eclipse.ui.PlatformUI;
59 import org.eclipse.ui.dialogs.PreferencesUtil;
60 import org.eclipse.ui.editors.text.EditorsUI;
61 import org.eclipse.ui.model.WorkbenchViewerComparator;
62 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
63
64 /*
65  * The page for setting the editor options.
66  */

67 public class AntEditorPreferencePage extends AbstractAntEditorPreferencePage {
68     
69     protected static class ControlData {
70         private String JavaDoc fKey;
71         private String JavaDoc[] fValues;
72         
73         public ControlData(String JavaDoc key, String JavaDoc[] values) {
74             fKey= key;
75             fValues= values;
76         }
77         
78         public String JavaDoc getKey() {
79             return fKey;
80         }
81         
82         public String JavaDoc getValue(boolean selection) {
83             int index= selection ? 0 : 1;
84             return fValues[index];
85         }
86         
87         public String JavaDoc getValue(int index) {
88             return fValues[index];
89         }
90         
91         public int getSelection(String JavaDoc value) {
92             if (value != null) {
93                 for (int i= 0; i < fValues.length; i++) {
94                     if (value.equals(fValues[i])) {
95                         return i;
96                     }
97                 }
98             }
99             return fValues.length -1; // assume the last option is the least severe
100
}
101     }
102     
103     /**
104      * Item in the highlighting color list.
105      *
106      * @since 3.0
107      */

108     private class HighlightingColorListItem {
109         /** Display name */
110         private String JavaDoc fDisplayName;
111         /** Color preference key */
112         private String JavaDoc fColorKey;
113         /** Bold preference key */
114         private String JavaDoc fBoldKey;
115         /** Italic preference key */
116         private String JavaDoc fItalicKey;
117         /** Item color */
118         private Color fItemColor;
119         
120         /**
121          * Initialize the item with the given values.
122          *
123          * @param displayName the display name
124          * @param colorKey the color preference key
125          * @param boldKey the bold preference key
126          * @param italicKey the italic preference key
127          * @param itemColor the item color
128          */

129         public HighlightingColorListItem(String JavaDoc displayName, String JavaDoc colorKey, String JavaDoc boldKey, String JavaDoc italicKey, Color itemColor) {
130             fDisplayName= displayName;
131             fColorKey= colorKey;
132             fBoldKey= boldKey;
133             fItalicKey= italicKey;
134             fItemColor= itemColor;
135         }
136         
137         /**
138          * @return the bold preference key
139          */

140         public String JavaDoc getBoldKey() {
141             return fBoldKey;
142         }
143         
144         /**
145          * @return the bold preference key
146          */

147         public String JavaDoc getItalicKey() {
148             return fItalicKey;
149         }
150         
151         /**
152          * @return the color preference key
153          */

154         public String JavaDoc getColorKey() {
155             return fColorKey;
156         }
157         
158         /**
159          * @return the display name
160          */

161         public String JavaDoc getDisplayName() {
162             return fDisplayName;
163         }
164         
165         /**
166          * @return the item color
167          */

168         public Color getItemColor() {
169             return fItemColor;
170         }
171     }
172     
173     /**
174      * Color list label provider.
175      *
176      * @since 3.0
177      */

178     private class ColorListLabelProvider extends LabelProvider implements IColorProvider {
179
180         /*
181          * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
182          */

183         public String JavaDoc getText(Object JavaDoc element) {
184             return ((HighlightingColorListItem)element).getDisplayName();
185         }
186         
187         /*
188          * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
189          */

190         public Color getForeground(Object JavaDoc element) {
191             return ((HighlightingColorListItem)element).getItemColor();
192         }
193
194         /*
195          * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
196          */

197         public Color getBackground(Object JavaDoc element) {
198             return null;
199         }
200     }
201     
202     /**
203      * Color list content provider.
204      *
205      * @since 3.0
206      */

207     private class ColorListContentProvider implements IStructuredContentProvider {
208
209         /*
210          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
211          */

212         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
213             return ((java.util.List JavaDoc)inputElement).toArray();
214         }
215
216         /*
217          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
218          */

219         public void dispose() {
220         }
221
222         /*
223          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
224          */

225         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
226         }
227     }
228     
229     /** The keys of the overlay store. */
230     private String JavaDoc[][] fSyntaxColorListModel;
231     
232     private final String JavaDoc[] fProblemPreferenceKeys= new String JavaDoc[] {
233             AntEditorPreferenceConstants.PROBLEM_CLASSPATH,
234             AntEditorPreferenceConstants.PROBLEM_PROPERTIES,
235             AntEditorPreferenceConstants.PROBLEM_IMPORTS,
236             AntEditorPreferenceConstants.PROBLEM_TASKS,
237             AntEditorPreferenceConstants.PROBLEM_SECURITY
238         };
239     
240     private ColorEditor fSyntaxForegroundColorEditor;
241     private Button fBoldCheckBox;
242     private Button fItalicCheckBox;
243     
244     private TableViewer fHighlightingColorListViewer;
245     private final java.util.List JavaDoc fHighlightingColorList= new ArrayList JavaDoc(5);
246     
247     private SourceViewer fPreviewViewer;
248     private AntPreviewerUpdater fPreviewerUpdater;
249     
250     private SelectionListener fSelectionListener;
251     protected Map JavaDoc fWorkingValues;
252     protected List JavaDoc fComboBoxes;
253     private List JavaDoc fProblemLabels;
254
255     private Button fIgnoreAllProblems;
256
257     private Text fBuildFilesToIgnoreProblems;
258     private Label fBuildFilesToIgnoreProblemsLabel;
259
260     private Label fSeverityLabel;
261
262     private Label fBuildFilesToIgnoreProblemsDescription;
263     
264     public AntEditorPreferencePage() {
265         super();
266         setDescription(AntPreferencesMessages.AntEditorPreferencePage_description);
267     }
268     
269     protected OverlayPreferenceStore createOverlayStore() {
270         fSyntaxColorListModel= new String JavaDoc[][] {
271                 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_text_1, IAntEditorColorConstants.TEXT_COLOR, null},
272                 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_processing_instuctions_2, IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR, null},
273                 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_constant_strings_3, IAntEditorColorConstants.STRING_COLOR, null},
274                 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_tags_4, IAntEditorColorConstants.TAG_COLOR, null},
275                 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_comments_5, IAntEditorColorConstants.XML_COMMENT_COLOR, null},
276                 {AntPreferencesMessages.AntEditorPreferencePage_26, IAntEditorColorConstants.XML_DTD_COLOR, null}
277             };
278         ArrayList JavaDoc overlayKeys= new ArrayList JavaDoc();
279         
280         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION));
281         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
282         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT));
283         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
284         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
285         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS));
286     
287         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED));
288         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS));
289         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD));
290         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING));
291         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS));
292         
293         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES));
294         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES));
295         
296         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
297         
298         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE));
299         
300         for (int i= 0; i < fSyntaxColorListModel.length; i++) {
301             String JavaDoc colorKey= fSyntaxColorListModel[i][1];
302             addTextKeyToCover(overlayKeys, colorKey);
303         }
304         
305         OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
306         overlayKeys.toArray(keys);
307         return new OverlayPreferenceStore(getPreferenceStore(), keys);
308     }
309
310     private void addTextKeyToCover(ArrayList JavaDoc overlayKeys, String JavaDoc mainKey) {
311         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey));
312         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX));
313         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX));
314     }
315     
316     private Control createAppearancePage(Composite parent) {
317         Font font= parent.getFont();
318
319         Composite appearanceComposite= new Composite(parent, SWT.NONE);
320         appearanceComposite.setFont(font);
321         GridLayout layout= new GridLayout();
322         layout.numColumns= 2;
323         appearanceComposite.setLayout(layout);
324
325         String JavaDoc labelText= AntPreferencesMessages.AntEditorPreferencePage_2;
326         addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES, 0);
327         
328         labelText= AntPreferencesMessages.AntEditorPreferencePage_4;
329         addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0);
330         
331         return appearanceComposite;
332     }
333             
334     /* (non-Javadoc)
335      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
336      */

337     protected Control createContents(Composite parent) {
338         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_EDITOR_PREFERENCE_PAGE);
339         getOverlayStore().load();
340         getOverlayStore().start();
341         
342         createHeader(parent);
343         
344         TabFolder folder= new TabFolder(parent, SWT.NONE);
345         folder.setLayout(new TabFolderLayout());
346         folder.setLayoutData(new GridData(GridData.FILL_BOTH));
347         
348         TabItem item= new TabItem(folder, SWT.NONE);
349         item.setText(AntPreferencesMessages.AntEditorPreferencePage_general);
350         item.setControl(createAppearancePage(folder));
351         
352         item= new TabItem(folder, SWT.NONE);
353         item.setText(AntPreferencesMessages.AntEditorPreferencePage_1);
354         item.setControl(createSyntaxPage(folder));
355         
356         item= new TabItem(folder, SWT.NONE);
357         item.setText(AntPreferencesMessages.AntEditorPreferencePage_10);
358         item.setControl(createProblemsTabContent(folder));
359         
360         item= new TabItem(folder, SWT.NONE);
361         item.setText(AntPreferencesMessages.AntEditorPreferencePage_19);
362         item.setControl(createFoldingTabContent(folder));
363         
364         initialize();
365         
366         applyDialogFont(parent);
367         return folder;
368     }
369     
370     private Control createFoldingTabContent(TabFolder folder) {
371         Composite composite= new Composite(folder, SWT.NULL);
372         
373         GridLayout layout= new GridLayout();
374         layout.numColumns= 2;
375         composite.setLayout(layout);
376         
377         addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_20, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, 0);
378         
379         Label label= new Label(composite, SWT.LEFT);
380         label.setText(AntPreferencesMessages.AntEditorPreferencePage_21);
381         
382         addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_22, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD, 0);
383         addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_23, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS, 0);
384         addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_24, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING, 0);
385         addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_25, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS, 0);
386         return composite;
387     }
388     
389     private void initialize() {
390         
391         initializeFields();
392         
393         for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) {
394             fHighlightingColorList.add(
395                 new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1],
396                         fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX,
397                         fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX, null));
398         }
399         fHighlightingColorListViewer.setInput(fHighlightingColorList);
400         fHighlightingColorListViewer.setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0)));
401     }
402     
403     /* (non-Javadoc)
404      * @see org.eclipse.ant.internal.ui.preferences.AbstractAntEditorPreferencePage#handleDefaults()
405      */

406     protected void handleDefaults() {
407         handleSyntaxColorListSelection();
408         restoreWorkingValuesToDefaults();
409         updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
410     }
411     
412     private Control createSyntaxPage(Composite parent) {
413         
414         Composite colorComposite= new Composite(parent, SWT.NONE);
415         colorComposite.setLayout(new GridLayout());
416
417         Label label= new Label(colorComposite, SWT.LEFT);
418         label.setText(AntPreferencesMessages.AntEditorPreferencePage_5);
419         label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
420
421         Composite editorComposite= new Composite(colorComposite, SWT.NONE);
422         GridLayout layout= new GridLayout();
423         layout.numColumns= 2;
424         layout.marginHeight= 0;
425         layout.marginWidth= 0;
426         editorComposite.setLayout(layout);
427         GridData gd= new GridData(GridData.FILL_BOTH);
428         editorComposite.setLayoutData(gd);
429
430         fHighlightingColorListViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
431         fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider());
432         fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider());
433         fHighlightingColorListViewer.setComparator(new WorkbenchViewerComparator());
434         gd= new GridData(GridData.FILL_BOTH);
435         gd.heightHint= convertHeightInCharsToPixels(5);
436         fHighlightingColorListViewer.getControl().setLayoutData(gd);
437                         
438         Composite stylesComposite= new Composite(editorComposite, SWT.NONE);
439         layout= new GridLayout();
440         layout.marginHeight= 0;
441         layout.marginWidth= 0;
442         layout.numColumns= 2;
443         stylesComposite.setLayout(layout);
444         stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
445         
446         label= new Label(stylesComposite, SWT.LEFT);
447         label.setText(AntPreferencesMessages.AntEditorPreferencePage_6);
448         gd= new GridData();
449         gd.horizontalAlignment= GridData.BEGINNING;
450         label.setLayoutData(gd);
451
452         fSyntaxForegroundColorEditor= new ColorEditor(stylesComposite);
453         Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton();
454         gd= new GridData(GridData.FILL_HORIZONTAL);
455         gd.horizontalAlignment= GridData.BEGINNING;
456         foregroundColorButton.setLayoutData(gd);
457         
458         fBoldCheckBox= new Button(stylesComposite, SWT.CHECK);
459         fBoldCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_7);
460         gd= new GridData(GridData.FILL_HORIZONTAL);
461         gd.horizontalAlignment= GridData.BEGINNING;
462         gd.horizontalSpan= 2;
463         fBoldCheckBox.setLayoutData(gd);
464         
465         fItalicCheckBox= new Button(stylesComposite, SWT.CHECK);
466         fItalicCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_8);
467         gd= new GridData(GridData.FILL_HORIZONTAL);
468         gd.horizontalAlignment= GridData.BEGINNING;
469         gd.horizontalSpan= 2;
470         fItalicCheckBox.setLayoutData(gd);
471         
472         label= new Label(colorComposite, SWT.LEFT);
473         label.setText(AntPreferencesMessages.AntEditorPreferencePage_9);
474         label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
475         
476         Control previewer= createPreviewer(colorComposite);
477         gd= new GridData(GridData.FILL_BOTH);
478         gd.widthHint= convertWidthInCharsToPixels(20);
479         gd.heightHint= convertHeightInCharsToPixels(5);
480         previewer.setLayoutData(gd);
481
482         fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
483             public void selectionChanged(SelectionChangedEvent event) {
484                 handleSyntaxColorListSelection();
485             }
486         });
487         
488         foregroundColorButton.addSelectionListener(new SelectionListener() {
489             public void widgetDefaultSelected(SelectionEvent e) {
490                 // do nothing
491
}
492             public void widgetSelected(SelectionEvent e) {
493                 HighlightingColorListItem item= getHighlightingColorListItem();
494                 PreferenceConverter.setValue(getOverlayStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue());
495             }
496         });
497
498         fBoldCheckBox.addSelectionListener(new SelectionListener() {
499             public void widgetDefaultSelected(SelectionEvent e) {
500                 // do nothing
501
}
502             public void widgetSelected(SelectionEvent e) {
503                 HighlightingColorListItem item= getHighlightingColorListItem();
504                 getOverlayStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
505             }
506         });
507                 
508         fItalicCheckBox.addSelectionListener(new SelectionListener() {
509             public void widgetDefaultSelected(SelectionEvent e) {
510                 // do nothing
511
}
512             public void widgetSelected(SelectionEvent e) {
513                 HighlightingColorListItem item= getHighlightingColorListItem();
514                 getOverlayStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
515             }
516         });
517                 
518         return colorComposite;
519     }
520     
521     private Control createPreviewer(Composite parent) {
522         fPreviewViewer = new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
523         
524         AntSourceViewerConfiguration configuration = new AntSourceViewerConfiguration();
525     
526         fPreviewViewer.configure(configuration);
527         fPreviewViewer.setEditable(false);
528         Font font= JFaceResources.getFont(JFaceResources.TEXT_FONT);
529         fPreviewViewer.getTextWidget().setFont(font);
530         
531         IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { getOverlayStore(), EditorsUI.getPreferenceStore() });
532         fPreviewerUpdater= new AntPreviewerUpdater(fPreviewViewer, configuration, store);
533         
534         String JavaDoc content= loadPreviewContentFromFile("SyntaxPreviewCode.txt"); //$NON-NLS-1$
535
IDocument document = new Document(content);
536         new AntDocumentSetupParticipant().setup(document);
537         fPreviewViewer.setDocument(document);
538         
539         return fPreviewViewer.getControl();
540     }
541     
542     private void handleSyntaxColorListSelection() {
543         HighlightingColorListItem item= getHighlightingColorListItem();
544         RGB rgb= PreferenceConverter.getColor(getOverlayStore(), item.getColorKey());
545         fSyntaxForegroundColorEditor.setColorValue(rgb);
546         fBoldCheckBox.setSelection(getOverlayStore().getBoolean(item.getBoldKey()));
547         fItalicCheckBox.setSelection(getOverlayStore().getBoolean(item.getItalicKey()));
548     }
549     
550     /**
551      * Returns the current highlighting color list item.
552      *
553      * @return the current highlighting color list item
554      * @since 3.0
555      */

556     private HighlightingColorListItem getHighlightingColorListItem() {
557         IStructuredSelection selection= (IStructuredSelection) fHighlightingColorListViewer.getSelection();
558         return (HighlightingColorListItem) selection.getFirstElement();
559     }
560     
561     /* (non-Javadoc)
562      * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
563      */

564     public void dispose() {
565         super.dispose();
566         if (fPreviewerUpdater != null) {
567             fPreviewerUpdater.dispose();
568         }
569     }
570     
571     private Composite createProblemsTabContent(TabFolder folder) {
572         fComboBoxes= new ArrayList JavaDoc();
573         fProblemLabels= new ArrayList JavaDoc();
574         initializeWorkingValues();
575         
576         String JavaDoc[] errorWarningIgnoreLabels= new String JavaDoc[] {
577                 AntPreferencesMessages.AntEditorPreferencePage_11, AntPreferencesMessages.AntEditorPreferencePage_12, AntPreferencesMessages.AntEditorPreferencePage_13};
578         String JavaDoc[] errorWarningIgnore= new String JavaDoc[] {
579                 AntEditorPreferenceConstants.BUILDFILE_ERROR,
580                 AntEditorPreferenceConstants.BUILDFILE_WARNING,
581                 AntEditorPreferenceConstants.BUILDFILE_IGNORE };
582         
583         int nColumns= 3;
584         
585         GridLayout layout= new GridLayout();
586         layout.numColumns= nColumns;
587
588         Composite othersComposite= new Composite(folder, SWT.NULL);
589         othersComposite.setLayout(layout);
590         
591         String JavaDoc labelText= AntPreferencesMessages.AntEditorPreferencePage_28;
592         fIgnoreAllProblems= addCheckBox(othersComposite, labelText, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL, 0);
593         
594         fIgnoreAllProblems.addSelectionListener(getSelectionListener());
595         
596         fBuildFilesToIgnoreProblemsDescription = new Label(othersComposite, SWT.WRAP);
597         fBuildFilesToIgnoreProblemsDescription.setText(AntPreferencesMessages.AntEditorPreferencePage_29);
598         GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
599         gd.horizontalSpan= nColumns;
600         fBuildFilesToIgnoreProblemsDescription.setLayoutData(gd);
601         
602         Control[] controls= addLabelledTextField(othersComposite, AntPreferencesMessages.AntEditorPreferencePage_30, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE, -1, 0, null);
603         fBuildFilesToIgnoreProblems= getTextControl(controls);
604         fBuildFilesToIgnoreProblemsLabel= getLabelControl(controls);
605         
606         fSeverityLabel= new Label(othersComposite, SWT.WRAP);
607         fSeverityLabel.setText(AntPreferencesMessages.AntEditorPreferencePage_14);
608         gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
609         gd.horizontalSpan= nColumns;
610         fSeverityLabel.setLayoutData(gd);
611                 
612         String JavaDoc label= AntPreferencesMessages.AntEditorPreferencePage_18;
613         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_TASKS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
614         
615         label= AntPreferencesMessages.AntEditorPreferencePage_15;
616         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_CLASSPATH, errorWarningIgnore, errorWarningIgnoreLabels, 0);
617         
618         label= AntPreferencesMessages.AntEditorPreferencePage_16;
619         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_PROPERTIES, errorWarningIgnore, errorWarningIgnoreLabels, 0);
620
621         label= AntPreferencesMessages.AntEditorPreferencePage_17;
622         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_IMPORTS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
623         
624         label= AntPreferencesMessages.AntEditorPreferencePage_27;
625         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_SECURITY, errorWarningIgnore, errorWarningIgnoreLabels, 0);
626         
627         updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
628         return othersComposite;
629     }
630     
631     private void initializeWorkingValues() {
632         fWorkingValues= new HashMap JavaDoc(fProblemPreferenceKeys.length);
633         for (int i = 0; i < fProblemPreferenceKeys.length; i++) {
634             String JavaDoc key = fProblemPreferenceKeys[i];
635             fWorkingValues.put(key, getPreferenceStore().getString(key));
636         }
637     }
638     
639     private void restoreWorkingValuesToDefaults() {
640         fWorkingValues= new HashMap JavaDoc(fProblemPreferenceKeys.length);
641         for (int i = 0; i < fProblemPreferenceKeys.length; i++) {
642             String JavaDoc key = fProblemPreferenceKeys[i];
643             fWorkingValues.put(key, getPreferenceStore().getDefaultString(key));
644         }
645         updateControls();
646     }
647
648     protected Combo addComboBox(Composite parent, String JavaDoc label, String JavaDoc key, String JavaDoc[] values, String JavaDoc[] valueLabels, int indent) {
649         ControlData data= new ControlData(key, values);
650         
651         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
652         gd.horizontalIndent= indent;
653                 
654         Label labelControl= new Label(parent, SWT.LEFT | SWT.WRAP);
655         labelControl.setText(label);
656         labelControl.setLayoutData(gd);
657         
658         Combo comboBox= new Combo(parent, SWT.READ_ONLY);
659         comboBox.setItems(valueLabels);
660         comboBox.setData(data);
661         comboBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
662         comboBox.addSelectionListener(getSelectionListener());
663         
664         Label placeHolder= new Label(parent, SWT.NONE);
665         placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
666         
667         String JavaDoc currValue= (String JavaDoc)fWorkingValues.get(key);
668         comboBox.select(data.getSelection(currValue));
669         
670         fProblemLabels.add(labelControl);
671         fComboBoxes.add(comboBox);
672         return comboBox;
673     }
674     
675     protected SelectionListener getSelectionListener() {
676         if (fSelectionListener == null) {
677             fSelectionListener= new SelectionListener() {
678                 public void widgetDefaultSelected(SelectionEvent e) {}
679     
680                 public void widgetSelected(SelectionEvent e) {
681                     controlChanged(e.widget);
682                 }
683             };
684         }
685         return fSelectionListener;
686     }
687     
688     protected void controlChanged(Widget widget) {
689         ControlData data= (ControlData) widget.getData();
690         String JavaDoc newValue= null;
691         if (widget instanceof Button) {
692             if (widget == fIgnoreAllProblems) {
693                 updateControlsForProblemReporting(!((Button)widget).getSelection());
694                 return;
695             }
696             newValue= data.getValue(((Button)widget).getSelection());
697         } else if (widget instanceof Combo) {
698             newValue= data.getValue(((Combo)widget).getSelectionIndex());
699         } else {
700             return;
701         }
702         fWorkingValues.put(data.getKey(), newValue);
703     }
704     
705     private void updateControlsForProblemReporting(boolean reportProblems) {
706         for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
707             ((Control) fComboBoxes.get(i)).setEnabled(reportProblems);
708             ((Control) fProblemLabels.get(i)).setEnabled(reportProblems);
709         }
710         fSeverityLabel.setEnabled(reportProblems);
711         fBuildFilesToIgnoreProblems.setEnabled(reportProblems);
712         fBuildFilesToIgnoreProblemsDescription.setEnabled(reportProblems);
713         fBuildFilesToIgnoreProblemsLabel.setEnabled(reportProblems);
714     }
715
716     protected void updateControls() {
717         // update the UI
718
for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
719             Combo curr= (Combo) fComboBoxes.get(i);
720             ControlData data= (ControlData) curr.getData();
721             
722             String JavaDoc currValue= (String JavaDoc) fWorkingValues.get(data.getKey());
723             curr.select(data.getSelection(currValue));
724         }
725     }
726     
727     /* (non-Javadoc)
728      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
729      */

730     public boolean performOk() {
731         Iterator JavaDoc iter= fWorkingValues.keySet().iterator();
732         IPreferenceStore store= getPreferenceStore();
733         while (iter.hasNext()) {
734             String JavaDoc key = (String JavaDoc) iter.next();
735             store.putValue(key, (String JavaDoc)fWorkingValues.get(key));
736         }
737         if (store.needsSaving()) {
738             //any AntModels listen for changes to the "PROBLEM" pref
739
//this is so that the models do not update for each and every pref modification
740
store.putValue(AntEditorPreferenceConstants.PROBLEM, "changed"); //$NON-NLS-1$
741
//ensure to clear as there may not be any models open currently
742
store.setToDefault(AntEditorPreferenceConstants.PROBLEM);
743         }
744         return super.performOk();
745     }
746     
747     private void createHeader(Composite contents) {
748         final Link link= new Link(contents, SWT.NONE);
749         final String JavaDoc target= "org.eclipse.ui.preferencePages.GeneralTextEditor"; //$NON-NLS-1$
750
link.setText(AntPreferencesMessages.AntEditorPreferencePage_0);
751         link.addSelectionListener(new SelectionAdapter() {
752             public void widgetSelected(SelectionEvent e) {
753                 PreferencesUtil.createPreferenceDialogOn(link.getShell(), target, null, null);
754             }
755         });
756         String JavaDoc linktooltip= AntPreferencesMessages.AntEditorPreferencePage_3;
757         link.setToolTipText(linktooltip);
758     }
759 }
760
Popular Tags