Fix nasty bug #706. See trac.
[phpeclipse.git] / net.sourceforge.phpeclipse / 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
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.preference.PreferencePage;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
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 net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock}.
27  * 
28  * @since 3.0
29  */
30 public abstract class AbstractConfigurationBlockPreferencePage extends
31                 PreferencePage implements IWorkbenchPreferencePage {
32
33         private IPreferenceConfigurationBlock fConfigurationBlock;
34
35         private OverlayPreferenceStore fOverlayStore;
36
37         /**
38          * Creates a new preference page.
39          */
40         public AbstractConfigurationBlockPreferencePage() {
41                 setDescription();
42                 setPreferenceStore();
43                 fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(),
44                                 new OverlayPreferenceStore.OverlayKey[] {});
45                 fConfigurationBlock = createConfigurationBlock(fOverlayStore);
46         }
47
48         protected abstract IPreferenceConfigurationBlock createConfigurationBlock(
49                         OverlayPreferenceStore overlayPreferenceStore);
50
51         protected abstract String getHelpId();
52
53         protected abstract void setDescription();
54
55         protected abstract void setPreferenceStore();
56
57         /*
58          * @see IWorkbenchPreferencePage#init()
59          */
60         public void init(IWorkbench workbench) {
61         }
62
63         /*
64          * @see PreferencePage#createControl(Composite)
65          */
66         public void createControl(Composite parent) {
67                 super.createControl(parent);
68                 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
69                                 getHelpId());
70         }
71
72         /*
73          * @see PreferencePage#createContents(Composite)
74          */
75         protected Control createContents(Composite parent) {
76
77                 fOverlayStore.load();
78                 fOverlayStore.start();
79
80                 fConfigurationBlock.createControl(parent);
81
82                 initialize();
83
84                 Dialog.applyDialogFont(parent);
85                 return parent;
86         }
87
88         private void initialize() {
89                 fConfigurationBlock.initialize();
90         }
91
92         /*
93          * @see PreferencePage#performOk()
94          */
95         public boolean performOk() {
96
97                 fConfigurationBlock.performOk();
98
99                 fOverlayStore.propagate();
100
101                 PHPeclipsePlugin.getDefault().savePluginPreferences();
102
103                 return true;
104         }
105
106         /*
107          * @see PreferencePage#performDefaults()
108          */
109         public void performDefaults() {
110
111                 fOverlayStore.loadDefaults();
112                 fConfigurationBlock.performDefaults();
113
114                 super.performDefaults();
115         }
116
117         /*
118          * @see DialogPage#dispose()
119          */
120         public void dispose() {
121
122                 fConfigurationBlock.dispose();
123
124                 if (fOverlayStore != null) {
125                         fOverlayStore.stop();
126                         fOverlayStore = null;
127                 }
128
129                 super.dispose();
130         }
131 }