001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.swt.widgets.Composite;
013: import org.eclipse.swt.widgets.Control;
014:
015: import org.eclipse.jface.dialogs.Dialog;
016: import org.eclipse.jface.preference.PreferencePage;
017:
018: import org.eclipse.ui.IWorkbench;
019: import org.eclipse.ui.IWorkbenchPreferencePage;
020: import org.eclipse.ui.PlatformUI;
021:
022: import org.eclipse.jdt.internal.ui.JavaPlugin;
023:
024: /**
025: * Abstract preference page which is used to wrap a
026: * {@link org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock}.
027: *
028: * @since 3.0
029: */
030: public abstract class AbstractConfigurationBlockPreferencePage extends
031: PreferencePage implements IWorkbenchPreferencePage {
032:
033: private IPreferenceConfigurationBlock fConfigurationBlock;
034: private OverlayPreferenceStore fOverlayStore;
035:
036: /**
037: * Creates a new preference page.
038: */
039: public AbstractConfigurationBlockPreferencePage() {
040: setDescription();
041: setPreferenceStore();
042: fOverlayStore = new OverlayPreferenceStore(
043: getPreferenceStore(),
044: new OverlayPreferenceStore.OverlayKey[] {});
045: fConfigurationBlock = createConfigurationBlock(fOverlayStore);
046: }
047:
048: protected abstract IPreferenceConfigurationBlock createConfigurationBlock(
049: OverlayPreferenceStore overlayPreferenceStore);
050:
051: protected abstract String getHelpId();
052:
053: protected abstract void setDescription();
054:
055: protected abstract void setPreferenceStore();
056:
057: /*
058: * @see IWorkbenchPreferencePage#init()
059: */
060: public void init(IWorkbench workbench) {
061: }
062:
063: /*
064: * @see PreferencePage#createControl(Composite)
065: */
066: public void createControl(Composite parent) {
067: super .createControl(parent);
068: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
069: getHelpId());
070: }
071:
072: /*
073: * @see PreferencePage#createContents(Composite)
074: */
075: protected Control createContents(Composite parent) {
076:
077: fOverlayStore.load();
078: fOverlayStore.start();
079:
080: Control content = fConfigurationBlock.createControl(parent);
081:
082: initialize();
083:
084: Dialog.applyDialogFont(content);
085: return content;
086: }
087:
088: private void initialize() {
089: fConfigurationBlock.initialize();
090: }
091:
092: /*
093: * @see PreferencePage#performOk()
094: */
095: public boolean performOk() {
096:
097: fConfigurationBlock.performOk();
098:
099: fOverlayStore.propagate();
100:
101: JavaPlugin.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: }
|