KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.jdt.internal.ui.preferences;
13
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.preference.PreferencePage;
19
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchPreferencePage;
22 import org.eclipse.ui.PlatformUI;
23
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25
26 /**
27  * Abstract preference page which is used to wrap a
28  * {@link org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock}.
29  *
30  * @since 3.0
31  */

32 public abstract class AbstractConfigurationBlockPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
33     
34     
35     private IPreferenceConfigurationBlock fConfigurationBlock;
36     private OverlayPreferenceStore fOverlayStore;
37     
38
39     /**
40      * Creates a new preference page.
41      */

42     public AbstractConfigurationBlockPreferencePage() {
43         setDescription();
44         setPreferenceStore();
45         fOverlayStore= new OverlayPreferenceStore(getPreferenceStore(), new OverlayPreferenceStore.OverlayKey[] {});
46         fConfigurationBlock= createConfigurationBlock(fOverlayStore);
47     }
48         
49     protected abstract IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore);
50     protected abstract String JavaDoc getHelpId();
51     protected abstract void setDescription();
52     protected abstract void setPreferenceStore();
53     
54     /*
55      * @see IWorkbenchPreferencePage#init()
56      */

57     public void init(IWorkbench workbench) {
58     }
59
60     /*
61      * @see PreferencePage#createControl(Composite)
62      */

63     public void createControl(Composite parent) {
64         super.createControl(parent);
65         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId());
66     }
67     
68     /*
69      * @see PreferencePage#createContents(Composite)
70      */

71     protected Control createContents(Composite parent) {
72         
73         fOverlayStore.load();
74         fOverlayStore.start();
75         
76         Control content= fConfigurationBlock.createControl(parent);
77         
78         initialize();
79         
80         Dialog.applyDialogFont(content);
81         return content;
82     }
83     
84     private void initialize() {
85         fConfigurationBlock.initialize();
86     }
87     
88     /*
89      * @see PreferencePage#performOk()
90      */

91     public boolean performOk() {
92         
93         fConfigurationBlock.performOk();
94
95         fOverlayStore.propagate();
96         
97         JavaPlugin.getDefault().savePluginPreferences();
98         
99         return true;
100     }
101     
102     /*
103      * @see PreferencePage#performDefaults()
104      */

105     public void performDefaults() {
106         
107         fOverlayStore.loadDefaults();
108         fConfigurationBlock.performDefaults();
109
110         super.performDefaults();
111     }
112     
113     /*
114      * @see DialogPage#dispose()
115      */

116     public void dispose() {
117         
118         fConfigurationBlock.dispose();
119         
120         if (fOverlayStore != null) {
121             fOverlayStore.stop();
122             fOverlayStore= null;
123         }
124         
125         super.dispose();
126     }
127 }
128
Popular Tags