001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.core.runtime.preferences.IScopeContext;
013:
014: import org.eclipse.core.resources.IProject;
015:
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018:
019: import org.eclipse.jface.dialogs.Dialog;
020: import org.eclipse.jface.preference.IPreferencePageContainer;
021:
022: import org.eclipse.ui.PlatformUI;
023: import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
024: import org.eclipse.ui.preferences.IWorkingCopyManager;
025: import org.eclipse.ui.preferences.WorkingCopyManager;
026:
027: import org.eclipse.jdt.internal.ui.JavaPlugin;
028:
029: import org.osgi.service.prefs.BackingStoreException;
030:
031: /**
032: * Abstract preference and property page which is used to wrap a
033: * {@link org.eclipse.jdt.internal.ui.preferences.IPreferenceAndPropertyConfigurationBlock}.
034: *
035: * @since 3.3
036: */
037: public abstract class AbstractConfigurationBlockPreferenceAndPropertyPage
038: extends PropertyAndPreferencePage {
039:
040: private IPreferenceAndPropertyConfigurationBlock fConfigurationBlock;
041: private PreferencesAccess fAccess;
042:
043: public AbstractConfigurationBlockPreferenceAndPropertyPage() {
044: }
045:
046: /**
047: * Create a configuration block which does modify settings in <code>context</code>.
048: *
049: * @param context the context to modify
050: * @return the preference block, not null
051: */
052: protected abstract IPreferenceAndPropertyConfigurationBlock createConfigurationBlock(
053: IScopeContext context);
054:
055: protected abstract String getHelpId();
056:
057: /**
058: * {@inheritDoc}
059: */
060: public void createControl(Composite parent) {
061: super .createControl(parent);
062: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
063: getHelpId());
064: }
065:
066: /**
067: * {@inheritDoc}
068: */
069: protected Control createPreferenceContent(Composite parent) {
070:
071: IPreferencePageContainer container = getContainer();
072: IWorkingCopyManager manager;
073: if (container instanceof IWorkbenchPreferenceContainer) {
074: manager = ((IWorkbenchPreferenceContainer) container)
075: .getWorkingCopyManager();
076: } else {
077: manager = new WorkingCopyManager(); // non shared
078: }
079: fAccess = PreferencesAccess.getWorkingCopyPreferences(manager);
080: IProject project = getProject();
081: IScopeContext context;
082: if (project != null) {
083: context = fAccess.getProjectScope(project);
084: } else {
085: context = fAccess.getInstanceScope();
086: }
087:
088: fConfigurationBlock = createConfigurationBlock(context);
089:
090: Control content = fConfigurationBlock.createControl(parent);
091:
092: fConfigurationBlock.initialize();
093:
094: Dialog.applyDialogFont(content);
095: return content;
096: }
097:
098: /**
099: * {@inheritDoc}
100: */
101: public boolean performOk() {
102: fConfigurationBlock.performOk();
103:
104: try {
105: fAccess.applyChanges();
106: } catch (BackingStoreException e) {
107: JavaPlugin.log(e);
108: }
109:
110: return true;
111: }
112:
113: /**
114: * {@inheritDoc}
115: */
116: public void performDefaults() {
117: fConfigurationBlock.performDefaults();
118: super .performDefaults();
119: }
120:
121: /**
122: * {@inheritDoc}
123: */
124: public void dispose() {
125: fConfigurationBlock.dispose();
126: super .dispose();
127: }
128:
129: /**
130: * {@inheritDoc}
131: */
132: protected void enableProjectSpecificSettings(
133: boolean useProjectSpecificSettings) {
134: super.enableProjectSpecificSettings(useProjectSpecificSettings);
135: if (useProjectSpecificSettings) {
136: fConfigurationBlock.enableProjectSettings();
137: } else {
138: fConfigurationBlock.disableProjectSettings();
139: }
140: }
141: }
|