KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > 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.ui.internal.editors.text;
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 /**
25  * Abstract preference page which is used to wrap a
26  * {@link org.eclipse.ui.internal.editors.text.IPreferenceConfigurationBlock}.
27  *
28  * @since 3.0
29  */

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

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

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

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

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

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

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

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