integration of cia.navi.cx
[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
26 /**
27  * Abstract preference page which is used to wrap a
28  * {@link net.sourceforge.phpdt.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 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                 fConfigurationBlock.createControl(parent);
77
78                 initialize();
79
80                 Dialog.applyDialogFont(parent);
81                 return parent;
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                 PHPeclipsePlugin.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 }