]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.jdt.internal.ui.preferences; | |
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 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
25 | ||
26 | /** | |
27 | * Abstract preference page which is used to wrap a | |
28 | * {@link org.eclipse.jdt.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 | @Override | |
64 | public void createControl(Composite parent) { | |
65 | super.createControl(parent); | |
66 | PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId()); | |
67 | } | |
68 | ||
69 | /* | |
70 | * @see PreferencePage#createContents(Composite) | |
71 | */ | |
72 | @Override | |
73 | protected Control createContents(Composite parent) { | |
74 | ||
75 | fOverlayStore.load(); | |
76 | fOverlayStore.start(); | |
77 | ||
78 | Control content= fConfigurationBlock.createControl(parent); | |
79 | ||
80 | initialize(); | |
81 | ||
82 | Dialog.applyDialogFont(content); | |
83 | return content; | |
84 | } | |
85 | ||
86 | private void initialize() { | |
87 | fConfigurationBlock.initialize(); | |
88 | } | |
89 | ||
90 | /* | |
91 | * @see PreferencePage#performOk() | |
92 | */ | |
93 | @Override | |
94 | public boolean performOk() { | |
95 | ||
96 | fConfigurationBlock.performOk(); | |
97 | ||
98 | fOverlayStore.propagate(); | |
99 | ||
100 | JavaPlugin.flushInstanceScope(); | |
101 | ||
102 | return true; | |
103 | } | |
104 | ||
105 | /* | |
106 | * @see PreferencePage#performDefaults() | |
107 | */ | |
108 | @Override | |
109 | public void performDefaults() { | |
110 | ||
111 | fOverlayStore.loadDefaults(); | |
112 | fConfigurationBlock.performDefaults(); | |
113 | ||
114 | super.performDefaults(); | |
115 | } | |
116 | ||
117 | /* | |
118 | * @see DialogPage#dispose() | |
119 | */ | |
120 | @Override | |
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 | } |