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

Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/ui/internal/preferences/ui/AbstractValidationSettingsPage.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 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 43-52 Link Here
43
import org.eclipse.ui.forms.events.ExpansionAdapter;
43
import org.eclipse.ui.forms.events.ExpansionAdapter;
44
import org.eclipse.ui.forms.events.ExpansionEvent;
44
import org.eclipse.ui.forms.events.ExpansionEvent;
45
import org.eclipse.ui.forms.widgets.ExpandableComposite;
45
import org.eclipse.ui.forms.widgets.ExpandableComposite;
46
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
47
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
46
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
48
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
47
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
49
import org.eclipse.wst.validation.ValidationFramework;
48
import org.eclipse.wst.validation.ValidationFramework;
49
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
50
import org.osgi.service.prefs.BackingStoreException;
50
import org.osgi.service.prefs.BackingStoreException;
51
51
52
/**
52
/**
Lines 359-374 Link Here
359
	public boolean performOk() {
359
	public boolean performOk() {
360
		if(super.performOk() && shouldRevalidateOnSettingsChange()) {
360
		if(super.performOk() && shouldRevalidateOnSettingsChange()) {
361
			MessageBox mb = new MessageBox(this.getShell(), SWT.APPLICATION_MODAL | SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.RIGHT);
361
			MessageBox mb = new MessageBox(this.getShell(), SWT.APPLICATION_MODAL | SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.RIGHT);
362
			mb.setText(HTMLUIMessages.Validation_Title);
362
			mb.setText(XMLUIMessages.Validation_Title);
363
			/* Choose which message to use based on if its project or workspace settings */
363
			/* Choose which message to use based on if its project or workspace settings */
364
			String msg = (getProject() == null) ? HTMLUIMessages.Validation_Workspace : HTMLUIMessages.Validation_Project;
364
			String msg = (getProject() == null) ? XMLUIMessages.Validation_Workspace : XMLUIMessages.Validation_Project;
365
			mb.setMessage(msg);
365
			mb.setMessage(msg);
366
			switch(mb.open()) {
366
			switch(mb.open()) {
367
				case SWT.CANCEL:
367
				case SWT.CANCEL:
368
					return false;
368
					return false;
369
				case SWT.YES:
369
				case SWT.YES:
370
					storeValues();
370
					storeValues();
371
					ValidateJob job = new ValidateJob(HTMLUIMessages.Validation_jobName);
371
					ValidateJob job = new ValidateJob(XMLUIMessages.Validation_jobName);
372
					job.schedule();
372
					job.schedule();
373
				case SWT.NO:
373
				case SWT.NO:
374
					storeValues();
374
					storeValues();
(-)src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java (-5 / +1 lines)
Lines 196-206 Link Here
196
	public static String HTMLValidationPreferencePage_8;
196
	public static String HTMLValidationPreferencePage_8;
197
	public static String HTMLValidationPreferencePage_9;
197
	public static String HTMLValidationPreferencePage_9;
198
	
198
	
199
	// Validation
199
200
	public static String Validation_Title;
201
	public static String Validation_Workspace;
202
	public static String Validation_Project;
203
	public static String Validation_jobName;
204
	
200
	
205
	// Hyperlinks
201
	// Hyperlinks
206
	public static String Hyperlink_line;
202
	public static String Hyperlink_line;
(-)src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties (-5 / +2 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2004, 2009 IBM Corporation and others.
2
# Copyright (c) 2004, 2010 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 171-180 Link Here
171
HTMLValidationPreferencePage_9=Invalid tag name:
171
HTMLValidationPreferencePage_9=Invalid tag name:
172
HTMLValidationPreferencePage_35=Attribute value refers to missing resource:
172
HTMLValidationPreferencePage_35=Attribute value refers to missing resource:
173
173
174
Validation_Title=Validation Settings Changed
174
175
Validation_Workspace=The validation settings have changed. A full validation is required for changes to take effect. Validate now?
176
Validation_Project=The validation settings have changed. A validation of the project is required for changes to take effect. Validate the project now?
177
Validation_jobName=Validating...
178
175
179
Hyperlink_line={0}={1} : line {2}
176
Hyperlink_line={0}={1} : line {2}
180
Open=Open ''{0}''
177
Open=Open ''{0}''
(-)src/org/eclipse/wst/html/ui/internal/preferences/ui/AbstractValidationSettingsPage.java (-400 lines)
Removed 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.wst.html.ui.internal.preferences.ui;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.ProjectScope;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.jobs.Job;
26
import org.eclipse.core.runtime.preferences.DefaultScope;
27
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
28
import org.eclipse.core.runtime.preferences.IPreferencesService;
29
import org.eclipse.core.runtime.preferences.IScopeContext;
30
import org.eclipse.jface.dialogs.IDialogSettings;
31
import org.eclipse.jface.resource.JFaceResources;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.widgets.Combo;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Control;
39
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.MessageBox;
41
import org.eclipse.swt.widgets.Widget;
42
import org.eclipse.ui.forms.events.ExpansionAdapter;
43
import org.eclipse.ui.forms.events.ExpansionEvent;
44
import org.eclipse.ui.forms.widgets.ExpandableComposite;
45
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
46
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
47
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
48
import org.eclipse.wst.validation.ValidationFramework;
49
import org.osgi.service.prefs.BackingStoreException;
50
51
/**
52
 * Based on org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock
53
 */
54
abstract class AbstractValidationSettingsPage extends PropertyPreferencePage {
55
56
	private List fCombos;
57
	private List fExpandables;
58
	
59
	private SelectionListener fSelectionListener;
60
	
61
	private IPreferencesService fPreferencesService = null;
62
	
63
	private static final String SETTINGS_EXPANDED = "expanded"; //$NON-NLS-1$
64
	
65
	private ValidationFramework fValidation;
66
	
67
	private class ComboData {
68
		private String fKey;
69
		private int[] fSeverities;
70
		private int fIndex;
71
		int originalSeverity = -2;
72
		
73
		public ComboData(String key, int[] severities, int index) {
74
			fKey = key;
75
			fSeverities = severities;
76
			fIndex = index;
77
		}
78
		
79
		public String getKey() {
80
			return fKey;
81
		}
82
		
83
		public void setIndex(int index) {
84
			fIndex = index;
85
		}
86
		
87
		public int getIndex() {
88
			return fIndex;
89
		}
90
		
91
		/**
92
		 * Sets the severity index based on <code>severity</code>.
93
		 * If the severity doesn't exist, the index is set to -1.
94
		 * 
95
		 * @param severity the severity level
96
		 */
97
		public void setSeverity(int severity) {
98
			for(int i = 0; fSeverities != null && i < fSeverities.length; i++) {
99
				if(fSeverities[i] == severity) {
100
					fIndex = i;
101
					return;
102
				}
103
			}
104
			
105
			fIndex = -1;
106
		}
107
		
108
		public int getSeverity() {
109
			return (fIndex >= 0 && fSeverities != null && fIndex < fSeverities.length) ? fSeverities[fIndex] : -1;
110
		}
111
		
112
		boolean isChanged() {
113
			return fSeverities[fIndex] != originalSeverity;
114
		}
115
	}
116
	
117
	public AbstractValidationSettingsPage() {
118
		super();
119
		fCombos = new ArrayList();
120
		fExpandables = new ArrayList();
121
		fPreferencesService = Platform.getPreferencesService();
122
		fValidation = ValidationFramework.getDefault();
123
	}
124
	
125
	/**
126
	 * Creates a Combo widget in the composite <code>parent</code>. The data
127
	 * in the Combo is associated with <code>key</code>. The Combo data is
128
	 * generated based on the integer <code>values</code> where the index
129
	 * of <code>values</code> corresponds to the index of <code>valueLabels</code>
130
	 * 
131
	 * @param parent the composite to create the combo box in
132
	 * @param label the label to give the combo box
133
	 * @param key the unique key to identify the combo box
134
	 * @param values the values represented by the combo options
135
	 * @param valueLabels the calues displayed in the combo box
136
	 * @param indent how far to indent the combo box label
137
	 * 
138
	 * @return the generated combo box
139
	 */
140
	protected Combo addComboBox(Composite parent, String label, String key, int[] values, String[] valueLabels, int indent) {
141
		GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
142
		gd.horizontalIndent= indent;
143
				
144
		Label labelControl= new Label(parent, SWT.LEFT);
145
		labelControl.setFont(JFaceResources.getDialogFont());
146
		labelControl.setText(label);
147
		labelControl.setLayoutData(gd);
148
				
149
		Combo comboBox= newComboControl(parent, key, values, valueLabels);
150
		comboBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
151
152
		return comboBox;
153
	}
154
	
155
	/**
156
	 * Creates a combo box and associates the combo data with the
157
	 * combo box.
158
	 * 
159
	 * @param composite the composite to create the combo box in
160
	 * @param key the unique key to identify the combo box
161
	 * @param values the values represented by the combo options
162
	 * @param valueLabels the values displayed in the combo box
163
	 * 
164
	 * @return the generated combo box
165
	 */
166
	protected Combo newComboControl(Composite composite, String key, int[] values, String[] valueLabels) {
167
		ComboData data = new ComboData(key, values, -1);
168
		
169
		Combo comboBox= new Combo(composite, SWT.READ_ONLY);
170
		comboBox.setItems(valueLabels);
171
		comboBox.setData(data);
172
		comboBox.addSelectionListener(getSelectionListener());
173
		comboBox.setFont(JFaceResources.getDialogFont());
174
			
175
		makeScrollableCompositeAware(comboBox);
176
		
177
		int severity = -1;
178
		if(key != null)
179
			severity = fPreferencesService.getInt(getPreferenceNodeQualifier(), key, ValidationMessage.WARNING, createPreferenceScopes());
180
181
		if (severity == ValidationMessage.ERROR || severity == ValidationMessage.WARNING || severity == ValidationMessage.IGNORE) {
182
			data.setSeverity(severity);
183
			data.originalSeverity = severity;
184
		}
185
		
186
		if(data.getIndex() >= 0)
187
			comboBox.select(data.getIndex());
188
		
189
		fCombos.add(comboBox);
190
		return comboBox;
191
	}
192
	
193
	protected SelectionListener getSelectionListener() {
194
		if (fSelectionListener == null) {
195
			fSelectionListener= new SelectionListener() {
196
				public void widgetDefaultSelected(SelectionEvent e) {}
197
	
198
				public void widgetSelected(SelectionEvent e) {
199
					controlChanged(e.widget);
200
				}
201
			};
202
		}
203
		return fSelectionListener;
204
	}
205
	
206
	protected void controlChanged(Widget widget) {
207
		ComboData data= (ComboData) widget.getData();
208
		if (widget instanceof Combo) {
209
			data.setIndex(((Combo)widget).getSelectionIndex());
210
		} else {
211
			return;
212
		}
213
	}
214
215
	/*
216
	 * (non-Javadoc)
217
	 * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSettingsPage#storeValues()
218
	 */
219
	protected void storeValues() {
220
		if(fCombos == null || fCombos.size() == 0)
221
			return;
222
		
223
		Iterator it = fCombos.iterator();
224
		
225
		IScopeContext[] contexts = createPreferenceScopes();
226
227
		while(it.hasNext()) {
228
			ComboData data = (ComboData) ((Combo)it.next()).getData();
229
			if(data.getKey() != null) {
230
				contexts[0].getNode(getPreferenceNodeQualifier()).putInt(data.getKey(), data.getSeverity());
231
			}
232
		}
233
		
234
		for(int i = 0; i < contexts.length; i++) {
235
			try {
236
				contexts[i].getNode(getPreferenceNodeQualifier()).flush();
237
			}
238
			catch (BackingStoreException e) {
239
				
240
			}
241
		}
242
	}
243
	
244
	protected ExpandableComposite getParentExpandableComposite(Control control) {
245
		Control parent= control.getParent();
246
		while (!(parent instanceof ExpandableComposite) && parent != null) {
247
			parent= parent.getParent();
248
		}
249
		if (parent instanceof ExpandableComposite) {
250
			return (ExpandableComposite) parent;
251
		}
252
		return null;
253
	}
254
	
255
	protected ExpandableComposite createStyleSection(Composite parent, String label, int nColumns) {
256
		ExpandableComposite excomposite= new ExpandableComposite(parent, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
257
		excomposite.setText(label);
258
		excomposite.setExpanded(false);
259
		excomposite.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
260
		excomposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, nColumns, 1));
261
		excomposite.addExpansionListener(new ExpansionAdapter() {
262
			public void expansionStateChanged(ExpansionEvent e) {
263
				expandedStateChanged((ExpandableComposite) e.getSource());
264
			}
265
		});
266
		fExpandables.add(excomposite);
267
		makeScrollableCompositeAware(excomposite);
268
		return excomposite;
269
	}
270
	
271
	protected final void expandedStateChanged(ExpandableComposite expandable) {
272
		ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(expandable);
273
		if (parentScrolledComposite != null) {
274
			parentScrolledComposite.reflow(true);
275
		}
276
	}
277
	
278
	private void makeScrollableCompositeAware(Control control) {
279
		ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(control);
280
		if (parentScrolledComposite != null) {
281
			parentScrolledComposite.adaptChild(control);
282
		}
283
	}
284
	
285
	protected ScrolledPageContent getParentScrolledComposite(Control control) {
286
		Control parent= control.getParent();
287
		while (!(parent instanceof ScrolledPageContent) && parent != null) {
288
			parent= parent.getParent();
289
		}
290
		if (parent instanceof ScrolledPageContent) {
291
			return (ScrolledPageContent) parent;
292
		}
293
		return null;
294
	}
295
	
296
	protected void storeSectionExpansionStates(IDialogSettings section) {
297
		for(int i = 0; i < fExpandables.size(); i++) {
298
			ExpandableComposite comp = (ExpandableComposite) fExpandables.get(i);
299
			section.put(SETTINGS_EXPANDED + String.valueOf(i), comp.isExpanded());
300
		}
301
	}
302
	
303
	protected void restoreSectionExpansionStates(IDialogSettings settings) {
304
		for (int i= 0; i < fExpandables.size(); i++) {
305
			ExpandableComposite excomposite= (ExpandableComposite) fExpandables.get(i);
306
			if (settings == null) {
307
				excomposite.setExpanded(i == 0); // only expand the first node by default
308
			} else {
309
				excomposite.setExpanded(settings.getBoolean(SETTINGS_EXPANDED + String.valueOf(i)));
310
			}
311
		}
312
	}
313
	
314
	protected void resetSeverities() {
315
		IEclipsePreferences defaultContext = new DefaultScope().getNode(getPreferenceNodeQualifier());
316
		for(int i = 0; i < fCombos.size(); i++) {
317
			ComboData data = (ComboData)((Combo)fCombos.get(i)).getData();
318
			int severity = defaultContext.getInt(data.getKey(), ValidationMessage.WARNING);
319
			data.setSeverity(severity);
320
			((Combo)fCombos.get(i)).select(data.getIndex());
321
		}
322
	}
323
	
324
	protected boolean shouldRevalidateOnSettingsChange() {
325
		Iterator it = fCombos.iterator();
326
327
		while (it.hasNext()) {
328
			ComboData data = (ComboData) ((Combo) it.next()).getData();
329
			if (data.isChanged())
330
				return true;
331
		}
332
		return false;
333
	}
334
	
335
	public boolean performOk() {
336
		if(super.performOk() && shouldRevalidateOnSettingsChange()) {
337
			MessageBox mb = new MessageBox(this.getShell(), SWT.APPLICATION_MODAL | SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.RIGHT);
338
			mb.setText(HTMLUIMessages.Validation_Title);
339
			/* Choose which message to use based on if its project or workspace settings */
340
			String msg = (getProject() == null) ? HTMLUIMessages.Validation_Workspace : HTMLUIMessages.Validation_Project;
341
			mb.setMessage(msg);
342
			switch(mb.open()) {
343
				case SWT.CANCEL:
344
					return false;
345
				case SWT.YES:
346
					storeValues();
347
					ValidateJob job = new ValidateJob(HTMLUIMessages.Validation_jobName);
348
					job.schedule();
349
				case SWT.NO:
350
					storeValues();
351
				default:
352
					return true;
353
			}
354
		}
355
		return true;
356
	}
357
	
358
	/**
359
	 * Performs validation after validation preferences have been modified.
360
	 */
361
	private class ValidateJob extends Job {
362
		
363
		public ValidateJob(String name) {
364
			super(name);
365
		}
366
367
		protected IStatus run(IProgressMonitor monitor) {
368
			IStatus status = Status.OK_STATUS;
369
			try {
370
				IProject[] projects = null;
371
				/* Changed preferences for a single project, only validate it */
372
				if(getProject() != null)
373
					projects = new IProject[] {getProject()};
374
				/* Workspace-wide preferences changed */
375
				else {
376
					/* Get all of the projects in the workspace */
377
					projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
378
					IEclipsePreferences prefs = null;
379
					List projectList = new ArrayList();
380
					
381
					/* Filter out projects that use project-specific settings or have been closed */
382
					for(int i = 0; i < projects.length; i++) {
383
						prefs = new ProjectScope(projects[i]).getNode(getPreferenceNodeQualifier());
384
						if(projects[i].isAccessible() && !prefs.getBoolean(getProjectSettingsKey(), false))
385
							projectList.add(projects[i]);
386
					}
387
					projects = (IProject[]) projectList.toArray(new IProject[projectList.size()]);
388
				}
389
				fValidation.validate(projects, true, false, monitor);
390
			}
391
			catch (CoreException ce) {
392
				status = Status.CANCEL_STATUS;
393
			}
394
			
395
			return status;
396
		}
397
		
398
	}
399
	
400
}
(-)src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 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 26-31 Link Here
26
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
26
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
27
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
27
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
28
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
28
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
29
import org.eclipse.wst.xml.ui.internal.preferences.AbstractValidationSettingsPage;
29
30
30
public class HTMLValidationPreferencePage extends AbstractValidationSettingsPage {
31
public class HTMLValidationPreferencePage extends AbstractValidationSettingsPage {
31
	
32
	
(-)src/org/eclipse/wst/html/ui/internal/preferences/ui/PropertyPreferencePage.java (-300 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 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
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
11
 *     
12
 *******************************************************************************/
13
package org.eclipse.wst.html.ui.internal.preferences.ui;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IWorkspace;
21
import org.eclipse.core.resources.ProjectScope;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.preferences.DefaultScope;
25
import org.eclipse.core.runtime.preferences.IScopeContext;
26
import org.eclipse.core.runtime.preferences.InstanceScope;
27
import org.eclipse.jface.dialogs.ControlEnableState;
28
import org.eclipse.jface.viewers.DecoratingLabelProvider;
29
import org.eclipse.jface.viewers.IStructuredContentProvider;
30
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.events.SelectionListener;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Link;
43
import org.eclipse.ui.IWorkbenchPreferencePage;
44
import org.eclipse.ui.dialogs.ListDialog;
45
import org.eclipse.ui.dialogs.PreferencesUtil;
46
import org.eclipse.ui.dialogs.PropertyPage;
47
import org.eclipse.ui.model.WorkbenchLabelProvider;
48
import org.eclipse.ui.views.navigator.ResourceSorter;
49
import org.eclipse.wst.sse.core.internal.tasks.TaskTagPreferenceKeys;
50
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
51
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
52
53
/**
54
 * Based loosely on org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage
55
 */
56
abstract class PropertyPreferencePage extends PropertyPage implements IWorkbenchPreferencePage {
57
	private static final boolean _debugPreferences = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.sse.ui/preferences-properties")); //$NON-NLS-1$ //$NON-NLS-2$
58
	/*
59
	 * Disable link data, prevents the display of a "workspace" or "project"
60
	 * settings link to prevent recursive dialog launching
61
	 */
62
	private static final Object DISABLE_LINK = "DISABLE_LINK"; //$NON-NLS-1$
63
64
	private Map fData = null;
65
66
	private Button fEnableProjectSettings;
67
68
	private Link fProjectSettingsLink;
69
	
70
	private Control fCommon;
71
	
72
	private ControlEnableState fEnablements;
73
74
	public PropertyPreferencePage() {
75
		super();
76
	}
77
78
	public final void applyData(Object data) {
79
		super.applyData(data);
80
		if (data instanceof Map) {
81
			fData = (Map) data;
82
			updateLinkEnablement();
83
		}
84
	}
85
86
	protected abstract Control createCommonContents(Composite composite);
87
88
	public final Control createContents(Composite parent) {
89
		Composite composite = new Composite(parent, SWT.NULL);
90
91
		GridLayout layout = new GridLayout();
92
		composite.setLayout(layout);
93
		GridData data = new GridData(GridData.FILL_BOTH);
94
		composite.setLayoutData(data);
95
96
		Composite checkLinkComposite = new Composite(composite, SWT.NONE);
97
		checkLinkComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
98
		checkLinkComposite.setLayout(new GridLayout(2, false));
99
100
		if (getProject() != null) {
101
			fEnableProjectSettings = new Button(checkLinkComposite, SWT.CHECK);
102
			fEnableProjectSettings.setText(SSEUIMessages.EnableProjectSettings); //$NON-NLS-1$//$NON-NLS-2$
103
			fEnableProjectSettings.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
104
			boolean enabledForProject = createPreferenceScopes()[0].getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false);
105
			fEnableProjectSettings.setSelection(enabledForProject);
106
		}
107
		else {
108
			Label spacer = new Label(checkLinkComposite, SWT.CHECK);
109
			spacer.setLayoutData(new GridData());
110
		}
111
112
		fProjectSettingsLink = new Link(checkLinkComposite, SWT.NONE);
113
		fProjectSettingsLink.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, true, false));
114
115
		/*
116
		 * "element" should be a project, if null, link to per-project
117
		 * properties
118
		 */
119
		if (getProject() != null) {
120
			fProjectSettingsLink.setText("<a>" + SSEUIMessages.ConfigureWorkspaceSettings + "</a>"); //$NON-NLS-1$//$NON-NLS-2$
121
		}
122
		else {
123
			fProjectSettingsLink.setText("<a>" + SSEUIMessages.ConfigureProjectSettings + "</a>"); //$NON-NLS-1$//$NON-NLS-2$
124
		}
125
126
		updateLinkEnablement();
127
128
		fProjectSettingsLink.addSelectionListener(new SelectionListener() {
129
			public void widgetDefaultSelected(SelectionEvent e) {
130
				widgetSelected(e);
131
			}
132
133
			public void widgetSelected(SelectionEvent e) {
134
				if (getProject() == null) {
135
					openProjectSettings();
136
				}
137
				else {
138
					openWorkspaceSettings();
139
				}
140
			}
141
142
		});
143
144
		if (getProject() != null) {
145
			Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
146
			line.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
147
		}
148
149
//		final Control common = createCommonContents(composite);
150
		fCommon = createCommonContents(composite);
151
		
152
		fCommon.setLayoutData(new GridData(GridData.FILL_BOTH));
153
154
		if (fEnableProjectSettings != null) {
155
			SelectionAdapter selectionAdapter = new SelectionAdapter() {
156
				public void widgetSelected(SelectionEvent e) {
157
					super.widgetSelected(e);
158
					enablePreferenceContent(fEnableProjectSettings.getSelection());
159
				}
160
			};
161
			selectionAdapter.widgetSelected(null);
162
			fEnableProjectSettings.addSelectionListener(selectionAdapter);
163
		}
164
		
165
		applyDialogFont(composite);
166
		return composite;
167
	}
168
169
	protected IScopeContext[] createPreferenceScopes() {
170
		IProject project = getProject();
171
		if (project != null) {
172
			return new IScopeContext[]{new ProjectScope(project), new InstanceScope(), new DefaultScope()};
173
		}
174
		return new IScopeContext[]{new InstanceScope(), new DefaultScope()};
175
	}
176
177
	protected abstract String getPreferenceNodeQualifier();
178
179
	protected abstract String getPreferencePageID();
180
181
	protected IProject getProject() {
182
		if (getElement() != null) {
183
			if (getElement() instanceof IProject) {
184
				return (IProject) getElement();
185
			}
186
			Object adapter = getElement().getAdapter(IProject.class);
187
			if (adapter instanceof IProject) {
188
				return (IProject) adapter;
189
			}
190
			adapter = getElement().getAdapter(IResource.class);
191
			if (adapter instanceof IProject) {
192
				return (IProject) adapter;
193
			}
194
		}
195
		return null;
196
	}
197
198
	protected abstract String getProjectSettingsKey();
199
200
	protected abstract String getPropertyPageID();
201
202
	protected boolean isElementSettingsEnabled() {
203
		return fEnableProjectSettings != null && fEnableProjectSettings.getSelection();
204
	}
205
206
	void openProjectSettings() {
207
		ListDialog dialog = new ListDialog(getShell()) {
208
209
			protected Control createDialogArea(Composite container) {
210
				Control area = super.createDialogArea(container);
211
				getTableViewer().setSorter(new ResourceSorter(ResourceSorter.NAME));
212
				return area;
213
			}
214
		};
215
		dialog.setMessage(SSEUIMessages.PropertyPreferencePage_02);
216
		dialog.setContentProvider(new IStructuredContentProvider() {
217
			public void dispose() {
218
			}
219
220
			public Object[] getElements(Object inputElement) {
221
				return ((IWorkspace) inputElement).getRoot().getProjects();
222
			}
223
224
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
225
			}
226
		});
227
		dialog.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), SSEUIPlugin.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
228
		dialog.setInput(ResourcesPlugin.getWorkspace());
229
		dialog.setTitle(SSEUIMessages.PropertyPreferencePage_01);
230
		if (dialog.open() == Window.OK) {
231
			Object[] result = dialog.getResult();
232
			if (result.length > 0) {
233
				IProject project = (IProject) dialog.getResult()[0];
234
				Map data = new HashMap();
235
				data.put(DISABLE_LINK, Boolean.TRUE);
236
				PreferencesUtil.createPropertyDialogOn(getShell(), project, getPropertyPageID(), new String[]{getPropertyPageID()}, data).open();
237
			}
238
		}
239
	}
240
241
	void openWorkspaceSettings() {
242
		Map data = new HashMap();
243
		data.put(DISABLE_LINK, Boolean.TRUE);
244
		PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferencePageID(), new String[]{getPreferencePageID()}, data).open();
245
	}
246
247
	public boolean performOk() {
248
		boolean ok = super.performOk();
249
		IScopeContext[] preferenceScopes = createPreferenceScopes();
250
		if (getProject() != null) {
251
			if (isElementSettingsEnabled()) {
252
				if (_debugPreferences) {
253
					System.out.println(getClass().getName() + " setting " + TaskTagPreferenceKeys.TASK_TAG_PER_PROJECT + " (" + true + ") in scope " + preferenceScopes[0].getName() + ":" + preferenceScopes[0].getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$  
254
				}
255
				preferenceScopes[0].getNode(getPreferenceNodeQualifier()).putBoolean(getProjectSettingsKey(), fEnableProjectSettings.getSelection());
256
			}
257
			else {
258
				if (_debugPreferences) {
259
					System.out.println(getClass().getName() + " removing " + TaskTagPreferenceKeys.TASK_TAG_PER_PROJECT + " from scope " + preferenceScopes[0].getName() + ":" + preferenceScopes[0].getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
260
				}
261
				preferenceScopes[0].getNode(getPreferenceNodeQualifier()).remove(getProjectSettingsKey());
262
			}
263
		}
264
		return ok;
265
	}
266
	
267
	protected void performDefaults() {
268
		if(getProject() != null && fEnableProjectSettings != null) {
269
			fEnableProjectSettings.setSelection(false);
270
			enablePreferenceContent(false);
271
		}
272
		super.performDefaults();
273
	}
274
275
	private void updateLinkEnablement() {
276
		if (fData != null && fProjectSettingsLink != null) {
277
			fProjectSettingsLink.setEnabled(!Boolean.TRUE.equals(fData.get(DISABLE_LINK)));
278
		}
279
	}
280
	
281
	/**
282
	 * Controls the enablement of the common content region
283
	 * of a property or preference page
284
	 * 
285
	 * @param enable the enabled state of the common content
286
	 * area
287
	 */
288
	protected void enablePreferenceContent(boolean enable) {
289
		if(enable) {
290
			if(fEnablements != null) {
291
				fEnablements.restore();
292
				fEnablements = null;
293
			}
294
		}
295
		else {
296
			if(fEnablements == null)
297
				fEnablements = ControlEnableState.disable(fCommon);
298
		}
299
	}
300
}
(-)src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java (+3 lines)
Lines 284-287 Link Here
284
    public static final String NAMESPACE_IN_PI_TARGET = "namespaceInPITarget"; //$NON-NLS-1$
284
    public static final String NAMESPACE_IN_PI_TARGET = "namespaceInPITarget"; //$NON-NLS-1$
285
    public static final String MISSING_TAG_NAME = "missingTagName"; //$NON-NLS-1$
285
    public static final String MISSING_TAG_NAME = "missingTagName"; //$NON-NLS-1$
286
    public static final String WHITESPACE_AT_START = "whitespaceAtStart"; //$NON-NLS-1$
286
    public static final String WHITESPACE_AT_START = "whitespaceAtStart"; //$NON-NLS-1$
287
    
288
    public static final String USE_PROJECT_SETTINGS = "use-project-settings";//$NON-NLS-1$
289
	
287
}
290
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 45-50 Link Here
45
Import-Package: com.ibm.icu.util; version="3.8",
45
Import-Package: com.ibm.icu.util; version="3.8",
46
 com.ibm.icu.text; version="3.8"
46
 com.ibm.icu.text; version="3.8"
47
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
47
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
48
 org.eclipse.ui.forms;bundle-version="[3.4.0,4.0.0)",
48
 org.eclipse.ui.views;bundle-version="[3.4.0,4.0.0)",
49
 org.eclipse.ui.views;bundle-version="[3.4.0,4.0.0)",
49
 org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
50
 org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
50
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
51
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
(-)plugin.properties (+1 lines)
Lines 24-29 Link Here
24
XML_Syntax_Coloring=Syntax Coloring
24
XML_Syntax_Coloring=Syntax Coloring
25
XML_Typing=Typing
25
XML_Typing=Typing
26
XML_Editor.name=XML Editor
26
XML_Editor.name=XML Editor
27
XML_Property_validation=XML Syntax
27
###############################################################################
28
###############################################################################
28
_UI_WIZARD_NEW_XML=XML File
29
_UI_WIZARD_NEW_XML=XML File
29
XML_New_File.tooltip=New XML File
30
XML_New_File.tooltip=New XML File
(-)plugin.xml (+14 lines)
Lines 227-232 Link Here
227
    	</page>
227
    	</page>
228
	</extension>
228
	</extension>
229
	
229
	
230
	<!-- Web content settings -->
231
	<extension point="org.eclipse.ui.propertyPages">
232
		<page
233
			name="%XML_Property_validation"
234
			class="org.eclipse.wst.xml.ui.internal.preferences.XMLValidatorPreferencePage"
235
			id="org.eclipse.wst.xml.ui.propertyPage.project.validation"
236
			category="ValidationPropertiesPage">
237
			<enabledWhen>
238
				<adapt type="org.eclipse.core.resources.IProject">
239
					
240
				</adapt>
241
			</enabledWhen>
242
		</page>
243
	</extension>
230
	<!-- Keywords for preference and properties pages -->
244
	<!-- Keywords for preference and properties pages -->
231
	<extension point="org.eclipse.ui.keywords">
245
	<extension point="org.eclipse.ui.keywords">
232
		<keyword
246
		<keyword
(-)src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java (+6 lines)
Lines 336-341 Link Here
336
	public static String Namespace_in_pi_target;
336
	public static String Namespace_in_pi_target;
337
	public static String Tag_name_missing;
337
	public static String Tag_name_missing;
338
	public static String Whitespace_at_start;
338
	public static String Whitespace_at_start;
339
	
340
	// Validation
341
	public static String Validation_Title;
342
	public static String Validation_Workspace;
343
	public static String Validation_Project;
344
	public static String Validation_jobName;
339
345
340
	static {
346
	static {
341
		// load message values from bundle file
347
		// load message values from bundle file
(-)src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties (-1 / +5 lines)
Lines 369-372 Link Here
369
Namespace_in_pi_target=In&valid name space in PI:
369
Namespace_in_pi_target=In&valid name space in PI:
370
Tag_name_missing=Missing tag n&ame:
370
Tag_name_missing=Missing tag n&ame:
371
Whitespace_at_start=Inva&lid white space at start:
371
Whitespace_at_start=Inva&lid white space at start:
372
_ERROR_XML_ATTRIBUTE_IS_INVALID=\"{0}\" is not a valid attribute name
372
_ERROR_XML_ATTRIBUTE_IS_INVALID=\"{0}\" is not a valid attribute name
373
Validation_Title=Validation Settings Changed
374
Validation_Workspace=The validation settings have changed. A full validation is required for changes to take effect. Validate now?
375
Validation_Project=The validation settings have changed. A validation of the project is required for changes to take effect. Validate the project now?
376
Validation_jobName=Validating...
(-)src/org/eclipse/wst/xml/ui/internal/preferences/AbstractValidationSettingsPage.java (+400 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.wst.xml.ui.internal.preferences;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.ProjectScope;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.jobs.Job;
26
import org.eclipse.core.runtime.preferences.DefaultScope;
27
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
28
import org.eclipse.core.runtime.preferences.IPreferencesService;
29
import org.eclipse.core.runtime.preferences.IScopeContext;
30
import org.eclipse.jface.dialogs.IDialogSettings;
31
import org.eclipse.jface.resource.JFaceResources;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.widgets.Combo;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Control;
39
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.MessageBox;
41
import org.eclipse.swt.widgets.Widget;
42
import org.eclipse.ui.forms.events.ExpansionAdapter;
43
import org.eclipse.ui.forms.events.ExpansionEvent;
44
import org.eclipse.ui.forms.widgets.ExpandableComposite;
45
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
46
import org.eclipse.wst.sse.ui.internal.preferences.ui.ScrolledPageContent;
47
import org.eclipse.wst.validation.ValidationFramework;
48
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
49
import org.osgi.service.prefs.BackingStoreException;
50
51
/**
52
 * Based on org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock
53
 */
54
public abstract class AbstractValidationSettingsPage extends PropertyPreferencePage {
55
56
	private List fCombos;
57
	private List fExpandables;
58
	
59
	private SelectionListener fSelectionListener;
60
	
61
	private IPreferencesService fPreferencesService = null;
62
	
63
	private static final String SETTINGS_EXPANDED = "expanded"; //$NON-NLS-1$
64
	
65
	private ValidationFramework fValidation;
66
	
67
	private class ComboData {
68
		private String fKey;
69
		private int[] fSeverities;
70
		private int fIndex;
71
		int originalSeverity = -2;
72
		
73
		public ComboData(String key, int[] severities, int index) {
74
			fKey = key;
75
			fSeverities = severities;
76
			fIndex = index;
77
		}
78
		
79
		public String getKey() {
80
			return fKey;
81
		}
82
		
83
		public void setIndex(int index) {
84
			fIndex = index;
85
		}
86
		
87
		public int getIndex() {
88
			return fIndex;
89
		}
90
		
91
		/**
92
		 * Sets the severity index based on <code>severity</code>.
93
		 * If the severity doesn't exist, the index is set to -1.
94
		 * 
95
		 * @param severity the severity level
96
		 */
97
		public void setSeverity(int severity) {
98
			for(int i = 0; fSeverities != null && i < fSeverities.length; i++) {
99
				if(fSeverities[i] == severity) {
100
					fIndex = i;
101
					return;
102
				}
103
			}
104
			
105
			fIndex = -1;
106
		}
107
		
108
		public int getSeverity() {
109
			return (fIndex >= 0 && fSeverities != null && fIndex < fSeverities.length) ? fSeverities[fIndex] : -1;
110
		}
111
		
112
		boolean isChanged() {
113
			return fSeverities[fIndex] != originalSeverity;
114
		}
115
	}
116
	
117
	public AbstractValidationSettingsPage() {
118
		super();
119
		fCombos = new ArrayList();
120
		fExpandables = new ArrayList();
121
		fPreferencesService = Platform.getPreferencesService();
122
		fValidation = ValidationFramework.getDefault();
123
	}
124
	
125
	/**
126
	 * Creates a Combo widget in the composite <code>parent</code>. The data
127
	 * in the Combo is associated with <code>key</code>. The Combo data is
128
	 * generated based on the integer <code>values</code> where the index
129
	 * of <code>values</code> corresponds to the index of <code>valueLabels</code>
130
	 * 
131
	 * @param parent the composite to create the combo box in
132
	 * @param label the label to give the combo box
133
	 * @param key the unique key to identify the combo box
134
	 * @param values the values represented by the combo options
135
	 * @param valueLabels the calues displayed in the combo box
136
	 * @param indent how far to indent the combo box label
137
	 * 
138
	 * @return the generated combo box
139
	 */
140
	protected Combo addComboBox(Composite parent, String label, String key, int[] values, String[] valueLabels, int indent) {
141
		GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
142
		gd.horizontalIndent= indent;
143
				
144
		Label labelControl= new Label(parent, SWT.LEFT);
145
		labelControl.setFont(JFaceResources.getDialogFont());
146
		labelControl.setText(label);
147
		labelControl.setLayoutData(gd);
148
				
149
		Combo comboBox= newComboControl(parent, key, values, valueLabels);
150
		comboBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
151
152
		return comboBox;
153
	}
154
	
155
	/**
156
	 * Creates a combo box and associates the combo data with the
157
	 * combo box.
158
	 * 
159
	 * @param composite the composite to create the combo box in
160
	 * @param key the unique key to identify the combo box
161
	 * @param values the values represented by the combo options
162
	 * @param valueLabels the values displayed in the combo box
163
	 * 
164
	 * @return the generated combo box
165
	 */
166
	protected Combo newComboControl(Composite composite, String key, int[] values, String[] valueLabels) {
167
		ComboData data = new ComboData(key, values, -1);
168
		
169
		Combo comboBox= new Combo(composite, SWT.READ_ONLY);
170
		comboBox.setItems(valueLabels);
171
		comboBox.setData(data);
172
		comboBox.addSelectionListener(getSelectionListener());
173
		comboBox.setFont(JFaceResources.getDialogFont());
174
			
175
		makeScrollableCompositeAware(comboBox);
176
		
177
		int severity = -1;
178
		if(key != null)
179
			severity = fPreferencesService.getInt(getPreferenceNodeQualifier(), key, ValidationMessage.WARNING, createPreferenceScopes());
180
181
		if (severity == ValidationMessage.ERROR || severity == ValidationMessage.WARNING || severity == ValidationMessage.IGNORE) {
182
			data.setSeverity(severity);
183
			data.originalSeverity = severity;
184
		}
185
		
186
		if(data.getIndex() >= 0)
187
			comboBox.select(data.getIndex());
188
		
189
		fCombos.add(comboBox);
190
		return comboBox;
191
	}
192
	
193
	protected SelectionListener getSelectionListener() {
194
		if (fSelectionListener == null) {
195
			fSelectionListener= new SelectionListener() {
196
				public void widgetDefaultSelected(SelectionEvent e) {}
197
	
198
				public void widgetSelected(SelectionEvent e) {
199
					controlChanged(e.widget);
200
				}
201
			};
202
		}
203
		return fSelectionListener;
204
	}
205
	
206
	protected void controlChanged(Widget widget) {
207
		ComboData data= (ComboData) widget.getData();
208
		if (widget instanceof Combo) {
209
			data.setIndex(((Combo)widget).getSelectionIndex());
210
		} else {
211
			return;
212
		}
213
	}
214
215
	/*
216
	 * (non-Javadoc)
217
	 * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSettingsPage#storeValues()
218
	 */
219
	protected void storeValues() {
220
		if(fCombos == null || fCombos.size() == 0)
221
			return;
222
		
223
		Iterator it = fCombos.iterator();
224
		
225
		IScopeContext[] contexts = createPreferenceScopes();
226
227
		while(it.hasNext()) {
228
			ComboData data = (ComboData) ((Combo)it.next()).getData();
229
			if(data.getKey() != null) {
230
				contexts[0].getNode(getPreferenceNodeQualifier()).putInt(data.getKey(), data.getSeverity());
231
			}
232
		}
233
		
234
		for(int i = 0; i < contexts.length; i++) {
235
			try {
236
				contexts[i].getNode(getPreferenceNodeQualifier()).flush();
237
			}
238
			catch (BackingStoreException e) {
239
				
240
			}
241
		}
242
	}
243
	
244
	protected ExpandableComposite getParentExpandableComposite(Control control) {
245
		Control parent= control.getParent();
246
		while (!(parent instanceof ExpandableComposite) && parent != null) {
247
			parent= parent.getParent();
248
		}
249
		if (parent instanceof ExpandableComposite) {
250
			return (ExpandableComposite) parent;
251
		}
252
		return null;
253
	}
254
	
255
	protected ExpandableComposite createStyleSection(Composite parent, String label, int nColumns) {
256
		ExpandableComposite excomposite= new ExpandableComposite(parent, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
257
		excomposite.setText(label);
258
		excomposite.setExpanded(false);
259
		excomposite.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
260
		excomposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, nColumns, 1));
261
		excomposite.addExpansionListener(new ExpansionAdapter() {
262
			public void expansionStateChanged(ExpansionEvent e) {
263
				expandedStateChanged((ExpandableComposite) e.getSource());
264
			}
265
		});
266
		fExpandables.add(excomposite);
267
		makeScrollableCompositeAware(excomposite);
268
		return excomposite;
269
	}
270
	
271
	protected final void expandedStateChanged(ExpandableComposite expandable) {
272
		ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(expandable);
273
		if (parentScrolledComposite != null) {
274
			parentScrolledComposite.reflow(true);
275
		}
276
	}
277
	
278
	private void makeScrollableCompositeAware(Control control) {
279
		ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(control);
280
		if (parentScrolledComposite != null) {
281
			parentScrolledComposite.adaptChild(control);
282
		}
283
	}
284
	
285
	protected ScrolledPageContent getParentScrolledComposite(Control control) {
286
		Control parent= control.getParent();
287
		while (!(parent instanceof ScrolledPageContent) && parent != null) {
288
			parent= parent.getParent();
289
		}
290
		if (parent instanceof ScrolledPageContent) {
291
			return (ScrolledPageContent) parent;
292
		}
293
		return null;
294
	}
295
	
296
	protected void storeSectionExpansionStates(IDialogSettings section) {
297
		for(int i = 0; i < fExpandables.size(); i++) {
298
			ExpandableComposite comp = (ExpandableComposite) fExpandables.get(i);
299
			section.put(SETTINGS_EXPANDED + String.valueOf(i), comp.isExpanded());
300
		}
301
	}
302
	
303
	protected void restoreSectionExpansionStates(IDialogSettings settings) {
304
		for (int i= 0; i < fExpandables.size(); i++) {
305
			ExpandableComposite excomposite= (ExpandableComposite) fExpandables.get(i);
306
			if (settings == null) {
307
				excomposite.setExpanded(i == 0); // only expand the first node by default
308
			} else {
309
				excomposite.setExpanded(settings.getBoolean(SETTINGS_EXPANDED + String.valueOf(i)));
310
			}
311
		}
312
	}
313
	
314
	protected void resetSeverities() {
315
		IEclipsePreferences defaultContext = new DefaultScope().getNode(getPreferenceNodeQualifier());
316
		for(int i = 0; i < fCombos.size(); i++) {
317
			ComboData data = (ComboData)((Combo)fCombos.get(i)).getData();
318
			int severity = defaultContext.getInt(data.getKey(), ValidationMessage.WARNING);
319
			data.setSeverity(severity);
320
			((Combo)fCombos.get(i)).select(data.getIndex());
321
		}
322
	}
323
	
324
	protected boolean shouldRevalidateOnSettingsChange() {
325
		Iterator it = fCombos.iterator();
326
327
		while (it.hasNext()) {
328
			ComboData data = (ComboData) ((Combo) it.next()).getData();
329
			if (data.isChanged())
330
				return true;
331
		}
332
		return false;
333
	}
334
	
335
	public boolean performOk() {
336
		if(super.performOk() && shouldRevalidateOnSettingsChange()) {
337
			MessageBox mb = new MessageBox(this.getShell(), SWT.APPLICATION_MODAL | SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.RIGHT);
338
			mb.setText(XMLUIMessages.Validation_Title);
339
			/* Choose which message to use based on if its project or workspace settings */
340
			String msg = (getProject() == null) ? XMLUIMessages.Validation_Workspace : XMLUIMessages.Validation_Project;
341
			mb.setMessage(msg);
342
			switch(mb.open()) {
343
				case SWT.CANCEL:
344
					return false;
345
				case SWT.YES:
346
					storeValues();
347
					ValidateJob job = new ValidateJob(XMLUIMessages.Validation_jobName);
348
					job.schedule();
349
				case SWT.NO:
350
					storeValues();
351
				default:
352
					return true;
353
			}
354
		}
355
		return true;
356
	}
357
	
358
	/**
359
	 * Performs validation after validation preferences have been modified.
360
	 */
361
	private class ValidateJob extends Job {
362
		
363
		public ValidateJob(String name) {
364
			super(name);
365
		}
366
367
		protected IStatus run(IProgressMonitor monitor) {
368
			IStatus status = Status.OK_STATUS;
369
			try {
370
				IProject[] projects = null;
371
				/* Changed preferences for a single project, only validate it */
372
				if(getProject() != null)
373
					projects = new IProject[] {getProject()};
374
				/* Workspace-wide preferences changed */
375
				else {
376
					/* Get all of the projects in the workspace */
377
					projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
378
					IEclipsePreferences prefs = null;
379
					List projectList = new ArrayList();
380
					
381
					/* Filter out projects that use project-specific settings or have been closed */
382
					for(int i = 0; i < projects.length; i++) {
383
						prefs = new ProjectScope(projects[i]).getNode(getPreferenceNodeQualifier());
384
						if(projects[i].isAccessible() && !prefs.getBoolean(getProjectSettingsKey(), false))
385
							projectList.add(projects[i]);
386
					}
387
					projects = (IProject[]) projectList.toArray(new IProject[projectList.size()]);
388
				}
389
				fValidation.validate(projects, true, false, monitor);
390
			}
391
			catch (CoreException ce) {
392
				status = Status.CANCEL_STATUS;
393
			}
394
			
395
			return status;
396
		}
397
		
398
	}
399
	
400
}
(-)src/org/eclipse/wst/xml/ui/internal/preferences/PropertyPreferencePage.java (+300 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
11
 *     
12
 *******************************************************************************/
13
package org.eclipse.wst.xml.ui.internal.preferences;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IWorkspace;
21
import org.eclipse.core.resources.ProjectScope;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.preferences.DefaultScope;
25
import org.eclipse.core.runtime.preferences.IScopeContext;
26
import org.eclipse.core.runtime.preferences.InstanceScope;
27
import org.eclipse.jface.dialogs.ControlEnableState;
28
import org.eclipse.jface.viewers.DecoratingLabelProvider;
29
import org.eclipse.jface.viewers.IStructuredContentProvider;
30
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.events.SelectionListener;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Link;
43
import org.eclipse.ui.IWorkbenchPreferencePage;
44
import org.eclipse.ui.dialogs.ListDialog;
45
import org.eclipse.ui.dialogs.PreferencesUtil;
46
import org.eclipse.ui.dialogs.PropertyPage;
47
import org.eclipse.ui.model.WorkbenchLabelProvider;
48
import org.eclipse.ui.views.navigator.ResourceSorter;
49
import org.eclipse.wst.sse.core.internal.tasks.TaskTagPreferenceKeys;
50
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
51
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
52
53
/**
54
 * Based loosely on org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage
55
 */
56
abstract class PropertyPreferencePage extends PropertyPage implements IWorkbenchPreferencePage {
57
	private static final boolean _debugPreferences = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.sse.ui/preferences-properties")); //$NON-NLS-1$ //$NON-NLS-2$
58
	/*
59
	 * Disable link data, prevents the display of a "workspace" or "project"
60
	 * settings link to prevent recursive dialog launching
61
	 */
62
	private static final Object DISABLE_LINK = "DISABLE_LINK"; //$NON-NLS-1$
63
64
	private Map fData = null;
65
66
	private Button fEnableProjectSettings;
67
68
	private Link fProjectSettingsLink;
69
	
70
	private Control fCommon;
71
	
72
	private ControlEnableState fEnablements;
73
74
	public PropertyPreferencePage() {
75
		super();
76
	}
77
78
	public final void applyData(Object data) {
79
		super.applyData(data);
80
		if (data instanceof Map) {
81
			fData = (Map) data;
82
			updateLinkEnablement();
83
		}
84
	}
85
86
	protected abstract Control createCommonContents(Composite composite);
87
88
	public final Control createContents(Composite parent) {
89
		Composite composite = new Composite(parent, SWT.NULL);
90
91
		GridLayout layout = new GridLayout();
92
		composite.setLayout(layout);
93
		GridData data = new GridData(GridData.FILL_BOTH);
94
		composite.setLayoutData(data);
95
96
		Composite checkLinkComposite = new Composite(composite, SWT.NONE);
97
		checkLinkComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
98
		checkLinkComposite.setLayout(new GridLayout(2, false));
99
100
		if (getProject() != null) {
101
			fEnableProjectSettings = new Button(checkLinkComposite, SWT.CHECK);
102
			fEnableProjectSettings.setText(SSEUIMessages.EnableProjectSettings); //$NON-NLS-1$//$NON-NLS-2$
103
			fEnableProjectSettings.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
104
			boolean enabledForProject = createPreferenceScopes()[0].getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false);
105
			fEnableProjectSettings.setSelection(enabledForProject);
106
		}
107
		else {
108
			Label spacer = new Label(checkLinkComposite, SWT.CHECK);
109
			spacer.setLayoutData(new GridData());
110
		}
111
112
		fProjectSettingsLink = new Link(checkLinkComposite, SWT.NONE);
113
		fProjectSettingsLink.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, true, false));
114
115
		/*
116
		 * "element" should be a project, if null, link to per-project
117
		 * properties
118
		 */
119
		if (getProject() != null) {
120
			fProjectSettingsLink.setText("<a>" + SSEUIMessages.ConfigureWorkspaceSettings + "</a>"); //$NON-NLS-1$//$NON-NLS-2$
121
		}
122
		else {
123
			fProjectSettingsLink.setText("<a>" + SSEUIMessages.ConfigureProjectSettings + "</a>"); //$NON-NLS-1$//$NON-NLS-2$
124
		}
125
126
		updateLinkEnablement();
127
128
		fProjectSettingsLink.addSelectionListener(new SelectionListener() {
129
			public void widgetDefaultSelected(SelectionEvent e) {
130
				widgetSelected(e);
131
			}
132
133
			public void widgetSelected(SelectionEvent e) {
134
				if (getProject() == null) {
135
					openProjectSettings();
136
				}
137
				else {
138
					openWorkspaceSettings();
139
				}
140
			}
141
142
		});
143
144
		if (getProject() != null) {
145
			Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
146
			line.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
147
		}
148
149
//		final Control common = createCommonContents(composite);
150
		fCommon = createCommonContents(composite);
151
		
152
		fCommon.setLayoutData(new GridData(GridData.FILL_BOTH));
153
154
		if (fEnableProjectSettings != null) {
155
			SelectionAdapter selectionAdapter = new SelectionAdapter() {
156
				public void widgetSelected(SelectionEvent e) {
157
					super.widgetSelected(e);
158
					enablePreferenceContent(fEnableProjectSettings.getSelection());
159
				}
160
			};
161
			selectionAdapter.widgetSelected(null);
162
			fEnableProjectSettings.addSelectionListener(selectionAdapter);
163
		}
164
		
165
		applyDialogFont(composite);
166
		return composite;
167
	}
168
169
	protected IScopeContext[] createPreferenceScopes() {
170
		IProject project = getProject();
171
		if (project != null) {
172
			return new IScopeContext[]{new ProjectScope(project), new InstanceScope(), new DefaultScope()};
173
		}
174
		return new IScopeContext[]{new InstanceScope(), new DefaultScope()};
175
	}
176
177
	protected abstract String getPreferenceNodeQualifier();
178
179
	protected abstract String getPreferencePageID();
180
181
	protected IProject getProject() {
182
		if (getElement() != null) {
183
			if (getElement() instanceof IProject) {
184
				return (IProject) getElement();
185
			}
186
			Object adapter = getElement().getAdapter(IProject.class);
187
			if (adapter instanceof IProject) {
188
				return (IProject) adapter;
189
			}
190
			adapter = getElement().getAdapter(IResource.class);
191
			if (adapter instanceof IProject) {
192
				return (IProject) adapter;
193
			}
194
		}
195
		return null;
196
	}
197
198
	protected abstract String getProjectSettingsKey();
199
200
	protected abstract String getPropertyPageID();
201
202
	protected boolean isElementSettingsEnabled() {
203
		return fEnableProjectSettings != null && fEnableProjectSettings.getSelection();
204
	}
205
206
	void openProjectSettings() {
207
		ListDialog dialog = new ListDialog(getShell()) {
208
209
			protected Control createDialogArea(Composite container) {
210
				Control area = super.createDialogArea(container);
211
				getTableViewer().setSorter(new ResourceSorter(ResourceSorter.NAME));
212
				return area;
213
			}
214
		};
215
		dialog.setMessage(SSEUIMessages.PropertyPreferencePage_02);
216
		dialog.setContentProvider(new IStructuredContentProvider() {
217
			public void dispose() {
218
			}
219
220
			public Object[] getElements(Object inputElement) {
221
				return ((IWorkspace) inputElement).getRoot().getProjects();
222
			}
223
224
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
225
			}
226
		});
227
		dialog.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), SSEUIPlugin.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
228
		dialog.setInput(ResourcesPlugin.getWorkspace());
229
		dialog.setTitle(SSEUIMessages.PropertyPreferencePage_01);
230
		if (dialog.open() == Window.OK) {
231
			Object[] result = dialog.getResult();
232
			if (result.length > 0) {
233
				IProject project = (IProject) dialog.getResult()[0];
234
				Map data = new HashMap();
235
				data.put(DISABLE_LINK, Boolean.TRUE);
236
				PreferencesUtil.createPropertyDialogOn(getShell(), project, getPropertyPageID(), new String[]{getPropertyPageID()}, data).open();
237
			}
238
		}
239
	}
240
241
	void openWorkspaceSettings() {
242
		Map data = new HashMap();
243
		data.put(DISABLE_LINK, Boolean.TRUE);
244
		PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferencePageID(), new String[]{getPreferencePageID()}, data).open();
245
	}
246
247
	public boolean performOk() {
248
		boolean ok = super.performOk();
249
		IScopeContext[] preferenceScopes = createPreferenceScopes();
250
		if (getProject() != null) {
251
			if (isElementSettingsEnabled()) {
252
				if (_debugPreferences) {
253
					System.out.println(getClass().getName() + " setting " + TaskTagPreferenceKeys.TASK_TAG_PER_PROJECT + " (" + true + ") in scope " + preferenceScopes[0].getName() + ":" + preferenceScopes[0].getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$  
254
				}
255
				preferenceScopes[0].getNode(getPreferenceNodeQualifier()).putBoolean(getProjectSettingsKey(), fEnableProjectSettings.getSelection());
256
			}
257
			else {
258
				if (_debugPreferences) {
259
					System.out.println(getClass().getName() + " removing " + TaskTagPreferenceKeys.TASK_TAG_PER_PROJECT + " from scope " + preferenceScopes[0].getName() + ":" + preferenceScopes[0].getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
260
				}
261
				preferenceScopes[0].getNode(getPreferenceNodeQualifier()).remove(getProjectSettingsKey());
262
			}
263
		}
264
		return ok;
265
	}
266
	
267
	protected void performDefaults() {
268
		if(getProject() != null && fEnableProjectSettings != null) {
269
			fEnableProjectSettings.setSelection(false);
270
			enablePreferenceContent(false);
271
		}
272
		super.performDefaults();
273
	}
274
275
	private void updateLinkEnablement() {
276
		if (fData != null && fProjectSettingsLink != null) {
277
			fProjectSettingsLink.setEnabled(!Boolean.TRUE.equals(fData.get(DISABLE_LINK)));
278
		}
279
	}
280
	
281
	/**
282
	 * Controls the enablement of the common content region
283
	 * of a property or preference page
284
	 * 
285
	 * @param enable the enabled state of the common content
286
	 * area
287
	 */
288
	protected void enablePreferenceContent(boolean enable) {
289
		if(enable) {
290
			if(fEnablements != null) {
291
				fEnablements.restore();
292
				fEnablements = null;
293
			}
294
		}
295
		else {
296
			if(fEnablements == null)
297
				fEnablements = ControlEnableState.disable(fCommon);
298
		}
299
	}
300
}
(-)src/org/eclipse/wst/xml/ui/internal/preferences/XMLValidatorPreferencePage.java (-481 / +437 lines)
Lines 13-23 Link Here
13
13
14
package org.eclipse.wst.xml.ui.internal.preferences;
14
package org.eclipse.wst.xml.ui.internal.preferences;
15
15
16
17
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.core.runtime.Preferences;
17
import org.eclipse.core.runtime.preferences.DefaultScope;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
19
import org.eclipse.core.runtime.preferences.IScopeContext;
18
import org.eclipse.jface.dialogs.ControlEnableState;
20
import org.eclipse.jface.dialogs.ControlEnableState;
19
import org.eclipse.jface.resource.JFaceResources;
21
import org.eclipse.jface.dialogs.IDialogSettings;
22
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.custom.ScrolledComposite;
21
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Point;
Lines 28-518 Link Here
28
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Group;
34
import org.eclipse.swt.widgets.Group;
31
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.ui.IWorkbench;
32
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
33
import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage;
34
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
37
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
35
import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
38
import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
36
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
39
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
37
import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds;
40
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
41
42
public class XMLValidatorPreferencePage extends AbstractValidationSettingsPage {
43
	private static final String SETTINGS_SECTION_NAME = "XMLValidationSeverities";//$NON-NLS-1$
44
	
45
	boolean fOriginalUseXIncludeButtonSelected;
46
	
47
	boolean fOriginalUseHonourAllButtonSelected;
48
	
49
	boolean fOriginalUseExtendedMarkupValidation;
50
51
	private Combo fIndicateNoGrammar = null;
52
53
	private Button fHonourAllSchemaLocations = null;
54
55
	private Button fUseXinclude = null;
56
57
	private Button fExtendedMarkupValidation;
58
	
59
	private Combo fMissingStartTag;
60
	
61
	private Combo fMissingEndTag;
62
63
	private Combo fMissingTagName;
64
65
	private Combo fEmptyElementTag;
66
67
	private Combo fEndTagWithAttributes;
68
69
	private Combo fInvalidWhitespaceBeforeTagname;
70
71
	private Combo fMissingClosingBracket;
72
73
	private Combo fMissingClosingQuote;
74
75
76
	private Combo fMissingQuotes;
77
78
	private Combo fInvalidNamespaceInPI;
79
80
81
	private Combo fInvalidWhitespaceAtStart;
82
	
83
	private Group fMarkupValidationGroup;
84
	private ControlEnableState fMarkupState;
85
86
87
	private static final int[] XML_SEVERITIES = { ValidationMessage.WARNING,
88
			ValidationMessage.ERROR, ValidationMessage.IGNORE };
89
90
	private static final String[] MARKUP_SEVERITIES = {
91
			XMLUIMessages.Severity_error, XMLUIMessages.Severity_warning,
92
			XMLUIMessages.Severity_ignore };
93
94
	protected void createContentsForValidatingGroup(Composite validatingGroup) {
95
		int nColumns = 3;
96
97
		GridLayout layout = new GridLayout(nColumns, false);
98
		layout.marginHeight = 0;
99
		layout.marginWidth = 0;
100
		validatingGroup.setLayout(layout);
101
102
		if (fIndicateNoGrammar == null)
103
			fIndicateNoGrammar = addComboBox(validatingGroup,
104
					XMLUIMessages.Indicate_no_grammar_specified,
105
					XMLCorePreferenceNames.INDICATE_NO_GRAMMAR, XML_SEVERITIES,
106
					MARKUP_SEVERITIES, 0);
107
108
		if (fUseXinclude == null) {
109
			fUseXinclude = createCheckBox(validatingGroup,
110
					XMLUIMessages.Use_XInclude);
111
			((GridData) fUseXinclude.getLayoutData()).horizontalSpan = 2;
112
		}
113
114
		if (fHonourAllSchemaLocations == null) {
115
			fHonourAllSchemaLocations = createCheckBox(validatingGroup,
116
					XMLUIMessages.Honour_all_schema_locations);
117
			((GridData) fHonourAllSchemaLocations.getLayoutData()).horizontalSpan = 2;
118
		}
119
		
120
		IScopeContext[] contexts = createPreferenceScopes();
121
		fOriginalUseXIncludeButtonSelected = contexts[0].getNode(getPreferenceNodeQualifier()).getBoolean(
122
				XMLCorePreferenceNames.USE_XINCLUDE, true);
123
124
		if (fUseXinclude != null) {
125
			fUseXinclude.setSelection(fOriginalUseXIncludeButtonSelected);
126
		}
127
		fOriginalUseHonourAllButtonSelected = contexts[0].getNode(getPreferenceNodeQualifier()).getBoolean(
128
				XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, true);
129
		if (fHonourAllSchemaLocations != null) {
130
			fHonourAllSchemaLocations.setSelection(fOriginalUseHonourAllButtonSelected);
131
		}
132
133
	}
134
135
	private void handleMarkupSeveritySelection(boolean selection) {
136
		if(selection) {
137
			if(fMarkupState != null) {
138
				fMarkupState.restore();
139
				fMarkupState = null;
140
			}
141
		}
142
		else {
143
			if(fMarkupState == null)
144
				fMarkupState = ControlEnableState.disable(fMarkupValidationGroup);
145
		}
146
	}
147
148
	
149
	protected void createContentsForMarkupValidationGroup(Composite parent) {
150
		
151
	    IScopeContext[] contexts = createPreferenceScopes();
152
	
153
		fOriginalUseExtendedMarkupValidation = contexts[0].getNode(getPreferenceNodeQualifier()).getBoolean(
154
				XMLCorePreferenceNames.MARKUP_VALIDATION, false);
155
		fExtendedMarkupValidation = createCheckBox(parent,
156
				XMLUIMessages.MarkupValidation_files);
157
158
		((GridData) fExtendedMarkupValidation.getLayoutData()).horizontalSpan = 2;
159
		fExtendedMarkupValidation.setSelection(fOriginalUseExtendedMarkupValidation);
160
161
		fExtendedMarkupValidation
162
				.addSelectionListener(new SelectionAdapter() {
163
					public void widgetSelected(SelectionEvent e) {
164
						handleMarkupSeveritySelection(fExtendedMarkupValidation
165
								.getSelection());
166
					}
167
				});
168
	
169
		fMarkupValidationGroup = createGroup(parent, 3);
170
		((GridLayout) fMarkupValidationGroup.getLayout()).makeColumnsEqualWidth = false;
171
		fMarkupValidationGroup
172
				.setText(XMLUIMessages.MarkupValidation_files_label);
173
		GridLayout layout = new GridLayout(3, false);
174
		layout.marginHeight = 0;
175
		layout.marginWidth = 0;
176
		fMarkupValidationGroup.setLayout(layout);
177
178
179
		if (fMissingStartTag == null)
180
			fMissingStartTag = addComboBox(fMarkupValidationGroup,
181
					XMLUIMessages.Missing_start_tag,
182
					XMLCorePreferenceNames.MISSING_START_TAG, XML_SEVERITIES,
183
					MARKUP_SEVERITIES, 0);
184
		if (fMissingEndTag == null)
185
			fMissingEndTag = addComboBox(fMarkupValidationGroup,
186
					XMLUIMessages.Missing_end_tag,
187
					XMLCorePreferenceNames.MISSING_END_TAG, XML_SEVERITIES,
188
					MARKUP_SEVERITIES, 0);
189
		if (fMissingTagName == null)
190
			fMissingTagName = addComboBox(fMarkupValidationGroup,
191
					XMLUIMessages.Tag_name_missing,
192
					XMLCorePreferenceNames.MISSING_TAG_NAME, XML_SEVERITIES,
193
					MARKUP_SEVERITIES, 0);
194
		if (fMissingQuotes == null)
195
			fMissingQuotes = addComboBox(fMarkupValidationGroup,
196
					XMLUIMessages.Missing_quotes,
197
					XMLCorePreferenceNames.MISSING_QUOTES, XML_SEVERITIES,
198
					MARKUP_SEVERITIES, 0);
199
		if (fMissingClosingBracket == null)
200
			fMissingClosingBracket = addComboBox(fMarkupValidationGroup,
201
					XMLUIMessages.Missing_closing_bracket,
202
					XMLCorePreferenceNames.MISSING_CLOSING_BRACKET,
203
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
204
		if (fMissingClosingQuote == null)
205
			fMissingClosingQuote = addComboBox(fMarkupValidationGroup,
206
					XMLUIMessages.Missing_closing_quote,
207
					XMLCorePreferenceNames.MISSING_CLOSING_QUOTE,
208
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
209
		if (fEmptyElementTag == null)
210
			fEmptyElementTag = addComboBox(fMarkupValidationGroup,
211
					XMLUIMessages.Empty_element_tag,
212
					XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE,
213
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
214
		if (fEndTagWithAttributes == null)
215
			fEndTagWithAttributes = addComboBox(fMarkupValidationGroup,
216
					XMLUIMessages.End_tag_with_attributes,
217
					XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES,
218
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
219
		if (fInvalidWhitespaceBeforeTagname == null)
220
			fInvalidWhitespaceBeforeTagname = addComboBox(
221
					fMarkupValidationGroup,
222
					XMLUIMessages.Invalid_whitespace_before_tagname,
223
					XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME,
224
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
225
		if (fInvalidNamespaceInPI == null)
226
			fInvalidNamespaceInPI = addComboBox(fMarkupValidationGroup,
227
					XMLUIMessages.Namespace_in_pi_target,
228
					XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET,
229
					XML_SEVERITIES, MARKUP_SEVERITIES, 0);
230
		if (fInvalidWhitespaceAtStart == null)
231
			fInvalidWhitespaceAtStart = addComboBox(fMarkupValidationGroup,
232
					XMLUIMessages.Whitespace_at_start,
233
					XMLCorePreferenceNames.WHITESPACE_AT_START, XML_SEVERITIES,
234
					MARKUP_SEVERITIES, 0);
235
		
236
		
237
		handleMarkupSeveritySelection(fOriginalUseExtendedMarkupValidation);
238
239
	}
240
241
	
242
	protected void performDefaultsForValidatingGroup() {
243
		IEclipsePreferences modelPreferences = new DefaultScope()
244
		.getNode(getPreferenceNodeQualifier());
245
		boolean useXIncludeButtonSelected = modelPreferences.getBoolean(
246
				XMLCorePreferenceNames.USE_XINCLUDE, true);
247
248
		if (fUseXinclude != null) {
249
			fUseXinclude.setSelection(useXIncludeButtonSelected);
250
		}
251
		boolean useHonourAllButtonSelected = modelPreferences.getBoolean(
252
				XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, true);
253
		if (fHonourAllSchemaLocations != null) {
254
			fHonourAllSchemaLocations.setSelection(useHonourAllButtonSelected);
255
		}
256
	}
257
258
	protected void performDefaultsForMarkupValidationGroup() {
259
		
260
		IEclipsePreferences modelPreferences = new DefaultScope()
261
				.getNode(getPreferenceNodeQualifier());
262
		boolean useExtendedMarkupValidation = modelPreferences.getBoolean(
263
				XMLCorePreferenceNames.MARKUP_VALIDATION, false);
264
	
265
		if (fExtendedMarkupValidation != null) {
266
			if (fExtendedMarkupValidation.getSelection() != useExtendedMarkupValidation) {
267
				handleMarkupSeveritySelection(useExtendedMarkupValidation);
268
			}
269
			fExtendedMarkupValidation.setSelection(useExtendedMarkupValidation);
270
271
		}
272
			
273
		
274
	}
38
275
276
	protected void storeValuesForValidatingGroup(IScopeContext[] contexts) {
277
		
278
		if (fUseXinclude != null) {
279
			boolean useXIncludeButtonSelected = fUseXinclude.getSelection();
280
			contexts[0].getNode(getPreferenceNodeQualifier()).putBoolean(
281
					XMLCorePreferenceNames.USE_XINCLUDE,
282
					useXIncludeButtonSelected);
283
		}
284
		if (fHonourAllSchemaLocations != null) {
285
			boolean honourAllButtonSelected = fHonourAllSchemaLocations
286
					.getSelection();
287
			contexts[0].getNode(getPreferenceNodeQualifier()).putBoolean(
288
					XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS,
289
					honourAllButtonSelected);
290
		}
291
	}
292
293
	protected void storeValuesForMarkupValidationGroup(IScopeContext[] contexts) {
294
		if (fExtendedMarkupValidation != null) {
295
			boolean extendedMarkupValidation = fExtendedMarkupValidation
296
					.getSelection();
297
			contexts[0].getNode(getPreferenceNodeQualifier()).putBoolean(
298
					XMLCorePreferenceNames.MARKUP_VALIDATION,
299
					extendedMarkupValidation);
300
		}
301
		
302
303
	}
304
	
305
	protected void performDefaults() {
306
		resetSeverities();
307
		performDefaultsForValidatingGroup();
308
		performDefaultsForMarkupValidationGroup();
309
		super.performDefaults();
310
	}
311
312
	protected Preferences getModelPreferences() {
313
		return XMLCorePlugin.getDefault().getPluginPreferences();
314
	}
39
315
40
public class XMLValidatorPreferencePage extends AbstractPreferencePage {
316
	protected void doSavePreferenceStore() {
41
  private Combo fIndicateNoGrammar;
317
		XMLCorePlugin.getDefault().savePluginPreferences(); // model
42
  
318
	}
43
  private Button fHonourAllSchemaLocations;
44
45
  private Button fUseXinclude;
46
  
47
  private Button fExtendedMarkupValidation;
48
  
49
  private Combo fEmptyElementTag;
50
  
51
  private Combo fEndTagWithAttributes;
52
  
53
  private Combo fInvalidWhitespaceBeforeTagname;
54
  
55
  private Combo fMissingClosingBracket;
56
  
57
  private Combo fMissingClosingQuote;
58
  
59
  private Combo fMissingEndTag;
60
  
61
  private Combo fMissingStartTag;
62
  
63
  private Combo fMissingQuotes;
64
  
65
  private Combo fInvalidNamespaceInPI;
66
  
67
  private Combo fMissingTagName;
68
  
69
  private Combo fInvalidWhitespaceAtStart;
70
71
  private Group fMarkupValidationGroup;
72
  private ControlEnableState fMarkupState;
73
 
74
  private static final String[] SEVERITIES = {XMLUIMessages.Indicate_no_grammar_specified_severities_error, XMLUIMessages.Indicate_no_grammar_specified_severities_warning, XMLUIMessages.Indicate_no_grammar_specified_severities_ignore};
75
  private static final String[] MARKUP_SEVERITIES = {XMLUIMessages.Severity_error, XMLUIMessages.Severity_warning, XMLUIMessages.Severity_ignore};
76
77
  protected Control createContents(Composite parent) {
78
    Composite composite = (Composite)super.createContents(parent);
79
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_VALIDATOR_HELPID);
80
    createContentsForValidatingGroup(composite);
81
    createContentsForMarkupValidationGroup(composite);
82
    setSize(composite);
83
    loadPreferences();
84
85
    return composite;
86
  }
87
88
  protected void createContentsForValidatingGroup(Composite parent) {
89
    Group validatingGroup = createGroup(parent, 2);
90
    ((GridLayout)validatingGroup.getLayout()).makeColumnsEqualWidth = false;
91
    validatingGroup.setText(XMLUIMessages.Validating_files);
92
93
    if (fIndicateNoGrammar == null) {
94
      createLabel(validatingGroup, XMLUIMessages.Indicate_no_grammar_specified);
95
      fIndicateNoGrammar = createCombo(validatingGroup, SEVERITIES);
96
    }
97
    if (fUseXinclude == null) {
98
      fUseXinclude = createCheckBox(validatingGroup, XMLUIMessages.Use_XInclude);
99
      ((GridData)fUseXinclude.getLayoutData()).horizontalSpan = 2;
100
    }
101
    if (fHonourAllSchemaLocations == null) {
102
      fHonourAllSchemaLocations = createCheckBox(validatingGroup, XMLUIMessages.Honour_all_schema_locations);
103
      ((GridData)fHonourAllSchemaLocations.getLayoutData()).horizontalSpan = 2;
104
    }
105
  }
106
  private void handleMarkupSeveritySelection(boolean selection){
107
	  if (selection) {
108
		  fMarkupState.restore();
109
	  }
110
	  else {
111
		  fMarkupState = ControlEnableState.disable(fMarkupValidationGroup);
112
	  }
113
  }
114
115
  protected void createContentsForMarkupValidationGroup(Composite parent) {
116
	   
117
	    if (fExtendedMarkupValidation == null) {
118
		    fExtendedMarkupValidation = createCheckBox(parent, XMLUIMessages.MarkupValidation_files);
119
		    ((GridData)fExtendedMarkupValidation.getLayoutData()).horizontalSpan = 2;
120
		    fExtendedMarkupValidation.addSelectionListener(new SelectionAdapter() {
121
				public void widgetSelected(SelectionEvent e) {
122
					handleMarkupSeveritySelection(fExtendedMarkupValidation.getSelection());
123
				}
124
			});
125
		}
126
	    fMarkupValidationGroup = createGroup(parent, 3);
127
	    ((GridLayout)fMarkupValidationGroup.getLayout()).makeColumnsEqualWidth = false;
128
	    fMarkupValidationGroup.setText(XMLUIMessages.MarkupValidation_files_label);
129
130
	    if (fMissingStartTag == null) {
131
	        fMissingStartTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_start_tag, MARKUP_SEVERITIES);
132
	    }
133
	    if (fMissingEndTag == null) {
134
	        fMissingEndTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_end_tag, MARKUP_SEVERITIES);
135
	    }
136
	    if (fMissingTagName == null) {
137
	        fMissingTagName = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Tag_name_missing, MARKUP_SEVERITIES);
138
	    }
139
	    if (fMissingQuotes == null) {
140
	        fMissingQuotes = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_quotes, MARKUP_SEVERITIES);
141
	    }
142
	    if (fMissingClosingBracket == null) {
143
	        fMissingClosingBracket = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_closing_bracket, MARKUP_SEVERITIES);
144
	    }
145
	    if (fMissingClosingQuote == null) {
146
	        fMissingClosingQuote = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_closing_quote, MARKUP_SEVERITIES);
147
	    }
148
	    if (fEmptyElementTag == null) {
149
	        fEmptyElementTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Empty_element_tag, MARKUP_SEVERITIES);
150
	    }
151
	    if (fEndTagWithAttributes == null) {
152
	        fEndTagWithAttributes = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.End_tag_with_attributes, MARKUP_SEVERITIES);
153
	    }
154
	    if (fInvalidWhitespaceBeforeTagname == null) {
155
	        fInvalidWhitespaceBeforeTagname = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Invalid_whitespace_before_tagname, MARKUP_SEVERITIES);
156
	    }
157
	    if (fInvalidNamespaceInPI == null) {
158
	        fInvalidNamespaceInPI = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Namespace_in_pi_target, MARKUP_SEVERITIES);
159
	    }
160
	    if (fInvalidWhitespaceAtStart == null) {
161
	        fInvalidWhitespaceAtStart = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Whitespace_at_start, MARKUP_SEVERITIES);
162
	    }
163
164
  }
165
166
  /**
167
   * @param parent 
168
   * @return
169
   */
170
  private Combo createCombo(Composite parent, String[] items) {
171
    Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
172
    combo.setItems(items);
173
174
    //GridData
175
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, true);
176
    combo.setLayoutData(data);
177
178
    return combo;
179
  }
180
181
  private Combo createMarkupCombo(Composite parent, String text, String[] items) {
182
	  Label label = new Label(parent, SWT.LEFT);
183
	  GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
184
		label.setFont(JFaceResources.getDialogFont());
185
		label.setText(text);
186
		label.setLayoutData(gd);
187
188
	  Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
189
	    combo.setItems(items);
190
191
	    //GridData
192
	   // GridData data = new GridData(SWT.FILL, SWT.CENTER, false, true);
193
	    combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
194
195
	    return combo;
196
  }
197
 
198
  protected void initializeValues() {
199
    initializeValuesForValidatingGroup();
200
    initializeValuesForMarkupValidationGroup();
201
  }
202
203
  protected void initializeValuesForValidatingGroup() {
204
    Preferences modelPreferences = getModelPreferences();
205
    int indicateNoGrammarButtonSelected = modelPreferences.getInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR);
206
    boolean useXIncludeButtonSelected = modelPreferences.getBoolean(XMLCorePreferenceNames.USE_XINCLUDE);
207
208
    if (fIndicateNoGrammar != null) {
209
      fIndicateNoGrammar.select(2 - indicateNoGrammarButtonSelected);
210
      fIndicateNoGrammar.setText(SEVERITIES[2 - indicateNoGrammarButtonSelected]);
211
    }
212
    if (fUseXinclude != null) {
213
      fUseXinclude.setSelection(useXIncludeButtonSelected);
214
    }
215
216
    boolean honourAllSelected = modelPreferences.getBoolean(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS);
217
    if (fHonourAllSchemaLocations != null) {
218
      fHonourAllSchemaLocations.setSelection(honourAllSelected);
219
    }
220
  }
221
  
222
  protected void initializeValuesForMarkupValidationGroup() {
223
	    Preferences modelPreferences = getModelPreferences();
224
	    boolean useExtendedMarkupValidation = modelPreferences.getBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION);
225
226
	    
227
	    if (fExtendedMarkupValidation != null) {
228
	    	fExtendedMarkupValidation.setSelection(useExtendedMarkupValidation);
229
	    }
230
	    int emptyElementTag = modelPreferences.getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE);
231
	    
232
	    if (fEmptyElementTag != null) {
233
	    	fEmptyElementTag.select(2 - emptyElementTag);
234
	    	fEmptyElementTag.setText(MARKUP_SEVERITIES[2 - emptyElementTag]);
235
		}
236
	    
237
	    int endTagWithAttributes  = modelPreferences.getInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES);
238
	    
239
	    if (fEndTagWithAttributes != null) {
240
	    	fEndTagWithAttributes.select(2 - endTagWithAttributes);
241
	    	fEndTagWithAttributes.setText(MARKUP_SEVERITIES[2 - endTagWithAttributes]);
242
		}
243
	    
244
	    int invalidWhitespaceBeforeTagname  = modelPreferences.getInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME);
245
	    
246
	    if (fInvalidWhitespaceBeforeTagname != null) {
247
	    	fInvalidWhitespaceBeforeTagname.select(2 - invalidWhitespaceBeforeTagname);
248
	    	fInvalidWhitespaceBeforeTagname.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceBeforeTagname]);
249
		}
250
	    
251
	    int missingClosingBracket  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET);
252
	    
253
	    if (fMissingClosingBracket != null) {
254
	    	fMissingClosingBracket.select(2 - missingClosingBracket);
255
	    	fMissingClosingBracket.setText(MARKUP_SEVERITIES[2 - missingClosingBracket]);
256
		}
257
	    
258
	    int missingClosingQuote  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE);
259
	    
260
	    if (fMissingClosingQuote != null) {
261
	    	fMissingClosingQuote.select(2 - missingClosingQuote);
262
	    	fMissingClosingQuote.setText(MARKUP_SEVERITIES[2 - missingClosingQuote]);
263
		}
264
	    
265
	    int missingEndTag  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_END_TAG);
266
	    
267
	    if (fMissingEndTag != null) {
268
	    	fMissingEndTag.select(2 - missingEndTag);
269
	    	fMissingEndTag.setText(MARKUP_SEVERITIES[2 - missingEndTag]);
270
		}
271
	    
272
	    int missingStartTag  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_START_TAG);
273
	    
274
	    if (fMissingStartTag != null) {
275
	    	fMissingStartTag.select(2 - missingStartTag);
276
	    	fMissingStartTag.setText(MARKUP_SEVERITIES[2 - missingStartTag]);
277
		}
278
	    
279
	    int missingQuotes  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_QUOTES);
280
	    
281
	    if (fMissingQuotes != null) {
282
	    	fMissingQuotes.select(2 - missingQuotes);
283
	    	fMissingQuotes.setText(MARKUP_SEVERITIES[2 - missingQuotes]);
284
		}
285
	    
286
	    int invalidNamespaceInPI  = modelPreferences.getInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET);
287
	    
288
	    if (fInvalidNamespaceInPI != null) {
289
	    	fInvalidNamespaceInPI.select(2 - invalidNamespaceInPI);
290
	    	fInvalidNamespaceInPI.setText(MARKUP_SEVERITIES[2 - invalidNamespaceInPI]);
291
		}
292
	    
293
	    int tagNameMissing  = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_TAG_NAME);
294
	    
295
	    if (fMissingTagName != null) {
296
	    	fMissingTagName.select(2 - tagNameMissing);
297
	    	fMissingTagName.setText(MARKUP_SEVERITIES[2 - tagNameMissing]);
298
		}
299
	    
300
	    int invalidWhitespaceAtStart  = modelPreferences.getInt(XMLCorePreferenceNames.WHITESPACE_AT_START);
301
	    
302
	    if (fInvalidWhitespaceAtStart != null) {
303
	    	fInvalidWhitespaceAtStart.select(2 - invalidWhitespaceAtStart);
304
	    	fInvalidWhitespaceAtStart.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceAtStart]);
305
		}
306
307
	    if (!useExtendedMarkupValidation)
308
	    	fMarkupState = ControlEnableState.disable(fMarkupValidationGroup);
309
  }
310
311
  protected void performDefaultsForValidatingGroup() {
312
    Preferences modelPreferences = getModelPreferences();
313
    int indicateNoGrammarButtonSelected = modelPreferences.getDefaultInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR);
314
    boolean useXIncludeButtonSelected = modelPreferences.getDefaultBoolean(XMLCorePreferenceNames.USE_XINCLUDE);
315
316
    if (fIndicateNoGrammar != null) {
317
      fIndicateNoGrammar.setSelection(new Point(indicateNoGrammarButtonSelected, 2 - indicateNoGrammarButtonSelected));
318
      fIndicateNoGrammar.setText(SEVERITIES[indicateNoGrammarButtonSelected]);
319
    }
320
    if (fUseXinclude != null) {
321
      fUseXinclude.setSelection(useXIncludeButtonSelected);
322
    }
323
324
    boolean honourAllButtonSelected = modelPreferences.getDefaultBoolean(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS);
325
    if (fHonourAllSchemaLocations != null) {
326
      fHonourAllSchemaLocations.setSelection(honourAllButtonSelected);
327
    }
328
  }
329
  
330
  protected void performDefaultsForMarkupValidationGroup() {
331
	  Preferences modelPreferences = getModelPreferences();
332
	    boolean useExtendedMarkupValidation = modelPreferences.getDefaultBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION);
333
334
	    
335
	    if (fExtendedMarkupValidation != null) {
336
	    	if (fExtendedMarkupValidation.getSelection() != useExtendedMarkupValidation) {
337
	    		handleMarkupSeveritySelection(useExtendedMarkupValidation);
338
	    	}
339
	    	fExtendedMarkupValidation.setSelection(useExtendedMarkupValidation);
340
	    	
341
	    }
342
	    int emptyElementTag = modelPreferences.getDefaultInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE);
343
	    
344
	    if (fEmptyElementTag != null) {
345
	    	fEmptyElementTag.setSelection(new Point(emptyElementTag,2 - emptyElementTag));
346
	    	fEmptyElementTag.setText(MARKUP_SEVERITIES[2 - emptyElementTag]);
347
		}
348
	    
349
	    int endTagWithAttributes  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES);
350
	    
351
	    if (fEndTagWithAttributes != null) {
352
	    	fEndTagWithAttributes.setSelection(new Point(endTagWithAttributes,2 - endTagWithAttributes));
353
	    	fEndTagWithAttributes.setText(MARKUP_SEVERITIES[2 - endTagWithAttributes]);
354
		}
355
	    
356
	    int invalidWhitespaceBeforeTagname  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME);
357
	    
358
	    if (fInvalidWhitespaceBeforeTagname != null) {
359
	    	fInvalidWhitespaceBeforeTagname.setSelection(new Point(invalidWhitespaceBeforeTagname,2 - invalidWhitespaceBeforeTagname));
360
	    	fInvalidWhitespaceBeforeTagname.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceBeforeTagname]);
361
		}
362
	    
363
	    int missingClosingBracket  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET);
364
	    
365
	    if (fMissingClosingBracket != null) {
366
	    	fMissingClosingBracket.setSelection(new Point(missingClosingBracket,2 - missingClosingBracket));
367
	    	fMissingClosingBracket.setText(MARKUP_SEVERITIES[2 - missingClosingBracket]);
368
		}
369
	    
370
	    int missingClosingQuote  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE);
371
	    
372
	    if (fMissingClosingQuote != null) {
373
	    	fMissingClosingQuote.setSelection(new Point(missingClosingQuote,2 - missingClosingQuote));
374
	    	fMissingClosingQuote.setText(MARKUP_SEVERITIES[2 - missingClosingQuote]);
375
		}
376
	    
377
	    int missingEndTag  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_END_TAG);
378
	    
379
	    if (fMissingEndTag != null) {
380
	    	fMissingEndTag.setSelection(new Point(missingEndTag,2 - missingEndTag));
381
	    	fMissingEndTag.setText(MARKUP_SEVERITIES[2 - missingEndTag]);
382
		}
383
	    
384
	    int missingStartTag  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_START_TAG);
385
	    
386
	    if (fMissingStartTag != null) {
387
	    	fMissingStartTag.setSelection(new Point(missingStartTag,2 - missingStartTag));
388
	    	fMissingStartTag.setText(MARKUP_SEVERITIES[2 - missingStartTag]);
389
		}
390
	    
391
	    int missingQuotes  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_QUOTES);
392
	    
393
	    if (fMissingQuotes != null) {
394
	    	fMissingQuotes.setSelection(new Point(missingQuotes,2 - missingQuotes));
395
	    	fMissingQuotes.setText(MARKUP_SEVERITIES[2 - missingQuotes]);
396
		}
397
	    
398
	    int invalidNamespaceInPI  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET);
399
	    
400
	    if (fInvalidNamespaceInPI != null) {
401
	    	fInvalidNamespaceInPI.setSelection(new Point(invalidNamespaceInPI,2 - invalidNamespaceInPI));
402
	    	fInvalidNamespaceInPI.setText(MARKUP_SEVERITIES[2 - invalidNamespaceInPI]);
403
		}
404
	    
405
	    int tagNameMissing  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_TAG_NAME);
406
	    
407
	    if (fMissingTagName != null) {
408
	    	fMissingTagName.setSelection(new Point(tagNameMissing,2 - tagNameMissing));
409
	    	fMissingTagName.setText(MARKUP_SEVERITIES[2 - tagNameMissing]);
410
		}
411
	    
412
	    int invalidWhitespaceAtStart  = modelPreferences.getDefaultInt(XMLCorePreferenceNames.WHITESPACE_AT_START);
413
	    
414
	    if (fInvalidWhitespaceAtStart != null) {
415
	    	fInvalidWhitespaceAtStart.setSelection(new Point(invalidWhitespaceAtStart,2 - invalidWhitespaceAtStart));
416
	    	fInvalidWhitespaceAtStart.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceAtStart]);
417
		}
418
	  }
419
420
  protected void storeValuesForValidatingGroup()
421
  {
422
    Preferences modelPreferences = getModelPreferences();
423
    if (fIndicateNoGrammar != null) {
424
      int warnNoGrammarButtonSelected = 2 - fIndicateNoGrammar.getSelectionIndex();
425
      modelPreferences.setValue(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR, warnNoGrammarButtonSelected);
426
    }
427
    if (fUseXinclude != null) {
428
      boolean useXIncludeButtonSelected = fUseXinclude.getSelection();
429
      modelPreferences.setValue(XMLCorePreferenceNames.USE_XINCLUDE, useXIncludeButtonSelected);
430
    }
431
    if (fHonourAllSchemaLocations != null) {
432
      boolean honourAllButtonSelected = fHonourAllSchemaLocations.getSelection();
433
      modelPreferences.setValue(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, honourAllButtonSelected);
434
    }
435
  }
436
  protected void storeValuesForMarkupValidationGroup()
437
  {
438
    Preferences modelPreferences = getModelPreferences();
439
    if (fExtendedMarkupValidation != null) {
440
        boolean extendedMarkupValidation = fExtendedMarkupValidation.getSelection();
441
        modelPreferences.setValue(XMLCorePreferenceNames.MARKUP_VALIDATION, extendedMarkupValidation);
442
    }
443
    if (fEmptyElementTag != null) {
444
      int emptyElementTag = 2 - fEmptyElementTag.getSelectionIndex();
445
      modelPreferences.setValue(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE, emptyElementTag);
446
    }
447
    if (fEndTagWithAttributes != null) {
448
        int endTagWithAttributes = 2 - fEndTagWithAttributes.getSelectionIndex();
449
        modelPreferences.setValue(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES, endTagWithAttributes);
450
    }
451
    if (fInvalidWhitespaceBeforeTagname != null) {
452
        int invalidWhitespaceBeforeTagname = 2 - fInvalidWhitespaceBeforeTagname.getSelectionIndex();
453
        modelPreferences.setValue(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME, invalidWhitespaceBeforeTagname);
454
    }
455
    if (fMissingClosingBracket != null) {
456
          int missingClosingBracket = 2 - fMissingClosingBracket.getSelectionIndex();
457
          modelPreferences.setValue(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, missingClosingBracket);
458
    }
459
    if (fMissingClosingQuote != null) {
460
        int missingClosingQuote = 2 - fMissingClosingQuote.getSelectionIndex();
461
        modelPreferences.setValue(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, missingClosingQuote);
462
    }
463
    if (fMissingEndTag != null) {
464
        int missingEndTag = 2 - fMissingEndTag.getSelectionIndex();
465
        modelPreferences.setValue(XMLCorePreferenceNames.MISSING_END_TAG, missingEndTag);
466
        modelPreferences.getInt(XMLCorePreferenceNames.MISSING_END_TAG);
467
    }
468
	if (fMissingStartTag != null) {
469
        int missingStartTag = 2 - fMissingStartTag.getSelectionIndex();
470
	    modelPreferences.setValue(XMLCorePreferenceNames.MISSING_START_TAG, missingStartTag);
471
	}
472
	if (fMissingQuotes != null) {
473
        int missingQuotes = 2 - fMissingQuotes.getSelectionIndex();
474
	    modelPreferences.setValue(XMLCorePreferenceNames.MISSING_QUOTES, missingQuotes);
475
	}
476
	if (fInvalidNamespaceInPI != null) {
477
        int invalidNamespaceInPI = 2 - fInvalidNamespaceInPI.getSelectionIndex();
478
	    modelPreferences.setValue(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET, invalidNamespaceInPI);
479
	}
480
	if (fMissingTagName != null) {
481
        int missingTagName = 2 - fMissingTagName.getSelectionIndex();
482
	    modelPreferences.setValue(XMLCorePreferenceNames.MISSING_TAG_NAME, missingTagName);
483
	}
484
	if (fInvalidWhitespaceAtStart != null) {
485
        int invalidWhitespaceAtStart = 2 - fInvalidWhitespaceAtStart.getSelectionIndex();
486
	    modelPreferences.setValue(XMLCorePreferenceNames.WHITESPACE_AT_START, invalidWhitespaceAtStart);
487
	}
488
    
489
    
490
  }
491
  
492
  protected void storeValues() {
493
    storeValuesForValidatingGroup();
494
    storeValuesForMarkupValidationGroup();
495
  }
496
497
  protected void performDefaults() {
498
    performDefaultsForValidatingGroup();
499
    performDefaultsForMarkupValidationGroup();
500
    super.performDefaults();
501
  }
502
  
503
  protected Preferences getModelPreferences() {
504
    return XMLCorePlugin.getDefault().getPluginPreferences();
505
  }  
506
  
507
  protected void doSavePreferenceStore() {
508
      XMLCorePlugin.getDefault().savePluginPreferences(); // model
509
  }
510
319
511
  public boolean performOk() {
320
	protected void storeValues() {
512
    boolean result = super.performOk();
321
		super.storeValues();
322
		IScopeContext[] contexts = createPreferenceScopes();
323
		
324
		storeValuesForValidatingGroup(contexts);
325
		storeValuesForMarkupValidationGroup(contexts);
326
	}
327
	protected Control createCommonContents(Composite parent) {
328
		final Composite page = new Composite(parent, SWT.NULL);
513
329
514
    doSavePreferenceStore();
330
		GridLayout layout = new GridLayout();
331
		layout.numColumns = 2;
332
		page.setLayout(layout);
333
334
		Group validatingGroup = new Group(page, SWT.NONE);
335
		validatingGroup.setLayoutData(GridDataFactory.fillDefaults()
336
				.grab(true, false).create());
337
		validatingGroup.setLayout(new GridLayout(1, false));
338
		validatingGroup.setText(XMLUIMessages.Validating_files);
339
		createContentsForValidatingGroup(validatingGroup);
340
		
341
342
		createContentsForMarkupValidationGroup(page);
343
	
344
		return page;
345
	}
346
347
	protected Composite createComposite(Composite parent, int numColumns) {
348
		Composite composite = new Composite(parent, SWT.NULL);
349
350
		// GridLayout
351
		GridLayout layout = new GridLayout();
352
		layout.numColumns = numColumns;
353
		composite.setLayout(layout);
354
355
		// GridData
356
		GridData data = new GridData(GridData.FILL);
357
		data.horizontalIndent = 0;
358
		data.verticalAlignment = GridData.FILL;
359
		data.horizontalAlignment = GridData.FILL;
360
		composite.setLayoutData(data);
361
362
		return composite;
363
	}
364
365
	protected Composite createScrolledComposite(Composite parent) {
366
		// create scrollbars for this parent when needed
367
		final ScrolledComposite sc1 = new ScrolledComposite(parent,
368
				SWT.H_SCROLL | SWT.V_SCROLL);
369
		sc1.setLayoutData(new GridData(GridData.FILL_BOTH));
370
		Composite composite = createComposite(sc1, 1);
371
		sc1.setContent(composite);
372
373
		// not calling setSize for composite will result in a blank composite,
374
		// so calling it here initially
375
		// setSize actually needs to be called after all controls are created,
376
		// so scrolledComposite
377
		// has correct minSize
378
		setSize(composite);
379
		return composite;
380
	}
381
382
	protected void setSize(Composite composite) {
383
		if (composite != null) {
384
			// Note: The font is set here in anticipation that the class
385
			// inheriting
386
			// this base class may add widgets to the dialog. setSize
387
			// is assumed to be called just before we go live.
388
			applyDialogFont(composite);
389
			Point minSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
390
			composite.setSize(minSize);
391
			// set scrollbar composite's min size so page is expandable but
392
			// has scrollbars when needed
393
			if (composite.getParent() instanceof ScrolledComposite) {
394
				ScrolledComposite sc1 = (ScrolledComposite) composite
395
						.getParent();
396
				sc1.setMinSize(minSize);
397
				sc1.setExpandHorizontal(true);
398
				sc1.setExpandVertical(true);
399
			}
400
		}
401
	}
402
403
	protected String getPreferenceNodeQualifier() {
404
		return XMLCorePlugin.getDefault().getBundle().getSymbolicName();
405
	}
515
406
516
    return result;
407
	protected String getPreferencePageID() {
517
  }
408
		return "org.eclipse.wst.sse.ui.preferences.xml.validation";//$NON-NLS-1$
409
	}
410
411
	protected String getProjectSettingsKey() {
412
		return XMLCorePreferenceNames.USE_PROJECT_SETTINGS;
413
	}
414
415
	protected String getPropertyPageID() {
416
		return "org.eclipse.wst.xml.ui.propertyPage.project.validation";//$NON-NLS-1$
417
	}
418
419
	public void init(IWorkbench workbench) {
420
	}
421
422
	private Group createGroup(Composite parent, int numColumns) {
423
424
		Group group = new Group(parent, SWT.NULL);
425
426
		// GridLayout
427
		GridLayout layout = new GridLayout();
428
		layout.numColumns = numColumns;
429
		group.setLayout(layout);
430
431
		// GridData
432
		GridData data = new GridData(GridData.FILL);
433
		data.horizontalIndent = 0;
434
		data.verticalAlignment = GridData.FILL;
435
		data.horizontalAlignment = GridData.FILL;
436
		data.grabExcessHorizontalSpace = true;
437
		group.setLayoutData(data);
438
439
		return group;
440
	}
441
442
	
443
444
	private Button createCheckBox(Composite group, String label) {
445
		Button button = new Button(group, SWT.CHECK | SWT.LEFT);
446
		button.setText(label);
447
448
		// button.setLayoutData(GridDataFactory.fillDefaults().create());
449
450
		// GridData
451
		GridData data = new GridData(GridData.FILL);
452
		data.verticalAlignment = GridData.CENTER;
453
		data.horizontalAlignment = GridData.FILL;
454
		button.setLayoutData(data);
455
456
		return button;
457
	}
458
	
459
	public void dispose() {
460
		storeSectionExpansionStates(getDialogSettings().addNewSection(SETTINGS_SECTION_NAME));
461
		super.dispose();
462
	}
463
464
	protected IDialogSettings getDialogSettings() {
465
		return XMLUIPlugin.getDefault().getDialogSettings();
466
	}
467
	
468
	protected boolean shouldRevalidateOnSettingsChange() {
469
		return fOriginalUseExtendedMarkupValidation != fExtendedMarkupValidation.getSelection() ||
470
		fOriginalUseXIncludeButtonSelected != fUseXinclude.getSelection() ||
471
		fOriginalUseHonourAllButtonSelected != fHonourAllSchemaLocations.getSelection() ||
472
		super.shouldRevalidateOnSettingsChange();
473
	}
518
}
474
}

Return to bug 254647