KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.internal.ui.preferences;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Text;
24
25 import org.eclipse.jface.dialogs.IDialogConstants;
26 import org.eclipse.jface.preference.IPreferenceStore;
27 import org.eclipse.jface.preference.PreferencePage;
28
29 import org.eclipse.ui.IWorkbench;
30 import org.eclipse.ui.IWorkbenchPreferencePage;
31 import org.eclipse.ui.PlatformUI;
32
33 import org.eclipse.jdt.internal.ui.JavaPlugin;
34
35 /**
36  * Preference page for work in progress.
37  */

38 public class WorkInProgressPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
39
40     private List JavaDoc fCheckBoxes;
41     private List JavaDoc fRadioButtons;
42     private List JavaDoc fTextControls;
43     
44     /**
45      * creates a new preference page.
46      */

47     public WorkInProgressPreferencePage() {
48         setPreferenceStore(getPreferenceStore());
49         fRadioButtons= new ArrayList JavaDoc();
50         fCheckBoxes= new ArrayList JavaDoc();
51         fTextControls= new ArrayList JavaDoc();
52     }
53
54     Button addCheckBox(Composite parent, String JavaDoc label, String JavaDoc key) {
55         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
56         
57         Button button= new Button(parent, SWT.CHECK);
58         button.setText(label);
59         button.setData(key);
60         button.setLayoutData(gd);
61
62         button.setSelection(getPreferenceStore().getBoolean(key));
63         
64         fCheckBoxes.add(button);
65         return button;
66     }
67     
68     /*
69      * @see PreferencePage#createControl(Composite)
70      */

71     public void createControl(Composite parent) {
72         super.createControl(parent);
73         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), "WORK_IN_PROGRESS_PREFERENCE_PAGE"); //$NON-NLS-1$
74
}
75
76     protected Control createContents(Composite parent) {
77         initializeDialogUnits(parent);
78         
79         Composite result= new Composite(parent, SWT.NONE);
80         GridLayout layout= new GridLayout();
81         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
82         layout.marginWidth= 0;
83         layout.verticalSpacing= convertVerticalDLUsToPixels(10);
84         layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
85         result.setLayout(layout);
86
87         // Add your controls here
88

89         applyDialogFont(result);
90         return result;
91     }
92     
93  
94     /*
95      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
96      */

97     public void init(IWorkbench workbench) {
98     }
99
100     protected void createSpacer(Composite composite, int columnSpan) {
101         Label label= new Label(composite, SWT.NONE);
102         GridData gd= new GridData();
103         gd.horizontalSpan= columnSpan;
104         label.setLayoutData(gd);
105     }
106
107     /*
108      * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()
109      */

110     protected IPreferenceStore doGetPreferenceStore() {
111         return JavaPlugin.getDefault().getPreferenceStore();
112     }
113
114     /*
115      * @see PreferencePage#performDefaults()
116      */

117     protected void performDefaults() {
118         IPreferenceStore store= getPreferenceStore();
119         for (int i= 0; i < fCheckBoxes.size(); i++) {
120             Button button= (Button) fCheckBoxes.get(i);
121             String JavaDoc key= (String JavaDoc) button.getData();
122             button.setSelection(store.getDefaultBoolean(key));
123         }
124         for (int i= 0; i < fRadioButtons.size(); i++) {
125             Button button= (Button) fRadioButtons.get(i);
126             String JavaDoc[] info= (String JavaDoc[]) button.getData();
127             button.setSelection(info[1].equals(store.getDefaultString(info[0])));
128         }
129         for (int i= 0; i < fTextControls.size(); i++) {
130             Text text= (Text) fTextControls.get(i);
131             String JavaDoc key= (String JavaDoc) text.getData();
132             text.setText(store.getDefaultString(key));
133         }
134         
135         super.performDefaults();
136     }
137
138     /*
139      * @see IPreferencePage#performOk()
140      */

141     public boolean performOk() {
142         IPreferenceStore store= getPreferenceStore();
143         for (int i= 0; i < fCheckBoxes.size(); i++) {
144             Button button= (Button) fCheckBoxes.get(i);
145             String JavaDoc key= (String JavaDoc) button.getData();
146             store.setValue(key, button.getSelection());
147         }
148         for (int i= 0; i < fRadioButtons.size(); i++) {
149             Button button= (Button) fRadioButtons.get(i);
150             if (button.getSelection()) {
151                 String JavaDoc[] info= (String JavaDoc[]) button.getData();
152                 store.setValue(info[0], info[1]);
153             }
154         }
155         for (int i= 0; i < fTextControls.size(); i++) {
156             Text text= (Text) fTextControls.get(i);
157             String JavaDoc key= (String JavaDoc) text.getData();
158             store.setValue(key, text.getText());
159         }
160         
161         JavaPlugin.getDefault().savePluginPreferences();
162         return super.performOk();
163     }
164
165     public static void initDefaults(IPreferenceStore store) {
166         // Initialize your defaults here
167
}
168 }
169
Popular Tags