Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / preferences / AbstractConfigurationBlockPreferencePage.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.preferences;
13
14 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
15 import net.sourceforge.phpeclipse.ui.WebUI;
16
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.preference.PreferencePage;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.IWorkbench;
22 import org.eclipse.ui.IWorkbenchPreferencePage;
23 import org.eclipse.ui.PlatformUI;
24
25 /**
26  * Abstract preference page which is used to wrap a
27  * {@link net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock}.
28  * 
29  * @since 3.0
30  */
31 public abstract class AbstractConfigurationBlockPreferencePage extends
32                 PreferencePage implements IWorkbenchPreferencePage {
33
34         private IPreferenceConfigurationBlock fConfigurationBlock;
35
36         private OverlayPreferenceStore fOverlayStore;
37
38         /**
39          * Creates a new preference page.
40          */
41         public AbstractConfigurationBlockPreferencePage() {
42                 setDescription();
43                 setPreferenceStore();
44                 fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(),
45                                 new OverlayPreferenceStore.OverlayKey[] {});
46                 fConfigurationBlock = createConfigurationBlock(fOverlayStore);
47         }
48
49         protected abstract IPreferenceConfigurationBlock createConfigurationBlock(
50                         OverlayPreferenceStore overlayPreferenceStore);
51
52         protected abstract String getHelpId();
53
54         protected abstract void setDescription();
55
56         protected abstract void setPreferenceStore();
57
58         /*
59          * @see IWorkbenchPreferencePage#init()
60          */
61         public void init(IWorkbench workbench) {
62         }
63
64         /*
65          * @see PreferencePage#createControl(Composite)
66          */
67         public void createControl(Composite parent) {
68                 super.createControl(parent);
69                 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
70                                 getHelpId());
71         }
72
73         /*
74          * @see PreferencePage#createContents(Composite)
75          */
76         protected Control createContents(Composite parent) {
77
78                 fOverlayStore.load();
79                 fOverlayStore.start();
80
81                 fConfigurationBlock.createControl(parent);
82
83                 initialize();
84
85                 Dialog.applyDialogFont(parent);
86                 return parent;
87         }
88
89         private void initialize() {
90                 fConfigurationBlock.initialize();
91         }
92
93         /*
94          * @see PreferencePage#performOk()
95          */
96         public boolean performOk() {
97
98                 fConfigurationBlock.performOk();
99
100                 fOverlayStore.propagate();
101
102                 WebUI.getDefault().savePluginPreferences();
103
104                 return true;
105         }
106
107         /*
108          * @see PreferencePage#performDefaults()
109          */
110         public void performDefaults() {
111
112                 fOverlayStore.loadDefaults();
113                 fConfigurationBlock.performDefaults();
114
115                 super.performDefaults();
116         }
117
118         /*
119          * @see DialogPage#dispose()
120          */
121         public void dispose() {
122
123                 fConfigurationBlock.dispose();
124
125                 if (fOverlayStore != null) {
126                         fOverlayStore.stop();
127                         fOverlayStore = null;
128                 }
129
130                 super.dispose();
131         }
132 }