View | Details | Raw Unified | Return to bug 168069 | Differences between
and this patch

Collapse All | Expand All

(-)contexts_PDE.xml (+5 lines)
Lines 695-700 Link Here
695
		<topic label="Dependencies page" href="guide/pde_manifest_dependencies.htm"/>
695
		<topic label="Dependencies page" href="guide/pde_manifest_dependencies.htm"/>
696
		<topic label="Extension point schema" href="guide/pde_schema.htm"/>
696
		<topic label="Extension point schema" href="guide/pde_schema.htm"/>
697
 	</context>
697
 	</context>
698
  <context id="project_selection_dialog">
699
     <description>This dialog is used to select a plugin project to configure specific settings for.</description>
700
     <topic href="guide/tools/preference_pages/compilers.htm" label="Compilers Preferences"/>
701
     <topic href="guide/tools/preference_pages/plugin_compiler.htm" label="Plug-in Compiler Preferences"/>
702
  </context>
698
 	<context id="java_attribute_wizard_page">
703
 	<context id="java_attribute_wizard_page">
699
 		<description>This wizard allows you to create a new Java class or select an existing one.</description>
704
 		<description>This wizard allows you to create a new Java class or select an existing one.</description>
700
 	</context>
705
 	</context>
(-)src/org/eclipse/pde/internal/core/PreferenceInitializer.java (-2 / +33 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-20 Link Here
13
import java.util.Locale;
13
import java.util.Locale;
14
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.Platform;
15
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
16
import org.eclipse.core.runtime.preferences.*;
17
import org.eclipse.pde.core.plugin.TargetPlatform;
17
import org.eclipse.pde.core.plugin.TargetPlatform;
18
import org.eclipse.pde.internal.core.builders.CompilerFlags;
19
import org.eclipse.pde.internal.core.natures.PDE;
20
import org.osgi.service.prefs.BackingStoreException;
18
21
19
public class PreferenceInitializer extends AbstractPreferenceInitializer {
22
public class PreferenceInitializer extends AbstractPreferenceInitializer {
20
23
Lines 40-44 Link Here
40
43
41
		preferences.setDefault(ICoreConstants.TARGET_PLATFORM_REALIZATION, TargetPlatform.getDefaultLocation().equals(TargetPlatform.getLocation()));
44
		preferences.setDefault(ICoreConstants.TARGET_PLATFORM_REALIZATION, TargetPlatform.getDefaultLocation().equals(TargetPlatform.getLocation()));
42
45
46
		//set defaults for compiler preferences in org.eclipse.pde pref node, not org.eclipse.pde.core
47
		IEclipsePreferences prefs = new DefaultScope().getNode(PDE.PLUGIN_ID);
48
		prefs.putInt(CompilerFlags.P_UNRESOLVED_IMPORTS, CompilerFlags.ERROR);
49
		prefs.putInt(CompilerFlags.P_UNRESOLVED_EX_POINTS, CompilerFlags.ERROR);
50
		prefs.putInt(CompilerFlags.P_NO_REQUIRED_ATT, CompilerFlags.ERROR);
51
		prefs.putInt(CompilerFlags.P_UNKNOWN_ELEMENT, CompilerFlags.WARNING);
52
		prefs.putInt(CompilerFlags.P_UNKNOWN_ATTRIBUTE, CompilerFlags.WARNING);
53
		prefs.putInt(CompilerFlags.P_DEPRECATED, CompilerFlags.WARNING);
54
		prefs.putInt(CompilerFlags.P_UNKNOWN_CLASS, CompilerFlags.WARNING);
55
		prefs.putInt(CompilerFlags.P_DISCOURAGED_CLASS, CompilerFlags.WARNING);
56
		prefs.putInt(CompilerFlags.P_UNKNOWN_RESOURCE, CompilerFlags.WARNING);
57
		prefs.putInt(CompilerFlags.P_UNKNOWN_IDENTIFIER, CompilerFlags.WARNING);
58
		prefs.putInt(CompilerFlags.P_NOT_EXTERNALIZED, CompilerFlags.IGNORE);
59
		prefs.putInt(CompilerFlags.P_BUILD, CompilerFlags.WARNING);
60
		prefs.putInt(CompilerFlags.P_INCOMPATIBLE_ENV, CompilerFlags.WARNING);
61
		prefs.putInt(CompilerFlags.P_MISSING_EXPORT_PKGS, CompilerFlags.IGNORE);
62
		prefs.putInt(CompilerFlags.P_MISSING_BUNDLE_CLASSPATH_ENTRIES, CompilerFlags.WARNING);
63
64
		prefs.putBoolean(CompilerFlags.S_CREATE_DOCS, false);
65
		prefs.put(CompilerFlags.S_DOC_FOLDER, "doc"); //$NON-NLS-1$
66
		prefs.putInt(CompilerFlags.S_OPEN_TAGS, CompilerFlags.WARNING);
67
68
		prefs.putInt(CompilerFlags.F_UNRESOLVED_PLUGINS, CompilerFlags.WARNING);
69
		prefs.putInt(CompilerFlags.F_UNRESOLVED_FEATURES, CompilerFlags.WARNING);
70
		try {
71
			prefs.flush();
72
		} catch (BackingStoreException e) {
73
		}
43
	}
74
	}
44
}
75
}
(-)src/org/eclipse/pde/internal/core/PDECore.java (-2 / +2 lines)
Lines 18-24 Link Here
18
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.jdt.launching.JavaRuntime;
19
import org.eclipse.jdt.launching.JavaRuntime;
20
import org.eclipse.pde.core.plugin.IPluginModelBase;
20
import org.eclipse.pde.core.plugin.IPluginModelBase;
21
import org.eclipse.pde.internal.core.builders.*;
21
import org.eclipse.pde.internal.core.builders.FeatureRebuilder;
22
import org.eclipse.pde.internal.core.builders.PluginRebuilder;
22
import org.eclipse.pde.internal.core.schema.SchemaRegistry;
23
import org.eclipse.pde.internal.core.schema.SchemaRegistry;
23
import org.eclipse.update.configurator.ConfiguratorUtils;
24
import org.eclipse.update.configurator.ConfiguratorUtils;
24
import org.osgi.framework.BundleContext;
25
import org.osgi.framework.BundleContext;
Lines 217-223 Link Here
217
	public void start(BundleContext context) throws Exception {
218
	public void start(BundleContext context) throws Exception {
218
		super.start(context);
219
		super.start(context);
219
		fBundleContext = context;
220
		fBundleContext = context;
220
		CompilerFlags.initializeDefaults();
221
		fJavaElementChangeListener = new JavaElementChangeListener();
221
		fJavaElementChangeListener = new JavaElementChangeListener();
222
		fJavaElementChangeListener.start();
222
		fJavaElementChangeListener.start();
223
		fPluginRebuilder = new PluginRebuilder();
223
		fPluginRebuilder = new PluginRebuilder();
(-)src/org/eclipse/pde/internal/core/builders/CompilerFlags.java (-159 / +40 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-98 Link Here
16
import org.eclipse.core.runtime.preferences.*;
16
import org.eclipse.core.runtime.preferences.*;
17
import org.eclipse.pde.internal.core.natures.PDE;
17
import org.eclipse.pde.internal.core.natures.PDE;
18
import org.osgi.service.prefs.BackingStoreException;
18
import org.osgi.service.prefs.BackingStoreException;
19
import org.osgi.service.prefs.Preferences;
20
19
20
/**
21
 * Class used to handle compiler related preferences. 
22
 * 
23
 * @noextend This class is not intended to be subclassed by clients.
24
 */
21
public class CompilerFlags {
25
public class CompilerFlags {
22
	public static final int ERROR = 0;
23
26
27
	/**
28
	 * Compiler flag options as integers
29
	 */
30
	public static final int ERROR = 0;
24
	public static final int WARNING = 1;
31
	public static final int WARNING = 1;
25
26
	public static final int IGNORE = 2;
32
	public static final int IGNORE = 2;
27
33
28
	public static final int MARKER = 0;
34
	/**
29
35
	 * categories of flags 
30
	public static final int BOOLEAN = 1;
36
	 */
31
32
	public static final int STRING = 2;
33
34
	public static final int PLUGIN_FLAGS = 0;
37
	public static final int PLUGIN_FLAGS = 0;
35
36
	public static final int SCHEMA_FLAGS = 1;
38
	public static final int SCHEMA_FLAGS = 1;
37
38
	public static final int FEATURE_FLAGS = 2;
39
	public static final int FEATURE_FLAGS = 2;
39
40
	public static final int SITE_FLAGS = 3;
40
	public static final int SITE_FLAGS = 3;
41
41
42
	// Project or Instance preferences
42
	/**
43
	public static final String USE_PROJECT_PREF = "compilers.use-project"; //$NON-NLS-1$
43
	 * plugin preferences
44
44
	 */
45
	// Manifest compiler flags
46
	public static final String P_UNRESOLVED_IMPORTS = "compilers.p.unresolved-import"; //$NON-NLS-1$
45
	public static final String P_UNRESOLVED_IMPORTS = "compilers.p.unresolved-import"; //$NON-NLS-1$
47
48
	public static final String P_UNRESOLVED_EX_POINTS = "compilers.p.unresolved-ex-points"; //$NON-NLS-1$
46
	public static final String P_UNRESOLVED_EX_POINTS = "compilers.p.unresolved-ex-points"; //$NON-NLS-1$
49
50
	public static final String P_UNKNOWN_ELEMENT = "compilers.p.unknown-element"; //$NON-NLS-1$
47
	public static final String P_UNKNOWN_ELEMENT = "compilers.p.unknown-element"; //$NON-NLS-1$
51
52
	public static final String P_UNKNOWN_ATTRIBUTE = "compilers.p.unknown-attribute"; //$NON-NLS-1$
48
	public static final String P_UNKNOWN_ATTRIBUTE = "compilers.p.unknown-attribute"; //$NON-NLS-1$
53
54
	public static final String P_UNKNOWN_CLASS = "compilers.p.unknown-class"; //$NON-NLS-1$
49
	public static final String P_UNKNOWN_CLASS = "compilers.p.unknown-class"; //$NON-NLS-1$
55
56
	public static final String P_DISCOURAGED_CLASS = "compilers.p.discouraged-class"; //$NON-NLS-1$
57
58
	public static final String P_UNKNOWN_RESOURCE = "compilers.p.unknown-resource"; //$NON-NLS-1$
50
	public static final String P_UNKNOWN_RESOURCE = "compilers.p.unknown-resource"; //$NON-NLS-1$
59
60
	public static final String P_UNKNOWN_IDENTIFIER = "compilers.p.unknown-identifier"; //$NON-NLS-1$
51
	public static final String P_UNKNOWN_IDENTIFIER = "compilers.p.unknown-identifier"; //$NON-NLS-1$
61
52
	public static final String P_DISCOURAGED_CLASS = "compilers.p.discouraged-class"; //$NON-NLS-1$
62
	public static final String P_NO_REQUIRED_ATT = "compilers.p.no-required-att"; //$NON-NLS-1$
53
	public static final String P_NO_REQUIRED_ATT = "compilers.p.no-required-att"; //$NON-NLS-1$
63
64
	public static final String P_NOT_EXTERNALIZED = "compilers.p.not-externalized-att"; //$NON-NLS-1$
54
	public static final String P_NOT_EXTERNALIZED = "compilers.p.not-externalized-att"; //$NON-NLS-1$
65
66
	public static final String P_BUILD = "compilers.p.build"; //$NON-NLS-1$
55
	public static final String P_BUILD = "compilers.p.build"; //$NON-NLS-1$
67
68
	public static final String P_INCOMPATIBLE_ENV = "compilers.incompatible-environment"; //$NON-NLS-1$
56
	public static final String P_INCOMPATIBLE_ENV = "compilers.incompatible-environment"; //$NON-NLS-1$
69
70
	public static final String P_MISSING_EXPORT_PKGS = "compilers.p.missing-packages"; //$NON-NLS-1$
57
	public static final String P_MISSING_EXPORT_PKGS = "compilers.p.missing-packages"; //$NON-NLS-1$
71
72
	public static final String P_DEPRECATED = "compilers.p.deprecated"; //$NON-NLS-1$
58
	public static final String P_DEPRECATED = "compilers.p.deprecated"; //$NON-NLS-1$
73
74
	public static final String P_MISSING_BUNDLE_CLASSPATH_ENTRIES = "compilers.p.missing-bundle-classpath-entries"; //$NON-NLS-1$
59
	public static final String P_MISSING_BUNDLE_CLASSPATH_ENTRIES = "compilers.p.missing-bundle-classpath-entries"; //$NON-NLS-1$
75
60
61
	/**
62
	 * schema preferences 
63
	 */
76
	public static final String S_CREATE_DOCS = "compilers.s.create-docs"; //$NON-NLS-1$
64
	public static final String S_CREATE_DOCS = "compilers.s.create-docs"; //$NON-NLS-1$
77
78
	public static final String S_DOC_FOLDER = "compilers.s.doc-folder"; //$NON-NLS-1$
65
	public static final String S_DOC_FOLDER = "compilers.s.doc-folder"; //$NON-NLS-1$
79
80
	public static final String S_OPEN_TAGS = "compilers.s.open-tags"; //$NON-NLS-1$
66
	public static final String S_OPEN_TAGS = "compilers.s.open-tags"; //$NON-NLS-1$
81
67
68
	/**
69
	 * feature preferences 
70
	 */
82
	public static final String F_UNRESOLVED_PLUGINS = "compilers.f.unresolved-plugins"; //$NON-NLS-1$
71
	public static final String F_UNRESOLVED_PLUGINS = "compilers.f.unresolved-plugins"; //$NON-NLS-1$
83
84
	public static final String F_UNRESOLVED_FEATURES = "compilers.f.unresolved-features"; //$NON-NLS-1$
72
	public static final String F_UNRESOLVED_FEATURES = "compilers.f.unresolved-features"; //$NON-NLS-1$
85
73
86
	private static final String[][] fFlags = { {P_UNRESOLVED_IMPORTS, P_INCOMPATIBLE_ENV, P_UNRESOLVED_EX_POINTS, P_NO_REQUIRED_ATT, P_UNKNOWN_ELEMENT, P_UNKNOWN_ATTRIBUTE, P_DEPRECATED, P_UNKNOWN_CLASS, P_DISCOURAGED_CLASS, P_UNKNOWN_RESOURCE, P_UNKNOWN_IDENTIFIER, P_NOT_EXTERNALIZED, P_BUILD, P_MISSING_EXPORT_PKGS, P_MISSING_BUNDLE_CLASSPATH_ENTRIES}, {S_CREATE_DOCS, S_DOC_FOLDER, S_OPEN_TAGS}, {F_UNRESOLVED_PLUGINS, F_UNRESOLVED_FEATURES}};
74
	/**
87
75
	 * Returns the value for the requested preference, or 0 if there was a problem getting the preference value
88
	public static int getFlagType(String flagId) {
76
	 * @param project to use as a project specific settings scope, or null
89
		if (flagId.equals(S_CREATE_DOCS))
77
	 * @param flagId the id of the preference to retrieve
90
			return BOOLEAN;
78
	 * @return the value for the given preference id
91
		if (flagId.equals(S_DOC_FOLDER))
79
	 */
92
			return STRING;
93
		return MARKER;
94
	}
95
96
	public static int getFlag(IProject project, String flagId) {
80
	public static int getFlag(IProject project, String flagId) {
97
		try {
81
		try {
98
			return Integer.parseInt(getString(project, flagId));
82
			return Integer.parseInt(getString(project, flagId));
Lines 101-229 Link Here
101
		}
85
		}
102
	}
86
	}
103
87
88
	/**
89
	 * Returns the boolean preference denoted by the flag id (preference id)
90
	 * @param project to use as a project specific settings scope, or null
91
	 * @param flagId the id of the preference to retrieve
92
	 * @return the boolean value for the given preference id
93
	 */
104
	public static boolean getBoolean(IProject project, String flagId) {
94
	public static boolean getBoolean(IProject project, String flagId) {
105
		return Boolean.valueOf(getString(project, flagId)).booleanValue();
95
		return Boolean.valueOf(getString(project, flagId)).booleanValue();
106
	}
96
	}
107
97
108
	/**
98
	/**
109
	 * 
99
	 * Returns the string preference for the given preference id
110
	 * @param project
100
	 * @param project to use as a project specific settings scope, or null
111
	 *            project to use PROJECT,INSTANCE,DEFAULT scope or null to use
101
	 * @param flagId the id of the preference to retrieve
112
	 *            only INSTANCE,DEFAULT scope
102
	 * @return preference value or an empty string, never <code>null</code>
113
	 * @param flagId
114
	 * @return value or ""
115
	 */
103
	 */
116
	public static String getString(IProject project, String flagId) {
104
	public static String getString(IProject project, String flagId) {
117
		IPreferencesService service = Platform.getPreferencesService();
105
		IPreferencesService service = Platform.getPreferencesService();
118
		IScopeContext[] contexts = project == null ? null : new IScopeContext[] {new ProjectScope(project)};
106
		IScopeContext[] contexts = project == null ? null : new IScopeContext[] {new ProjectScope(project)};
119
		return service.getString(PDE.PLUGIN_ID, flagId, "", //$NON-NLS-1$
107
		return service.getString(PDE.PLUGIN_ID, flagId, "", project == null ? null : contexts); //$NON-NLS-1$
120
				project == null ? null : contexts);
121
	}
122
123
	public static int getDefaultFlag(String flagId) {
124
		return new DefaultScope().getNode(PDE.PLUGIN_ID).getInt(flagId, 0);
125
	}
126
127
	public static String getDefaultString(String flagId) {
128
		return new DefaultScope().getNode(PDE.PLUGIN_ID).get(flagId, ""); //$NON-NLS-1$
129
	}
130
131
	public static boolean getDefaultBoolean(String flagId) {
132
		return new DefaultScope().getNode(PDE.PLUGIN_ID).getBoolean(flagId, false);
133
	}
134
135
	public static void setFlag(String flagId, int value) {
136
		if (getDefaultFlag(flagId) == value)
137
			new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId);
138
		else
139
			new InstanceScope().getNode(PDE.PLUGIN_ID).putInt(flagId, value);
140
	}
141
142
	public static void setFlag(IProject project, String flagId, int value) {
143
		setString(project, flagId, Integer.toString(value));
144
	}
145
146
	public static void setBoolean(String flagId, boolean value) {
147
		if (getDefaultBoolean(flagId) == value)
148
			new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId);
149
		else
150
			new InstanceScope().getNode(PDE.PLUGIN_ID).putBoolean(flagId, value);
151
	}
152
153
	public static void setBoolean(IProject project, String flagId, boolean value) {
154
		setString(project, flagId, Boolean.toString(value));
155
	}
156
157
	public static void setString(String flagId, String value) {
158
		if (getDefaultString(flagId).equals(value))
159
			new InstanceScope().getNode(PDE.PLUGIN_ID).remove(flagId);
160
		else
161
			new InstanceScope().getNode(PDE.PLUGIN_ID).put(flagId, value);
162
	}
163
164
	/**
165
	 * Sets preference on PROJECT scope
166
	 * 
167
	 * @param project
168
	 * @param flagId
169
	 * @param value
170
	 */
171
	public static void setString(IProject project, String flagId, String value) {
172
		if (project == null)
173
			return;
174
		Preferences preferences = new ProjectScope(project).getNode(PDE.PLUGIN_ID);
175
		preferences.put(flagId, value);
176
		try {
177
			preferences.flush();
178
		} catch (BackingStoreException bse) {
179
		}
180
	}
181
182
	/**
183
	 * Clears preference from Project scope
184
	 * 
185
	 * @param project
186
	 * @param flagId
187
	 */
188
	public static void clear(IProject project, String flagId) {
189
		if (project == null)
190
			return;
191
		Preferences preferences = new ProjectScope(project).getNode(PDE.PLUGIN_ID);
192
		preferences.remove(flagId);
193
		try {
194
			preferences.flush();
195
		} catch (BackingStoreException bse) {
196
		}
197
	}
198
199
	public static void initializeDefaults() {
200
		Preferences node = new DefaultScope().getNode(PDE.PLUGIN_ID);
201
		node.putInt(P_UNRESOLVED_IMPORTS, ERROR);
202
		node.putInt(P_UNRESOLVED_EX_POINTS, ERROR);
203
		node.putInt(P_NO_REQUIRED_ATT, ERROR);
204
		node.putInt(P_UNKNOWN_ELEMENT, WARNING);
205
		node.putInt(P_UNKNOWN_ATTRIBUTE, WARNING);
206
		node.putInt(P_DEPRECATED, WARNING);
207
		node.putInt(P_UNKNOWN_CLASS, WARNING);
208
		node.putInt(P_DISCOURAGED_CLASS, WARNING);
209
		node.putInt(P_UNKNOWN_RESOURCE, WARNING);
210
		node.putInt(P_UNKNOWN_IDENTIFIER, WARNING);
211
		node.putInt(P_NOT_EXTERNALIZED, IGNORE);
212
		node.putInt(P_BUILD, WARNING);
213
		node.putInt(P_INCOMPATIBLE_ENV, WARNING);
214
		node.putInt(P_MISSING_EXPORT_PKGS, IGNORE);
215
		node.putInt(P_MISSING_BUNDLE_CLASSPATH_ENTRIES, WARNING);
216
217
		node.putBoolean(S_CREATE_DOCS, false);
218
		node.put(S_DOC_FOLDER, "doc"); //$NON-NLS-1$
219
		node.putInt(S_OPEN_TAGS, WARNING);
220
221
		node.putInt(F_UNRESOLVED_PLUGINS, WARNING);
222
		node.putInt(F_UNRESOLVED_FEATURES, WARNING);
223
	}
224
225
	public static String[] getFlags(int group) {
226
		return fFlags[group];
227
	}
108
	}
228
109
229
	/**
110
	/**
(-)src/org/eclipse/pde/internal/ui/preferences/CompilersConfigurationTab.java (-480 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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.pde.internal.ui.preferences;
12
13
import java.util.*;
14
import java.util.List;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.jface.dialogs.*;
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.pde.internal.core.builders.CompilerFlags;
21
import org.eclipse.pde.internal.core.natures.PDE;
22
import org.eclipse.pde.internal.ui.PDEPlugin;
23
import org.eclipse.pde.internal.ui.PDEUIMessages;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.*;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.*;
29
30
/**
31
 * A configuration block used to modify PDE compiler settings. Can be used as a preference page (a null project)
32
 * or as a property page (applicable to plugin projects).
33
 */
34
public class CompilersConfigurationTab {
35
36
	private Set fBuilders = new HashSet();
37
38
	private Set fChangedControls = new HashSet();
39
40
	private Composite fFeaturePage;
41
42
	private List fFlagControls;
43
44
	private Composite fPluginPage;
45
46
	private Composite fSchemaPage;
47
48
	private Shell fShell;
49
50
	// The size of label array must match CompilerFlag.fFlags
51
	private static final String[][] fLabels = { {PDEUIMessages.compilers_p_unresolved_import, PDEUIMessages.CompilersConfigurationTab_incompatEnv, PDEUIMessages.compilers_p_unresolved_ex_points, PDEUIMessages.compilers_p_no_required_att, PDEUIMessages.compilers_p_unknown_element, PDEUIMessages.compilers_p_unknown_attribute, PDEUIMessages.compilers_p_deprecated, PDEUIMessages.compilers_p_unknown_class, PDEUIMessages.compilers_p_discouraged_class, PDEUIMessages.compilers_p_unknown_resource, PDEUIMessages.compilers_p_unknown_identifier, PDEUIMessages.compilers_p_not_externalized_att, PDEUIMessages.CompilersConfigurationTab_buildPropertiesErrors, PDEUIMessages.compilers_p_exported_pkgs, PDEUIMessages.CompilersConfigurationTab_missingBundleClasspathEntries},
52
			{PDEUIMessages.compilers_s_create_docs, PDEUIMessages.compilers_s_doc_folder, PDEUIMessages.compilers_s_open_tags}, {PDEUIMessages.compilers_f_unresolved_plugins, PDEUIMessages.compilers_f_unresolved_features}, {}};
53
54
	/**
55
	 * The backing project may be <code>null</code>
56
	 */
57
	private IProject project;
58
59
	/**
60
	 * Constructor
61
	 * @param project
62
	 */
63
	public CompilersConfigurationTab(IProject project) {
64
		this.project = project;
65
	}
66
67
	/**
68
	 * Adds the specified control to a listing of controls that have changes
69
	 * @param control
70
	 */
71
	private void addChangedConrol(Control control) {
72
		String flagId = (String) control.getData();
73
		boolean doAdd = false;
74
		if (control instanceof Combo) {
75
			int newIndex = ((Combo) control).getSelectionIndex();
76
			int oldIndex = CompilerFlags.getFlag(project, flagId);
77
			doAdd = (newIndex != oldIndex);
78
		} else if (control instanceof Button) {
79
			boolean newValue = ((Button) control).getSelection();
80
			boolean oldValue = CompilerFlags.getBoolean(project, flagId);
81
			doAdd = oldValue != newValue;
82
		} else if (control instanceof Text) {
83
			String newValue = ((Text) control).getText();
84
			String oldValue = CompilerFlags.getString(project, flagId);
85
			doAdd = !newValue.equals(oldValue);
86
		}
87
		if (doAdd)
88
			fChangedControls.add(control);
89
		else if (fChangedControls.contains(control))
90
			fChangedControls.remove(control);
91
	}
92
93
	/**
94
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
95
	 */
96
	public Control createContents(Composite parent) {
97
		fShell = parent.getShell();
98
99
		Composite container = new Composite(parent, SWT.NULL);
100
		GridLayout layout = new GridLayout();
101
		container.setLayout(layout);
102
103
		fFlagControls = new ArrayList();
104
		SelectionListener listener = new SelectionAdapter() {
105
			public void widgetSelected(SelectionEvent e) {
106
				addChangedConrol((Control) e.widget);
107
			}
108
		};
109
110
		ModifyListener mlistener = new ModifyListener() {
111
			public void modifyText(ModifyEvent e) {
112
				addChangedConrol((Control) e.widget);
113
			}
114
		};
115
116
		String[] choices = new String[] {PDEUIMessages.CompilersConfigurationBlock_error, PDEUIMessages.CompilersConfigurationBlock_warning, PDEUIMessages.CompilersConfigurationBlock_ignore}; //  
117
118
		if (project != null) { // property page
119
			try {
120
				if (project.hasNature(PDE.PLUGIN_NATURE)) {
121
					fPluginPage = createPage(container, PDEUIMessages.CompilersConfigurationBlock_plugins, CompilerFlags.PLUGIN_FLAGS, choices);
122
				}
123
			} catch (CoreException ce) {
124
			}
125
		} else { // preference page
126
			TabFolder folder = new TabFolder(container, SWT.NONE);
127
			GridData gd = new GridData(GridData.FILL_BOTH);
128
			folder.setLayoutData(gd);
129
130
			fPluginPage = createPage(folder, PDEUIMessages.CompilersConfigurationBlock_plugins, CompilerFlags.PLUGIN_FLAGS, choices);
131
			fSchemaPage = createPage(folder, PDEUIMessages.CompilersConfigurationBlock_schemas, CompilerFlags.SCHEMA_FLAGS, choices);
132
			fFeaturePage = createPage(folder, PDEUIMessages.CompilersConfigurationBlock_features, CompilerFlags.FEATURE_FLAGS, choices);
133
		}
134
135
		for (int i = 0; i < fFlagControls.size(); i++) {
136
			Control control = (Control) fFlagControls.get(i);
137
			if (control instanceof Combo) {
138
				((Combo) control).addSelectionListener(listener);
139
			} else if (control instanceof Button) {
140
				((Button) control).addSelectionListener(listener);
141
			} else if (control instanceof Text) {
142
				((Text) control).addModifyListener(mlistener);
143
			}
144
		}
145
		Dialog.applyDialogFont(parent);
146
		return container;
147
	}
148
149
	/**
150
	 * Creates a preference element for the given flag and choices
151
	 * @param page
152
	 * @param flagId
153
	 * @param choices
154
	 * @return a new pref control
155
	 */
156
	private Control createFlag(Composite page, String flagId, String[] choices) {
157
		Control control = null;
158
		if (CompilerFlags.getFlagType(flagId) == CompilerFlags.MARKER) {
159
			Label label = new Label(page, SWT.NULL);
160
			label.setText(getFlagLabel(flagId));
161
			label.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false));
162
			Combo combo = new Combo(page, SWT.READ_ONLY);
163
			combo.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false));
164
			combo.setItems(choices);
165
			combo.select(CompilerFlags.getFlag(project, flagId));
166
			control = combo;
167
		} else if (CompilerFlags.getFlagType(flagId) == CompilerFlags.BOOLEAN) {
168
			Button button = new Button(page, SWT.CHECK);
169
			button.setText(getFlagLabel(flagId));
170
			button.setSelection(CompilerFlags.getBoolean(project, flagId));
171
			GridData gd = new GridData();
172
			gd.horizontalSpan = 2;
173
			button.setLayoutData(gd);
174
			control = button;
175
		} else if (CompilerFlags.getFlagType(flagId) == CompilerFlags.STRING) {
176
			Label label = new Label(page, SWT.NULL);
177
			label.setText(getFlagLabel(flagId));
178
			Text text = new Text(page, SWT.SINGLE | SWT.BORDER);
179
			text.setText(CompilerFlags.getString(project, flagId));
180
			GridData gd = new GridData(GridData.FILL_HORIZONTAL);
181
			gd.widthHint = 50;
182
			text.setLayoutData(gd);
183
184
			new Label(page, SWT.NULL).setLayoutData(new GridData());
185
			GridData sgd = new GridData();
186
			Label slabel = new Label(page, SWT.NULL);
187
			slabel.setText(PDEUIMessages.CompilersConfigurationBlock_label);
188
			sgd.horizontalSpan = 2;
189
			slabel.setLayoutData(sgd);
190
191
			control = text;
192
		}
193
		control.setData(flagId);
194
		return control;
195
	}
196
197
	/**
198
	 * Returns the corresponding flag label given the id
199
	 * @param flagId
200
	 * @return the label for the flag with the given id
201
	 */
202
	private String getFlagLabel(String flagId) {
203
		for (int i = 0; i < fLabels.length; i++) {
204
			String[] flags = CompilerFlags.getFlags(i);
205
			for (int j = 0; j < flags.length; j++) {
206
				if (flags[j].equals(flagId)) {
207
					return fLabels[i][j];
208
				}
209
			}
210
		}
211
		return ""; //$NON-NLS-1$
212
	}
213
214
	/**
215
	 * Creates a new page in the parent tab folder
216
	 * @param folder
217
	 * @param name the name of the tab
218
	 * @param index the index of the message to use for the tab
219
	 * @param choices the listing of choices
220
	 * @return a new page in the parent tab folder
221
	 */
222
	private Composite createPage(Composite parent, String name, int index, String[] choices) {
223
		Composite page = new Composite(parent, SWT.NONE);
224
		page.setLayout(new GridLayout(2, false));
225
		page.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
226
227
		if (parent instanceof TabFolder) {
228
			TabItem tab = new TabItem((TabFolder) parent, SWT.NONE);
229
			tab.setText(name);
230
			tab.setControl(page);
231
		}
232
233
		createVerticalSpacer(page, 1);
234
		Label label = new Label(page, SWT.NULL);
235
		String labelText;
236
		if (index == CompilerFlags.SCHEMA_FLAGS) {
237
			labelText = PDEUIMessages.CompilersConfigurationBlock_altlabel;
238
		} else {
239
			labelText = PDEUIMessages.CompilersConfigurationBlock_label;
240
		}
241
		label.setText(labelText);
242
		GridData gd = new GridData(SWT.BEGINNING, SWT.TOP, true, false);
243
		gd.horizontalSpan = 2;
244
		label.setLayoutData(gd);
245
		createVerticalSpacer(page, 1);
246
		String[] flagIds = CompilerFlags.getFlags(index);
247
		for (int i = 0; i < flagIds.length; i++) {
248
			Control control = createFlag(page, flagIds[i], choices);
249
			fFlagControls.add(control);
250
		}
251
		return page;
252
	}
253
254
	/**
255
	 * Creates a vertical spacer for separating components. If applied to a 
256
	 * <code>GridLayout</code>, this method will automatically span all of the columns of the parent
257
	 * to make vertical space
258
	 * 
259
	 * @param parent the parent composite to add this spacer to
260
	 * @param numlines the number of vertical lines to make as space
261
	 */
262
	public static void createVerticalSpacer(Composite parent, int numlines) {
263
		Label lbl = new Label(parent, SWT.NONE);
264
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
265
		Layout layout = parent.getLayout();
266
		if (layout instanceof GridLayout) {
267
			gd.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns;
268
		}
269
		gd.heightHint = numlines;
270
		lbl.setLayoutData(gd);
271
	}
272
273
	/**
274
	 * Performs a full build of the workspace
275
	 */
276
	private void doFullBuild() {
277
		Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) {
278
			public boolean belongsTo(Object family) {
279
				return ResourcesPlugin.FAMILY_MANUAL_BUILD == family;
280
			}
281
282
			protected IStatus run(IProgressMonitor monitor) {
283
				try {
284
					IProject[] projects = null;
285
					if (project == null) {
286
						projects = PDEPlugin.getWorkspace().getRoot().getProjects();
287
					} else {
288
						projects = new IProject[] {project};
289
					}
290
					monitor.beginTask("", projects.length * 2); //$NON-NLS-1$
291
					for (int i = 0; i < projects.length; i++) {
292
						IProject projectToBuild = projects[i];
293
						if (!projectToBuild.isOpen())
294
							continue;
295
						if (projectToBuild.hasNature(PDE.PLUGIN_NATURE)) {
296
							if (fBuilders.contains(PDE.MANIFEST_BUILDER_ID))
297
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.MANIFEST_BUILDER_ID, null, new SubProgressMonitor(monitor, 1));
298
							else
299
								monitor.worked(1);
300
							if (fBuilders.contains(PDE.SCHEMA_BUILDER_ID))
301
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.SCHEMA_BUILDER_ID, null, new SubProgressMonitor(monitor, 1));
302
							else
303
								monitor.worked(1);
304
						} else if (projectToBuild.hasNature(PDE.FEATURE_NATURE)) {
305
							if (fBuilders.contains(PDE.FEATURE_BUILDER_ID))
306
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.FEATURE_BUILDER_ID, null, new SubProgressMonitor(monitor, 2));
307
						} else {
308
							monitor.worked(2);
309
						}
310
					}
311
				} catch (CoreException e) {
312
					return e.getStatus();
313
				} catch (OperationCanceledException e) {
314
					return Status.CANCEL_STATUS;
315
				} finally {
316
					monitor.done();
317
				}
318
				return Status.OK_STATUS;
319
			}
320
		};
321
		buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
322
		buildJob.setUser(true);
323
		buildJob.schedule();
324
	}
325
326
	/**
327
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
328
	 */
329
	public void performDefaults() {
330
		fChangedControls.clear();
331
		for (int i = 0; i < fFlagControls.size(); i++) {
332
			boolean hasChange = false;
333
			Control control = (Control) fFlagControls.get(i);
334
			String flagId = (String) control.getData();
335
			if (control instanceof Combo) {
336
				if (project != null)
337
					hasChange = CompilerFlags.getFlag(project, flagId) != CompilerFlags.getDefaultFlag(flagId);
338
				else
339
					hasChange = ((Combo) control).getSelectionIndex() != CompilerFlags.getDefaultFlag(flagId);
340
				((Combo) control).select(CompilerFlags.getDefaultFlag(flagId));
341
			} else if (control instanceof Button) {
342
				if (project != null)
343
					hasChange = CompilerFlags.getBoolean(project, flagId) != CompilerFlags.getDefaultBoolean(flagId);
344
				else
345
					hasChange = ((Button) control).getSelection() != CompilerFlags.getDefaultBoolean(flagId);
346
				((Button) control).setSelection(CompilerFlags.getDefaultBoolean(flagId));
347
			} else if (control instanceof Text) {
348
				if (project != null)
349
					hasChange = !CompilerFlags.getString(project, flagId).equals(CompilerFlags.getDefaultString(flagId));
350
				else
351
					hasChange = ((Text) control).getText() != CompilerFlags.getDefaultString(flagId);
352
				((Text) control).setText(CompilerFlags.getDefaultString(flagId));
353
			}
354
			if (hasChange)
355
				fChangedControls.add(control);
356
		}
357
	}
358
359
	/**
360
	 * Applies the changes settings (if any), and requests a full build (if needed)
361
	 * @param enabled
362
	 * @return the success of the operation
363
	 */
364
	public boolean performOk(boolean enabled) {
365
		Set changedControls = fChangedControls;
366
		if (!enabled) {
367
			// fChangedControls is not a valid change.
368
			// The change is the difference between values in
369
			// PROJECT,INSTANCE,DEFAULT
370
			// and INSTANCE,DEFAULT scopes.
371
			changedControls = new HashSet();
372
			for (Iterator iter = fFlagControls.iterator(); iter.hasNext();) {
373
				Control control = (Control) iter.next();
374
				String flagId = (String) control.getData();
375
				if (!CompilerFlags.getString(project, flagId).equals(CompilerFlags.getString(null, flagId))) {
376
					changedControls.add(control);
377
					break;
378
				}
379
			}
380
		}
381
		boolean build = false;
382
		if (changedControls.size() > 0) {
383
			String title;
384
			String message;
385
			if (project != null) {
386
				title = PDEUIMessages.CompilersConfigurationBlock_rebuild_title;
387
				message = PDEUIMessages.CompilersConfigurationBlock_rebuild_message;
388
			} else {
389
				title = PDEUIMessages.CompilersConfigurationBlock_rebuild_many_title;
390
				message = PDEUIMessages.CompilersConfigurationBlock_rebuild_many_message;
391
392
			}
393
394
			MessageDialog dialog = new MessageDialog(fShell, title, null, message, MessageDialog.QUESTION, new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}, 2);
395
			int res = dialog.open();
396
397
			if (res == 2) {
398
				return false;
399
			} else if (res == 0) {
400
				build = true;
401
			}
402
		}
403
		if (project != null && enabled != CompilerFlags.getBoolean(project, CompilerFlags.USE_PROJECT_PREF)) {
404
			if (enabled) {
405
				CompilerFlags.setBoolean(project, CompilerFlags.USE_PROJECT_PREF, true);
406
			} else {
407
				CompilerFlags.clear(project, CompilerFlags.USE_PROJECT_PREF);
408
			}
409
		}
410
		if (changedControls.size() > 0) {
411
			fBuilders = new HashSet();
412
			for (Iterator iter = changedControls.iterator(); iter.hasNext();) {
413
				Control control = (Control) iter.next();
414
				String flagId = (String) control.getData();
415
				if (control instanceof Combo) {
416
					int index = ((Combo) control).getSelectionIndex();
417
					if (project == null) {
418
						CompilerFlags.setFlag(flagId, index);
419
					}
420
				} else if (control instanceof Button) {
421
					boolean value = ((Button) control).getSelection();
422
					if (project == null) {
423
						CompilerFlags.setBoolean(flagId, value);
424
					}
425
				} else if (control instanceof Text) {
426
					String value = ((Text) control).getText();
427
					if (project == null) {
428
						CompilerFlags.setString(flagId, value);
429
					}
430
				}
431
				if (control.getParent().equals(fPluginPage))
432
					fBuilders.add(PDE.MANIFEST_BUILDER_ID);
433
				else if (control.getParent().equals(fSchemaPage))
434
					fBuilders.add(PDE.SCHEMA_BUILDER_ID);
435
				else if (control.getParent().equals(fFeaturePage)) {
436
					fBuilders.add(PDE.FEATURE_BUILDER_ID);
437
					fBuilders.add(PDE.SITE_BUILDER_ID);
438
				}
439
			}
440
			if (project == null) {
441
				CompilerFlags.save();
442
			}
443
		}
444
		if (project != null) {
445
			for (Iterator iter = fFlagControls.iterator(); iter.hasNext();) {
446
				Control control = (Control) iter.next();
447
				String flagId = (String) control.getData();
448
				if (control instanceof Combo) {
449
					int index = ((Combo) control).getSelectionIndex();
450
					if (enabled) {
451
						CompilerFlags.setFlag(project, flagId, index);
452
					} else {
453
						CompilerFlags.clear(project, flagId);
454
					}
455
				} else if (control instanceof Button) {
456
					boolean value = ((Button) control).getSelection();
457
					if (enabled) {
458
						CompilerFlags.setBoolean(project, flagId, value);
459
					} else {
460
						CompilerFlags.clear(project, flagId);
461
					}
462
				} else if (control instanceof Text) {
463
					String value = ((Text) control).getText();
464
					if (enabled) {
465
						CompilerFlags.setString(project, flagId, value);
466
					} else {
467
						CompilerFlags.clear(project, flagId);
468
					}
469
				}
470
			}
471
		}
472
473
		if (build && fBuilders.size() > 0) {
474
			doFullBuild();
475
		}
476
477
		fChangedControls.clear();
478
		return true;
479
	}
480
}
(-)src/org/eclipse/pde/internal/ui/preferences/CompilersPreferencePage.java (-35 / +107 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-37 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.preferences;
11
package org.eclipse.pde.internal.ui.preferences;
12
12
13
import org.eclipse.jface.dialogs.Dialog;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jdt.core.*;
19
import org.eclipse.jface.dialogs.IDialogConstants;
14
import org.eclipse.jface.preference.PreferencePage;
20
import org.eclipse.jface.preference.PreferencePage;
15
import org.eclipse.pde.internal.ui.IHelpContextIds;
21
import org.eclipse.pde.internal.core.natures.PDE;
16
import org.eclipse.pde.internal.ui.PDEUIMessages;
22
import org.eclipse.pde.internal.ui.*;
17
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.widgets.*;
19
import org.eclipse.ui.*;
28
import org.eclipse.ui.*;
29
import org.eclipse.ui.dialogs.PreferencesUtil;
30
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
20
31
32
/**
33
 * Allows PDE compiler preferences to be set
34
 */
21
public class CompilersPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
35
public class CompilersPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
22
36
23
	private CompilersConfigurationTab configurationBlock;
37
	public static final String NO_LINK = "PropertyAndPreferencePage.nolink"; //$NON-NLS-1$
38
39
	private PDECompilersConfigurationBlock fBlock = null;
40
	private Link link = null;
41
42
	private HashMap fPageData = null;
24
43
25
	/**
44
	/**
26
	 *  
45
	 *  
27
	 */
46
	 */
28
	public CompilersPreferencePage() {
47
	public CompilersPreferencePage() {
29
		super();
48
		super();
30
		setDescription(PDEUIMessages.CompilersPreferencePage_desc);
49
		// only used when page is shown programmatically
31
		// only used when page is shown programatically
32
		setTitle(PDEUIMessages.CompilersPreferencePage_title);
50
		setTitle(PDEUIMessages.CompilersPreferencePage_title);
33
34
		configurationBlock = new CompilersConfigurationTab(null);
35
	}
51
	}
36
52
37
	/*
53
	/*
Lines 40-83 Link Here
40
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
56
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
41
	 */
57
	 */
42
	protected Control createContents(Composite parent) {
58
	protected Control createContents(Composite parent) {
43
		Control result = configurationBlock.createContents(parent);
59
		Composite comp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH, 0, 0);
44
		Dialog.applyDialogFont(result);
60
		link = new Link(comp, SWT.NONE);
45
		return result;
61
		link.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
62
		link.setFont(comp.getFont());
63
		link.setText(PDEUIMessages.CompilersPreferencePage_configure_project_specific_settings);
64
		link.addSelectionListener(new SelectionAdapter() {
65
			public void widgetSelected(SelectionEvent e) {
66
				HashSet set = new HashSet();
67
				try {
68
					IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
69
					IProject project = null;
70
					for (int i = 0; i < projects.length; i++) {
71
						project = projects[i].getProject();
72
						try {
73
							if (project.hasNature(PDE.PLUGIN_NATURE) && fBlock.hasProjectSpecificSettings(project)) {
74
								set.add(projects[i]);
75
							}
76
						} catch (CoreException ce) {
77
							//do nothing ignore the project
78
						}
79
					}
80
				} catch (JavaModelException jme) {
81
					//ignore
82
				}
83
				ProjectSelectionDialog psd = new ProjectSelectionDialog(getShell(), set);
84
				if (psd.open() == IDialogConstants.OK_ID) {
85
					HashMap data = new HashMap();
86
					data.put(NO_LINK, Boolean.TRUE);
87
					PreferencesUtil.createPropertyDialogOn(getShell(), ((IJavaProject) psd.getFirstResult()).getProject(), "org.eclipse.pde.internal.ui.properties.compilersPropertyPage", //$NON-NLS-1$
88
							new String[] {"org.eclipse.pde.internal.ui.properties.compilersPropertyPage"}, data).open(); //$NON-NLS-1$
89
				}
90
			}
91
		});
92
		fBlock = new PDECompilersConfigurationBlock(null, (IWorkbenchPreferenceContainer) getContainer());
93
		fBlock.createControl(comp);
94
		PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IHelpContextIds.COMPILERS_PREFERENCE_PAGE);
95
		return comp;
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
100
	 */
101
	public void dispose() {
102
		if (fBlock != null) {
103
			fBlock.dispose();
104
		}
105
		super.dispose();
46
	}
106
	}
47
107
48
	/*
108
	/* (non-Javadoc)
49
	 * @see PreferencePage#createControl(Composite)
109
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
50
	 */
110
	 */
51
	public void createControl(Composite parent) {
111
	public void init(IWorkbench workbench) {
52
		super.createControl(parent);
53
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.COMPILERS_PREFERENCE_PAGE);
54
	}
112
	}
55
113
56
	/*
114
	/* (non-Javadoc)
57
	 * (non-Javadoc)
115
	 * @see org.eclipse.jface.preference.PreferencePage#performCancel()
58
	 * 
59
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
60
	 */
116
	 */
61
	public void init(IWorkbench workbench) {
117
	public boolean performCancel() {
118
		fBlock.performCancel();
119
		return super.performCancel();
62
	}
120
	}
63
121
64
	/*
122
	/* (non-Javadoc)
65
	 * @see PreferencePage#performDefaults()
123
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
124
	 */
125
	public boolean performOk() {
126
		fBlock.performOK();
127
		return super.performOk();
128
	}
129
130
	/* (non-Javadoc)
131
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
132
	 */
133
	protected void performApply() {
134
		fBlock.performApply();
135
		super.performApply();
136
	}
137
138
	/**
139
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
66
	 */
140
	 */
67
	protected void performDefaults() {
141
	protected void performDefaults() {
68
		configurationBlock.performDefaults();
142
		fBlock.performDefaults();
69
		super.performDefaults();
143
		super.performDefaults();
70
	}
144
	}
71
145
72
	/*
146
	/**
73
	 * @see IPreferencePage#performOk()
147
	 * @see org.eclipse.jface.preference.PreferencePage#applyData(java.lang.Object)
74
	 */
148
	 */
75
	public boolean performOk() {
149
	public void applyData(Object data) {
76
		if (!configurationBlock.performOk(true)) {
150
		if (data instanceof HashMap) {
77
			getContainer().updateButtons();
151
			fPageData = (HashMap) data;
78
			return false;
152
			link.setVisible(!Boolean.TRUE.equals(fPageData.get(NO_LINK)));
79
		}
153
		}
80
		return super.performOk();
81
	}
154
	}
82
83
}
155
}
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-5 / +14 lines)
Lines 91-96 Link Here
91
91
92
	public static String OrganizeManifestsProcessor_rootMessage;
92
	public static String OrganizeManifestsProcessor_rootMessage;
93
93
94
	public static String PDECompilersConfigurationBlock_general;
95
96
	public static String PDECompilersConfigurationBlock_references;
97
98
	public static String PDECompilersConfigurationBlock_setting_changed_project;
99
100
	public static String PDECompilersConfigurationBlock_settings_changed;
101
102
	public static String PDECompilersConfigurationBlock_settings_changed_all;
103
104
	public static String PDECompilersConfigurationBlock_usage;
105
94
	public static String PDEWizardNewFileCreationPage_errorMsgStartsWithDot;
106
	public static String PDEWizardNewFileCreationPage_errorMsgStartsWithDot;
95
107
96
	public static String CommandComposerPart_formTitle;
108
	public static String CommandComposerPart_formTitle;
Lines 1895-1911 Link Here
1895
	public static String SiteHTML_loadError;
1907
	public static String SiteHTML_loadError;
1896
1908
1897
	//
1909
	//
1898
1899
	public static String CompilersConfigurationBlock_error;
1900
	public static String CompilersConfigurationBlock_warning;
1901
	public static String CompilersConfigurationBlock_ignore;
1902
	public static String CompilersConfigurationBlock_plugins;
1910
	public static String CompilersConfigurationBlock_plugins;
1903
	public static String CompilersConfigurationBlock_schemas;
1911
	public static String CompilersConfigurationBlock_schemas;
1904
	public static String CompilersConfigurationBlock_features;
1912
	public static String CompilersConfigurationBlock_features;
1905
	public static String CompilersConfigurationBlock_label;
1913
	public static String CompilersConfigurationBlock_label;
1906
	public static String CompilersConfigurationBlock_altlabel;
1914
	public static String CompilersConfigurationBlock_altlabel;
1907
1915
1908
	public static String CompilersPreferencePage_desc;
1916
	public static String CompilersPreferencePage_configure_project_specific_settings;
1917
1909
	public static String CompilersPreferencePage_title;
1918
	public static String CompilersPreferencePage_title;
1910
1919
1911
	public static String CompilersPropertyPage_useworkspacesettings_change;
1920
	public static String CompilersPropertyPage_useworkspacesettings_change;
(-)src/org/eclipse/pde/internal/ui/IPreferenceConstants.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui;
11
package org.eclipse.pde.internal.ui;
12
12
13
/**
14
 * Listing of constants used in PDE preferences
15
 * 
16
 * @noimplement This interface is not intended to be implemented by clients.
17
 */
13
public interface IPreferenceConstants {
18
public interface IPreferenceConstants {
14
19
20
	//compiler options
21
	public static final String VALUE_ERROR = "Error"; //$NON-NLS-1$
22
	public static final String VALUE_WARNING = "Warning"; //$NON-NLS-1$
23
	public static final String VALUE_IGNORE = "Ignore"; //$NON-NLS-1$
24
15
	// Main preference page	
25
	// Main preference page	
16
	public static final String PROP_SHOW_OBJECTS = "Preferences.MainPage.showObjects"; //$NON-NLS-1$
26
	public static final String PROP_SHOW_OBJECTS = "Preferences.MainPage.showObjects"; //$NON-NLS-1$
17
	public static final String VALUE_USE_IDS = "useIds"; //$NON-NLS-1$
27
	public static final String VALUE_USE_IDS = "useIds"; //$NON-NLS-1$
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-4 / +7 lines)
Lines 55-60 Link Here
55
ToggleLinkWithEditorAction_label = Lin&k with Editor
55
ToggleLinkWithEditorAction_label = Lin&k with Editor
56
ToggleLinkWithEditorAction_toolTip = Link with Editor
56
ToggleLinkWithEditorAction_toolTip = Link with Editor
57
ToggleLinkWithEditorAction_description = Link with active editorPDEMultiPageContentOutline.SortingAction.label = Sort
57
ToggleLinkWithEditorAction_description = Link with active editorPDEMultiPageContentOutline.SortingAction.label = Sort
58
PDECompilersConfigurationBlock_general=General
59
PDECompilersConfigurationBlock_references=References
60
PDECompilersConfigurationBlock_setting_changed_project=Compiler settings have changed. A rebuild of the project is required for the changes to take effect.\n\nRebuild {0} now?
61
PDECompilersConfigurationBlock_settings_changed=Settings Changed
62
PDECompilersConfigurationBlock_settings_changed_all=Compiler settings have changed. A full build is required for the changes to take effect.\n\nDo a full build now?
63
PDECompilersConfigurationBlock_usage=Usage
58
PDEMultiPageContentOutline_SortingAction_label = Sort
64
PDEMultiPageContentOutline_SortingAction_label = Sort
59
PDEMultiPageContentOutline_SortingAction_tooltip = Sort
65
PDEMultiPageContentOutline_SortingAction_tooltip = Sort
60
PDEMultiPageContentOutline_SortingAction_description = Sorts elements in the outline
66
PDEMultiPageContentOutline_SortingAction_description = Sorts elements in the outline
Lines 1436-1444 Link Here
1436
1442
1437
##############
1443
##############
1438
1444
1439
CompilersConfigurationBlock_error=Error
1440
CompilersConfigurationBlock_warning=Warning
1441
CompilersConfigurationBlock_ignore=Ignore
1442
CompilersConfigurationBlock_plugins=&Plug-ins
1445
CompilersConfigurationBlock_plugins=&Plug-ins
1443
CompilersConfigurationBlock_schemas=&Schemas
1446
CompilersConfigurationBlock_schemas=&Schemas
1444
CompilersConfigurationBlock_features=&Features and Update Sites
1447
CompilersConfigurationBlock_features=&Features and Update Sites
Lines 1457-1466 Link Here
1457
CompCSCreationOperation_introduction=Introduction
1460
CompCSCreationOperation_introduction=Introduction
1458
CompilersConfigurationBlock_altlabel=Select the following compiler options:
1461
CompilersConfigurationBlock_altlabel=Select the following compiler options:
1459
1462
1460
CompilersPreferencePage_desc=Options for manifest compilers
1461
CompCSTaskGroupDetails_Type=Type*:
1463
CompCSTaskGroupDetails_Type=Type*:
1462
CompCSTaskGroupDetails_Name=Name*:
1464
CompCSTaskGroupDetails_Name=Name*:
1463
CompCSTaskDetails_SkipLabel=This task is optional
1465
CompCSTaskDetails_SkipLabel=This task is optional
1466
CompilersPreferencePage_configure_project_specific_settings=<A>Configure Project Specific Settings...</A>
1464
CompilersPreferencePage_title=Plug-in Compiler
1467
CompilersPreferencePage_title=Plug-in Compiler
1465
CompCSMasterTreeSection_addTask=Add Task
1468
CompCSMasterTreeSection_addTask=Add Task
1466
CompCSTaskGroupDetails_Choice=Choice
1469
CompCSTaskGroupDetails_Choice=Choice
(-)src/org/eclipse/pde/internal/ui/IHelpContextIds.java (+1 lines)
Lines 24-29 Link Here
24
	public static final String IMPLICIT_PLUGINS_PREFERENCE_PAGE = PREFIX + "implicit_plugins_preference_page"; //$NON-NLS-1$
24
	public static final String IMPLICIT_PLUGINS_PREFERENCE_PAGE = PREFIX + "implicit_plugins_preference_page"; //$NON-NLS-1$
25
	public static final String LAUNCHING_ARGS_PREFERENCE_PAGE = PREFIX + "launching_args_preference_page"; //$NON-NLS-1$
25
	public static final String LAUNCHING_ARGS_PREFERENCE_PAGE = PREFIX + "launching_args_preference_page"; //$NON-NLS-1$
26
	public static final String COMPILERS_PREFERENCE_PAGE = PREFIX + "compilers_preference_page"; //$NON-NLS-1$
26
	public static final String COMPILERS_PREFERENCE_PAGE = PREFIX + "compilers_preference_page"; //$NON-NLS-1$
27
	public static final String PROJECT_SELECTION_DIALOG = PREFIX + "project_selection_dialog"; //$NON-NLS-1$
27
	public static final String TARGET_ENVIRONMENT_PREFERENCE_PAGE = PREFIX + "target_environment_preference_page"; //$NON-NLS-1$
28
	public static final String TARGET_ENVIRONMENT_PREFERENCE_PAGE = PREFIX + "target_environment_preference_page"; //$NON-NLS-1$
28
	public static final String TARGET_PLATFORM_PREFERENCE_PAGE = PREFIX + "target_platform_preference_page"; //$NON-NLS-1$
29
	public static final String TARGET_PLATFORM_PREFERENCE_PAGE = PREFIX + "target_platform_preference_page"; //$NON-NLS-1$
29
30
(-)src/org/eclipse/pde/internal/ui/properties/CompilersPropertyPage.java (-81 / +85 lines)
Lines 10-40 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.properties;
11
package org.eclipse.pde.internal.ui.properties;
12
12
13
import java.util.HashMap;
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IProject;
14
import org.eclipse.jface.dialogs.ControlEnableState;
15
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.pde.internal.core.builders.CompilerFlags;
16
import org.eclipse.pde.internal.ui.*;
17
import org.eclipse.pde.internal.ui.IHelpContextIds;
17
import org.eclipse.pde.internal.ui.preferences.CompilersPreferencePage;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
18
import org.eclipse.pde.internal.ui.preferences.PDECompilersConfigurationBlock;
19
import org.eclipse.pde.internal.ui.preferences.CompilersConfigurationTab;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.*;
23
import org.eclipse.swt.widgets.*;
26
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.dialogs.PreferencesUtil;
28
import org.eclipse.ui.dialogs.PropertyPage;
25
import org.eclipse.ui.dialogs.PropertyPage;
26
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
29
27
30
/**
28
/**
31
 * The PDE manifest compiler options property page for plugin projects
29
 * The PDE manifest compiler options property page for plugin projects
32
 */
30
 */
33
public class CompilersPropertyPage extends PropertyPage {
31
public class CompilersPropertyPage extends PropertyPage {
34
32
35
	private ControlEnableState blockEnableState;
33
	/**
36
	private CompilersConfigurationTab configurationBlock;
34
	 * The data map passed when showing the page
37
	private Control configurationBlockControl;
35
	 */
36
	private HashMap fPageData = null;
37
38
	/**
39
	 * The control block 
40
	 */
41
	private PDECompilersConfigurationBlock fBlock = null;
38
42
39
	/**
43
	/**
40
	 * If project specific settings are being used or not
44
	 * If project specific settings are being used or not
Lines 52-105 Link Here
52
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
56
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
53
	 */
57
	 */
54
	protected Control createContents(Composite parent) {
58
	protected Control createContents(Composite parent) {
55
		configurationBlock = new CompilersConfigurationTab(getProject());
59
		Composite comp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH, 0, 0);
56
		Composite composite = new Composite(parent, SWT.NONE);
60
		Composite tcomp = SWTFactory.createComposite(comp, 2, 1, GridData.FILL_HORIZONTAL, 0, 0);
57
		GridLayout layout = new GridLayout();
61
		fProjectSpecific = new Button(tcomp, SWT.CHECK);
58
		layout.marginHeight = 0;
59
		layout.marginWidth = 0;
60
		layout.numColumns = 2;
61
		composite.setLayout(layout);
62
63
		fProjectSpecific = new Button(composite, SWT.CHECK);
64
		fProjectSpecific.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false));
62
		fProjectSpecific.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false));
65
		fProjectSpecific.setText(PDEUIMessages.CompilersPropertyPage_useprojectsettings_label);
63
		fProjectSpecific.setText(PDEUIMessages.CompilersPropertyPage_useprojectsettings_label);
66
		fProjectSpecific.addSelectionListener(new SelectionAdapter() {
64
		fProjectSpecific.addSelectionListener(new SelectionAdapter() {
67
			public void widgetSelected(SelectionEvent e) {
65
			public void widgetSelected(SelectionEvent e) {
68
				updateEnableState();
66
				boolean psp = fProjectSpecific.getSelection();
69
			}
67
				fBlock.useProjectSpecificSettings(psp);
70
		});
68
				if (fWorkspaceLink != null) {
71
69
					fWorkspaceLink.setEnabled(!psp);
72
		fWorkspaceLink = new Link(composite, SWT.NONE);
70
				}
73
		fWorkspaceLink.setText(PDEUIMessages.CompilersPropertyPage_useworkspacesettings_change);
74
		fWorkspaceLink.addSelectionListener(new SelectionAdapter() {
75
			public void widgetSelected(SelectionEvent e) {
76
				String id = "org.eclipse.pde.ui.CompilersPreferencePage"; //$NON-NLS-1$
77
				PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] {id}, null).open();
78
			}
71
			}
79
		});
72
		});
80
73
81
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
74
		if (offerLink()) {
82
		data.horizontalSpan = 2;
75
			fWorkspaceLink = new Link(tcomp, SWT.NONE);
83
76
			fWorkspaceLink.setText(PDEUIMessages.CompilersPropertyPage_useworkspacesettings_change);
84
		configurationBlockControl = configurationBlock.createContents(composite);
77
			fWorkspaceLink.addSelectionListener(new SelectionAdapter() {
85
		configurationBlockControl.setLayoutData(data);
78
				public void widgetSelected(SelectionEvent e) {
86
79
					HashMap data = new HashMap();
87
		boolean useProjectSettings = CompilerFlags.getBoolean(getProject(), CompilerFlags.USE_PROJECT_PREF);
80
					data.put(CompilersPreferencePage.NO_LINK, Boolean.TRUE);
88
81
					SWTFactory.showPreferencePage(getShell(), "org.eclipse.pde.ui.CompilersPreferencePage", data); //$NON-NLS-1$
89
		fProjectSpecific.setSelection(useProjectSettings);
82
				}
90
		fWorkspaceLink.setEnabled(!useProjectSettings);
83
			});
84
		}
91
85
92
		updateEnableState();
86
		fBlock = new PDECompilersConfigurationBlock(getProject(), (IWorkbenchPreferenceContainer) getContainer());
93
		Dialog.applyDialogFont(composite);
87
		fBlock.createControl(comp);
94
		return composite;
95
	}
96
88
97
	/*
89
		boolean ps = fBlock.hasProjectSpecificSettings(getProject());
98
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
90
		fProjectSpecific.setSelection(ps);
99
	 */
91
		fBlock.useProjectSpecificSettings(ps);
100
	public void createControl(Composite parent) {
92
		if (fWorkspaceLink != null) {
101
		super.createControl(parent);
93
			fWorkspaceLink.setEnabled(!ps);
102
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.COMPILERS_PROPERTY_PAGE);
94
		}
95
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.COMPILERS_PROPERTY_PAGE);
96
		Dialog.applyDialogFont(comp);
97
		return comp;
103
	}
98
	}
104
99
105
	/**
100
	/**
Lines 109-159 Link Here
109
		return (IProject) getElement().getAdapter(IProject.class);
104
		return (IProject) getElement().getAdapter(IProject.class);
110
	}
105
	}
111
106
112
	/*
107
	/* (non-Javadoc)
113
	 * @see org.eclipse.jface.preference.IPreferencePage#performDefaults()
108
	 * @see org.eclipse.jface.preference.PreferencePage#performCancel()
114
	 */
109
	 */
115
	protected void performDefaults() {
110
	public boolean performCancel() {
116
		if (useProjectSettings()) {
111
		fBlock.performCancel();
117
			fProjectSpecific.setSelection(false);
112
		return super.performCancel();
118
			updateEnableState();
119
			configurationBlock.performDefaults();
120
		}
121
		super.performDefaults();
122
	}
113
	}
123
114
124
	/*
115
	/* (non-Javadoc)
125
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
116
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
126
	 */
117
	 */
127
	public boolean performOk() {
118
	public boolean performOk() {
128
		if (!configurationBlock.performOk(useProjectSettings())) {
119
		fBlock.performOK();
129
			getContainer().updateButtons();
130
			return false;
131
		}
132
		return super.performOk();
120
		return super.performOk();
133
	}
121
	}
134
122
135
	/**
123
	/**
136
	 * Updates the enabled state of the controls based on the project specific settings
124
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
137
	 */
125
	 */
138
	private void updateEnableState() {
126
	protected void performDefaults() {
139
		if (useProjectSettings()) {
127
		fBlock.performDefaults();
140
			if (blockEnableState != null) {
128
		super.performDefaults();
141
				fWorkspaceLink.setEnabled(false);
129
	}
142
				blockEnableState.restore();
130
143
				blockEnableState = null;
131
	/* (non-Javadoc)
144
			}
132
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
145
		} else {
133
	 */
146
			if (blockEnableState == null) {
134
	protected void performApply() {
147
				fWorkspaceLink.setEnabled(true);
135
		fBlock.performApply();
148
				blockEnableState = ControlEnableState.disable(configurationBlockControl);
136
		super.performApply();
149
			}
137
	}
150
		}
138
139
	/* (non-Javadoc)
140
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
141
	 */
142
	public void dispose() {
143
		fBlock.dispose();
144
		super.dispose();
151
	}
145
	}
152
146
153
	/**
147
	/**
154
	 * @return if project specific settings are being configured
148
	 * @return true if the link should be shown, false otherwise
155
	 */
149
	 */
156
	private boolean useProjectSettings() {
150
	private boolean offerLink() {
157
		return fProjectSpecific.getSelection();
151
		return fPageData == null || !Boolean.TRUE.equals(fPageData.get(CompilersPreferencePage.NO_LINK));
152
	}
153
154
	/**
155
	 * @see org.eclipse.jface.preference.PreferencePage#applyData(java.lang.Object)
156
	 */
157
	public void applyData(Object data) {
158
		if (data instanceof HashMap) {
159
			fPageData = (HashMap) data;
160
			fWorkspaceLink.setVisible(!Boolean.TRUE.equals(fPageData.get(CompilersPreferencePage.NO_LINK)));
161
		}
158
	}
162
	}
159
}
163
}
(-)src/org/eclipse/pde/internal/ui/preferences/ProjectSelectionDialog.java (+185 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.pde.internal.ui.preferences;
12
13
import java.util.HashSet;
14
import java.util.Set;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.jdt.core.*;
18
import org.eclipse.jdt.ui.*;
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.dialogs.IDialogSettings;
21
import org.eclipse.jface.viewers.*;
22
import org.eclipse.pde.internal.core.natures.PDE;
23
import org.eclipse.pde.internal.ui.*;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.graphics.Font;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.widgets.*;
30
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.dialogs.SelectionStatusDialog;
32
33
/**
34
 * A dialog for selecting a project to configure project specific settings for
35
 * 
36
 * @since 1.0.0
37
 */
38
public class ProjectSelectionDialog extends SelectionStatusDialog {
39
40
	class ApiJavaElementContentProvider extends StandardJavaElementContentProvider {
41
		public Object[] getChildren(Object element) {
42
			if (element instanceof IJavaModel) {
43
				IJavaModel model = (IJavaModel) element;
44
				HashSet set = new HashSet();
45
				try {
46
					IJavaProject[] projects = model.getJavaProjects();
47
					for (int i = 0; i < projects.length; i++) {
48
						if (projects[i].getProject().hasNature(PDE.PLUGIN_NATURE)) {
49
							set.add(projects[i]);
50
						}
51
					}
52
				} catch (JavaModelException jme) {
53
					//ignore
54
				} catch (CoreException ce) {
55
					//ignore
56
				}
57
				return set.toArray();
58
			}
59
			return super.getChildren(element);
60
		}
61
	}
62
63
	// the visual selection widget group
64
	private TableViewer fTableViewer;
65
	private Set fProjectsWithSpecifics;
66
67
	// sizing constants
68
	private final static int SIZING_SELECTION_WIDGET_HEIGHT = 250;
69
	private final static int SIZING_SELECTION_WIDGET_WIDTH = 300;
70
71
	private final static String DIALOG_SETTINGS_SHOW_ALL = "ProjectSelectionDialog.show_all"; //$NON-NLS-1$
72
73
	/**
74
	 * The filter for the viewer
75
	 */
76
	private ViewerFilter fFilter;
77
78
	/**
79
	 * Constructor
80
	 * @param parentShell
81
	 * @param projectsWithSpecifics
82
	 */
83
	public ProjectSelectionDialog(Shell parentShell, Set projectsWithSpecifics) {
84
		super(parentShell);
85
		setTitle("Project Specific Configuration");
86
		setMessage("&Select the project to configure:");
87
		fProjectsWithSpecifics = projectsWithSpecifics;
88
89
		fFilter = new ViewerFilter() {
90
			public boolean select(Viewer viewer, Object parentElement, Object element) {
91
				return fProjectsWithSpecifics.contains(element);
92
			}
93
		};
94
	}
95
96
	/* (non-Javadoc)
97
	 * Method declared on Dialog.
98
	 */
99
	protected Control createDialogArea(Composite parent) {
100
		// page group
101
		Composite composite = (Composite) super.createDialogArea(parent);
102
103
		Font font = parent.getFont();
104
		composite.setFont(font);
105
106
		createMessageArea(composite);
107
108
		fTableViewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
109
		fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
110
			public void selectionChanged(SelectionChangedEvent event) {
111
				doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
112
			}
113
		});
114
		fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
115
			public void doubleClick(DoubleClickEvent event) {
116
				okPressed();
117
			}
118
		});
119
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
120
		data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
121
		data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
122
		fTableViewer.getTable().setLayoutData(data);
123
124
		fTableViewer.setLabelProvider(new JavaElementLabelProvider());
125
		fTableViewer.setContentProvider(new ApiJavaElementContentProvider());
126
		fTableViewer.setComparator(new JavaElementComparator());
127
		fTableViewer.getControl().setFont(font);
128
129
		Button checkbox = SWTFactory.createCheckButton(composite, "Show only &projects with project specific settings", null, false, 1);
130
		checkbox.addSelectionListener(new SelectionListener() {
131
			public void widgetSelected(SelectionEvent e) {
132
				updateFilter(((Button) e.widget).getSelection());
133
			}
134
135
			public void widgetDefaultSelected(SelectionEvent e) {
136
				updateFilter(((Button) e.widget).getSelection());
137
			}
138
		});
139
		IDialogSettings dialogSettings = PDEPlugin.getDefault().getDialogSettings();
140
		boolean doFilter = !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !fProjectsWithSpecifics.isEmpty();
141
		checkbox.setSelection(doFilter);
142
		updateFilter(doFilter);
143
144
		IJavaModel input = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
145
		fTableViewer.setInput(input);
146
147
		doSelectionChanged(new Object[0]);
148
		Dialog.applyDialogFont(composite);
149
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.PROJECT_SELECTION_DIALOG);
150
		return composite;
151
	}
152
153
	/**
154
	 * Handles the change in selection of the viewer and updates the status of the dialog at the same time
155
	 * @param objects
156
	 */
157
	private void doSelectionChanged(Object[] objects) {
158
		if (objects.length != 1) {
159
			updateStatus(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "")); //$NON-NLS-1$
160
			setSelectionResult(null);
161
		} else {
162
			updateStatus(new Status(IStatus.OK, PDEPlugin.getPluginId(), "")); //$NON-NLS-1$
163
			setSelectionResult(objects);
164
		}
165
	}
166
167
	/**
168
	 * Updates the viewer filter based on the selection of the 'show project with...' button
169
	 * @param selected
170
	 */
171
	protected void updateFilter(boolean selected) {
172
		if (selected) {
173
			fTableViewer.addFilter(fFilter);
174
		} else {
175
			fTableViewer.removeFilter(fFilter);
176
		}
177
		PDEPlugin.getDefault().getDialogSettings().put(DIALOG_SETTINGS_SHOW_ALL, !selected);
178
	}
179
180
	/* (non-Javadoc)
181
	 * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
182
	 */
183
	protected void computeResult() {
184
	}
185
}
(-)src/org/eclipse/pde/internal/ui/PixelConverter.java (+43 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.pde.internal.ui;
12
13
14
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.swt.graphics.FontMetrics;
16
import org.eclipse.swt.graphics.GC;
17
import org.eclipse.swt.widgets.Control;
18
19
public class PixelConverter {
20
	
21
	private FontMetrics fFontMetrics;
22
	
23
	public PixelConverter(Control control) {
24
		GC gc = new GC(control);
25
		gc.setFont(control.getFont());
26
		fFontMetrics= gc.getFontMetrics();
27
		gc.dispose();
28
	}
29
		
30
	/**
31
	 * @see DialogPage#convertHorizontalDLUsToPixels
32
	 */
33
	public int convertHorizontalDLUsToPixels(int dlus) {
34
		return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
35
	}
36
	
37
	/**
38
	 * @see DialogPage#convertWidthInCharsToPixels
39
	 */
40
	public int convertWidthInCharsToPixels(int chars) {
41
		return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
42
	}	
43
}
(-)src/org/eclipse/pde/internal/ui/SWTFactory.java (+546 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.pde.internal.ui;
12
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.jface.resource.JFaceResources;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.*;
22
import org.eclipse.ui.dialogs.PreferencesUtil;
23
import org.eclipse.ui.forms.widgets.ExpandableComposite;
24
import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
25
26
/**
27
 * Factory class to create some SWT resources. 
28
 * 
29
 * @since 3.4.0
30
 */
31
public class SWTFactory {
32
33
	/**
34
	 * Returns a width hint for a button control.
35
	 */
36
	public static int getButtonWidthHint(Button button) {
37
		button.setFont(JFaceResources.getDialogFont());
38
		PixelConverter converter = new PixelConverter(button);
39
		int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
40
		return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
41
	}
42
43
	/**
44
	 * Sets width and height hint for the button control.
45
	 * <b>Note:</b> This is a NOP if the button's layout data is not
46
	 * an instance of <code>GridData</code>.
47
	 * 
48
	 * @param	the button for which to set the dimension hint
49
	 */
50
	public static void setButtonDimensionHint(Button button) {
51
		Assert.isNotNull(button);
52
		Object gd = button.getLayoutData();
53
		if (gd instanceof GridData) {
54
			((GridData) gd).widthHint = getButtonWidthHint(button);
55
			((GridData) gd).horizontalAlignment = GridData.FILL;
56
		}
57
	}
58
59
	/**
60
	 * Creates a check box button using the parents' font
61
	 * 
62
	 * @param parent the parent to add the button to
63
	 * @param label the label for the button
64
	 * @param image the image for the button 
65
	 * @param checked the initial checked state of the button
66
	 * @param hspan the horizontal span to take up in the parent composite
67
	 * @return a new checked button set to the initial checked state
68
	 */
69
	public static Button createCheckButton(Composite parent, String label, Image image, boolean checked, int hspan) {
70
		Button button = new Button(parent, SWT.CHECK);
71
		button.setFont(parent.getFont());
72
		button.setSelection(checked);
73
		if (image != null) {
74
			button.setImage(image);
75
		}
76
		if (label != null) {
77
			button.setText(label);
78
		}
79
		GridData gd = new GridData();
80
		gd.horizontalSpan = hspan;
81
		button.setLayoutData(gd);
82
		setButtonDimensionHint(button);
83
		return button;
84
	}
85
86
	/**
87
	 * Creates and returns a new push button with the given
88
	 * label and/or image.
89
	 * 
90
	 * @param parent parent control
91
	 * @param label button label or <code>null</code>
92
	 * @param image image of <code>null</code>
93
	 * @return a new push button
94
	 */
95
	public static Button createPushButton(Composite parent, String label, Image image) {
96
		Button button = new Button(parent, SWT.PUSH);
97
		button.setFont(parent.getFont());
98
		if (image != null) {
99
			button.setImage(image);
100
		}
101
		if (label != null) {
102
			button.setText(label);
103
		}
104
		GridData gd = new GridData();
105
		button.setLayoutData(gd);
106
		SWTFactory.setButtonDimensionHint(button);
107
		return button;
108
	}
109
110
	/**
111
	 * Creates and returns a new push button with the given
112
	 * label and/or image.
113
	 * 
114
	 * @param parent parent control
115
	 * @param label button label or <code>null</code>
116
	 * @param image image of <code>null</code>
117
	 * @param fill the alignment for the new button
118
	 * @return a new push button
119
	 */
120
	public static Button createPushButton(Composite parent, String label, Image image, int fill) {
121
		Button button = new Button(parent, SWT.PUSH);
122
		button.setFont(parent.getFont());
123
		if (image != null) {
124
			button.setImage(image);
125
		}
126
		if (label != null) {
127
			button.setText(label);
128
		}
129
		GridData gd = new GridData(fill);
130
		button.setLayoutData(gd);
131
		SWTFactory.setButtonDimensionHint(button);
132
		return button;
133
	}
134
135
	/**
136
	 * Creates and returns a new radio button with the given
137
	 * label.
138
	 * 
139
	 * @param parent parent control
140
	 * @param label button label or <code>null</code>
141
	 * @return a new radio button
142
	 */
143
	public static Button createRadioButton(Composite parent, String label) {
144
		Button button = new Button(parent, SWT.RADIO);
145
		button.setFont(parent.getFont());
146
		if (label != null) {
147
			button.setText(label);
148
		}
149
		GridData gd = new GridData();
150
		button.setLayoutData(gd);
151
		SWTFactory.setButtonDimensionHint(button);
152
		return button;
153
	}
154
155
	/**
156
	 * Creates a new label widget
157
	 * 
158
	 * @param parent the parent composite to add this label widget to
159
	 * @param text the text for the label
160
	 * @param hspan the horizontal span to take up in the parent composite
161
	 * @return the new label
162
	 */
163
	public static Label createLabel(Composite parent, String text, int hspan) {
164
		Label l = new Label(parent, SWT.NONE);
165
		l.setFont(parent.getFont());
166
		l.setText(text);
167
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
168
		gd.horizontalSpan = hspan;
169
		gd.grabExcessHorizontalSpace = false;
170
		l.setLayoutData(gd);
171
		return l;
172
	}
173
174
	/**
175
	 * Creates a new label widget
176
	 * 
177
	 * @param parent the parent composite to add this label widget to
178
	 * @param text the text for the label
179
	 * @param font the font for the label
180
	 * @param hspan the horizontal span to take up in the parent composite
181
	 * @return the new label
182
	 */
183
	public static Label createLabel(Composite parent, String text, Font font, int hspan) {
184
		Label l = new Label(parent, SWT.NONE);
185
		l.setFont(font);
186
		l.setText(text);
187
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
188
		gd.horizontalSpan = hspan;
189
		l.setLayoutData(gd);
190
		return l;
191
	}
192
193
	/**
194
	 * Creates a wrapping label
195
	 * 
196
	 * @param parent the parent composite to add this label to
197
	 * @param text the text to be displayed in the label
198
	 * @param hspan the horizontal span that label should take up in the parent composite
199
	 * @param wrapwidth the width hint that the label should wrap at
200
	 * @return a new label that wraps at a specified width
201
	 */
202
	public static Label createWrapLabel(Composite parent, String text, int hspan, int wrapwidth) {
203
		Label l = new Label(parent, SWT.NONE | SWT.WRAP);
204
		l.setFont(parent.getFont());
205
		l.setText(text);
206
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
207
		gd.horizontalSpan = hspan;
208
		gd.widthHint = wrapwidth;
209
		l.setLayoutData(gd);
210
		return l;
211
	}
212
213
	/**
214
	 * Creates a wrapping label
215
	 * 
216
	 * @param parent the parent composite to add this label to
217
	 * @param text the text to be displayed in the label
218
	 * @param hspan the horizontal span that label should take up in the parent composite
219
	 * @return a new label that wraps at a specified width
220
	 */
221
	public static Label createWrapLabel(Composite parent, String text, int hspan) {
222
		Label l = new Label(parent, SWT.NONE | SWT.WRAP);
223
		l.setFont(parent.getFont());
224
		l.setText(text);
225
		GridData gd = new GridData(GridData.BEGINNING);
226
		gd.horizontalSpan = hspan;
227
		l.setLayoutData(gd);
228
		return l;
229
	}
230
231
	/**
232
	 * Creates a scrolled composite 
233
	 * 
234
	 * @param parent the parent to add to
235
	 * @param columns the number of columns for the composite
236
	 * @param hspan the horizontal span to take up in the parent
237
	 * @param marginwidth the width of the margins
238
	 * @param marginheight the height of the margins
239
	 * @return a new scrolled composite
240
	 */
241
	public static SharedScrolledComposite createScrolledComposite(Composite parent, int columns, int hspan, int marginwidth, int marginheight) {
242
		SharedScrolledComposite comp = new SharedScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL) {};
243
		GridLayout layout = new GridLayout(columns, false);
244
		layout.marginHeight = marginheight;
245
		layout.marginWidth = marginwidth;
246
		comp.setLayout(layout);
247
		GridData gd = new GridData(GridData.FILL_BOTH);
248
		gd.horizontalSpan = hspan;
249
		comp.setLayoutData(gd);
250
		comp.setExpandHorizontal(true);
251
		comp.setExpandVertical(true);
252
		return comp;
253
	}
254
255
	/**
256
	 * Creates an ExpandibleComposite widget
257
	 * 
258
	 * @param parent the parent to add this widget to
259
	 * @param style the style for ExpandibleComposite expanding handle, and layout
260
	 * @param label the label for the widget
261
	 * @param hspan how many columns to span in the parent
262
	 * @param fill the fill style for the widget
263
	 * Can be one of <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or <code>GridData.FILL_VERTICAL</code>
264
	 * @return a new ExpandibleComposite widget
265
	 */
266
	public static ExpandableComposite createExpandibleComposite(Composite parent, String label, int hspan, int fill) {
267
		ExpandableComposite ex = new ExpandableComposite(parent, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
268
		ex.setText(label);
269
		ex.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
270
		GridData gd = new GridData(fill);
271
		gd.horizontalSpan = hspan;
272
		gd.grabExcessHorizontalSpace = true;
273
		ex.setLayoutData(gd);
274
		return ex;
275
	}
276
277
	/**
278
	 * Creates a new text widget 
279
	 * 
280
	 * @param parent the parent composite to add this text widget to
281
	 * @param hspan the horizontal span to take up on the parent composite
282
	 * @return the new text widget
283
	 * 
284
	 */
285
	public static Text createSingleText(Composite parent, int hspan) {
286
		Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);
287
		t.setFont(parent.getFont());
288
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
289
		gd.horizontalSpan = hspan;
290
		t.setLayoutData(gd);
291
		return t;
292
	}
293
294
	/**
295
	 * Creates a new text widget 
296
	 * 
297
	 * @param parent the parent composite to add this text widget to
298
	 * @param style the style bits for the text widget
299
	 * @param hspan the horizontal span to take up on the parent composite
300
	 * @param fill the fill for the grid layout
301
	 * @return the new text widget
302
	 */
303
	public static Text createText(Composite parent, int style, int hspan, int fill) {
304
		Text t = new Text(parent, style);
305
		t.setFont(parent.getFont());
306
		GridData gd = new GridData(fill);
307
		gd.horizontalSpan = hspan;
308
		t.setLayoutData(gd);
309
		return t;
310
	}
311
312
	/**
313
	 * Creates a new text widget 
314
	 * 
315
	 * @param parent the parent composite to add this text widget to
316
	 * @param style the style bits for the text widget
317
	 * @param hspan the horizontal span to take up on the parent composite
318
	 * @return the new text widget
319
	 */
320
	public static Text createText(Composite parent, int style, int hspan) {
321
		Text t = new Text(parent, style);
322
		t.setFont(parent.getFont());
323
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
324
		gd.horizontalSpan = hspan;
325
		t.setLayoutData(gd);
326
		return t;
327
	}
328
329
	/**
330
	 * Creates a new text widget 
331
	 * 
332
	 * @param parent the parent composite to add this text widget to
333
	 * @param style the style bits for the text widget
334
	 * @param hspan the horizontal span to take up on the parent composite
335
	 * @param width the desired width of the text widget
336
	 * @param height the desired height of the text widget
337
	 * @param fill the fill style for the widget
338
	 * @return the new text widget
339
	 */
340
	public static Text createText(Composite parent, int style, int hspan, int width, int height, int fill) {
341
		Text t = new Text(parent, style);
342
		t.setFont(parent.getFont());
343
		GridData gd = new GridData(fill);
344
		gd.horizontalSpan = hspan;
345
		gd.widthHint = width;
346
		gd.heightHint = height;
347
		t.setLayoutData(gd);
348
		return t;
349
	}
350
351
	/**
352
	 * Creates a Group widget
353
	 * 
354
	 * @param parent the parent composite to add this group to
355
	 * @param text the text for the heading of the group
356
	 * @param columns the number of columns within the group
357
	 * @param hspan the horizontal span the group should take up on the parent
358
	 * @param fill the style for how this composite should fill into its parent
359
	 * @return the new group
360
	 */
361
	public static Group createGroup(Composite parent, String text, int columns, int hspan, int fill) {
362
		Group g = new Group(parent, SWT.NONE);
363
		g.setLayout(new GridLayout(columns, false));
364
		g.setText(text);
365
		g.setFont(parent.getFont());
366
		GridData gd = new GridData(fill);
367
		gd.horizontalSpan = hspan;
368
		g.setLayoutData(gd);
369
		return g;
370
	}
371
372
	/**
373
	 * Creates a composite that uses the parent's font and has a grid layout
374
	 * 
375
	 * @param parent the parent to add the composite to
376
	 * @param columns the number of columns the composite should have
377
	 * @param hspan the horizontal span the new composite should take up in the parent
378
	 * @param fill the fill style of the composite {@link GridData}
379
	 * @return a new composite with a grid layout
380
	 */
381
	public static Composite createComposite(Composite parent, int columns, int hspan, int fill) {
382
		Composite g = new Composite(parent, SWT.NONE);
383
		g.setLayout(new GridLayout(columns, false));
384
		g.setFont(parent.getFont());
385
		GridData gd = new GridData(fill);
386
		gd.horizontalSpan = hspan;
387
		gd.grabExcessHorizontalSpace = true;
388
		g.setLayoutData(gd);
389
		return g;
390
	}
391
392
	/**
393
	 * Creates a composite that uses the parent's font and has a grid layout
394
	 * 
395
	 * @param parent the parent to add the composite to
396
	 * @param font the font to use for this composite
397
	 * @param columns the number of columns the composite should have
398
	 * @param hspan the horizontal span the new composite should take up in the parent
399
	 * @param fill the fill style of the composite {@link GridData}
400
	 * @return a new composite with a grid layout
401
	 */
402
	public static Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) {
403
		Composite g = new Composite(parent, SWT.NONE);
404
		g.setLayout(new GridLayout(columns, false));
405
		g.setFont(font);
406
		GridData gd = new GridData(fill);
407
		gd.horizontalSpan = hspan;
408
		gd.grabExcessHorizontalSpace = true;
409
		g.setLayoutData(gd);
410
		return g;
411
	}
412
413
	/**
414
	 * Creates a composite that uses the parent's font and has a grid layout
415
	 * 
416
	 * @param parent the parent to add the composite to
417
	 * @param columns the number of columns the composite should have
418
	 * @param hspan the horizontal span the new composite should take up in the parent
419
	 * @param fill the fill style of the composite {@link GridData}
420
	 * @param style the style of the composite
421
	 * @return a new composite with a grid layout
422
	 */
423
	public static Composite createComposite(Composite parent, int columns, int hspan, int fill, int style) {
424
		Composite g = new Composite(parent, style);
425
		g.setLayout(new GridLayout(columns, false));
426
		g.setFont(parent.getFont());
427
		GridData gd = new GridData(fill);
428
		gd.horizontalSpan = hspan;
429
		gd.grabExcessHorizontalSpace = true;
430
		g.setLayoutData(gd);
431
		return g;
432
	}
433
434
	/**
435
	 * Creates a vertical spacer for separating components. If applied to a 
436
	 * <code>GridLayout</code>, this method will automatically span all of the columns of the parent
437
	 * to make vertical space
438
	 * 
439
	 * @param parent the parent composite to add this spacer to
440
	 * @param numlines the number of vertical lines to make as space
441
	 */
442
	public static void createVerticalSpacer(Composite parent, int numlines) {
443
		Label lbl = new Label(parent, SWT.NONE);
444
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
445
		Layout layout = parent.getLayout();
446
		if (layout instanceof GridLayout) {
447
			gd.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns;
448
		}
449
		gd.heightHint = numlines;
450
		lbl.setLayoutData(gd);
451
	}
452
453
	/**
454
	 * Creates a horizontal spacer for separating components
455
	 * 
456
	 * @param comp
457
	 * @param numlines
458
	 */
459
	public static void createHorizontalSpacer(Composite comp, int numlines) {
460
		Label lbl = new Label(comp, SWT.NONE);
461
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
462
		gd.horizontalSpan = numlines;
463
		lbl.setLayoutData(gd);
464
	}
465
466
	/**
467
	 * Creates a Composite widget
468
	 * 
469
	 * @param parent the parent composite to add this composite to
470
	 * @param columns the number of columns within the composite
471
	 * @param hspan the horizontal span the composite should take up on the parent
472
	 * @param fill the style for how this composite should fill into its parent
473
	 * @param marginwidth the width of the margin to place on the sides of the composite (default is 5, specified by GridLayout)
474
	 * @param marginheight the height of the margin to place o the top and bottom of the composite
475
	 * @return the new composite
476
	 */
477
	public static Composite createComposite(Composite parent, int columns, int hspan, int fill, int marginwidth, int marginheight) {
478
		Composite g = new Composite(parent, SWT.NONE);
479
		GridLayout layout = new GridLayout(columns, false);
480
		layout.marginWidth = marginwidth;
481
		layout.marginHeight = marginheight;
482
		g.setLayout(layout);
483
		g.setFont(parent.getFont());
484
		GridData gd = new GridData(fill);
485
		gd.horizontalSpan = hspan;
486
		g.setLayoutData(gd);
487
		return g;
488
	}
489
490
	/**
491
	 * This method is used to make a combo box
492
	 * 
493
	 * @param parent the parent composite to add the new combo to
494
	 * @param style the style for the Combo
495
	 * @param hspan the horizontal span to take up on the parent composite
496
	 * @param fill how the combo will fill into the composite
497
	 * Can be one of <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or <code>GridData.FILL_VERTICAL</code>
498
	 * @param items the item to put into the combo
499
	 * @return a new Combo instance
500
	 */
501
	public static Combo createCombo(Composite parent, int style, int hspan, int fill, String[] items) {
502
		Combo c = new Combo(parent, style);
503
		c.setFont(parent.getFont());
504
		GridData gd = new GridData(fill);
505
		gd.horizontalSpan = hspan;
506
		c.setLayoutData(gd);
507
		if (items != null) {
508
			c.setItems(items);
509
		}
510
		c.select(0);
511
		return c;
512
	}
513
514
	/**
515
	 * This method is used to make a combo box with a default fill style of GridData.FILL_HORIZONTAL
516
	 * 
517
	 * @param parent the parent composite to add the new combo to
518
	 * @param style the style for the Combo
519
	 * @param hspan the horizontal span to take up on the parent composite
520
	 * @param items the item to put into the combo
521
	 * @return a new Combo instance
522
	 */
523
	public static Combo createCombo(Composite parent, int style, int hspan, String[] items) {
524
		Combo c = new Combo(parent, style);
525
		c.setFont(parent.getFont());
526
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
527
		gd.horizontalSpan = hspan;
528
		c.setLayoutData(gd);
529
		if (items != null) {
530
			c.setItems(items);
531
		}
532
		c.select(0);
533
		return c;
534
	}
535
536
	/**
537
	 * This method allows us to open the preference dialog on the specific page, in this case the perspective page
538
	 * 
539
	 * @param shell the parent shell
540
	 * @param id the id of preference page to show
541
	 * @param page the actual page to show
542
	 */
543
	public static void showPreferencePage(Shell shell, String id, Object data) {
544
		PreferencesUtil.createPreferenceDialogOn(shell, id, new String[] {id}, data).open();
545
	}
546
}
(-)src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java (+912 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.pde.internal.ui.preferences;
12
13
import com.ibm.icu.text.MessageFormat;
14
import java.util.*;
15
import java.util.List;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.core.runtime.preferences.*;
20
import org.eclipse.jface.dialogs.IDialogSettings;
21
import org.eclipse.jface.dialogs.MessageDialog;
22
import org.eclipse.jface.resource.JFaceResources;
23
import org.eclipse.pde.internal.core.builders.CompilerFlags;
24
import org.eclipse.pde.internal.core.natures.PDE;
25
import org.eclipse.pde.internal.ui.*;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.custom.ScrolledComposite;
28
import org.eclipse.swt.events.*;
29
import org.eclipse.swt.graphics.Point;
30
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.*;
33
import org.eclipse.ui.forms.events.ExpansionAdapter;
34
import org.eclipse.ui.forms.events.ExpansionEvent;
35
import org.eclipse.ui.forms.widgets.ExpandableComposite;
36
import org.eclipse.ui.preferences.*;
37
import org.osgi.service.prefs.BackingStoreException;
38
39
/**
40
 * A configuration block for setting PDE compiler preferences
41
 * 
42
 * @since 3.4
43
 */
44
public class PDECompilersConfigurationBlock {
45
46
	/**
47
	 * Provides data information for created controls
48
	 */
49
	protected static class ControlData {
50
		private Key key;
51
		private String[] values;
52
53
		/**
54
		 * Constructor
55
		 * @param key
56
		 * @param values
57
		 */
58
		public ControlData(Key key, String[] values) {
59
			this.key = key;
60
			this.values = values;
61
		}
62
63
		public Key getKey() {
64
			return key;
65
		}
66
67
		public String getValue(boolean selection) {
68
			int index = selection ? 0 : 1;
69
			return values[index];
70
		}
71
72
		public String getValue(int index) {
73
			return values[index];
74
		}
75
76
		public int getSelection(String value) {
77
			if (value != null) {
78
				for (int i = 0; i < values.length; i++) {
79
					if (value.equals(values[i])) {
80
						return i;
81
					}
82
				}
83
			}
84
			return values.length - 1; // assume the last option is the least severe
85
		}
86
	}
87
88
	/**
89
	 * Provides management for changed/stored values for a given preference key
90
	 */
91
	protected static class Key {
92
93
		private String qualifier;
94
		private String key;
95
96
		/**
97
		 * Constructor
98
		 * @param qualifier
99
		 * @param key
100
		 */
101
		public Key(String qualifier, String key) {
102
			this.qualifier = qualifier;
103
			this.key = key;
104
		}
105
106
		/**
107
		 * Returns the {@link IEclipsePreferences} node for the given context and {@link IWorkingCopyManager}
108
		 * @param context
109
		 * @param manager
110
		 * @return the {@link IEclipsePreferences} node or <code>null</code>
111
		 */
112
		private IEclipsePreferences getNode(IScopeContext context, IWorkingCopyManager manager) {
113
			IEclipsePreferences node = context.getNode(qualifier);
114
			if (manager != null) {
115
				return manager.getWorkingCopy(node);
116
			}
117
			return node;
118
		}
119
120
		/**
121
		 * Returns the value stored in the {@link IEclipsePreferences} node from the given context and working copy manager
122
		 * @param context
123
		 * @param manager
124
		 * @return the value from the {@link IEclipsePreferences} node or <code>null</code>
125
		 */
126
		public String getStoredValue(IScopeContext context, IWorkingCopyManager manager) {
127
			IEclipsePreferences node = getNode(context, manager);
128
			if (node != null) {
129
				return node.get(key, null);
130
			}
131
			return null;
132
		}
133
134
		/**
135
		 * Returns the stored value of this {@link IEclipsePreferences} node using a given lookup order, and allowing the
136
		 * top scope to be ignored
137
		 * @param lookupOrder
138
		 * @param ignoreTopScope
139
		 * @param manager
140
		 * @return the value from the {@link IEclipsePreferences} node or <code>null</code>
141
		 */
142
		public String getStoredValue(IScopeContext[] lookupOrder, boolean ignoreTopScope, IWorkingCopyManager manager) {
143
			for (int i = ignoreTopScope ? 1 : 0; i < lookupOrder.length; i++) {
144
				String value = getStoredValue(lookupOrder[i], manager);
145
				if (value != null) {
146
					return value;
147
				}
148
			}
149
			return null;
150
		}
151
152
		/**
153
		 * Sets the value of this key
154
		 * @param context
155
		 * @param value
156
		 * @param manager
157
		 */
158
		public void setStoredValue(IScopeContext context, String value, IWorkingCopyManager manager) {
159
			IEclipsePreferences node = getNode(context, manager);
160
			if (value != null) {
161
				node.put(key, value);
162
			} else {
163
				node.remove(key);
164
			}
165
		}
166
167
		/* (non-Javadoc)
168
		 * @see java.lang.Object#toString()
169
		 */
170
		public String toString() {
171
			return qualifier + '/' + key;
172
		}
173
	}
174
175
	/**
176
	 * Returns a new {@link Key} for the {@link PDEPlugin} preference store
177
	 * @param key
178
	 * @return the new {@link Key} for the {@link PDEPlugin} preference store
179
	 */
180
	protected final static Key getPDEPrefKey(String key) {
181
		return new Key(PDE.PLUGIN_ID, key);
182
	}
183
184
	//unresolved
185
	private static final Key KEY_P_UNRESOLVED_IMPORTS = getPDEPrefKey(CompilerFlags.P_UNRESOLVED_IMPORTS);
186
	private static final Key KEY_P_UNRESOLVED_EX_POINTS = getPDEPrefKey(CompilerFlags.P_UNRESOLVED_EX_POINTS);
187
	private static final Key KEY_F_UNRESOLVED_PLUGINS = getPDEPrefKey(CompilerFlags.F_UNRESOLVED_PLUGINS);
188
	private static final Key KEY_F_UNRESOLVED_FEATURES = getPDEPrefKey(CompilerFlags.F_UNRESOLVED_FEATURES);
189
190
	//unknown elements
191
	private static final Key KEY_P_UNKNOWN_ELEMENT = getPDEPrefKey(CompilerFlags.P_UNKNOWN_ELEMENT);
192
	private static final Key KEY_P_UNKNOWN_ATTRIBUTE = getPDEPrefKey(CompilerFlags.P_UNKNOWN_ATTRIBUTE);
193
	private static final Key KEY_P_UNKNOWN_CLASS = getPDEPrefKey(CompilerFlags.P_UNKNOWN_CLASS);
194
	private static final Key KEY_P_UNKNOWN_RESOURCE = getPDEPrefKey(CompilerFlags.P_UNKNOWN_RESOURCE);
195
	private static final Key KEY_P_UNKNOWN_IDENTIFIER = getPDEPrefKey(CompilerFlags.P_UNKNOWN_IDENTIFIER);
196
197
	//general
198
	private static final Key KEY_P_DISCOURAGED_CLASS = getPDEPrefKey(CompilerFlags.P_DISCOURAGED_CLASS);
199
	private static final Key KEY_P_NO_REQUIRED_ATT = getPDEPrefKey(CompilerFlags.P_NO_REQUIRED_ATT);
200
	private static final Key KEY_P_BUILD = getPDEPrefKey(CompilerFlags.P_BUILD);
201
	private static final Key KEY_P_NOT_EXTERNALIZED = getPDEPrefKey(CompilerFlags.P_NOT_EXTERNALIZED);
202
	private static final Key KEY_P_INCOMPATIBLE_ENV = getPDEPrefKey(CompilerFlags.P_INCOMPATIBLE_ENV);
203
	private static final Key KEY_P_MISSING_EXPORT_PKGS = getPDEPrefKey(CompilerFlags.P_MISSING_EXPORT_PKGS);
204
	private static final Key KEY_P_DEPRECATED = getPDEPrefKey(CompilerFlags.P_DEPRECATED);
205
	private static final Key KEY_P_MISSING_BUNDLE_CLASSPATH_ENTRIES = getPDEPrefKey(CompilerFlags.P_MISSING_BUNDLE_CLASSPATH_ENTRIES);
206
	private static final Key KEY_S_CREATE_DOCS = getPDEPrefKey(CompilerFlags.S_CREATE_DOCS);
207
	private static final Key KEY_S_DOC_FOLDER = getPDEPrefKey(CompilerFlags.S_DOC_FOLDER);
208
	private static final Key KEY_S_OPEN_TAGS = getPDEPrefKey(CompilerFlags.S_OPEN_TAGS);
209
210
	private static String[] SEVERITIES = {IPreferenceConstants.VALUE_ERROR, IPreferenceConstants.VALUE_WARNING, IPreferenceConstants.VALUE_IGNORE};
211
212
	private static Key[] fgAllKeys = {KEY_F_UNRESOLVED_FEATURES, KEY_F_UNRESOLVED_PLUGINS, KEY_P_BUILD, KEY_P_DEPRECATED, KEY_P_DISCOURAGED_CLASS, KEY_P_INCOMPATIBLE_ENV, KEY_P_MISSING_BUNDLE_CLASSPATH_ENTRIES, KEY_P_MISSING_EXPORT_PKGS, KEY_P_NO_REQUIRED_ATT, KEY_P_NOT_EXTERNALIZED, KEY_P_UNKNOWN_ATTRIBUTE, KEY_P_UNKNOWN_CLASS, KEY_P_UNKNOWN_ELEMENT, KEY_P_UNKNOWN_IDENTIFIER, KEY_P_UNKNOWN_RESOURCE, KEY_P_UNRESOLVED_EX_POINTS, KEY_P_UNRESOLVED_IMPORTS, KEY_S_CREATE_DOCS, KEY_S_DOC_FOLDER, KEY_S_OPEN_TAGS};
213
214
	/**
215
	 * Constant representing the {@link IDialogSettings} section for this block
216
	 */
217
	private static final String SETTINGS = "pde_compiler_errorwarnings_block"; //$NON-NLS-1$
218
219
	/**
220
	 * The context of settings locations to search for values in
221
	 */
222
	private IScopeContext[] fLookupOrder = null;
223
224
	/**
225
	 * The project this block is working on settings for. Only applies in the 
226
	 * case of project specific settings
227
	 */
228
	private IProject fProject = null;
229
230
	/**
231
	 * the working copy manager to work with settings
232
	 */
233
	private IWorkingCopyManager fManager = null;
234
235
	/**
236
	 * The main composite for the configuration block, used for enabling/disabling the block 
237
	 */
238
	private Composite fMainComp = null;
239
240
	/**
241
	 * Stored old fProject specific settings. 
242
	 */
243
	private IdentityHashMap fOldProjectSettings = null;
244
245
	/**
246
	 * Map of controls to the tab they appear on. Allows for optimizing which builders
247
	 * are used if changes are made
248
	 */
249
	private HashMap fControlMap = new HashMap(3);
250
251
	/**
252
	 * Listing of all of the {@link ExpandableComposite}s in the block
253
	 */
254
	private ArrayList fExpComps = new ArrayList();
255
256
	/**
257
	 * Flag used to know if the page needs saving or not
258
	 */
259
	private boolean fDirty = false;
260
261
	/**
262
	 * counter to know how many times we have prompted users' to rebuild
263
	 */
264
	private int fRebuildcount = 0;
265
266
	/**
267
	 * Set of builders to use when building if there are changes
268
	 */
269
	private HashSet fBuilders = new HashSet(4);
270
271
	/**
272
	 * The parent this block has been added to 
273
	 */
274
	private Composite fParent = null;
275
276
	/**
277
	 * Default selection listener for combo and check controls 
278
	 */
279
	private SelectionListener selectionlistener = new SelectionAdapter() {
280
		public void widgetSelected(SelectionEvent e) {
281
			if (e.widget instanceof Combo) {
282
				Combo combo = (Combo) e.widget;
283
				ControlData data = (ControlData) combo.getData();
284
				data.key.setStoredValue(fLookupOrder[0], Integer.toString(combo.getSelectionIndex()), fManager);
285
				fDirty = true;
286
				fRebuildcount = 0;
287
			} else if (e.widget instanceof Button) {
288
				Button button = (Button) e.widget;
289
				ControlData data = (ControlData) button.getData();
290
				data.key.setStoredValue(fLookupOrder[0], Boolean.toString(button.getSelection()), fManager);
291
				fDirty = true;
292
				fRebuildcount = 0;
293
			}
294
			addBuilder((Control) e.widget);
295
		}
296
	};
297
298
	/**
299
	 * Default modify listener for text controls
300
	 */
301
	private ModifyListener modifylistener = new ModifyListener() {
302
		public void modifyText(ModifyEvent e) {
303
			if (e.widget instanceof Text) {
304
				Text text = (Text) e.widget;
305
				ControlData data = (ControlData) text.getData();
306
				data.key.setStoredValue(fLookupOrder[0], text.getText().trim(), fManager);
307
				fDirty = true;
308
				fRebuildcount = 0;
309
			}
310
		}
311
	};
312
313
	/**
314
	 * Constructor
315
	 * @param project
316
	 * @param container
317
	 */
318
	public PDECompilersConfigurationBlock(IProject project, IWorkbenchPreferenceContainer container) {
319
		fProject = project;
320
		if (fProject != null) {
321
			fLookupOrder = new IScopeContext[] {new ProjectScope(fProject), new InstanceScope(), new DefaultScope()};
322
		} else {
323
			fLookupOrder = new IScopeContext[] {new InstanceScope(), new DefaultScope()};
324
		}
325
		if (container == null) {
326
			fManager = new WorkingCopyManager();
327
		} else {
328
			fManager = container.getWorkingCopyManager();
329
		}
330
		if (fProject == null || hasProjectSpecificSettings(fProject)) {
331
			fOldProjectSettings = null;
332
		} else {
333
			fOldProjectSettings = new IdentityHashMap();
334
			for (int i = 0; i < fgAllKeys.length; i++) {
335
				fOldProjectSettings.put(fgAllKeys[i], fgAllKeys[i].getStoredValue(fLookupOrder, false, fManager));
336
			}
337
		}
338
	}
339
340
	/**
341
	 * returns if this block has fProject specific settings
342
	 * @param fProject
343
	 * @return true if there are fProject specific settings, false otherwise
344
	 */
345
	public boolean hasProjectSpecificSettings(IProject project) {
346
		if (project != null) {
347
			IScopeContext projectContext = new ProjectScope(project);
348
			for (int i = 0; i < fgAllKeys.length; i++) {
349
				if (fgAllKeys[i].getStoredValue(projectContext, fManager) != null) {
350
					return true;
351
				}
352
			}
353
		}
354
		return false;
355
	}
356
357
	/**
358
	 * Sets using project specific settings
359
	 * @param enable
360
	 */
361
	public void useProjectSpecificSettings(boolean enable) {
362
		boolean disabled = fOldProjectSettings == null;
363
		if (enable != disabled && fProject != null) {
364
			if (enable) {
365
				for (int i = 0; i < fgAllKeys.length; i++) {
366
					fgAllKeys[i].setStoredValue(fLookupOrder[0], (String) fOldProjectSettings.get(fgAllKeys[i]), fManager);
367
				}
368
				fOldProjectSettings = null;
369
				updateControls();
370
			} else {
371
				fOldProjectSettings = new IdentityHashMap();
372
				String old = null;
373
				for (int i = 0; i < fgAllKeys.length; i++) {
374
					old = fgAllKeys[i].getStoredValue(fLookupOrder, false, fManager);
375
					fOldProjectSettings.put(fgAllKeys[i], old);
376
					fgAllKeys[i].setStoredValue(fLookupOrder[0], null, fManager);
377
				}
378
			}
379
		}
380
		fDirty = true;
381
		enableControl(fMainComp, enable);
382
	}
383
384
	/**
385
	 * Updates all of the registered {@link Control}s on the page.
386
	 * Registration implies that the {@link Control} was added to the map
387
	 * fControlMap
388
	 */
389
	private void updateControls() {
390
		HashSet controls = null;
391
		Control control = null;
392
		for (Iterator iter = fControlMap.keySet().iterator(); iter.hasNext();) {
393
			controls = (HashSet) fControlMap.get(iter.next());
394
			if (controls == null) {
395
				continue;
396
			}
397
			for (Iterator iter2 = controls.iterator(); iter2.hasNext();) {
398
				control = (Control) iter2.next();
399
				if (control instanceof Combo) {
400
					Combo combo = (Combo) control;
401
					ControlData data = (ControlData) combo.getData();
402
					int index = 0;
403
					try {
404
						index = Integer.parseInt(data.key.getStoredValue(fLookupOrder, false, fManager));
405
					} catch (Exception e) {
406
						//set the default if something goes wrong
407
						index = Integer.parseInt(data.key.getStoredValue(fLookupOrder, true, fManager));
408
					}
409
					combo.select(data.getSelection(SEVERITIES[index]));
410
				} else if (control instanceof Button) {
411
					Button button = (Button) control;
412
					ControlData data = (ControlData) button.getData();
413
					button.setSelection(Boolean.valueOf(data.key.getStoredValue(fLookupOrder, false, fManager)).booleanValue());
414
				} else if (control instanceof Text) {
415
					Text text = (Text) control;
416
					ControlData data = (ControlData) text.getData();
417
					text.setText(data.key.getStoredValue(fLookupOrder, false, fManager));
418
				}
419
			}
420
		}
421
	}
422
423
	/**
424
	 * recursive method to enable/disable all of the controls on the main page
425
	 * @param ctrl
426
	 * @param enabled
427
	 */
428
	private void enableControl(Control ctrl, boolean enabled) {
429
		ctrl.setEnabled(enabled);
430
		if (ctrl instanceof Composite) {
431
			Composite comp = (Composite) ctrl;
432
			Control[] children = comp.getChildren();
433
			for (int i = 0; i < children.length; i++) {
434
				enableControl(children[i], enabled);
435
			}
436
		}
437
	}
438
439
	/**
440
	 * Creates the control in the parent control
441
	 * 
442
	 * @param parent the parent control
443
	 */
444
	public Control createControl(Composite parent) {
445
		fParent = parent;
446
		fMainComp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH, 0, 0);
447
		TabFolder folder = null;
448
		if (fProject == null) {
449
			SWTFactory.createVerticalSpacer(parent, 1);
450
			folder = new TabFolder(fMainComp, SWT.NONE);
451
			GridData gd = new GridData(GridData.FILL_BOTH);
452
			gd.heightHint = 375;
453
			gd.widthHint = 400;
454
			folder.setLayoutData(gd);
455
		}
456
457
		Composite main = (folder == null ? fMainComp : folder);
458
		//plugins page
459
		createPage(CompilerFlags.PLUGIN_FLAGS, main, PDEUIMessages.CompilersConfigurationBlock_plugins, PDEUIMessages.CompilersConfigurationBlock_label);
460
461
		if (fProject == null) {
462
			//the sharing property page does not use these two tabs
463
			//schema page
464
			createPage(CompilerFlags.SCHEMA_FLAGS, main, PDEUIMessages.CompilersConfigurationBlock_schemas, PDEUIMessages.CompilersConfigurationBlock_altlabel);
465
466
			//features / sites page
467
			createPage(CompilerFlags.FEATURE_FLAGS, main, PDEUIMessages.CompilersConfigurationBlock_features, PDEUIMessages.CompilersConfigurationBlock_label);
468
		}
469
		restoreExpansionState();
470
		return fMainComp;
471
	}
472
473
	/**
474
	 * Creates a tab page parented in the folder
475
	 * @param kind
476
	 * @param folder
477
	 * @param name
478
	 * @param description
479
	 * @return a new composite to act as the page for a tab
480
	 */
481
	private Composite createPage(int kind, Composite folder, String name, String description) {
482
		Composite page = SWTFactory.createComposite(folder, 1, 1, GridData.FILL_BOTH);
483
		Composite parent = page;
484
		if (fProject == null) {
485
			TabItem tab = new TabItem((TabFolder) folder, SWT.NONE);
486
			tab.setText(name);
487
			tab.setControl(page);
488
			parent = SWTFactory.createComposite(page, 2, 1, GridData.FILL_BOTH);
489
		}
490
		SWTFactory.createWrapLabel(parent, description, 2);
491
		SWTFactory.createVerticalSpacer(parent, 1);
492
		switch (kind) {
493
			case CompilerFlags.PLUGIN_FLAGS : {
494
				ScrolledComposite scomp = createScrolledComposite(parent, 1);
495
				Composite sbody = SWTFactory.createComposite(scomp, 1, 1, GridData.FILL_BOTH);
496
				scomp.setContent(sbody);
497
				//General
498
				Composite client = createExpansibleComposite(sbody, PDEUIMessages.PDECompilersConfigurationBlock_general);
499
				initializeComboControls(client, new String[] {PDEUIMessages.compilers_p_no_required_att, PDEUIMessages.CompilersConfigurationTab_buildPropertiesErrors, PDEUIMessages.CompilersConfigurationTab_incompatEnv, PDEUIMessages.compilers_p_exported_pkgs, PDEUIMessages.CompilersConfigurationTab_missingBundleClasspathEntries}, new Key[] {KEY_P_NO_REQUIRED_ATT, KEY_P_BUILD, KEY_P_INCOMPATIBLE_ENV, KEY_P_MISSING_EXPORT_PKGS, KEY_P_MISSING_BUNDLE_CLASSPATH_ENTRIES}, CompilerFlags.PLUGIN_FLAGS);
500
				//Usage
501
				client = createExpansibleComposite(sbody, PDEUIMessages.PDECompilersConfigurationBlock_usage);
502
				initializeComboControls(client, new String[] {PDEUIMessages.compilers_p_unresolved_import, PDEUIMessages.compilers_p_unresolved_ex_points, PDEUIMessages.compilers_p_deprecated, PDEUIMessages.compilers_p_not_externalized_att}, new Key[] {KEY_P_UNRESOLVED_IMPORTS, KEY_P_UNRESOLVED_EX_POINTS, KEY_P_DEPRECATED, KEY_P_NOT_EXTERNALIZED}, CompilerFlags.PLUGIN_FLAGS);
503
				//References
504
				client = createExpansibleComposite(sbody, PDEUIMessages.PDECompilersConfigurationBlock_references);
505
				initializeComboControls(client, new String[] {PDEUIMessages.compilers_p_unknown_element, PDEUIMessages.compilers_p_unknown_attribute, PDEUIMessages.compilers_p_unknown_class, PDEUIMessages.compilers_p_discouraged_class, PDEUIMessages.compilers_p_unknown_resource, PDEUIMessages.compilers_p_unknown_identifier}, new Key[] {KEY_P_UNKNOWN_ELEMENT, KEY_P_UNKNOWN_ATTRIBUTE, KEY_P_UNKNOWN_CLASS, KEY_P_DISCOURAGED_CLASS, KEY_P_UNKNOWN_RESOURCE, KEY_P_UNKNOWN_IDENTIFIER,}, CompilerFlags.PLUGIN_FLAGS);
506
507
				break;
508
			}
509
			case CompilerFlags.SCHEMA_FLAGS : {
510
				createCheckControl(parent, PDEUIMessages.compilers_s_create_docs, KEY_S_CREATE_DOCS, CompilerFlags.SCHEMA_FLAGS);
511
				Composite comp = SWTFactory.createComposite(parent, 2, 2, GridData.FILL_HORIZONTAL, 0, 0);
512
				createTextControl(comp, PDEUIMessages.compilers_s_doc_folder, KEY_S_DOC_FOLDER, CompilerFlags.SCHEMA_FLAGS);
513
				SWTFactory.createVerticalSpacer(parent, 1);
514
				initializeComboControls(parent, new String[] {PDEUIMessages.compilers_s_open_tags}, new Key[] {KEY_S_OPEN_TAGS}, CompilerFlags.SCHEMA_FLAGS);
515
				break;
516
			}
517
			case CompilerFlags.FEATURE_FLAGS : {
518
				initializeComboControls(parent, new String[] {PDEUIMessages.compilers_f_unresolved_features, PDEUIMessages.compilers_f_unresolved_plugins}, new Key[] {KEY_F_UNRESOLVED_FEATURES, KEY_F_UNRESOLVED_PLUGINS}, CompilerFlags.FEATURE_FLAGS);
519
				break;
520
			}
521
		}
522
		return page;
523
	}
524
525
	/**
526
	 * Creates a set of combo boxes for the given string/ key pairs
527
	 * @param composite
528
	 * @param labels
529
	 * @param keys
530
	 * @param tabkind
531
	 */
532
	private void initializeComboControls(Composite composite, String[] labels, Key[] keys, int tabkind) {
533
		for (int i = 0, max = labels.length; i < max; i++) {
534
			createComboControl(composite, labels[i], keys[i], tabkind);
535
		}
536
	}
537
538
	/**
539
	 * Creates a checkbox button control in the parent
540
	 * @param parent
541
	 * @param label
542
	 * @param key
543
	 * @param tabkind
544
	 */
545
	private void createCheckControl(Composite parent, String label, Key key, int tabkind) {
546
		Button button = SWTFactory.createCheckButton(parent, label, null, false, 2);
547
		ControlData data = new ControlData(key, new String[] {Boolean.toString(false)});
548
		button.setData(data);
549
		button.setSelection(Boolean.valueOf(data.key.getStoredValue(fLookupOrder, false, fManager)).booleanValue());
550
		button.addSelectionListener(selectionlistener);
551
		Integer mapkey = new Integer(tabkind);
552
		HashSet controls = (HashSet) fControlMap.get(mapkey);
553
		if (controls == null) {
554
			controls = new HashSet(8);
555
			fControlMap.put(mapkey, controls);
556
		}
557
		controls.add(button);
558
	}
559
560
	/**
561
	 * Disposes the controls from this page
562
	 */
563
	public void dispose() {
564
		fMainComp.getParent().dispose();
565
		fExpComps.clear();
566
		fControlMap.clear();
567
	}
568
569
	/**
570
	 * Creates a {@link Label} | {@link Combo} control. The combo is initialized from the given {@link Key}
571
	 * @param parent
572
	 * @param label
573
	 * @param key
574
	 * @param tabkind
575
	 */
576
	protected void createComboControl(Composite parent, String label, Key key, int tabkind) {
577
		Label lbl = new Label(parent, SWT.NONE);
578
		GridData gd = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
579
		lbl.setLayoutData(gd);
580
		lbl.setText(label);
581
		Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
582
		gd = new GridData(GridData.END, GridData.CENTER, false, false);
583
		ControlData data = new ControlData(key, SEVERITIES);
584
		combo.setData(data);
585
		combo.setItems(SEVERITIES);
586
		combo.addSelectionListener(selectionlistener);
587
		int index = 0;
588
		try {
589
			index = Integer.parseInt(key.getStoredValue(fLookupOrder, false, fManager));
590
		} catch (Exception e) {
591
			//set the default if something goes wrong
592
			index = Integer.parseInt(key.getStoredValue(fLookupOrder, true, fManager));
593
		}
594
		combo.select(data.getSelection(SEVERITIES[index]));
595
		Integer mapkey = new Integer(tabkind);
596
		HashSet controls = (HashSet) fControlMap.get(mapkey);
597
		if (controls == null) {
598
			controls = new HashSet(8);
599
			fControlMap.put(mapkey, controls);
600
		}
601
		controls.add(combo);
602
	}
603
604
	/**
605
	 * Creates a new text control on the parent for the given pref key
606
	 * @param parent
607
	 * @param label
608
	 * @param key
609
	 * @param tabkind
610
	 */
611
	private void createTextControl(Composite parent, String label, Key key, int tabkind) {
612
		SWTFactory.createLabel(parent, label, 1);
613
		Text text = SWTFactory.createSingleText(parent, 1);
614
		ControlData data = new ControlData(key, new String[0]);
615
		text.setData(data);
616
		text.setText(data.key.getStoredValue(fLookupOrder, false, fManager));
617
		text.addModifyListener(modifylistener);
618
		Integer mapkey = new Integer(tabkind);
619
		HashSet controls = (HashSet) fControlMap.get(mapkey);
620
		if (controls == null) {
621
			controls = new HashSet(8);
622
			fControlMap.put(mapkey, controls);
623
		}
624
		controls.add(text);
625
	}
626
627
	/**
628
	 * Creates a scrolled composite
629
	 * @param parent
630
	 * @param columns
631
	 * @return a new scrolled composite
632
	 */
633
	protected ScrolledComposite createScrolledComposite(Composite parent, int columns) {
634
		ScrolledComposite scomp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
635
		scomp.setExpandHorizontal(true);
636
		scomp.setExpandVertical(true);
637
		scomp.setLayout(new GridLayout(1, false));
638
		scomp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
639
		scomp.addListener(SWT.Resize, new Listener() {
640
			public void handleEvent(Event event) {
641
				handleExpand(getScrollingParent(event.widget));
642
			}
643
		});
644
		return scomp;
645
	}
646
647
	/**
648
	 * Creates an {@link ExpandableComposite} with a client composite and a default grid layout
649
	 * @param parent
650
	 * @param title
651
	 * @return a new expandable composite
652
	 */
653
	private Composite createExpansibleComposite(Composite parent, String title) {
654
		ExpandableComposite ecomp = SWTFactory.createExpandibleComposite(parent, title, 1, GridData.FILL_HORIZONTAL);
655
		ecomp.addExpansionListener(new ExpansionAdapter() {
656
			public void expansionStateChanged(ExpansionEvent e) {
657
				Object obj = e.getSource();
658
				handleExpand(getScrollingParent(obj));
659
			}
660
		});
661
		ecomp.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
662
		fExpComps.add(ecomp);
663
		Composite client = SWTFactory.createComposite(ecomp, 2, 1, GridData.FILL_BOTH);
664
		ecomp.setClient(client);
665
		return client;
666
	}
667
668
	/**
669
	 * Returns the scrolling parent for the given ExpandibleComposite object
670
	 * @param obj
671
	 * @return the scrolling parent of the given object or <code>null</code> if there isn't one
672
	 */
673
	private ScrolledComposite getScrollingParent(Object obj) {
674
		if (obj instanceof ExpandableComposite) {
675
			ExpandableComposite ecomp = (ExpandableComposite) obj;
676
			Composite parent = ecomp.getParent();
677
			while (parent != null && !(parent instanceof ScrolledComposite)) {
678
				parent = parent.getParent();
679
			}
680
			if (parent != null) {
681
				return (ScrolledComposite) parent;
682
			}
683
		}
684
		if (obj instanceof ScrolledComposite) {
685
			return (ScrolledComposite) obj;
686
		}
687
		return null;
688
	}
689
690
	/**
691
	 * Handles one of the expandable composites being expanded 
692
	 */
693
	private void handleExpand(ScrolledComposite composite) {
694
		if (composite == null) {
695
			return;
696
		}
697
		try {
698
			composite.setRedraw(false);
699
			Composite c = (Composite) composite.getContent();
700
			if (c == null) {
701
				return;
702
			}
703
			Point newSize = c.computeSize(SWT.DEFAULT, SWT.DEFAULT);
704
			composite.setMinSize(newSize);
705
			c.layout(true);
706
		} finally {
707
			composite.setRedraw(true);
708
		}
709
	}
710
711
	/**
712
	 * Saves all of the changes on the page
713
	 */
714
	public void performOK() {
715
		save();
716
		persistExpansionState();
717
	}
718
719
	/**
720
	 * Directly applies all of the changes on the page
721
	 */
722
	public void performApply() {
723
		save();
724
	}
725
726
	/**
727
	 * Performs the save operation on the working cop manager
728
	 */
729
	private void save() {
730
		if (fDirty) {
731
			try {
732
				ArrayList changes = new ArrayList();
733
				collectChanges(fLookupOrder[0], changes);
734
				if (changes.size() > 0) {
735
					if (fRebuildcount < 1) {
736
						fRebuildcount++;
737
						fManager.applyChanges();
738
						String message = PDEUIMessages.PDECompilersConfigurationBlock_settings_changed_all;
739
						if (fProject != null) {
740
							message = MessageFormat.format(PDEUIMessages.PDECompilersConfigurationBlock_setting_changed_project, new String[] {fProject.getName()});
741
						}
742
						if (MessageDialog.openQuestion(fParent.getShell(), PDEUIMessages.PDECompilersConfigurationBlock_settings_changed, message)) {
743
							doFullBuild();
744
						}
745
					}
746
				}
747
				fDirty = false;
748
			} catch (BackingStoreException bse) {
749
				PDEPlugin.log(bse);
750
			}
751
		}
752
	}
753
754
	/**
755
	 * Collects the keys that have changed on the page into the specified list
756
	 * @param changes the {@link List} to collect changed keys into
757
	 */
758
	private void collectChanges(IScopeContext context, List changes) {
759
		Key key = null;
760
		String origval = null, newval = null;
761
		boolean complete = fOldProjectSettings == null && fProject != null;
762
		for (int i = 0; i < fgAllKeys.length; i++) {
763
			key = fgAllKeys[i];
764
			origval = key.getStoredValue(context, null);
765
			newval = key.getStoredValue(context, fManager);
766
			if (newval == null) {
767
				if (origval != null) {
768
					changes.add(key);
769
				} else if (complete) {
770
					key.setStoredValue(context, key.getStoredValue(fLookupOrder, true, fManager), fManager);
771
					changes.add(key);
772
				}
773
			} else if (!newval.equals(origval)) {
774
				changes.add(key);
775
			}
776
		}
777
	}
778
779
	/**
780
	 * Cancels all of the changes on the page
781
	 */
782
	public void performCancel() {
783
		persistExpansionState();
784
	}
785
786
	/**
787
	 * Reverts all of the settings back to their defaults
788
	 */
789
	public void performDefaults() {
790
		String defval = null;
791
		for (int i = 0; i < fgAllKeys.length; i++) {
792
			defval = fgAllKeys[i].getStoredValue(fLookupOrder, true, fManager);
793
			fgAllKeys[i].setStoredValue(fLookupOrder[0], defval, fManager);
794
		}
795
		updateControls();
796
		fDirty = true;
797
		fRebuildcount = 0;
798
	}
799
800
	/**
801
	 * Stores the expansion state of the composites
802
	 */
803
	private void persistExpansionState() {
804
		IDialogSettings settings = PDEPlugin.getDefault().getDialogSettings().addNewSection(SETTINGS);
805
		for (int i = 0; i < fExpComps.size(); i++) {
806
			settings.put(Integer.toString(i), ((ExpandableComposite) fExpComps.get(i)).isExpanded());
807
		}
808
	}
809
810
	/**
811
	 * Restores the expansion state of the composites in this block.
812
	 * If there are no settings, than the first composite is expanded by default
813
	 */
814
	private void restoreExpansionState() {
815
		IDialogSettings settings = PDEPlugin.getDefault().getDialogSettings().getSection(SETTINGS);
816
		if (settings != null) {
817
			for (int i = 0; i < fExpComps.size(); i++) {
818
				((ExpandableComposite) fExpComps.get(i)).setExpanded(settings.getBoolean(Integer.toString(i)));
819
			}
820
		} else {
821
			((ExpandableComposite) fExpComps.get(0)).setExpanded(true);
822
		}
823
	}
824
825
	/**
826
	 * Adds the associated builder for the tab this control lives on. Lookups are done using 
827
	 * hash codes for constant time containment checks
828
	 * @param control
829
	 */
830
	private void addBuilder(Control control) {
831
		HashSet controls = null;
832
		Integer key = null;
833
		for (Iterator iter = fControlMap.keySet().iterator(); iter.hasNext();) {
834
			key = (Integer) iter.next();
835
			controls = (HashSet) fControlMap.get(key);
836
			if (controls == null) {
837
				continue;
838
			}
839
			if (controls.contains(control)) {
840
				switch (key.intValue()) {
841
					case CompilerFlags.PLUGIN_FLAGS : {
842
						fBuilders.add(PDE.MANIFEST_BUILDER_ID);
843
						break;
844
					}
845
					case CompilerFlags.SCHEMA_FLAGS : {
846
						fBuilders.add(PDE.SCHEMA_BUILDER_ID);
847
						break;
848
					}
849
					case CompilerFlags.FEATURE_FLAGS :
850
					case CompilerFlags.SITE_FLAGS : {
851
						fBuilders.add(PDE.FEATURE_BUILDER_ID);
852
						break;
853
					}
854
				}
855
				return;
856
			}
857
		}
858
	}
859
860
	/**
861
	 * Performs a full build of the workspace
862
	 */
863
	private void doFullBuild() {
864
		Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) {
865
			public boolean belongsTo(Object family) {
866
				return ResourcesPlugin.FAMILY_MANUAL_BUILD == family;
867
			}
868
869
			protected IStatus run(IProgressMonitor monitor) {
870
				try {
871
					IProject[] projects = null;
872
					if (fProject == null) {
873
						projects = PDEPlugin.getWorkspace().getRoot().getProjects();
874
					} else {
875
						projects = new IProject[] {fProject};
876
					}
877
					monitor.beginTask("", projects.length * 2); //$NON-NLS-1$
878
					for (int i = 0; i < projects.length; i++) {
879
						IProject projectToBuild = projects[i];
880
						if (!projectToBuild.isOpen())
881
							continue;
882
						if (projectToBuild.hasNature(PDE.PLUGIN_NATURE)) {
883
							if (fBuilders.contains(PDE.MANIFEST_BUILDER_ID))
884
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.MANIFEST_BUILDER_ID, null, new SubProgressMonitor(monitor, 1));
885
							else
886
								monitor.worked(1);
887
							if (fBuilders.contains(PDE.SCHEMA_BUILDER_ID))
888
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.SCHEMA_BUILDER_ID, null, new SubProgressMonitor(monitor, 1));
889
							else
890
								monitor.worked(1);
891
						} else if (projectToBuild.hasNature(PDE.FEATURE_NATURE)) {
892
							if (fBuilders.contains(PDE.FEATURE_BUILDER_ID))
893
								projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, PDE.FEATURE_BUILDER_ID, null, new SubProgressMonitor(monitor, 2));
894
						} else {
895
							monitor.worked(2);
896
						}
897
					}
898
				} catch (CoreException e) {
899
					return e.getStatus();
900
				} catch (OperationCanceledException e) {
901
					return Status.CANCEL_STATUS;
902
				} finally {
903
					monitor.done();
904
				}
905
				return Status.OK_STATUS;
906
			}
907
		};
908
		buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
909
		buildJob.setUser(true);
910
		buildJob.schedule();
911
	}
912
}

Return to bug 168069