KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
15 import org.eclipse.jface.preference.PreferenceConverter;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.events.SelectionListener;
20 import org.eclipse.swt.graphics.Font;
21 import org.eclipse.swt.graphics.RGB;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.List;
29
30 /*
31  * The page for setting the Ant editor code assist options.
32  */

33 public class AntCodeAssistPreferencePage extends AbstractAntEditorPreferencePage {
34         
35     private final String JavaDoc[][] fContentAssistColorListModel= new String JavaDoc[][] {
36         {AntPreferencesMessages.AntCodeAssistPreferencePage_backgroundForCompletionProposals, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND },
37         {AntPreferencesMessages.AntCodeAssistPreferencePage_foregroundForCompletionProposals, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND },
38     };
39
40     private List JavaDoc fContentAssistColorList;
41     private ColorEditor fContentAssistColorEditor;
42     
43     private Control fAutoInsertDelayText;
44     private Control fAutoInsertTriggerText;
45     private Label fAutoInsertDelayLabel;
46     private Label fAutoInsertTriggerLabel;
47     
48     protected OverlayPreferenceStore createOverlayStore() {
49         
50         ArrayList JavaDoc overlayKeys= new ArrayList JavaDoc();
51         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION));
52         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
53         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT));
54         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS));
55         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
56         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
57         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS));
58     
59         OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
60         overlayKeys.toArray(keys);
61         return new OverlayPreferenceStore(getPreferenceStore(), keys);
62     }
63     
64     private Control createContentAssistPage(Composite parent) {
65         Font font= parent.getFont();
66         Composite contentAssistComposite= new Composite(parent, SWT.NULL);
67         GridLayout layout= new GridLayout();
68         layout.numColumns= 2;
69         contentAssistComposite.setLayout(layout);
70         contentAssistComposite.setFont(font);
71
72         String JavaDoc text= AntPreferencesMessages.AntCodeAssistPreferencePage_Insert;
73         addCheckBox(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT, 0);
74
75         text= AntPreferencesMessages.AntCodeAssistPreferencePage_0;
76         addCheckBox(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS, 0);
77         
78         text= AntPreferencesMessages.AntCodeAssistPreferencePage__Enable_auto_activation_2;
79         final Button autoactivation= addCheckBox(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION, 0);
80         autoactivation.addSelectionListener(new SelectionAdapter(){
81             public void widgetSelected(SelectionEvent e) {
82                 updateAutoactivationControls();
83             }
84         });
85         
86         Control[] labelledTextField;
87         text= AntPreferencesMessages.AntCodeAssistPreferencePage_Auto_activation__delay__3;
88         String JavaDoc[] errorMessages= new String JavaDoc[]{AntPreferencesMessages.AntCodeAssistPreferencePage_empty_input_auto_activation, AntPreferencesMessages.AntCodeAssistPreferencePage_invalid_input_auto_activation};
89         labelledTextField= addLabelledTextField(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY, 4, 0, errorMessages);
90         fAutoInsertDelayLabel= getLabelControl(labelledTextField);
91         fAutoInsertDelayText= getTextControl(labelledTextField);
92         
93         text= AntPreferencesMessages.AntCodeAssistPreferencePage_Auto_activation_tri_ggers__4;
94         labelledTextField= addLabelledTextField(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS, 4, 0, null);
95         fAutoInsertTriggerLabel= getLabelControl(labelledTextField);
96         fAutoInsertTriggerText= getTextControl(labelledTextField);
97         
98         Label label= new Label(contentAssistComposite, SWT.LEFT);
99         label.setText(AntPreferencesMessages.AntCodeAssistPreferencePage_Code_assist_colo_r_options__5);
100         label.setFont(font);
101         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
102         gd.horizontalSpan= 2;
103         label.setLayoutData(gd);
104
105         Composite editorComposite= new Composite(contentAssistComposite, SWT.NONE);
106         layout= new GridLayout();
107         layout.numColumns= 2;
108         layout.marginHeight= 0;
109         layout.marginWidth= 0;
110         editorComposite.setLayout(layout);
111         editorComposite.setFont(font);
112         gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
113         gd.horizontalSpan= 2;
114         editorComposite.setLayoutData(gd);
115
116         fContentAssistColorList= new List JavaDoc(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
117         gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
118         gd.heightHint= convertHeightInCharsToPixels(3);
119         fContentAssistColorList.setLayoutData(gd);
120         fContentAssistColorList.setFont(font);
121                         
122         Composite stylesComposite= new Composite(editorComposite, SWT.NONE);
123         layout= new GridLayout();
124         layout.marginHeight= 0;
125         layout.marginWidth= 0;
126         layout.numColumns= 2;
127         stylesComposite.setLayout(layout);
128         stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
129         stylesComposite.setFont(font);
130         
131         label= new Label(stylesComposite, SWT.LEFT);
132         label.setText(AntPreferencesMessages.AntEditorPreferencePage_6);
133         label.setFont(font);
134         gd= new GridData();
135         gd.horizontalAlignment= GridData.BEGINNING;
136         label.setLayoutData(gd);
137
138         fContentAssistColorEditor= new ColorEditor(stylesComposite);
139         Button colorButton= fContentAssistColorEditor.getButton();
140         gd= new GridData(GridData.FILL_HORIZONTAL);
141         gd.horizontalAlignment= GridData.BEGINNING;
142         colorButton.setLayoutData(gd);
143
144         fContentAssistColorList.addSelectionListener(new SelectionListener() {
145             public void widgetDefaultSelected(SelectionEvent e) {
146                 // do nothing
147
}
148             public void widgetSelected(SelectionEvent e) {
149                 handleContentAssistColorListSelection();
150             }
151         });
152         
153         colorButton.addSelectionListener(new SelectionListener() {
154             public void widgetDefaultSelected(SelectionEvent e) {
155                 // do nothing
156
}
157             public void widgetSelected(SelectionEvent e) {
158                 int i= fContentAssistColorList.getSelectionIndex();
159                 if (i == -1) { //bug 85590
160
return;
161                 }
162                 String JavaDoc key= fContentAssistColorListModel[i][1];
163                 
164                 PreferenceConverter.setValue(getOverlayStore(), key, fContentAssistColorEditor.getColorValue());
165             }
166         });
167
168         return contentAssistComposite;
169     }
170     
171     private void handleContentAssistColorListSelection() {
172         int i= fContentAssistColorList.getSelectionIndex();
173         if (i == -1) { //bug 85590
174
return;
175         }
176         String JavaDoc key= fContentAssistColorListModel[i][1];
177         RGB rgb= PreferenceConverter.getColor(getOverlayStore(), key);
178         fContentAssistColorEditor.setColorValue(rgb);
179     }
180         
181     private void updateAutoactivationControls() {
182        boolean autoactivation= getOverlayStore().getBoolean(AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION);
183        fAutoInsertDelayText.setEnabled(autoactivation);
184        fAutoInsertDelayLabel.setEnabled(autoactivation);
185
186        fAutoInsertTriggerText.setEnabled(autoactivation);
187        fAutoInsertTriggerLabel.setEnabled(autoactivation);
188    }
189     
190     /* (non-Javadoc)
191      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
192      */

193     protected Control createContents(Composite parent) {
194         getOverlayStore().load();
195         getOverlayStore().start();
196         
197         Composite control= new Composite(parent, SWT.NONE);
198         GridLayout layout= new GridLayout();
199         layout.numColumns= 2;
200         layout.marginHeight= 0;
201         layout.marginWidth= 0;
202         control.setLayout(layout);
203         createContentAssistPage(control);
204                 
205         initialize();
206         
207         applyDialogFont(control);
208         //TODO set help context
209
//WorkbenchHelp.setHelp(control, IAntUIHelpContextIds.ANT_CONTENTASSIST_PREFERENCE_PAGE);
210
return control;
211     }
212     
213     private void initialize() {
214         
215         initializeFields();
216         
217         for (int i= 0; i < fContentAssistColorListModel.length; i++) {
218             fContentAssistColorList.add(fContentAssistColorListModel[i][0]);
219         }
220         fContentAssistColorList.getDisplay().asyncExec(new Runnable JavaDoc() {
221             public void run() {
222                 if (fContentAssistColorList != null && !fContentAssistColorList.isDisposed()) {
223                     fContentAssistColorList.select(0);
224                     handleContentAssistColorListSelection();
225                 }
226             }
227         });
228     }
229     
230     /* (non-Javadoc)
231      * @see org.eclipse.ant.internal.ui.preferences.AbstractAntEditorPreferencePage#handleDefaults()
232      */

233     protected void handleDefaults() {
234         handleContentAssistColorListSelection();
235         updateAutoactivationControls();
236     }
237 }
238
Popular Tags