KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > AbstractConfigurationBlockPreferenceAndPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.eclipse.core.runtime.preferences.IScopeContext;
14
15 import org.eclipse.core.resources.IProject;
16
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.preference.IPreferencePageContainer;
22
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
25 import org.eclipse.ui.preferences.IWorkingCopyManager;
26 import org.eclipse.ui.preferences.WorkingCopyManager;
27
28 import org.eclipse.jdt.internal.ui.JavaPlugin;
29
30 import org.osgi.service.prefs.BackingStoreException;
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     private 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 JavaDoc getHelpId();
55     
56     /**
57      * {@inheritDoc}
58      */

59     public void createControl(Composite parent) {
60         super.createControl(parent);
61         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId());
62     }
63     
64     /**
65      * {@inheritDoc}
66      */

67     protected Control createPreferenceContent(Composite parent) {
68         
69         IPreferencePageContainer container= getContainer();
70         IWorkingCopyManager manager;
71         if (container instanceof IWorkbenchPreferenceContainer) {
72             manager= ((IWorkbenchPreferenceContainer)container).getWorkingCopyManager();
73         } else {
74             manager= new WorkingCopyManager(); // non shared
75
}
76         fAccess= PreferencesAccess.getWorkingCopyPreferences(manager);
77         IProject project= getProject();
78         IScopeContext context;
79         if (project != null) {
80             context= fAccess.getProjectScope(project);
81         } else {
82             context= fAccess.getInstanceScope();
83         }
84         
85         fConfigurationBlock= createConfigurationBlock(context);
86         
87         Control content= fConfigurationBlock.createControl(parent);
88         
89         fConfigurationBlock.initialize();
90         
91         Dialog.applyDialogFont(content);
92         return content;
93     }
94     
95     /**
96      * {@inheritDoc}
97      */

98     public boolean performOk() {
99         fConfigurationBlock.performOk();
100         
101         try {
102             fAccess.applyChanges();
103         } catch (BackingStoreException e) {
104             JavaPlugin.log(e);
105         }
106         
107         return true;
108     }
109     
110     /**
111      * {@inheritDoc}
112      */

113     public void performDefaults() {
114         fConfigurationBlock.performDefaults();
115         super.performDefaults();
116     }
117     
118     /**
119      * {@inheritDoc}
120      */

121     public void dispose() {
122         fConfigurationBlock.dispose();
123         super.dispose();
124     }
125     
126     /**
127      * {@inheritDoc}
128      */

129     protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
130         super.enableProjectSpecificSettings(useProjectSpecificSettings);
131         if (useProjectSpecificSettings) {
132             fConfigurationBlock.enableProjectSettings();
133         } else {
134             fConfigurationBlock.disableProjectSettings();
135         }
136     }
137 }
138
Popular Tags