]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/preferences/AbstractConfigurationBlockPreferenceAndPropertyPage.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / preferences / AbstractConfigurationBlockPreferenceAndPropertyPage.java
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 package org.eclipse.jdt.internal.ui.preferences;
12
13 import org.osgi.service.prefs.BackingStoreException;
14
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17
18 import org.eclipse.core.runtime.preferences.IScopeContext;
19
20 import org.eclipse.core.resources.IProject;
21
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.preference.IPreferencePageContainer;
24
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
27 import org.eclipse.ui.preferences.IWorkingCopyManager;
28 import org.eclipse.ui.preferences.WorkingCopyManager;
29
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32 /**
33  * Abstract preference and property page which is used to wrap a
34  * {@link org.eclipse.jdt.internal.ui.preferences.IPreferenceAndPropertyConfigurationBlock}.
35  *
36  * @since 3.3
37  */
38 public abstract class AbstractConfigurationBlockPreferenceAndPropertyPage extends PropertyAndPreferencePage {
39
40         private IPreferenceAndPropertyConfigurationBlock fConfigurationBlock;
41         PreferencesAccess fAccess;
42
43         public AbstractConfigurationBlockPreferenceAndPropertyPage() {
44         }
45
46         /**
47          * Create a configuration block which does modify settings in <code>context</code>.
48          *
49          * @param context the context to modify
50          * @return the preference block, not null
51          */
52         protected abstract IPreferenceAndPropertyConfigurationBlock createConfigurationBlock(IScopeContext context);
53
54         protected abstract String getHelpId();
55
56         /**
57          * {@inheritDoc}
58          */
59         @Override
60         public void createControl(Composite parent) {
61                 super.createControl(parent);
62                 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId());
63         }
64
65         /**
66          * {@inheritDoc}
67          */
68         @Override
69         protected Control createPreferenceContent(Composite parent) {
70
71                 IPreferencePageContainer container= getContainer();
72                 IWorkingCopyManager manager;
73                 if (container instanceof IWorkbenchPreferenceContainer) {
74                         manager= ((IWorkbenchPreferenceContainer)container).getWorkingCopyManager();
75                 } else {
76                         manager= new WorkingCopyManager(); // non shared
77                 }
78                 fAccess= PreferencesAccess.getWorkingCopyPreferences(manager);
79                 IProject project= getProject();
80                 IScopeContext context;
81                 context= fAccess.generated_467733558802250908(project);
82
83                 fConfigurationBlock= createConfigurationBlock(context);
84
85                 Control content= fConfigurationBlock.createControl(parent);
86
87                 fConfigurationBlock.initialize();
88
89                 Dialog.applyDialogFont(content);
90                 return content;
91         }
92
93         /**
94          * {@inheritDoc}
95          */
96         @Override
97         public boolean performOk() {
98                 fConfigurationBlock.performOk();
99
100                 try {
101                 fAccess.applyChanges();
102         } catch (BackingStoreException e) {
103                 JavaPlugin.log(e);
104         }
105
106                 return true;
107         }
108
109         /**
110          * {@inheritDoc}
111          */
112         @Override
113         public void performDefaults() {
114                 fConfigurationBlock.performDefaults();
115                 super.performDefaults();
116         }
117
118         /**
119          * {@inheritDoc}
120          */
121         @Override
122         public void dispose() {
123                 fConfigurationBlock.dispose();
124                 super.dispose();
125         }
126
127         /**
128          * {@inheritDoc}
129          */
130         @Override
131         protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
132                 super.enableProjectSpecificSettings(useProjectSpecificSettings);
133                 if (useProjectSpecificSettings) {
134                         fConfigurationBlock.enableProjectSettings();
135                 } else {
136                         fConfigurationBlock.disableProjectSettings();
137                 }
138         }
139 }