Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6cebaa5afb8cb526670e98f5594e9736d8ef39a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*******************************************************************************
 * Copyright (c) 2005 BEA Systems, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   {INITIAL_AUTHOR} - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.apt.ui.internal.preferences;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;

/**
 * Base class for APT preference and property pages.
 */
public abstract class BasePreferencePage extends PropertyAndPreferencePage {
	private BaseConfigurationBlock fConfigurationBlock;

	protected Control createPreferenceContent(Composite composite) {
		return getConfigurationBlock().createPreferenceContent(composite);
	}
	
	@Override
	public void createControl(Composite parent) {
		super.createControl(parent);
		String contextId = getContextHelpId();
		if (contextId != null) {
			PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), contextId);
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
	 */
	public void dispose() {
		if (getConfigurationBlock() != null) {
			getConfigurationBlock().dispose();
		}
		super.dispose();
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#enableProjectSpecificSettings(boolean)
	 */
	protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
		if (getConfigurationBlock() != null) {
			getConfigurationBlock().useProjectSpecificSettings(useProjectSpecificSettings);
		}
		super.enableProjectSpecificSettings(useProjectSpecificSettings);
	}

	protected BaseConfigurationBlock getConfigurationBlock() {
		return fConfigurationBlock;
	}
	
	/**
	 * Derived classes should override by returning a string that refers
	 * to a context topic entry in docs/contexts_APT.xml.  The default
	 * implementation returns null, which causes context help to be disabled.
	 */
	protected String getContextHelpId() {
		return null;
	}
	
	protected boolean hasProjectSpecificOptions(IProject project) {
		// Workaround for bug 106111 / 111144:
		// See BaseConfigurationBlock.hasProjectSpecificOptionsNoCache() for details.
		return getConfigurationBlock().hasProjectSpecificOptionsNoCache(project);
	}
	
	/*
	 * @see org.eclipse.jface.preference.IPreferencePage#performApply()
	 */
	public void performApply() {
		if (getConfigurationBlock() != null) {
			getConfigurationBlock().performApply();
		}
	}
	
	/*
	 * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
	 */
	protected void performDefaults() {
		super.performDefaults();
		if (getConfigurationBlock() != null) {
			getConfigurationBlock().performDefaults();
		}
	}
	
	/*
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
	 */
	public boolean performOk() {
		if (getConfigurationBlock() != null && !getConfigurationBlock().performOk()) {
			return false;
		}	
		return super.performOk();
	}
	
	protected void setConfigurationBlock(BaseConfigurationBlock configurationBlock) {
		fConfigurationBlock = configurationBlock;
	}
	
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#setElement(org.eclipse.core.runtime.IAdaptable)
	 */
	public void setElement(IAdaptable element) {
		super.setElement(element);
		setDescription(null); // no description for property page
	}
}

Back to the top