KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.internal.ui.preferences;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23 import org.eclipse.jface.preference.IPreferenceStore;
24 import org.eclipse.jface.preference.PreferencePage;
25 import org.eclipse.jface.resource.JFaceResources;
26
27 import org.eclipse.ui.IWorkbench;
28 import org.eclipse.ui.IWorkbenchPreferencePage;
29 import org.eclipse.ui.PlatformUI;
30
31 import org.eclipse.jdt.ui.PreferenceConstants;
32
33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
34 import org.eclipse.jdt.internal.ui.JavaPlugin;
35 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
36 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
37 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
38 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
39 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
40 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
41 import org.eclipse.jdt.internal.ui.wizards.dialogfields.Separator;
42 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
43
44 public class AppearancePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
45
46     private static final String JavaDoc SHOW_CU_CHILDREN= PreferenceConstants.SHOW_CU_CHILDREN;
47     private static final String JavaDoc PREF_METHOD_RETURNTYPE= PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE;
48     private static final String JavaDoc PREF_METHOD_TYPEPARAMETERS= PreferenceConstants.APPEARANCE_METHOD_TYPEPARAMETERS;
49     private static final String JavaDoc PREF_COMPRESS_PACKAGE_NAMES= PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES;
50     private static final String JavaDoc PREF_PKG_NAME_PATTERN_FOR_PKG_VIEW= PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW;
51     private static final String JavaDoc STACK_BROWSING_VIEWS_VERTICALLY= PreferenceConstants.BROWSING_STACK_VERTICALLY;
52     private static final String JavaDoc PREF_FOLD_PACKAGES_IN_PACKAGE_EXPLORER= PreferenceConstants.APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER;
53     private static final String JavaDoc PREF_CATEGORY= PreferenceConstants.APPEARANCE_CATEGORY;
54     
55     public static final String JavaDoc PREF_COLORED_LABELS= "colored_labels_in_views"; //$NON-NLS-1$
56

57
58     private SelectionButtonDialogField fShowMethodReturnType;
59     private SelectionButtonDialogField fShowCategory;
60     private SelectionButtonDialogField fCompressPackageNames;
61     private SelectionButtonDialogField fStackBrowsingViewsVertically;
62     private SelectionButtonDialogField fShowMembersInPackageView;
63     private StringDialogField fPackageNamePattern;
64     private SelectionButtonDialogField fFoldPackagesInPackageExplorer;
65     private SelectionButtonDialogField fShowMethodTypeParameters;
66     private SelectionButtonDialogField fShowColoredLabels;
67     
68     public AppearancePreferencePage() {
69         setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
70         setDescription(PreferencesMessages.AppearancePreferencePage_description);
71     
72         IDialogFieldListener listener= new IDialogFieldListener() {
73             public void dialogFieldChanged(DialogField field) {
74                 doDialogFieldChanged(field);
75             }
76         };
77     
78         fShowMethodReturnType= new SelectionButtonDialogField(SWT.CHECK);
79         fShowMethodReturnType.setDialogFieldListener(listener);
80         fShowMethodReturnType.setLabelText(PreferencesMessages.AppearancePreferencePage_methodreturntype_label);
81
82         fShowMethodTypeParameters= new SelectionButtonDialogField(SWT.CHECK);
83         fShowMethodTypeParameters.setDialogFieldListener(listener);
84         fShowMethodTypeParameters.setLabelText(PreferencesMessages.AppearancePreferencePage_methodtypeparams_label);
85
86         fShowCategory= new SelectionButtonDialogField(SWT.CHECK);
87         fShowCategory.setDialogFieldListener(listener);
88         fShowCategory.setLabelText(PreferencesMessages.AppearancePreferencePage_showCategory_label);
89         
90         fShowMembersInPackageView= new SelectionButtonDialogField(SWT.CHECK);
91         fShowMembersInPackageView.setDialogFieldListener(listener);
92         fShowMembersInPackageView.setLabelText(PreferencesMessages.AppearancePreferencePage_showMembersInPackagesView);
93
94         fStackBrowsingViewsVertically= new SelectionButtonDialogField(SWT.CHECK);
95         fStackBrowsingViewsVertically.setDialogFieldListener(listener);
96         fStackBrowsingViewsVertically.setLabelText(PreferencesMessages.AppearancePreferencePage_stackViewsVerticallyInTheJavaBrowsingPerspective);
97
98         fFoldPackagesInPackageExplorer= new SelectionButtonDialogField(SWT.CHECK);
99         fFoldPackagesInPackageExplorer.setDialogFieldListener(listener);
100         fFoldPackagesInPackageExplorer.setLabelText(PreferencesMessages.AppearancePreferencePage_foldEmptyPackages);
101
102         fCompressPackageNames= new SelectionButtonDialogField(SWT.CHECK);
103         fCompressPackageNames.setDialogFieldListener(listener);
104         fCompressPackageNames.setLabelText(PreferencesMessages.AppearancePreferencePage_pkgNamePatternEnable_label);
105
106         fPackageNamePattern= new StringDialogField();
107         fPackageNamePattern.setDialogFieldListener(listener);
108         fPackageNamePattern.setLabelText(PreferencesMessages.AppearancePreferencePage_pkgNamePattern_label);
109         
110         fShowColoredLabels= new SelectionButtonDialogField(SWT.CHECK);
111         fShowColoredLabels.setDialogFieldListener(listener);
112         fShowColoredLabels.setLabelText(PreferencesMessages.AppearancePreferencePage_coloredlabels_label);
113     }
114
115     private void initFields() {
116         IPreferenceStore prefs= getPreferenceStore();
117         fShowMethodReturnType.setSelection(prefs.getBoolean(PREF_METHOD_RETURNTYPE));
118         fShowMethodTypeParameters.setSelection(prefs.getBoolean(PREF_METHOD_TYPEPARAMETERS));
119         fShowMembersInPackageView.setSelection(prefs.getBoolean(SHOW_CU_CHILDREN));
120         fShowCategory.setSelection(prefs.getBoolean(PREF_CATEGORY));
121         fStackBrowsingViewsVertically.setSelection(prefs.getBoolean(STACK_BROWSING_VIEWS_VERTICALLY));
122         fPackageNamePattern.setText(prefs.getString(PREF_PKG_NAME_PATTERN_FOR_PKG_VIEW));
123         fCompressPackageNames.setSelection(prefs.getBoolean(PREF_COMPRESS_PACKAGE_NAMES));
124         fPackageNamePattern.setEnabled(fCompressPackageNames.isSelected());
125         fFoldPackagesInPackageExplorer.setSelection(prefs.getBoolean(PREF_FOLD_PACKAGES_IN_PACKAGE_EXPLORER));
126         
127         fShowColoredLabels.setSelection(prefs.getBoolean(PREF_COLORED_LABELS));
128     }
129     
130     /*
131      * @see PreferencePage#createControl(Composite)
132      */

133     public void createControl(Composite parent) {
134         super.createControl(parent);
135         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.APPEARANCE_PREFERENCE_PAGE);
136     }
137
138     /*
139      * @see PreferencePage#createContents(Composite)
140      */

141     protected Control createContents(Composite parent) {
142         initializeDialogUnits(parent);
143         int nColumns= 1;
144                 
145         Composite result= new Composite(parent, SWT.NONE);
146         result.setFont(parent.getFont());
147         
148         GridLayout layout= new GridLayout();
149         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
150         layout.marginWidth= 0;
151         layout.numColumns= nColumns;
152         result.setLayout(layout);
153                 
154         fShowMethodReturnType.doFillIntoGrid(result, nColumns);
155         fShowMethodTypeParameters.doFillIntoGrid(result, nColumns);
156         fShowCategory.doFillIntoGrid(result, nColumns);
157         fShowMembersInPackageView.doFillIntoGrid(result, nColumns);
158         fShowColoredLabels.doFillIntoGrid(result, nColumns);
159         fFoldPackagesInPackageExplorer.doFillIntoGrid(result, nColumns);
160
161         new Separator().doFillIntoGrid(result, nColumns);
162         
163         fCompressPackageNames.doFillIntoGrid(result, nColumns);
164         fPackageNamePattern.doFillIntoGrid(result, 2);
165         LayoutUtil.setHorizontalGrabbing(fPackageNamePattern.getTextControl(null));
166         LayoutUtil.setWidthHint(fPackageNamePattern.getLabelControl(null), convertWidthInCharsToPixels(65));
167         
168         new Separator().doFillIntoGrid(result, nColumns);
169         fStackBrowsingViewsVertically.doFillIntoGrid(result, nColumns);
170         
171         String JavaDoc noteTitle= PreferencesMessages.AppearancePreferencePage_note;
172         String JavaDoc noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives;
173         Composite noteControl= createNoteComposite(JFaceResources.getDialogFont(), result, noteTitle, noteMessage);
174         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
175         gd.horizontalSpan= 2;
176         noteControl.setLayoutData(gd);
177         
178         initFields();
179         
180         Dialog.applyDialogFont(result);
181         return result;
182     }
183     
184     private void doDialogFieldChanged(DialogField field) {
185         if (field == fCompressPackageNames)
186             fPackageNamePattern.setEnabled(fCompressPackageNames.isSelected());
187     
188         updateStatus(getValidationStatus());
189     }
190     
191     private IStatus getValidationStatus(){
192         if (fCompressPackageNames.isSelected() && fPackageNamePattern.getText().equals("")) //$NON-NLS-1$
193
return new StatusInfo(IStatus.ERROR, PreferencesMessages.AppearancePreferencePage_packageNameCompressionPattern_error_isEmpty);
194         else
195             return new StatusInfo();
196     }
197     
198     private void updateStatus(IStatus status) {
199         setValid(!status.matches(IStatus.ERROR));
200         StatusUtil.applyToStatusLine(this, status);
201     }
202     
203     /*
204      * @see IWorkbenchPreferencePage#init(IWorkbench)
205      */

206     public void init(IWorkbench workbench) {
207     }
208     
209     /*
210      * @see IPreferencePage#performOk()
211      */

212     public boolean performOk() {
213         IPreferenceStore prefs= getPreferenceStore();
214         prefs.setValue(PREF_METHOD_RETURNTYPE, fShowMethodReturnType.isSelected());
215         prefs.setValue(PREF_METHOD_TYPEPARAMETERS, fShowMethodTypeParameters.isSelected());
216         prefs.setValue(PREF_CATEGORY, fShowCategory.isSelected());
217         prefs.setValue(SHOW_CU_CHILDREN, fShowMembersInPackageView.isSelected());
218         prefs.setValue(STACK_BROWSING_VIEWS_VERTICALLY, fStackBrowsingViewsVertically.isSelected());
219         prefs.setValue(PREF_PKG_NAME_PATTERN_FOR_PKG_VIEW, fPackageNamePattern.getText());
220         prefs.setValue(PREF_COMPRESS_PACKAGE_NAMES, fCompressPackageNames.isSelected());
221         prefs.setValue(PREF_FOLD_PACKAGES_IN_PACKAGE_EXPLORER, fFoldPackagesInPackageExplorer.isSelected());
222         prefs.setValue(PREF_COLORED_LABELS, fShowColoredLabels.isSelected());
223         JavaPlugin.getDefault().savePluginPreferences();
224         return super.performOk();
225     }
226     
227     /*
228      * @see PreferencePage#performDefaults()
229      */

230     protected void performDefaults() {
231         IPreferenceStore prefs= getPreferenceStore();
232         fShowMethodReturnType.setSelection(prefs.getDefaultBoolean(PREF_METHOD_RETURNTYPE));
233         fShowMethodTypeParameters.setSelection(prefs.getDefaultBoolean(PREF_METHOD_TYPEPARAMETERS));
234         fShowCategory.setSelection(prefs.getDefaultBoolean(PREF_CATEGORY));
235         fShowMembersInPackageView.setSelection(prefs.getDefaultBoolean(SHOW_CU_CHILDREN));
236         fStackBrowsingViewsVertically.setSelection(prefs.getDefaultBoolean(STACK_BROWSING_VIEWS_VERTICALLY));
237         fPackageNamePattern.setText(prefs.getDefaultString(PREF_PKG_NAME_PATTERN_FOR_PKG_VIEW));
238         fCompressPackageNames.setSelection(prefs.getDefaultBoolean(PREF_COMPRESS_PACKAGE_NAMES));
239         fFoldPackagesInPackageExplorer.setSelection(prefs.getDefaultBoolean(PREF_FOLD_PACKAGES_IN_PACKAGE_EXPLORER));
240         fShowColoredLabels.setSelection(false);
241         super.performDefaults();
242     }
243 }
244
245
Popular Tags