001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 BEA Systems, Inc.
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: * wharley@bea.com - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.apt.ui.internal.preferences;
011:
012: import org.eclipse.core.resources.IProject;
013: import org.eclipse.core.runtime.IAdaptable;
014: import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Control;
017: import org.eclipse.ui.PlatformUI;
018:
019: /**
020: * Base class for APT preference and property pages.
021: */
022: public abstract class BasePreferencePage extends
023: PropertyAndPreferencePage {
024: private BaseConfigurationBlock fConfigurationBlock;
025:
026: protected Control createPreferenceContent(Composite composite) {
027: return getConfigurationBlock().createPreferenceContent(
028: composite);
029: }
030:
031: @Override
032: public void createControl(Composite parent) {
033: super .createControl(parent);
034: String contextId = getContextHelpId();
035: if (contextId != null) {
036: PlatformUI.getWorkbench().getHelpSystem().setHelp(
037: getControl(), contextId);
038: }
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.jface.dialogs.DialogPage#dispose()
043: */
044: public void dispose() {
045: if (getConfigurationBlock() != null) {
046: getConfigurationBlock().dispose();
047: }
048: super .dispose();
049: }
050:
051: /* (non-Javadoc)
052: * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#enableProjectSpecificSettings(boolean)
053: */
054: protected void enableProjectSpecificSettings(
055: boolean useProjectSpecificSettings) {
056: if (getConfigurationBlock() != null) {
057: getConfigurationBlock().useProjectSpecificSettings(
058: useProjectSpecificSettings);
059: }
060: super .enableProjectSpecificSettings(useProjectSpecificSettings);
061: }
062:
063: protected BaseConfigurationBlock getConfigurationBlock() {
064: return fConfigurationBlock;
065: }
066:
067: /**
068: * Derived classes should override by returning a string that refers
069: * to a context topic entry in docs/contexts_APT.xml. The default
070: * implementation returns null, which causes context help to be disabled.
071: */
072: protected String getContextHelpId() {
073: return null;
074: }
075:
076: protected boolean hasProjectSpecificOptions(IProject project) {
077: // Workaround for bug 106111 / 111144:
078: // See BaseConfigurationBlock.hasProjectSpecificOptionsNoCache() for details.
079: return getConfigurationBlock()
080: .hasProjectSpecificOptionsNoCache(project);
081: }
082:
083: /*
084: * See bug 136498: don't show workspace preferences.
085: */
086: @Override
087: protected boolean offerLink() {
088: return false;
089: }
090:
091: /*
092: * @see org.eclipse.jface.preference.IPreferencePage#performApply()
093: */
094: public void performApply() {
095: if (getConfigurationBlock() != null) {
096: getConfigurationBlock().performApply();
097: }
098: }
099:
100: /*
101: * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
102: */
103: protected void performDefaults() {
104: super .performDefaults();
105: if (getConfigurationBlock() != null) {
106: getConfigurationBlock().performDefaults();
107: }
108: }
109:
110: /*
111: * @see org.eclipse.jface.preference.IPreferencePage#performOk()
112: */
113: public boolean performOk() {
114: if (getConfigurationBlock() != null
115: && !getConfigurationBlock().performOk()) {
116: return false;
117: }
118: return super .performOk();
119: }
120:
121: protected void setConfigurationBlock(
122: BaseConfigurationBlock configurationBlock) {
123: fConfigurationBlock = configurationBlock;
124: }
125:
126: /* (non-Javadoc)
127: * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#setElement(org.eclipse.core.runtime.IAdaptable)
128: */
129: public void setElement(IAdaptable element) {
130: super .setElement(element);
131: setDescription(null); // no description for property page
132: }
133: }
|