KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.events.SelectionListener;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Group;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26
27 import org.eclipse.jface.dialogs.Dialog;
28 import org.eclipse.jface.dialogs.IDialogConstants;
29 import org.eclipse.jface.dialogs.MessageDialog;
30 import org.eclipse.jface.preference.IPreferenceStore;
31 import org.eclipse.jface.preference.PreferencePage;
32
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.IWorkbenchPreferencePage;
35 import org.eclipse.ui.PlatformUI;
36
37 import org.eclipse.jdt.ui.PreferenceConstants;
38
39 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
40 import org.eclipse.jdt.internal.ui.JavaPlugin;
41 import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
42 import org.eclipse.jdt.internal.ui.refactoring.RefactoringSavePreferences;
43 import org.eclipse.jdt.internal.ui.util.SWTUtil;
44     
45 /*
46  * The page for setting general java plugin preferences.
47  * See PreferenceConstants to access or change these values through public API.
48  */

49 public class JavaBasePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
50     
51     public static final String JavaDoc JAVA_BASE_PREF_PAGE_ID= "org.eclipse.jdt.ui.preferences.JavaBasePreferencePage"; //$NON-NLS-1$
52

53     private static final String JavaDoc OPEN_TYPE_HIERARCHY= PreferenceConstants.OPEN_TYPE_HIERARCHY;
54     private static final String JavaDoc OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE= PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE;
55     private static final String JavaDoc OPEN_TYPE_HIERARCHY_IN_VIEW_PART= PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_VIEW_PART;
56
57     private static final String JavaDoc DOUBLE_CLICK= PreferenceConstants.DOUBLE_CLICK;
58     private static final String JavaDoc DOUBLE_CLICK_GOES_INTO= PreferenceConstants.DOUBLE_CLICK_GOES_INTO;
59     private static final String JavaDoc DOUBLE_CLICK_EXPANDS= PreferenceConstants.DOUBLE_CLICK_EXPANDS;
60
61     private ArrayList JavaDoc fCheckBoxes;
62     private ArrayList JavaDoc fRadioButtons;
63     private ArrayList JavaDoc fTextControls;
64     
65     public JavaBasePreferencePage() {
66         super();
67         setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
68         setDescription(PreferencesMessages.JavaBasePreferencePage_description);
69     
70         fRadioButtons= new ArrayList JavaDoc();
71         fCheckBoxes= new ArrayList JavaDoc();
72         fTextControls= new ArrayList JavaDoc();
73     }
74
75     /*
76      * @see IWorkbenchPreferencePage#init(IWorkbench)
77      */

78     public void init(IWorkbench workbench) {
79     }
80     
81     /*
82      * @see PreferencePage#createControl(Composite)
83      */

84     public void createControl(Composite parent) {
85         super.createControl(parent);
86         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.JAVA_BASE_PREFERENCE_PAGE);
87     }
88
89     private Button addRadioButton(Composite parent, String JavaDoc label, String JavaDoc key, String JavaDoc value) {
90         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
91         
92         Button button= new Button(parent, SWT.RADIO);
93         button.setText(label);
94         button.setData(new String JavaDoc[] { key, value });
95         button.setLayoutData(gd);
96
97         button.setSelection(value.equals(getPreferenceStore().getString(key)));
98         
99         fRadioButtons.add(button);
100         return button;
101     }
102     
103     private Button addCheckBox(Composite parent, String JavaDoc label, String JavaDoc key) {
104         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
105         
106         Button button= new Button(parent, SWT.CHECK);
107         button.setText(label);
108         button.setData(key);
109         button.setLayoutData(gd);
110
111         button.setSelection(getPreferenceStore().getBoolean(key));
112         
113         fCheckBoxes.add(button);
114         return button;
115     }
116     
117     protected Control createContents(Composite parent) {
118         initializeDialogUnits(parent);
119         
120         Composite result= new Composite(parent, SWT.NONE);
121         GridLayout layout= new GridLayout();
122         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
123         layout.marginWidth= 0;
124         layout.verticalSpacing= convertVerticalDLUsToPixels(10);
125         layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
126         result.setLayout(layout);
127         
128         // new Label(composite, SWT.NONE); // spacer
129
// Group linkSettings= new Group(result, SWT.NONE);
130
// linkSettings.setLayout(new GridLayout());
131
// linkSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132
// linkSettings.setText(PreferencesMessages.getString("JavaBasePreferencePage.linkSettings.text")); //$NON-NLS-1$
133
//addCheckBox(linkSettings, PreferencesMessages.getString("JavaBasePreferencePage.linkJavaBrowsingViewsCheckbox.text"), LINK_BROWSING_VIEW_TO_EDITOR); //$NON-NLS-1$
134
//addCheckBox(linkSettings, PreferencesMessages.getString("JavaBasePreferencePage.linkPackageView"), LINK_PACKAGES_TO_EDITOR); //$NON-NLS-1$
135
//addCheckBox(linkSettings, PreferencesMessages.getString("JavaBasePreferencePage.linkTypeHierarchy"), LINK_TYPEHIERARCHY_TO_EDITOR); //$NON-NLS-1$
136

137         // new Label(result, SWT.NONE); // spacer
138

139         Group doubleClickGroup= new Group(result, SWT.NONE);
140         doubleClickGroup.setLayout(new GridLayout());
141         doubleClickGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
142         doubleClickGroup.setText(PreferencesMessages.JavaBasePreferencePage_doubleclick_action);
143         addRadioButton(doubleClickGroup, PreferencesMessages.JavaBasePreferencePage_doubleclick_gointo, DOUBLE_CLICK, DOUBLE_CLICK_GOES_INTO);
144         addRadioButton(doubleClickGroup, PreferencesMessages.JavaBasePreferencePage_doubleclick_expand, DOUBLE_CLICK, DOUBLE_CLICK_EXPANDS);
145
146         // new Label(result, SWT.NONE); // spacer
147

148         Group typeHierarchyGroup= new Group(result, SWT.NONE);
149         typeHierarchyGroup.setLayout(new GridLayout());
150         typeHierarchyGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
151         typeHierarchyGroup.setText(PreferencesMessages.JavaBasePreferencePage_openTypeHierarchy);
152         addRadioButton(typeHierarchyGroup, PreferencesMessages.JavaBasePreferencePage_inPerspective, OPEN_TYPE_HIERARCHY, OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE);
153         addRadioButton(typeHierarchyGroup, PreferencesMessages.JavaBasePreferencePage_inView, OPEN_TYPE_HIERARCHY, OPEN_TYPE_HIERARCHY_IN_VIEW_PART);
154
155         Group refactoringGroup= new Group(result, SWT.NONE);
156         refactoringGroup.setLayout(new GridLayout());
157         refactoringGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
158         refactoringGroup.setText(PreferencesMessages.JavaBasePreferencePage_refactoring_title);
159         addCheckBox(refactoringGroup,
160             PreferencesMessages.JavaBasePreferencePage_refactoring_auto_save,
161             RefactoringSavePreferences.PREF_SAVE_ALL_EDITORS);
162         addCheckBox(refactoringGroup,
163                 PreferencesMessages.JavaBasePreferencePage_refactoring_lightweight,
164                 PreferenceConstants.REFACTOR_LIGHTWEIGHT);
165
166         Group group= new Group(result, SWT.NONE);
167         group.setLayout(new GridLayout());
168         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
169         group.setText(PreferencesMessages.JavaBasePreferencePage_search);
170         
171         addCheckBox(group, PreferencesMessages.JavaBasePreferencePage_search_small_menu, PreferenceConstants.SEARCH_USE_REDUCED_MENU);
172
173         
174         layout= new GridLayout();
175         layout.numColumns= 2;
176         
177         Group dontAskGroup= new Group(result, SWT.NONE);
178         dontAskGroup.setLayout(layout);
179         dontAskGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
180         dontAskGroup.setText(PreferencesMessages.JavaBasePreferencePage_dialogs);
181         
182         Label label= new Label(dontAskGroup, SWT.WRAP);
183         label.setText(PreferencesMessages.JavaBasePreferencePage_do_not_hide_description);
184         GridData data= new GridData(GridData.FILL, GridData.CENTER, true, false);
185         data.widthHint= convertVerticalDLUsToPixels(50);
186         label.setLayoutData(data);
187         
188         Button clearButton= new Button(dontAskGroup, SWT.PUSH);
189         clearButton.setText(PreferencesMessages.JavaBasePreferencePage_do_not_hide_button);
190         clearButton.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
191         clearButton.addSelectionListener(new SelectionListener() {
192             public void widgetSelected(SelectionEvent e) {
193                 unhideAllDialogs();
194             }
195             public void widgetDefaultSelected(SelectionEvent e) {
196                 unhideAllDialogs();
197             }
198         });
199         
200         
201         SWTUtil.setButtonDimensionHint(clearButton);
202         Dialog.applyDialogFont(result);
203         return result;
204     }
205     
206     protected final void unhideAllDialogs() {
207         OptionalMessageDialog.clearAllRememberedStates();
208         MessageDialog.openInformation(getShell(), PreferencesMessages.JavaBasePreferencePage_do_not_hide_dialog_title, PreferencesMessages.JavaBasePreferencePage_do_not_hide_dialog_message);
209     }
210
211     /*
212      * @see PreferencePage#performDefaults()
213      */

214     protected void performDefaults() {
215         IPreferenceStore store= getPreferenceStore();
216         for (int i= 0; i < fCheckBoxes.size(); i++) {
217             Button button= (Button) fCheckBoxes.get(i);
218             String JavaDoc key= (String JavaDoc) button.getData();
219             button.setSelection(store.getDefaultBoolean(key));
220         }
221         for (int i= 0; i < fRadioButtons.size(); i++) {
222             Button button= (Button) fRadioButtons.get(i);
223             String JavaDoc[] info= (String JavaDoc[]) button.getData();
224             button.setSelection(info[1].equals(store.getDefaultString(info[0])));
225         }
226         for (int i= 0; i < fTextControls.size(); i++) {
227             Text text= (Text) fTextControls.get(i);
228             String JavaDoc key= (String JavaDoc) text.getData();
229             text.setText(store.getDefaultString(key));
230         }
231         super.performDefaults();
232     }
233
234     /*
235      * @see IPreferencePage#performOk()
236      */

237     public boolean performOk() {
238         IPreferenceStore store= getPreferenceStore();
239         for (int i= 0; i < fCheckBoxes.size(); i++) {
240             Button button= (Button) fCheckBoxes.get(i);
241             String JavaDoc key= (String JavaDoc) button.getData();
242             store.setValue(key, button.getSelection());
243         }
244         for (int i= 0; i < fRadioButtons.size(); i++) {
245             Button button= (Button) fRadioButtons.get(i);
246             if (button.getSelection()) {
247                 String JavaDoc[] info= (String JavaDoc[]) button.getData();
248                 store.setValue(info[0], info[1]);
249             }
250         }
251         for (int i= 0; i < fTextControls.size(); i++) {
252             Text text= (Text) fTextControls.get(i);
253             String JavaDoc key= (String JavaDoc) text.getData();
254             store.setValue(key, text.getText());
255         }
256         
257         JavaPlugin.getDefault().savePluginPreferences();
258         return super.performOk();
259     }
260
261
262 }
263
264
265
Popular Tags