Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 132228 | Differences between
and this patch

Collapse All | Expand All

(-)validateui/org/eclipse/wst/validation/internal/ui/ValidationPreferencePage.java (-9 / +67 lines)
Lines 12-18 Link Here
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.HashMap;
15
import java.util.List;
16
import java.util.List;
17
import java.util.Map;
16
import java.util.logging.Level;
18
import java.util.logging.Level;
17
19
18
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
Lines 30-35 Link Here
30
import org.eclipse.jface.viewers.TableViewer;
32
import org.eclipse.jface.viewers.TableViewer;
31
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.jface.viewers.Viewer;
32
import org.eclipse.jface.viewers.ViewerSorter;
34
import org.eclipse.jface.viewers.ViewerSorter;
35
import org.eclipse.jface.window.Window;
33
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.ScrolledComposite;
37
import org.eclipse.swt.custom.ScrolledComposite;
35
import org.eclipse.swt.events.MouseAdapter;
38
import org.eclipse.swt.events.MouseAdapter;
Lines 44-51 Link Here
44
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Button;
45
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Composite;
46
import org.eclipse.swt.widgets.Control;
49
import org.eclipse.swt.widgets.Control;
50
import org.eclipse.swt.widgets.Display;
47
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.Label;
48
import org.eclipse.swt.widgets.MessageBox;
52
import org.eclipse.swt.widgets.MessageBox;
53
import org.eclipse.swt.widgets.Shell;
49
import org.eclipse.swt.widgets.Table;
54
import org.eclipse.swt.widgets.Table;
50
import org.eclipse.swt.widgets.TableColumn;
55
import org.eclipse.swt.widgets.TableColumn;
51
import org.eclipse.swt.widgets.TableItem;
56
import org.eclipse.swt.widgets.TableItem;
Lines 250-255 Link Here
250
	// order to access this field)
255
	// order to access this field)
251
	//private boolean _isAutoBuildEnabled; // initialized in the constructor
256
	//private boolean _isAutoBuildEnabled; // initialized in the constructor
252
	private ValidatorMetaData[] _oldVmd = null; // Cache the enabled validators so that, if
257
	private ValidatorMetaData[] _oldVmd = null; // Cache the enabled validators so that, if
258
  private Map _oldDelegates = null; // Cache the validator delegates.
253
	// there is no change to this list, the
259
	// there is no change to this list, the
254
	// expensive task list update can be avoided
260
	// expensive task list update can be avoided
255
	private boolean _allow = false; // Cache the value of the prefence "allow projects to
261
	private boolean _allow = false; // Cache the value of the prefence "allow projects to
Lines 336-351 Link Here
336
			}
342
			}
337
		}
343
		}
338
344
345
    private Image getImage(String imageName) {
346
      boolean isDisabled = !validatorsTable.isEnabled();
347
      if (isDisabled) {
348
          imageName = imageName + "_disabled";  //$NON-NLS-N$
349
      }
350
      Image image = ValidationUIPlugin.getPlugin().getImage(imageName);
351
      return image;
352
    }
353
    
339
		public Image getColumnImage(Object element, int columnIndex) {
354
		public Image getColumnImage(Object element, int columnIndex) {
340
			if(columnIndex == 1) {
355
			if(columnIndex == 1) {
341
				if(((ValidatorMetaData)element).isManualValidation())
356
				if(((ValidatorMetaData)element).isManualValidation())
342
					return  ValidationUIPlugin.getPlugin().getImage("ok_tbl");
357
					return  getImage("ok_tbl");
343
				return ValidationUIPlugin.getPlugin().getImage("fail_tbl");
358
				return getImage("fail_tbl");
344
			} else if(columnIndex == 2) {
359
			} 
360
      else if(columnIndex == 2) {
345
				if(((ValidatorMetaData)element).isBuildValidation())
361
				if(((ValidatorMetaData)element).isBuildValidation())
346
					return ValidationUIPlugin.getPlugin().getImage("ok_tbl");;
362
					return getImage("ok_tbl");;
347
				return ValidationUIPlugin.getPlugin().getImage("fail_tbl");
363
				return getImage("fail_tbl");
348
			}
364
			}
365
      else if (columnIndex == 3)
366
      {
367
        ValidatorMetaData vmd = (ValidatorMetaData)element;
368
369
        if (vmd.isDelegating())
370
        {
371
          return getImage("settings");          
372
        }
373
      }
349
			return null;
374
			return null;
350
		
375
		
351
		}
376
		}
Lines 409-415 Link Here
409
		// that, if there is no change to this
434
		// that, if there is no change to this
410
		// list, the expensive task list
435
		// list, the expensive task list
411
		// update can be avoided
436
		// update can be avoided
412
		_allow = pagePreferences.canProjectsOverride();
437
438
    _oldDelegates =  new HashMap(pagePreferences.getDelegatingValidators());
439
		
440
    _allow = pagePreferences.canProjectsOverride();
413
441
414
		page = createPage(parent);
442
		page = createPage(parent);
415
	}
443
	}
Lines 427-432 Link Here
427
        buildColumn.setText("Build");
455
        buildColumn.setText("Build");
428
        buildColumn.setResizable(false);
456
        buildColumn.setResizable(false);
429
        buildColumn.setWidth(30);
457
        buildColumn.setWidth(30);
458
        TableColumn settingsColumn = new TableColumn(table, SWT.NONE);
459
        settingsColumn.setText("Settings");
460
        settingsColumn.setResizable(false);
461
        settingsColumn.setWidth(40);
430
    }
462
    }
431
	
463
	
432
	public Composite createPage(Composite parent) throws InvocationTargetException {
464
	public Composite createPage(Composite parent) throws InvocationTargetException {
Lines 484-489 Link Here
484
				validatorsTable.setEnabled(!disableAllValidation.getSelection());
516
				validatorsTable.setEnabled(!disableAllValidation.getSelection());
485
				enableAllButton.setEnabled(!disableAllValidation.getSelection());
517
				enableAllButton.setEnabled(!disableAllValidation.getSelection());
486
				disableAllButton.setEnabled(!disableAllValidation.getSelection());
518
				disableAllButton.setEnabled(!disableAllValidation.getSelection());
519
        validatorList.refresh();
487
			}
520
			}
488
		});
521
		});
489
		
522
		
Lines 499-506 Link Here
499
		validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
532
		validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
500
		TableLayout tableLayout = new TableLayout();
533
		TableLayout tableLayout = new TableLayout();
501
		tableLayout.addColumnData(new ColumnWeightData(160, true));
534
		tableLayout.addColumnData(new ColumnWeightData(160, true));
502
        tableLayout.addColumnData(new ColumnWeightData(40, true));
535
    tableLayout.addColumnData(new ColumnWeightData(40, true));
503
        tableLayout.addColumnData(new ColumnWeightData(30, true));
536
    tableLayout.addColumnData(new ColumnWeightData(30, true));
537
    tableLayout.addColumnData(new ColumnWeightData(40, true));
538
    
504
		validatorsTable.setHeaderVisible(true);
539
		validatorsTable.setHeaderVisible(true);
505
		validatorsTable.setLinesVisible(true);
540
		validatorsTable.setLinesVisible(true);
506
        validatorsTable.setLayout(tableLayout);
541
        validatorsTable.setLayout(tableLayout);
Lines 613-618 Link Here
613
    case 2:
648
    case 2:
614
      vmd.setBuildValidation(!vmd.isBuildValidation());
649
      vmd.setBuildValidation(!vmd.isBuildValidation());
615
      break;
650
      break;
651
    case 3:
652
      {
653
        if (!vmd.isDelegating()) {
654
          break;
655
        }
656
          
657
        String delegateID = pagePreferences.getDelegateUniqueName(vmd);
658
  
659
        Shell shell = Display.getCurrent().getActiveShell();
660
        DelegatingValidatorPreferencesDialog dialog = new DelegatingValidatorPreferencesDialog(shell, vmd, delegateID);
661
  
662
        dialog.setBlockOnOpen(true);
663
        dialog.create();
664
  
665
        int result = dialog.open();
666
  
667
        if (result == Window.OK)
668
        {
669
          pagePreferences.setDelegateUniqueName(vmd, dialog.getDelegateID());
670
        }
671
      }
672
      break;
616
    default:
673
    default:
617
      break;
674
      break;
618
    }
675
    }
Lines 840-846 Link Here
840
			try {
897
			try {
841
				if (project.isOpen()) {
898
				if (project.isOpen()) {
842
					ProjectConfiguration prjp = ConfigurationManager.getManager().getProjectConfiguration(project);
899
					ProjectConfiguration prjp = ConfigurationManager.getManager().getProjectConfiguration(project);
843
					if (!prjp.doesProjectOverride() && (prjp.hasEnabledValidatorsChanged(_oldVmd, allowChanged) || true)) {
900
					if (!prjp.doesProjectOverride() && (prjp.hasEnabledValidatorsChanged(_oldVmd, allowChanged) || true) && 
901
              (prjp.haveDelegatesChanged(_oldDelegates, allowChanged) || true)) {
844
						// If the project used to override the preferences, and the preferences
902
						// If the project used to override the preferences, and the preferences
845
						// make that impossible now, then update the task list.
903
						// make that impossible now, then update the task list.
846
						//
904
						//
(-)validateui/org/eclipse/wst/validation/internal/ui/ValidationPropertiesPage.java (-12 / +74 lines)
Lines 13-19 Link Here
13
13
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.HashMap;
16
import java.util.List;
17
import java.util.List;
18
import java.util.Map;
17
import java.util.logging.Level;
19
import java.util.logging.Level;
18
20
19
import javax.swing.event.HyperlinkEvent;
21
import javax.swing.event.HyperlinkEvent;
Lines 30-35 Link Here
30
import org.eclipse.jface.viewers.TableViewer;
32
import org.eclipse.jface.viewers.TableViewer;
31
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.jface.viewers.Viewer;
32
import org.eclipse.jface.viewers.ViewerSorter;
34
import org.eclipse.jface.viewers.ViewerSorter;
35
import org.eclipse.jface.window.Window;
33
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.ScrolledComposite;
37
import org.eclipse.swt.custom.ScrolledComposite;
35
import org.eclipse.swt.events.MouseAdapter;
38
import org.eclipse.swt.events.MouseAdapter;
Lines 46-53 Link Here
46
import org.eclipse.swt.widgets.Button;
49
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Composite;
50
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Control;
51
import org.eclipse.swt.widgets.Control;
52
import org.eclipse.swt.widgets.Display;
49
import org.eclipse.swt.widgets.Label;
53
import org.eclipse.swt.widgets.Label;
50
import org.eclipse.swt.widgets.MessageBox;
54
import org.eclipse.swt.widgets.MessageBox;
55
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Table;
56
import org.eclipse.swt.widgets.Table;
52
import org.eclipse.swt.widgets.TableColumn;
57
import org.eclipse.swt.widgets.TableColumn;
53
import org.eclipse.swt.widgets.TableItem;
58
import org.eclipse.swt.widgets.TableItem;
Lines 61-67 Link Here
61
import org.eclipse.wst.validation.internal.GlobalConfiguration;
66
import org.eclipse.wst.validation.internal.GlobalConfiguration;
62
import org.eclipse.wst.validation.internal.ProjectConfiguration;
67
import org.eclipse.wst.validation.internal.ProjectConfiguration;
63
import org.eclipse.wst.validation.internal.ValidatorMetaData;
68
import org.eclipse.wst.validation.internal.ValidatorMetaData;
69
import org.eclipse.wst.validation.internal.delegates.IDelegatingValidator;
64
import org.eclipse.wst.validation.internal.operations.ValidatorManager;
70
import org.eclipse.wst.validation.internal.operations.ValidatorManager;
71
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
65
import org.eclipse.wst.validation.internal.ui.plugin.ValidationUIPlugin;
72
import org.eclipse.wst.validation.internal.ui.plugin.ValidationUIPlugin;
66
73
67
/**
74
/**
Lines 241-246 Link Here
241
		private boolean canOverride = false;
248
		private boolean canOverride = false;
242
249
243
		private ValidatorMetaData[] oldVmd = null; // Cache the enabled validators so that, if there
250
		private ValidatorMetaData[] oldVmd = null; // Cache the enabled validators so that, if there
251
    private Map oldDelegates = null; // Cache the validator delegates.
244
252
245
		// is no change to this list, the expensive task
253
		// is no change to this list, the expensive task
246
		// list update can be avoided
254
		// list update can be avoided
Lines 340-357 Link Here
340
				return null;
348
				return null;
341
			}
349
			}
342
350
343
			public Image getColumnImage(Object element, int columnIndex) {
351
      private Image getImage(String imageName) {
352
        boolean isDisabled = !validatorsTable.isEnabled();
353
        if (isDisabled) {
354
            imageName = imageName + "_disabled";  //$NON-NLS-N$
355
        }
356
        Image image = ValidationUIPlugin.getPlugin().getImage(imageName);
357
        return image;
358
      }
359
      
360
361
      public Image getColumnImage(Object element, int columnIndex) {
344
				if(columnIndex == 1) {
362
				if(columnIndex == 1) {
345
					if(((ValidatorMetaData)element).isManualValidation())
363
					if(((ValidatorMetaData)element).isManualValidation())
346
						return  ValidationUIPlugin.getPlugin().getImage("ok_tbl");
364
						return  getImage("ok_tbl");
347
					return ValidationUIPlugin.getPlugin().getImage("fail_tbl");
365
					return getImage("fail_tbl");
348
				} else if(columnIndex == 2) {
366
				} else if(columnIndex == 2) {
349
					if(((ValidatorMetaData)element).isBuildValidation())
367
					if(((ValidatorMetaData)element).isBuildValidation())
350
						return ValidationUIPlugin.getPlugin().getImage("ok_tbl");;
368
						return getImage("ok_tbl");;
351
					return ValidationUIPlugin.getPlugin().getImage("fail_tbl");
369
					return getImage("fail_tbl");
352
				}
370
				}
371
        else if (columnIndex == 3)
372
        {
373
          ValidatorMetaData vmd = (ValidatorMetaData)element;
374
375
          if (vmd.isDelegating())
376
          {
377
            return getImage("settings");          
378
          }
379
        }
353
				return null;
380
				return null;
354
			
355
			}
381
			}
356
		}
382
		}
357
383
Lines 401-409 Link Here
401
			//isAutoBuildEnabled = vMgr.isGlobalAutoBuildEnabled();
427
			//isAutoBuildEnabled = vMgr.isGlobalAutoBuildEnabled();
402
			//isBuilderConfigured = ValidatorManager.doesProjectSupportBuildValidation(getProject());
428
			//isBuilderConfigured = ValidatorManager.doesProjectSupportBuildValidation(getProject());
403
			oldVmd = pagePreferences.getEnabledValidators(); // Cache the enabled validators so
429
			oldVmd = pagePreferences.getEnabledValidators(); // Cache the enabled validators so
404
			// that, if there is no change to this
430
      // that, if there is no change to this
405
			// list, the expensive task list update
431
      // list, the expensive task list update
406
			// can be avoided
432
      // can be avoided
433
434
      oldDelegates =  new HashMap(pagePreferences.getDelegatingValidators());
407
435
408
			createPage(parent);
436
			createPage(parent);
409
		}
437
		}
Lines 421-426 Link Here
421
	        buildColumn.setText("Build");
449
	        buildColumn.setText("Build");
422
	        buildColumn.setResizable(false);
450
	        buildColumn.setResizable(false);
423
	        buildColumn.setWidth(30);
451
	        buildColumn.setWidth(30);
452
          TableColumn settingsColumn = new TableColumn(table, SWT.NONE);
453
          settingsColumn.setText("Settings");
454
          settingsColumn.setResizable(false);
455
          settingsColumn.setWidth(40);
424
	    }
456
	    }
425
457
426
		/**
458
		/**
Lines 506-511 Link Here
506
					validatorsTable.setEnabled(!disableAllValidation.getSelection());
538
					validatorsTable.setEnabled(!disableAllValidation.getSelection());
507
					enableAllButton.setEnabled(!disableAllValidation.getSelection());
539
					enableAllButton.setEnabled(!disableAllValidation.getSelection());
508
					disableAllButton.setEnabled(!disableAllValidation.getSelection());
540
					disableAllButton.setEnabled(!disableAllValidation.getSelection());
541
          try {
542
            updateWidgets();
543
          } catch (InvocationTargetException exc) {
544
            displayAndLogError(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_INTERNAL_TITLE), ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_INTERNAL_PAGE), exc);
545
          }
509
				}
546
				}
510
			});
547
			});
511
			
548
			
Lines 523-530 Link Here
523
			validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
560
			validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
524
			TableLayout tableLayout = new TableLayout();
561
			TableLayout tableLayout = new TableLayout();
525
			tableLayout.addColumnData(new ColumnWeightData(160, true));
562
			tableLayout.addColumnData(new ColumnWeightData(160, true));
526
	        tableLayout.addColumnData(new ColumnWeightData(40, true));
563
	    tableLayout.addColumnData(new ColumnWeightData(40, true));
527
	        tableLayout.addColumnData(new ColumnWeightData(30, true));
564
	    tableLayout.addColumnData(new ColumnWeightData(30, true));
565
      tableLayout.addColumnData(new ColumnWeightData(40, true));
528
			validatorsTable.setHeaderVisible(true);
566
			validatorsTable.setHeaderVisible(true);
529
			validatorsTable.setLinesVisible(true);
567
			validatorsTable.setLinesVisible(true);
530
	        validatorsTable.setLayout(tableLayout);
568
	        validatorsTable.setLayout(tableLayout);
Lines 756-761 Link Here
756
      case 2:
794
      case 2:
757
        vmd.setBuildValidation(!vmd.isBuildValidation());
795
        vmd.setBuildValidation(!vmd.isBuildValidation());
758
        break;
796
        break;
797
      case 3:
798
      {
799
        if (!vmd.isDelegating()) {
800
          break;
801
        }
802
        
803
        String delegateID = pagePreferences.getDelegateUniqueName(vmd);
804
  
805
        Shell shell = Display.getCurrent().getActiveShell();
806
        DelegatingValidatorPreferencesDialog dialog = new DelegatingValidatorPreferencesDialog(shell, vmd, delegateID);
807
  
808
        dialog.setBlockOnOpen(true);
809
        dialog.create();
810
  
811
        int result = dialog.open();
812
  
813
        if (result == Window.OK)
814
        {
815
          pagePreferences.setDelegateUniqueName(vmd, dialog.getDelegateID());
816
        }
817
      }
759
      default:
818
      default:
760
        break;
819
        break;
761
      }
820
      }
Lines 816-823 Link Here
816
		 */
875
		 */
817
		private void enableDependentControls(boolean overridePreferences) {
876
		private void enableDependentControls(boolean overridePreferences) {
818
			validatorsTable.setEnabled(overridePreferences);
877
			validatorsTable.setEnabled(overridePreferences);
878
      validatorList.refresh();
819
			enableAllButton.setEnabled(overridePreferences); // since help messsage isn't
879
			enableAllButton.setEnabled(overridePreferences); // since help messsage isn't
820
			disableAllButton.setEnabled(overridePreferences);
880
			disableAllButton.setEnabled(overridePreferences);
881
      
821
		}
882
		}
822
883
823
		protected void updateHelp() throws InvocationTargetException {
884
		protected void updateHelp() throws InvocationTargetException {
Lines 939-945 Link Here
939
			// Persist the values.
1000
			// Persist the values.
940
			storeValues();
1001
			storeValues();
941
1002
942
			if (pagePreferences.hasEnabledValidatorsChanged(oldVmd, false)) { 
1003
			if (pagePreferences.hasEnabledValidatorsChanged(oldVmd, false) ||
1004
          pagePreferences.haveDelegatesChanged(oldDelegates, false)) { 
943
				// false means that the preference "allow" value hasn't changed
1005
				// false means that the preference "allow" value hasn't changed
944
				ValidatorManager.getManager().updateTaskList(getProject()); 
1006
				ValidatorManager.getManager().updateTaskList(getProject()); 
945
			}
1007
			}
(-)validateui/org/eclipse/wst/validation/internal/ui/ResourceConstants.java (-1 / +4 lines)
Lines 89-92 Link Here
89
	
89
	
90
	/* package */static final String DISABLE_VALIDATION = "DISABLE_VALIDATION"; //$NON-NLS-1$
90
	/* package */static final String DISABLE_VALIDATION = "DISABLE_VALIDATION"; //$NON-NLS-1$
91
	static final String INFO = "INFO"; //$NON-NLS-1$
91
	static final String INFO = "INFO"; //$NON-NLS-1$
92
}
92
  
93
  String DELEGATES_DIALOG_TITLE = "DELEGATES_DIALOG_TITLE"; //$NON-NLS-1$
94
  String DELEGATES_COMBO_LABEL = "DELEGATES_COMBO_LABEL"; //$NON-NLS-1$
95
 }
(-)property_files/validate_ui.properties (+3 lines)
Lines 110-115 Link Here
110
DISABLE_VALIDATION=Suspend all validators
110
DISABLE_VALIDATION=Suspend all validators
111
INFO=This preference applies to the projects that have org.eclipse.wst.validation.validationbuilder defined.Validators are run on the projects based on the filters defined in the org.eclipse.wst.validation.validator extension point.
111
INFO=This preference applies to the projects that have org.eclipse.wst.validation.validationbuilder defined.Validators are run on the projects based on the filters defined in the org.eclipse.wst.validation.validator extension point.
112
112
113
DELEGATES_DIALOG_TITLE=Validator Preferences
114
DELEGATES_COMBO_LABEL=Implementation:
115
113
#
116
#
114
# End Validation Builder Framework UI Strings
117
# End Validation Builder Framework UI Strings
115
#
118
#
(-)validateui/org/eclipse/wst/validation/internal/ui/DelegatingValidatorPreferencesDialog.java (+267 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.ui;
13
14
import java.util.Map;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.resource.JFaceResources;
18
import org.eclipse.jface.viewers.ComboViewer;
19
import org.eclipse.jface.viewers.ILabelProvider;
20
import org.eclipse.jface.viewers.ILabelProviderListener;
21
import org.eclipse.jface.viewers.ISelectionChangedListener;
22
import org.eclipse.jface.viewers.IStructuredContentProvider;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.Shell;
35
import org.eclipse.wst.validation.internal.ValidatorMetaData;
36
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegateDescriptor;
37
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegatesRegistry;
38
39
/**
40
 * Dialog used to allow the user to select a validator delegate from the list of
41
 * registered delegates for a given delegating validator.
42
 */
43
public class DelegatingValidatorPreferencesDialog extends Dialog
44
{
45
  /**
46
   * The delegating validator's descriptor.
47
   */
48
  private ValidatorMetaData delegatingValidatorDescriptor;
49
50
  /**
51
   * The selected validator delegate ID.
52
   */
53
  private String delegateID;
54
55
  /**
56
   * Constructs the dialog on the given shell.
57
   * 
58
   * @param parentShell
59
   *          the dialog's parent. Must not be null.
60
   * @param targetID
61
   *          the delegating validator's id
62
   * 
63
   * @param delegateID
64
   *          the ID of the currently selected validator delegate.
65
   */
66
  protected DelegatingValidatorPreferencesDialog(Shell parentShell, ValidatorMetaData vmd, String delegateID)
67
  {
68
    super(parentShell);
69
70
    delegatingValidatorDescriptor = vmd;
71
    this.delegateID = delegateID;
72
  }
73
74
  /*
75
   * (non-Javadoc)
76
   * 
77
   * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
78
   */
79
  protected Control createDialogArea(Composite parent)
80
  {
81
    super.createDialogArea(parent);
82
83
    getShell().setText(ResourceHandler.getExternalizedMessage(ResourceConstants.DELEGATES_DIALOG_TITLE));
84
85
    GridLayout layout = new GridLayout();
86
    parent.setLayout(layout);
87
88
    Label label = new Label(parent, SWT.NONE);
89
    GridData labelData = new GridData(SWT.FILL, SWT.CENTER, true, false);
90
    labelData.widthHint = 250;
91
    label.setLayoutData(labelData);
92
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
93
    String delegatingValidatorName = delegatingValidatorDescriptor.getValidatorDisplayName();
94
    label.setText(delegatingValidatorName);
95
96
    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
97
    GridData separatorData = new GridData(SWT.FILL, SWT.CENTER, true, false);
98
    separator.setLayoutData(separatorData);
99
100
    Composite group = new Composite(parent, SWT.NONE);
101
    GridData groupGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
102
    group.setLayoutData(groupGridData);
103
    GridLayout groupLayout = new GridLayout(2, false);
104
    group.setLayout(groupLayout);
105
106
    Label comboLabel = new Label(group, SWT.NONE);
107
    comboLabel.setLayoutData(new GridData());
108
    comboLabel.setText(ResourceHandler.getExternalizedMessage(ResourceConstants.DELEGATES_COMBO_LABEL));
109
    
110
    Combo combo = new Combo(group, SWT.NONE);
111
    GridData comboGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
112
    combo.setLayoutData(comboGridData);
113
114
    final ComboViewer comboViewer = new ComboViewer(combo);
115
    comboViewer.setContentProvider(new DelegatesContentProvider());
116
    comboViewer.setLabelProvider(new DelegatesLabelProvider());
117
    String targetID = delegatingValidatorDescriptor.getValidatorUniqueName();
118
119
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener()
120
    {
121
122
      public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
123
      {
124
        IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection();
125
        setDelegateID(((ValidatorDelegateDescriptor) selection.getFirstElement()).getId());
126
      }
127
    });
128
129
    comboViewer.setInput(targetID);
130
131
    ValidatorDelegateDescriptor selected = ValidatorDelegatesRegistry.getInstance().getDescriptor(targetID, delegateID);
132
133
    if (selected != null)
134
    {
135
      comboViewer.setSelection(new StructuredSelection(new Object[] { selected }));
136
    }
137
138
    Label endSeparator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
139
    GridData endSeparatorData = new GridData(SWT.FILL, SWT.CENTER, true, false); 
140
    endSeparator.setLayoutData(endSeparatorData);
141
    
142
    return parent;
143
  }
144
145
  /**
146
   * Provides contents for the delegate validators combo box.
147
   */
148
  private final class DelegatesContentProvider implements IStructuredContentProvider
149
  {
150
    public void dispose()
151
    {
152
    }
153
154
    /*
155
     * (non-Javadoc)
156
     * 
157
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
158
     */
159
    public Object[] getElements(Object inputElement)
160
    {
161
      String targetID = (String) inputElement;
162
      Map delegatesByID = ValidatorDelegatesRegistry.getInstance().getDelegateDescriptors(targetID);
163
      
164
      if (delegatesByID == null)
165
      {
166
        return new Object[] {};
167
      }
168
169
      return delegatesByID.values().toArray();
170
    }
171
172
    /*
173
     * (non-Javadoc)
174
     * 
175
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
176
     *      java.lang.Object, java.lang.Object)
177
     */
178
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
179
    {
180
    }
181
  }
182
183
  /**
184
   * Provides the labels/images for the delegate validator combo box
185
   * 
186
   * @author vbaciul
187
   * 
188
   */
189
  private final class DelegatesLabelProvider implements ILabelProvider
190
  {
191
    /*
192
     * (non-Javadoc)
193
     * 
194
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
195
     */
196
    public void addListener(ILabelProviderListener listener)
197
    {
198
    }
199
200
    /*
201
     * (non-Javadoc)
202
     * 
203
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
204
     */
205
    public void dispose()
206
    {
207
    }
208
209
    /*
210
     * (non-Javadoc)
211
     * 
212
     * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
213
     */
214
    public Image getImage(Object element)
215
    {
216
      return null;
217
    }
218
219
    /*
220
     * (non-Javadoc)
221
     * 
222
     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
223
     */
224
    public String getText(Object element)
225
    {
226
      return ((ValidatorDelegateDescriptor) element).getName();
227
    }
228
229
    /*
230
     * (non-Javadoc)
231
     * 
232
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
233
     *      java.lang.String)
234
     */
235
    public boolean isLabelProperty(Object element, String property)
236
    {
237
      return false;
238
    }
239
240
    /*
241
     * (non-Javadoc)
242
     * 
243
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
244
     */
245
    public void removeListener(ILabelProviderListener listener)
246
    {
247
    }
248
  }
249
250
  /*
251
   * Provides the ID of the currently selected validator delegate ID.
252
   */
253
  public String getDelegateID()
254
  {
255
    return delegateID;
256
  }
257
258
  /**
259
   * Sets the currently selected validator delegate ID.
260
   * 
261
   * @param delegateID
262
   */
263
  private void setDelegateID(String delegateID)
264
  {
265
    this.delegateID = delegateID;
266
  }
267
}
(-)validate/org/eclipse/wst/validation/internal/ProjectConfiguration.java (+38 lines)
Lines 11-16 Link Here
11
package org.eclipse.wst.validation.internal;
11
package org.eclipse.wst.validation.internal;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Map;
14
import java.util.logging.Level;
15
import java.util.logging.Level;
15
16
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.resources.IMarker;
Lines 19-24 Link Here
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.jem.util.logger.LogEntry;
21
import org.eclipse.jem.util.logger.LogEntry;
21
import org.eclipse.jem.util.logger.proxy.Logger;
22
import org.eclipse.jem.util.logger.proxy.Logger;
23
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegateDescriptor;
22
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
24
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
23
25
24
26
Lines 146-151 Link Here
146
		return super.getValidators();
148
		return super.getValidators();
147
	}
149
	}
148
150
151
	/*
152
   * (non-Javadoc)
153
   * @see org.eclipse.wst.validation.internal.ValidationConfiguration#getDelegatingValidators()
154
	 */
155
  public Map getDelegatingValidators() throws InvocationTargetException {
156
    if (useGlobalPreference()) {
157
      return ConfigurationManager.getManager().getGlobalConfiguration().getDelegatingValidators();
158
    }
159
    return super.getDelegatingValidators();
160
  }
161
149
	/**
162
	/**
150
	 * @see org.eclipse.wst.validation.internal.operations.internal.attribute.ValidationConfiguration#getEnabledIncrementalValidators(boolean)
163
	 * @see org.eclipse.wst.validation.internal.operations.internal.attribute.ValidationConfiguration#getEnabledIncrementalValidators(boolean)
151
	 */
164
	 */
Lines 266-271 Link Here
266
279
267
		setEnabledManualValidators(gp.getManualEnabledValidators());
280
		setEnabledManualValidators(gp.getManualEnabledValidators());
268
		setEnabledBuildValidators(gp.getBuildEnabledValidators());
281
		setEnabledBuildValidators(gp.getBuildEnabledValidators());
282
    setDelegatingValidators(gp.getDelegatingValidators());
269
		
283
		
270
		// except for this field, which is unique to the project preferences
284
		// except for this field, which is unique to the project preferences
271
		setDoesProjectOverride(getDoesProjectOverrideDefault());
285
		setDoesProjectOverride(getDoesProjectOverrideDefault());
Lines 276-281 Link Here
276
		GlobalConfiguration gp = ConfigurationManager.getManager().getGlobalConfiguration();
290
		GlobalConfiguration gp = ConfigurationManager.getManager().getGlobalConfiguration();
277
		setEnabledManualValidators(gp.getManualEnabledValidators());
291
		setEnabledManualValidators(gp.getManualEnabledValidators());
278
		setEnabledBuildValidators(gp.getBuildEnabledValidators());
292
		setEnabledBuildValidators(gp.getBuildEnabledValidators());
293
    setDelegatingValidators(gp.getDelegatingValidators());
279
	}
294
	}
280
295
281
	/**
296
	/**
Lines 464-469 Link Here
464
		return false;
479
		return false;
465
	}
480
	}
466
481
482
  public boolean haveDelegatesChanged(Map oldDelegates, boolean allow) throws InvocationTargetException {
483
484
    if (super.haveDelegatesChanged(oldDelegates)) {
485
      return true;
486
    }
487
488
    if (allow) {
489
      Map projDelegates = super.getDelegatingValidators(); 
490
      GlobalConfiguration gp = ConfigurationManager.getManager().getGlobalConfiguration();
491
      return gp.haveDelegatesChanged(projDelegates);
492
    }
493
      
494
    return false;
495
  }
496
467
497
468
	/**
498
	/**
469
	 * @see org.eclipse.wst.validation.internal.operations.internal.attribute.ValidationConfiguration#deserialize(String)
499
	 * @see org.eclipse.wst.validation.internal.operations.internal.attribute.ValidationConfiguration#deserialize(String)
Lines 580-583 Link Here
580
		}
610
		}
581
		return super.isDisableAllValidation();
611
		return super.isDisableAllValidation();
582
	}	
612
	}	
613
614
  public ValidatorDelegateDescriptor getDelegateDescriptor(ValidatorMetaData vmd) throws InvocationTargetException {
615
    if (useGlobalPreference()) {
616
      return ConfigurationManager.getManager().getGlobalConfiguration().getDelegateDescriptor(vmd);
617
    }
618
    
619
    return super.getDelegateDescriptor(vmd);
620
  }
583
}
621
}
(-)validate/org/eclipse/wst/validation/internal/ResourceConstants.java (-1 / +5 lines)
Lines 113-117 Link Here
113
	public static final String VBF_STATUS_LOOKING = "VBF_STATUS_LOOKING"; //$NON-NLS-1$ 
113
	public static final String VBF_STATUS_LOOKING = "VBF_STATUS_LOOKING"; //$NON-NLS-1$ 
114
	public static final String VBF_STATUS_LOOKINGDONE = "VBF_STATUS_LOOKINGDONE"; //$NON-NLS-1$ 
114
	public static final String VBF_STATUS_LOOKINGDONE = "VBF_STATUS_LOOKINGDONE"; //$NON-NLS-1$ 
115
	public static final String VBF_STATUS_REMOVING = "VBF_STATUS_REMOVING"; //$NON-NLS-1$ 
115
	public static final String VBF_STATUS_REMOVING = "VBF_STATUS_REMOVING"; //$NON-NLS-1$ 
116
	public static final String VBF_STATUS_REMOVINGDONE = "VBF_STATUS_REMOVINGDONE"; //$NON-NLS-1$ 
116
	public static final String VBF_STATUS_REMOVINGDONE = "VBF_STATUS_REMOVINGDONE"; //$NON-NLS-1$
117
  
118
  public static final String VBF_WRONG_CONTEXT_FOR_DELEGATE = "VBF_WRONG_CONTEXT_FOR_DELEGATE"; //$NON-NLS-1$
119
  public static final String VBF_NO_DELEGATE = "VBF_NO_DELEGATE"; //$NON-NLS-1$
120
  public static final String VBF_CANNOT_INSTANTIATE_DELEGATE = "VBF_CANNOT_INSTANTIATE_DELEGATE"; //$NON-NLS-1$  
117
}
121
}
(-)validate/org/eclipse/wst/validation/internal/ValidatorMetaData.java (+10 lines)
Lines 22-27 Link Here
22
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jem.util.logger.proxy.Logger;
24
import org.eclipse.jem.util.logger.proxy.Logger;
25
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegatesRegistry;
25
import org.eclipse.wst.validation.internal.operations.IWorkbenchContext;
26
import org.eclipse.wst.validation.internal.operations.IWorkbenchContext;
26
import org.eclipse.wst.validation.internal.operations.WorkbenchContext;
27
import org.eclipse.wst.validation.internal.operations.WorkbenchContext;
27
import org.eclipse.wst.validation.internal.plugin.ValidationHelperRegistryReader;
28
import org.eclipse.wst.validation.internal.plugin.ValidationHelperRegistryReader;
Lines 537-540 Link Here
537
	public void setManualValidation(boolean manualValidation) {
538
	public void setManualValidation(boolean manualValidation) {
538
		this.manualValidation = manualValidation;
539
		this.manualValidation = manualValidation;
539
	}
540
	}
541
  
542
	/**
543
   * Determines if the validator described by this metadata object is a delegating validator. 
544
   * @return true if the validator described by this metadata object is a delegating validator, false otherwise.
545
	 */
546
  public boolean isDelegating() {
547
    String targetID = getValidatorUniqueName();
548
    return ValidatorDelegatesRegistry.getInstance().hasDelegates(targetID);
549
  }
540
}
550
}
(-)validate/org/eclipse/wst/validation/internal/GlobalConfiguration.java (-1 / +2 lines)
Lines 63-72 Link Here
63
		_canProjectsOverride = can;
63
		_canProjectsOverride = can;
64
	}
64
	}
65
65
66
	public void resetToDefault() {
66
	public void resetToDefault()  throws InvocationTargetException {
67
		setDisableAllValidation(getDisableValidationDefault());
67
		setDisableAllValidation(getDisableValidationDefault());
68
		setEnabledValidators(getEnabledValidatorsDefault());
68
		setEnabledValidators(getEnabledValidatorsDefault());
69
		setCanProjectsOverride(getCanProjectsOverrideDefault());
69
		setCanProjectsOverride(getCanProjectsOverrideDefault());
70
    setDefaultDelegates(getValidators());
70
	}
71
	}
71
72
72
	/**
73
	/**
(-)validate/org/eclipse/wst/validation/internal/ConfigurationConstants.java (-1 / +3 lines)
Lines 38-44 Link Here
38
	public static final int DEPTH_INFINITE = IResource.DEPTH_INFINITE;
38
	public static final int DEPTH_INFINITE = IResource.DEPTH_INFINITE;
39
	public static final int DEPTH_ZERO = IResource.DEPTH_ZERO;
39
	public static final int DEPTH_ZERO = IResource.DEPTH_ZERO;
40
	/* package */static final String ELEMENT_SEPARATOR = ";"; //$NON-NLS-1$ // separates the name of one IValidator from the next in the list of enabled validators for a project or preference
40
	/* package */static final String ELEMENT_SEPARATOR = ";"; //$NON-NLS-1$ // separates the name of one IValidator from the next in the list of enabled validators for a project or preference
41
41
  static final String DELEGATES_SEPARATOR = "="; //$NON-NLS-1$ // Separates the delegating validator id from the delegate validator id in the list of delegates
42
	// The following values must match the attributes in the preference marker as shown in
42
	// The following values must match the attributes in the preference marker as shown in
43
	// plugin.xml
43
	// plugin.xml
44
	// Even though the plugin.xml values are not used to create new Preference or Project markers,
44
	// Even though the plugin.xml values are not used to create new Preference or Project markers,
Lines 46-51 Link Here
46
	// These are the QualifiedNames used to persist the user's settings.
46
	// These are the QualifiedNames used to persist the user's settings.
47
	/* package */static final String ENABLED_MANUAL_VALIDATORS = "enabledManualValidatorList"; //$NON-NLS-1$ // String
47
	/* package */static final String ENABLED_MANUAL_VALIDATORS = "enabledManualValidatorList"; //$NON-NLS-1$ // String
48
	/* package */static final String ENABLED_BUILD_VALIDATORS = "enabledBuildValidatorList"; //$NON-NLS-1$ // String
48
	/* package */static final String ENABLED_BUILD_VALIDATORS = "enabledBuildValidatorList"; //$NON-NLS-1$ // String
49
  /* package */static final String DELEGATE_VALIDATORS = "delegateValidatorList"; //$NON-NLS-1$ // String
49
	public static final String J2EE_PLUGIN_ID = "org.eclipse.jst.j2ee"; //$NON-NLS-1$ // For 4.03, this is the plugin id that the validation constants were declared in.
50
	public static final String J2EE_PLUGIN_ID = "org.eclipse.jst.j2ee"; //$NON-NLS-1$ // For 4.03, this is the plugin id that the validation constants were declared in.
50
	/* package */static final String MAXNUMMESSAGES = "maxNumMessages"; //$NON-NLS-1$ // integer
51
	/* package */static final String MAXNUMMESSAGES = "maxNumMessages"; //$NON-NLS-1$ // integer
51
	public static final String PLUGIN_ID = ValidationPlugin.PLUGIN_ID;
52
	public static final String PLUGIN_ID = ValidationPlugin.PLUGIN_ID;
Lines 61-66 Link Here
61
	/* package */static final QualifiedName USER_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
62
	/* package */static final QualifiedName USER_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
62
	/* package */static final QualifiedName USER_MANUAL_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationManualConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
63
	/* package */static final QualifiedName USER_MANUAL_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationManualConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
63
	/* package */static final QualifiedName USER_BUILD_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationBuildConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
64
	/* package */static final QualifiedName USER_BUILD_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationBuildConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
65
  /* package */static final QualifiedName DELEGATES_PREFERENCE = new QualifiedName(PLUGIN_ID, "ValidationDelegatesConfiguration"); //$NON-NLS-1$ // ValidationConfiguration for the IResource
64
66
65
	// Validation message marker constants
67
	// Validation message marker constants
66
	/* package */static final String VALIDATION_MARKER = PLUGIN_ID + ".problemmarker"; //$NON-NLS-1$ // The extension which is used to add validation markers to the task list
68
	/* package */static final String VALIDATION_MARKER = PLUGIN_ID + ".problemmarker"; //$NON-NLS-1$ // The extension which is used to add validation markers to the task list
(-)validate/org/eclipse/wst/validation/internal/ValidationConfiguration.java (-4 / +174 lines)
Lines 30-35 Link Here
30
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.jem.util.logger.LogEntry;
31
import org.eclipse.jem.util.logger.LogEntry;
32
import org.eclipse.jem.util.logger.proxy.Logger;
32
import org.eclipse.jem.util.logger.proxy.Logger;
33
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegateDescriptor;
34
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegatesRegistry;
33
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
35
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
34
36
35
37
Lines 49-54 Link Here
49
	// disabled.
51
	// disabled.
50
	protected HashMap manualValidators = null;
52
	protected HashMap manualValidators = null;
51
	protected HashMap buildValidators = null;
53
	protected HashMap buildValidators = null;
54
  private Map _delegatesByTarget = null;
52
55
53
	public static String getEnabledElementsAsString(Set elements) {
56
	public static String getEnabledElementsAsString(Set elements) {
54
		if (elements == null) {
57
		if (elements == null) {
Lines 125-130 Link Here
125
128
126
	protected ValidationConfiguration() throws InvocationTargetException {
129
	protected ValidationConfiguration() throws InvocationTargetException {
127
		_validators = new HashMap();
130
		_validators = new HashMap();
131
    _delegatesByTarget = new HashMap();
128
	}
132
	}
129
133
130
	protected ValidationConfiguration(IResource resource, ValidatorMetaData[] validators) throws InvocationTargetException {
134
	protected ValidationConfiguration(IResource resource, ValidatorMetaData[] validators) throws InvocationTargetException {
Lines 373-379 Link Here
373
		}
377
		}
374
	}
378
	}
375
	
379
	
376
	
380
  public void setDefaultDelegates(ValidatorMetaData[] vmds) throws InvocationTargetException {
381
    _delegatesByTarget.clear();
382
    for (int i = 0; i < vmds.length; i++) {
383
      ValidatorMetaData vmd = vmds[i];
384
      if (vmd == null) {
385
        continue;
386
      }
387
      String targetID = vmd.getValidatorUniqueName();
388
      String delegateID = ValidatorDelegatesRegistry.getInstance().getDefaultDelegate(targetID);
389
      if (delegateID == null) {
390
        continue;
391
      }
392
      _delegatesByTarget.put(targetID, ValidatorDelegatesRegistry.getInstance().getDefaultDelegate(targetID));
393
    }
394
  }
377
395
378
	/**
396
	/**
379
	 * Returns the number of configured validators on the given project or installed validators in
397
	 * Returns the number of configured validators on the given project or installed validators in
Lines 563-568 Link Here
563
			getResource().setPersistentProperty(ConfigurationConstants.USER_PREFERENCE, serialize());
581
			getResource().setPersistentProperty(ConfigurationConstants.USER_PREFERENCE, serialize());
564
			getResource().setPersistentProperty(ConfigurationConstants.USER_MANUAL_PREFERENCE, serializeManualSetting());
582
			getResource().setPersistentProperty(ConfigurationConstants.USER_MANUAL_PREFERENCE, serializeManualSetting());
565
			getResource().setPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE, serializeBuildSetting());
583
			getResource().setPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE, serializeBuildSetting());
584
      getResource().setPersistentProperty(ConfigurationConstants.DELEGATES_PREFERENCE, serializeDelegatesSetting());
566
		} catch (CoreException exc) {
585
		} catch (CoreException exc) {
567
			throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SAVE, new String[]{getResource().getName()}));
586
			throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SAVE, new String[]{getResource().getName()}));
568
		}
587
		}
Lines 719-724 Link Here
719
			deserializeManual(storedManualConfiguration);
738
			deserializeManual(storedManualConfiguration);
720
			String storedBuildConfiguration = resource.getPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE);
739
			String storedBuildConfiguration = resource.getPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE);
721
			deserializeBuild(storedBuildConfiguration);
740
			deserializeBuild(storedBuildConfiguration);
741
      String storedDelegatesConfiguration = resource.getPersistentProperty(ConfigurationConstants.DELEGATES_PREFERENCE);
742
      deserializeDelegates(storedDelegatesConfiguration);
722
		} catch (CoreException exc) {
743
		} catch (CoreException exc) {
723
			throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{getResource().getName()}));
744
			throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{getResource().getName()}));
724
		}
745
		}
Lines 748-753 Link Here
748
		setEnabledManualValidators(getStringAsEnabledElementsArray(manualValidation));
769
		setEnabledManualValidators(getStringAsEnabledElementsArray(manualValidation));
749
	}
770
	}
750
771
772
	private void deserializeDelegates(String storedConfiguration) throws InvocationTargetException {
773
774
    if (storedConfiguration == null || storedConfiguration.length() == 0) {
775
	    // Assume that the configuration has never been set (new workspace).
776
	    resetToDefault();
777
	    return;
778
	  }
779
780
	  int delegatesIndex = storedConfiguration.indexOf(ConfigurationConstants.DELEGATE_VALIDATORS);
781
782
	  String delegates = storedConfiguration.substring(delegatesIndex + ConfigurationConstants.DELEGATE_VALIDATORS.length(),storedConfiguration.length());
783
784
	  if (delegates == null) {
785
	    return;
786
	  }
787
788
	  StringTokenizer tokenizer = new StringTokenizer(delegates, ConfigurationConstants.ELEMENT_SEPARATOR);
789
	  while (tokenizer.hasMoreTokens()) {
790
	    String delegateConfiguration = tokenizer.nextToken();
791
	    int separatorIndex = delegateConfiguration.indexOf(ConfigurationConstants.DELEGATES_SEPARATOR);
792
	    String targetID = delegateConfiguration.substring(0, separatorIndex);
793
	    String delegateID = delegateConfiguration.substring(separatorIndex + 1);
794
      _delegatesByTarget.put(targetID, delegateID);
795
	  }
796
	}
797
751
	protected void copyTo(ValidationConfiguration up) throws InvocationTargetException {
798
	protected void copyTo(ValidationConfiguration up) throws InvocationTargetException {
752
		up.setVersion(getVersion());
799
		up.setVersion(getVersion());
753
		up.setResource(getResource());
800
		up.setResource(getResource());
Lines 756-764 Link Here
756
		up.setEnabledValidators(getEnabledValidators());
803
		up.setEnabledValidators(getEnabledValidators());
757
		up.setEnabledManualValidators(getManualEnabledValidators());
804
		up.setEnabledManualValidators(getManualEnabledValidators());
758
		up.setEnabledBuildValidators(getBuildEnabledValidators());
805
		up.setEnabledBuildValidators(getBuildEnabledValidators());
806
    up.setDelegatingValidators(getDelegatingValidators());
759
	}
807
	}
760
808
761
	/**
809
  public Map getDelegatingValidators() throws InvocationTargetException {
810
    return _delegatesByTarget;
811
  }
812
813
  public void setDelegatingValidators(Map source)
814
  {
815
    // It is safe to copy this map as it contains only immutable strings.
816
    _delegatesByTarget.putAll(source);
817
  }
818
819
  /**
762
	 * Return true if the enabled validators have not changed since this ValidationConfiguration was
820
	 * Return true if the enabled validators have not changed since this ValidationConfiguration was
763
	 * constructed, false otherwise. (This method is needed for the Properties and Preference pages;
821
	 * constructed, false otherwise. (This method is needed for the Properties and Preference pages;
764
	 * if the list of validators hasn't changed, then there is no need to update the task list;
822
	 * if the list of validators hasn't changed, then there is no need to update the task list;
Lines 787-792 Link Here
787
845
788
		return false;
846
		return false;
789
	}
847
	}
848
  
849
  /**
850
   * Determines if there has been a change in the list of delegate validators.
851
   * @param oldDelegates a Map with the old delegates ID by target ID.
852
   * @return true if there has been a change, false otherwise.
853
   * @throws InvocationTargetException
854
   */
855
  protected boolean haveDelegatesChanged(Map oldDelegates) throws InvocationTargetException {
856
    
857
    if (oldDelegates == null) {
858
      return true;
859
    }
860
    
861
    Iterator iterator = oldDelegates.keySet().iterator();
862
    
863
    while (iterator.hasNext())
864
    {
865
      String targetID = (String) iterator.next();
866
      String oldDelegateID = (String) oldDelegates.get(targetID);
867
      String newDelegateID = (String) _delegatesByTarget.get(targetID);
868
      
869
      if (oldDelegateID == null || newDelegateID == null) {
870
        return true;
871
      }
872
        
873
      if (!newDelegateID.equals(oldDelegateID)) {
874
        return true;
875
      }
876
    }
877
    
878
    if (oldDelegates.size() != _delegatesByTarget.size()) {
879
      return true;
880
    }
881
    
882
    return false;
883
  }
790
884
791
	protected String serialize() throws InvocationTargetException {
885
	protected String serialize() throws InvocationTargetException {
792
		StringBuffer buffer = new StringBuffer();
886
		StringBuffer buffer = new StringBuffer();
Lines 811-817 Link Here
811
		return buffer.toString();
905
		return buffer.toString();
812
	}
906
	}
813
907
814
	/**
908
  protected String serializeDelegatesSetting() throws InvocationTargetException {
909
    StringBuffer buffer = new StringBuffer();
910
    buffer.append(ConfigurationConstants.DELEGATE_VALIDATORS);
911
    buffer.append(getDelegatesAsString(getValidatorMetaData()));
912
    return buffer.toString();
913
  }
914
915
  /**
916
   * Provides a String which contains pairs of targetID=delegateID separated by a semicolon.
917
   * @param validatorMetaData a Map with the currently configured validators.
918
   * @return a String.
919
   */
920
  private String getDelegatesAsString(Map validatorMetaData) {
921
    
922
    StringBuffer buffer = new StringBuffer();
923
    Iterator iterator = validatorMetaData.keySet().iterator();
924
    
925
    while (iterator.hasNext()) {
926
    
927
      ValidatorMetaData vmd = (ValidatorMetaData) iterator.next();
928
      String targetID = vmd.getValidatorUniqueName();
929
      String delegateID = getDelegateUniqueName(vmd);
930
      
931
      if (delegateID == null) {
932
        continue;
933
      }
934
935
      // Write out pairs targetID=delegateID
936
937
      buffer.append(targetID);
938
      buffer.append(ConfigurationConstants.DELEGATES_SEPARATOR);
939
      buffer.append(delegateID);
940
      buffer.append(ConfigurationConstants.ELEMENT_SEPARATOR);
941
    }
942
    
943
    return buffer.toString();
944
  }
945
  
946
  /**
947
   * Provides the delegate's ID of the validator delegate configured in this configuration for 
948
   * a given delegating validator.
949
   * 
950
   * @param vmd the delegating validator's metadata. Must not be null.
951
   * @return a String with the unique name (ID) of the validator delegate, null if there isn't one.
952
   */
953
  public String getDelegateUniqueName(ValidatorMetaData vmd) {
954
    String targetID = vmd.getValidatorUniqueName();    
955
    return (String) _delegatesByTarget.get(targetID);
956
  }
957
958
  /**
959
   * Sets the delegate's ID of the validator delegate to be used in this configuration for the
960
   * given delegating validator.
961
   * 
962
   * @param vmd the delegating validator's metadata. Must not be null.
963
   * @param delegateID a String with the unique name (ID) of the validator delegate. Must not be null.
964
   */
965
  public void setDelegateUniqueName(ValidatorMetaData vmd, String delegateID) {
966
    String targetID = vmd.getValidatorUniqueName();    
967
    _delegatesByTarget.put(targetID, delegateID);
968
  }
969
970
  /**
815
	 * Deserialize everything except the version number; the version is deserialized first, in the
971
	 * Deserialize everything except the version number; the version is deserialized first, in the
816
	 * loadVersion() method.
972
	 * loadVersion() method.
817
	 */
973
	 */
Lines 874-878 Link Here
874
	
1030
	
875
	public int numberOfManualEnabledValidators() throws InvocationTargetException {
1031
	public int numberOfManualEnabledValidators() throws InvocationTargetException {
876
		return getManualEnabledValidators().length;
1032
		return getManualEnabledValidators().length;
877
	}	
1033
	}
1034
1035
  /**
1036
   * Provides the delegate validator descriptor of the validator delegate configured 
1037
   * for the given delegating validator in the context of this configuration. 
1038
   * @param vmd the delegating validator's meta data. Must not be null.
1039
   * @return a ValidatorDelegateDescriptor for the given delegating validator.
1040
   */
1041
  public ValidatorDelegateDescriptor getDelegateDescriptor(ValidatorMetaData vmd)  throws InvocationTargetException {
1042
    String targetID = vmd.getValidatorUniqueName();
1043
    String delegateID = getDelegateUniqueName(vmd);
1044
  
1045
    ValidatorDelegateDescriptor descriptor = ValidatorDelegatesRegistry.getInstance().getDescriptor(targetID, delegateID); 
1046
    return descriptor;    
1047
  }
878
}
1048
}
(-)plugin.xml (-1 / +2 lines)
Lines 7-13 Link Here
7
   <extension-point id="validator" name="%Validator" schema="xsds/validatorExtSchema.exsd"/>
7
   <extension-point id="validator" name="%Validator" schema="xsds/validatorExtSchema.exsd"/>
8
   <extension-point id="referencialFileValidator" name="%ReferencialFileValidator" schema="xsds/referencialFileExtSchema.exsd"/>
8
   <extension-point id="referencialFileValidator" name="%ReferencialFileValidator" schema="xsds/referencialFileExtSchema.exsd"/>
9
   <extension-point id="validationSelectionHandler" name="%validationSelectionHandler" schema="xsds/validationSelectionHandler.exsd"/>
9
   <extension-point id="validationSelectionHandler" name="%validationSelectionHandler" schema="xsds/validationSelectionHandler.exsd"/>
10
   <extension-point id="validationHelper" name="validationHelper" schema="xsds/validationHelper.exsd"/>   
10
   <extension-point id="validationHelper" name="validationHelper" schema="xsds/validationHelper.exsd"/>
11
   <extension-point id="validatorDelegates" name="%ValidatorDelegates" schema="xsds/validatorDelegates.exsd"/>   
11
   
12
   
12
<!--============================-->
13
<!--============================-->
13
<!-- Validation Contributions   -->
14
<!-- Validation Contributions   -->
(-)plugin.properties (-1 / +2 lines)
Lines 17-20 Link Here
17
VALIDATION_PREFERENCEMARKER_NAME=Validation Preferences
17
VALIDATION_PREFERENCEMARKER_NAME=Validation Preferences
18
Validator=Validator
18
Validator=Validator
19
ReferencialFileValidator=ReferencialFileValidator
19
ReferencialFileValidator=ReferencialFileValidator
20
validationSelectionHandler=validationSelectionHandler
20
validationSelectionHandler=validationSelectionHandler
21
ValidatorDelegates=Validator Delegates
(-)validate/org/eclipse/wst/validation/internal/operations/IWorkbenchContext.java (-2 / +2 lines)
Lines 13-19 Link Here
13
import org.eclipse.core.resources.IFile;
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
16
import org.eclipse.wst.validation.internal.provisional.core.IProjectValidationContext;
17
17
18
18
19
19
Lines 23-29 Link Here
23
 * also needs to load items from the eclipse workbench. This interface should be extended by
23
 * also needs to load items from the eclipse workbench. This interface should be extended by
24
 * workbench IHelpers, so that items can be added to, and from, the task list.
24
 * workbench IHelpers, so that items can be added to, and from, the task list.
25
 */
25
 */
26
public interface IWorkbenchContext extends IValidationContext {
26
public interface IWorkbenchContext extends IProjectValidationContext {
27
	/**
27
	/**
28
	 * When the validation is complete, this method will be called so that the IWorkbenchContext can
28
	 * When the validation is complete, this method will be called so that the IWorkbenchContext can
29
	 * clean up any resources it allocated during the validation.
29
	 * clean up any resources it allocated during the validation.
(-)property_files/validate_base.properties (+4 lines)
Lines 128-133 Link Here
128
VBF_STATUS_REMOVING=Removing validation messages owned by uninstalled validators...
128
VBF_STATUS_REMOVING=Removing validation messages owned by uninstalled validators...
129
VBF_STATUS_REMOVINGDONE=Removing validation messages owned by uninstalled validators...done.
129
VBF_STATUS_REMOVINGDONE=Removing validation messages owned by uninstalled validators...done.
130
130
131
VBF_WRONG_CONTEXT_FOR_DELEGATE=The validator {0} is a being invoked with a wrong context. Please use an IProjectValidationContext.
132
VBF_NO_DELEGATE=The validator {0} is a delegating validator but no delegate can found for it.
133
VBF_CANNOT_INSTANTIATE_DELEGATE=The validator delegate {0} registered for {1} cannot be instantiated.
134
131
# The following message will be deleted soon.
135
# The following message will be deleted soon.
132
VBF_TASK_WARN_MESSAGE_LIMIT_ABORT=IWAE0034W IWAD3000I: {1} terminated validation of {0} because the maximum number of messages were reported. Some messages may be missing.
136
VBF_TASK_WARN_MESSAGE_LIMIT_ABORT=IWAE0034W IWAD3000I: {1} terminated validation of {0} because the maximum number of messages were reported. Some messages may be missing.
133
137
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 8-13 Link Here
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.wst.validation.internal;x-internal:=true,
9
Export-Package: org.eclipse.wst.validation.internal;x-internal:=true,
10
 org.eclipse.wst.validation.internal.core;x-internal:=true,
10
 org.eclipse.wst.validation.internal.core;x-internal:=true,
11
 org.eclipse.wst.validation.internal.delegates;x-internal:=true,
11
 org.eclipse.wst.validation.internal.operations;x-internal:=true,
12
 org.eclipse.wst.validation.internal.operations;x-internal:=true,
12
 org.eclipse.wst.validation.internal.plugin;x-internal:=true,
13
 org.eclipse.wst.validation.internal.plugin;x-internal:=true,
13
 org.eclipse.wst.validation.internal.provisional;x-internal:=true,
14
 org.eclipse.wst.validation.internal.provisional;x-internal:=true,
(-)xsds/validatorDelegates.exsd (+134 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.wst.validation">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.wst.validation" id="validatorDelegates" name="Validator Delegates"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point allows validator providers to contribute alternate implementations for a delegating validator.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="delegate"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="delegate">
46
      <annotation>
47
         <documentation>
48
            Defines a validator delegate. Delegating validators can have one or more delegates registered, only one of which can be active (selected) at once.
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  Specifies the class name of the delegate validator. The class must implement IValidator.
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="java" basedOn="org.eclipse.wst.validation.internal.provisional.core.IValidator"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="target" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  Specifies the id of the validator extension for which this delegate is being registered.
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
         <attribute name="name" type="string" use="required">
70
            <annotation>
71
               <documentation>
72
                  
73
               </documentation>
74
            </annotation>
75
         </attribute>
76
      </complexType>
77
   </element>
78
79
   <annotation>
80
      <appInfo>
81
         <meta.section type="since"/>
82
      </appInfo>
83
      <documentation>
84
         &lt;b&gt;This extension point is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.&lt;/b&gt;
85
      </documentation>
86
   </annotation>
87
88
   <annotation>
89
      <appInfo>
90
         <meta.section type="examples"/>
91
      </appInfo>
92
      <documentation>
93
         &lt;extension point=&quot;org.eclipse.wst.validation.validatorDelegates&quot;&gt;
94
    &lt;delegate
95
          class=&quot;com.acme.fast.SuperFastValidator&quot;
96
          name=&quot;Super fast validator&quot;
97
          target=&quot;org.acme.core.ACMEDelegatingValidator&quot;/&gt;
98
 &lt;/extension&gt;
99
      </documentation>
100
   </annotation>
101
102
   <annotation>
103
      <appInfo>
104
         <meta.section type="apiInfo"/>
105
      </appInfo>
106
      <documentation>
107
         A delegate validator will have to implement the IValidator interface.
108
The target validator, the one who will delegate its implementation to a delegate validator will have to extend org.eclipse.wst.validation.delegates.BaseDelegatingValidator.
109
      </documentation>
110
   </annotation>
111
112
   <annotation>
113
      <appInfo>
114
         <meta.section type="implementation"/>
115
      </appInfo>
116
      <documentation>
117
         
118
      </documentation>
119
   </annotation>
120
121
   <annotation>
122
      <appInfo>
123
         <meta.section type="copyright"/>
124
      </appInfo>
125
      <documentation>
126
         Copyright (c) 2006 IBM Corporation and others.&lt;br&gt;
127
All rights reserved. This program and the accompanying materials are made 
128
available under the terms of the Eclipse Public License v1.0 which accompanies 
129
this distribution, and is available at &lt;a
130
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
131
      </documentation>
132
   </annotation>
133
134
</schema>
(-)validate/org/eclipse/wst/validation/internal/delegates/IDelegatingValidator.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.delegates;
13
14
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
15
16
/**
17
 * A delegating validator delegates the actual validation work to a delegate
18
 * validator. This is a marker interface used internally by the framework to
19
 * determine if a delegate is a delegating validator.
20
 * 
21
 * [Issue] Could/should this interface be replaced with an attribute on the
22
 * validators extension definition?
23
 * 
24
 * <p>
25
 * <b>Note:</b> This class/interface is part of an interim API that is still
26
 * under development and expected to change significantly before reaching
27
 * stability. It is being made available at this early stage to solicit feedback
28
 * from pioneering adopters on the understanding that any code that uses this
29
 * API will almost certainly be broken (repeatedly) as the API evolves.
30
 * </p>
31
 */
32
public interface IDelegatingValidator extends IValidator
33
{
34
}
(-)validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistryReader.java (+114 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.delegates;
13
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.core.runtime.IExtensionPoint;
16
import org.eclipse.core.runtime.IExtensionRegistry;
17
import org.eclipse.core.runtime.Platform;
18
19
/**
20
 * This class reads the plugin extension registry and registers each delegating
21
 * validator descriptor with the delegates registry.
22
 * 
23
 * @see ValidatorDelegatesRegistry
24
 */
25
class ValidatorDelegatesRegistryReader
26
{
27
  /**
28
   * The delegate class attribute. Must be visible in the package because it is
29
   * used by other classes in the package.
30
   */
31
  static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$
32
33
  /**
34
   * The delegate element name.
35
   */
36
  private static final String DELEGATE_ELEMENT = "delegate"; //$NON-NLS-1$
37
38
  /**
39
   * The validator delegates extension point id.
40
   */
41
  private static final String EXTENSION_POINT_ID = "validatorDelegates"; //$NON-NLS-1$
42
43
  /**
44
   * The delegate name attribute.
45
   */
46
  private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
47
48
  /**
49
   * Plugin id.
50
   */
51
  private static final String PLUGIN_ID = "org.eclipse.wst.validation"; //$NON-NLS-1$
52
53
  /**
54
   * The target id attribute name.
55
   */
56
  private static final String TARGET_ATTRIBUTE = "target"; //$NON-NLS-1$
57
58
  /**
59
   * The validator registry where the descriptors being read will be placed.
60
   */
61
  private ValidatorDelegatesRegistry registry;
62
63
  /**
64
   * Constructor.
65
   * 
66
   * @param registry
67
   *          the registry where the descriptors being read will be placed.
68
   */
69
  public ValidatorDelegatesRegistryReader(ValidatorDelegatesRegistry registry)
70
  {
71
    this.registry = registry;
72
  }
73
74
  /**
75
   * Reads a configuration element.
76
   * 
77
   * @param element
78
   *          the platform configuration element being read.
79
   */
80
  private void readElement(IConfigurationElement element)
81
  {
82
    String elementName = element.getName();
83
84
    if (elementName.equals(DELEGATE_ELEMENT))
85
    {
86
      String delegateID = (String) element.getAttribute(CLASS_ATTRIBUTE);
87
      String delegateName = (String) element.getAttribute(NAME_ATTRIBUTE);
88
      String targetValidatorID = (String) element.getAttribute(TARGET_ATTRIBUTE);
89
90
      ValidatorDelegateDescriptor descriptor = new ValidatorDelegateDescriptor(delegateID, element, delegateName, targetValidatorID);
91
92
      registry.add(descriptor);
93
    }
94
  }
95
96
  /**
97
   * Read from the extensions registry and parse it.
98
   */
99
  void readRegistry()
100
  {
101
    IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
102
    IExtensionPoint point = pluginRegistry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID);
103
104
    if (point != null)
105
    {
106
      IConfigurationElement[] elements = point.getConfigurationElements();
107
108
      for (int index = 0; index < elements.length; index++)
109
      {
110
        readElement(elements[index]);
111
      }
112
    }
113
  }
114
}
(-)validate/org/eclipse/wst/validation/internal/delegates/DelegatingValidator.java (+237 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.delegates;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.List;
16
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.wst.validation.internal.ConfigurationManager;
19
import org.eclipse.wst.validation.internal.ProjectConfiguration;
20
import org.eclipse.wst.validation.internal.ResourceConstants;
21
import org.eclipse.wst.validation.internal.ResourceHandler;
22
import org.eclipse.wst.validation.internal.ValidationRegistryReader;
23
import org.eclipse.wst.validation.internal.ValidatorMetaData;
24
import org.eclipse.wst.validation.internal.core.ValidationException;
25
import org.eclipse.wst.validation.internal.operations.LocalizedMessage;
26
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
27
import org.eclipse.wst.validation.internal.provisional.core.IProjectValidationContext;
28
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
29
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
30
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
31
32
/**
33
 * This class is to be used as a base class by clients who want to provide
34
 * alternate validator implementations for a given validator type.
35
 * 
36
 * It locates the currently configured delegate for this validator and calls its
37
 * validate method.
38
 * 
39
 * @see IValidator
40
 * @see IDelegatingValidator
41
 * 
42
 * <p>
43
 * <b>Note:</b> This class/interface is part of an interim API that is still
44
 * under development and expected to change significantly before reaching
45
 * stability. It is being made available at this early stage to solicit feedback
46
 * from pioneering adopters on the understanding that any code that uses this
47
 * API will almost certainly be broken (repeatedly) as the API evolves.
48
 * </p>
49
 */
50
public class DelegatingValidator implements IDelegatingValidator
51
{
52
  /**
53
   * Default constructor.
54
   */
55
  public DelegatingValidator()
56
  {
57
  }
58
59
  /*
60
   * (non-Javadoc)
61
   * 
62
   * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#cleanup(org.eclipse.wst.validation.internal.provisional.core.IReporter)
63
   */
64
  public void cleanup(IReporter reporter)
65
  {
66
    // [Issue] This method does not get passed the validation context. How are
67
    // going to know the delegate in order to invoke its cleanup method?
68
  }
69
70
  /*
71
   * (non-Javadoc)
72
   * 
73
   * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#validate(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
74
   *      org.eclipse.wst.validation.internal.provisional.core.IReporter)
75
   */
76
  public void validate(IValidationContext helper, IReporter reporter) throws ValidationException
77
  {
78
    ValidatorMetaData vmd = ValidationRegistryReader.getReader().getValidatorMetaData(this);
79
    String validatorName = vmd.getValidatorDisplayName();
80
81
    // We need to ensure that the context is an IProjectValidationContext. The
82
    // limitation of using an IValidationContext is that it does not readily
83
    // provide the project the validator is being invoked upon.
84
85
    if (!(helper instanceof IProjectValidationContext))
86
    {
87
      throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_WRONG_CONTEXT_FOR_DELEGATE, new String[] { validatorName })));
88
    }
89
90
    IProjectValidationContext projectContext = (IProjectValidationContext) helper;
91
    IProject project = projectContext.getProject();
92
93
    ValidatorDelegateDescriptor delegateDescriptor = null;
94
95
    try
96
    {
97
      ProjectConfiguration projectConfig = ConfigurationManager.getManager().getProjectConfiguration(project);
98
99
      delegateDescriptor = projectConfig.getDelegateDescriptor(vmd);
100
    }
101
    catch (InvocationTargetException e)
102
    {
103
      // Already dealt with by the framework.
104
    }
105
    finally
106
    {
107
      if (delegateDescriptor == null)
108
      {
109
        throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_NO_DELEGATE, new String[] { vmd.getValidatorDisplayName() })));
110
      }
111
    }
112
113
    IValidator delegate = delegateDescriptor.getValidator();
114
115
    // We need to make it look like this validator is the one generating
116
    // messages so we wrap the reporter and use this validator as the source.
117
    // The validation framework does not recognize our validators because they
118
    // are not registered directly with the framework.
119
    // We could make them work like the aggregated validators but that would
120
    // create problems with markers not being cleaned up if someone switches
121
    // validators.
122
    // TODO : Maybe we could clear all the markers generated by a delegate when
123
    // the user chooses a different delegate implementation?
124
125
    DelegatingReporter delegatingReporter = new DelegatingReporter(this, reporter);
126
127
    delegate.validate(helper, delegatingReporter);
128
  }
129
130
  /**
131
   * Wraps the original reporter instance to make it look like this validator is
132
   * the one generating messages. This is needed because the framework ignores
133
   * messages coming from the delegate validator because it is not registered
134
   * with the validation framework.
135
   */
136
  private class DelegatingReporter implements IReporter
137
  {
138
    /**
139
     * The reporter passed originally to the delegating validator by the
140
     * framework.
141
     */
142
    IReporter delegatingReporter;
143
144
    /**
145
     * The delegating validator.
146
     */
147
    IValidator delegatingValidator;
148
149
    /**
150
     * Constructor.
151
     * 
152
     * @param validator
153
     *          the original validator.
154
     * @param reporter
155
     *          the reporter originally passed to the delegating validator.
156
     */
157
    DelegatingReporter(IValidator validator, IReporter reporter)
158
    {
159
      delegatingReporter = reporter;
160
      delegatingValidator = validator;
161
    }
162
163
    /*
164
     * (non-Javadoc)
165
     * 
166
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#addMessage(org.eclipse.wst.validation.internal.provisional.core.IValidator,
167
     *      org.eclipse.wst.validation.internal.provisional.core.IMessage)
168
     */
169
    public void addMessage(IValidator origin, IMessage message)
170
    {
171
      delegatingReporter.addMessage(delegatingValidator, message);
172
    }
173
174
    /*
175
     * (non-Javadoc)
176
     * 
177
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#displaySubtask(org.eclipse.wst.validation.internal.provisional.core.IValidator,
178
     *      org.eclipse.wst.validation.internal.provisional.core.IMessage)
179
     */
180
    public void displaySubtask(IValidator validator, IMessage message)
181
    {
182
      delegatingReporter.displaySubtask(delegatingValidator, message);
183
    }
184
185
    /*
186
     * (non-Javadoc)
187
     * 
188
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#getMessages()
189
     */
190
    public List getMessages()
191
    {
192
      return delegatingReporter.getMessages();
193
    }
194
195
    /*
196
     * (non-Javadoc)
197
     * 
198
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#isCancelled()
199
     */
200
    public boolean isCancelled()
201
    {
202
      return delegatingReporter.isCancelled();
203
    }
204
205
    /*
206
     * (non-Javadoc)
207
     * 
208
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#removeAllMessages(org.eclipse.wst.validation.internal.provisional.core.IValidator)
209
     */
210
    public void removeAllMessages(IValidator origin)
211
    {
212
      delegatingReporter.removeAllMessages(delegatingValidator);
213
    }
214
215
    /*
216
     * (non-Javadoc)
217
     * 
218
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#removeAllMessages(org.eclipse.wst.validation.internal.provisional.core.IValidator,
219
     *      java.lang.Object)
220
     */
221
    public void removeAllMessages(IValidator origin, Object object)
222
    {
223
      delegatingReporter.removeAllMessages(delegatingValidator, object);
224
    }
225
226
    /*
227
     * (non-Javadoc)
228
     * 
229
     * @see org.eclipse.wst.validation.internal.provisional.core.IReporter#removeMessageSubset(org.eclipse.wst.validation.internal.provisional.core.IValidator,
230
     *      java.lang.Object, java.lang.String)
231
     */
232
    public void removeMessageSubset(IValidator validator, Object obj, String groupName)
233
    {
234
      delegatingReporter.removeMessageSubset(delegatingValidator, obj, groupName);
235
    }
236
  }
237
}
(-)validate_core/org/eclipse/wst/validation/internal/provisional/core/IProjectValidationContext.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.provisional.core;
13
14
import org.eclipse.core.resources.IProject;
15
16
/**
17
 * IProjectValidationContext extends IValidationContext to provide access to a
18
 * reference to the project on which a validator is being invoked.
19
 * <p>
20
 * <b>Note:</b> This class/interface is part of an interim API that is still
21
 * under development and expected to change significantly before reaching
22
 * stability. It is being made available at this early stage to solicit feedback
23
 * from pioneering adopters on the understanding that any code that uses this
24
 * API will almost certainly be broken (repeatedly) as the API evolves.
25
 * </p>
26
 */
27
public interface IProjectValidationContext extends IValidationContext
28
{
29
  /**
30
   * Provides the project on which the validator is being invoked.
31
   * 
32
   * @return an IProject reference to the project on which the validator is
33
   *         being invoked.
34
   */
35
  IProject getProject();
36
}
(-)validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegateDescriptor.java (+137 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.delegates;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.wst.validation.internal.ResourceConstants;
17
import org.eclipse.wst.validation.internal.ResourceHandler;
18
import org.eclipse.wst.validation.internal.ValidationRegistryReader;
19
import org.eclipse.wst.validation.internal.core.ValidationException;
20
import org.eclipse.wst.validation.internal.operations.LocalizedMessage;
21
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
22
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
23
24
/**
25
 * ValidatorDelegateDescriptor stores information about a delegate validator.
26
 * 
27
 * It is also used to store the instance of the validator it describes. To
28
 * obtain the instance call getValidator().
29
 */
30
public class ValidatorDelegateDescriptor
31
{
32
  /**
33
   * The instance of the validator refered to by this descriptor.
34
   */
35
  private IValidator delegate;
36
37
  /**
38
   * The platform configuration element describing this delegate.
39
   */
40
  private IConfigurationElement delegateConfiguration;
41
42
  /**
43
   * The delegating validator's ID.
44
   */
45
  private String delegatingValidatorID;
46
47
  /**
48
   * The delegate's ID.
49
   */
50
  private String id;
51
52
  /**
53
   * The delegate's display name.
54
   */
55
  private String name;
56
57
  /**
58
   * Constructs a descriptor.
59
   * 
60
   * @param id
61
   *          the delegate's uniques id. Must be unique in the context of a
62
   *          delegating validator.
63
   * @param delegateConfiguration
64
   *          the delegates configuration element
65
   * @param delegateName
66
   *          the delegate's display name.
67
   * @param targetValidatorID
68
   *          the target validator's unique id.
69
   */
70
  public ValidatorDelegateDescriptor(String id, IConfigurationElement delegateConfiguration, String delegateName, String targetValidatorID)
71
  {
72
    this.id = id;
73
    this.delegateConfiguration = delegateConfiguration;
74
    this.name = delegateName;
75
    this.delegatingValidatorID = targetValidatorID;
76
  }
77
78
  /**
79
   * Provides the delegate's ID.
80
   * 
81
   * @return a string with the fully qualified class name of this validator
82
   *         implementation.
83
   */
84
  public String getId()
85
  {
86
    return id;
87
  }
88
89
  /**
90
   * Provides the delegate's name.
91
   * 
92
   * @return a String with the validator's display name.
93
   */
94
  public String getName()
95
  {
96
    return name;
97
  }
98
99
  /**
100
   * Retrieves the target validator's ID.
101
   * 
102
   * @return a String with the fully qualified class name of the delegating
103
   *         validator who will delegate its implementation to the validator
104
   *         described by this descriptor.
105
   */
106
  public String getTargetID()
107
  {
108
    return delegatingValidatorID;
109
  }
110
111
  /**
112
   * Provides the instance of the validator delegate pointed to by this
113
   * descriptor.
114
   * 
115
   * @return an IValidator instance.
116
   * @throws ValidationException
117
   */
118
  public IValidator getValidator() throws ValidationException
119
  {
120
    if (delegate != null)
121
    {
122
      return delegate;
123
    }
124
125
    try
126
    {
127
      delegate = (IValidator) delegateConfiguration.createExecutableExtension(ValidatorDelegatesRegistryReader.CLASS_ATTRIBUTE);
128
    }
129
    catch (CoreException e)
130
    {
131
      String delegatingValidatorName = ValidationRegistryReader.getReader().getValidatorMetaData(getTargetID()).getValidatorDisplayName();
132
      throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_CANNOT_INSTANTIATE_DELEGATE, new String[] { getName(), delegatingValidatorName })));
133
    }
134
135
    return delegate;
136
  }
137
}
(-)validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java (+200 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.wst.validation.internal.delegates;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.wst.validation.internal.core.ValidationException;
19
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
20
21
/**
22
 * ValidatorDelegatesRegistry is a singleton used to store validator delegate
23
 * descriptors for each delegating validator.
24
 */
25
public class ValidatorDelegatesRegistry
26
{
27
  /**
28
   * The one and only instance of this registry.
29
   */
30
  private static ValidatorDelegatesRegistry instance;
31
32
  /**
33
   * Provides the one and only instance of this class.
34
   * 
35
   * The actual platform extension registry reading happens at this time.
36
   * 
37
   * @see ValidatorDelegatesRegistryReader
38
   * 
39
   * @return the validator delegates registry singleton instance.
40
   */
41
  public static ValidatorDelegatesRegistry getInstance()
42
  {
43
    if (instance == null)
44
    {
45
      instance = new ValidatorDelegatesRegistry();
46
47
      ValidatorDelegatesRegistryReader reader = new ValidatorDelegatesRegistryReader(instance);
48
      reader.readRegistry();
49
    }
50
51
    return instance;
52
  }
53
54
  /**
55
   * The map of target validator id to Map of delegates by id.
56
   */
57
  private Map delegatesByTarget = new HashMap();
58
59
  /**
60
   * Adds a descriptor to the registry.
61
   * 
62
   * @param descriptor
63
   *          the descriptor to add. Must not be null.
64
   */
65
  void add(ValidatorDelegateDescriptor descriptor)
66
  {
67
    if (descriptor == null)
68
    {
69
      return;
70
    }
71
72
    String targetID = descriptor.getTargetID();
73
74
    Map delegates = (Map) delegatesByTarget.get(targetID);
75
76
    if (delegates == null)
77
    {
78
      delegates = new HashMap();
79
      delegatesByTarget.put(targetID, delegates);
80
    }
81
82
    delegates.put(descriptor.getId(), descriptor);
83
  }
84
85
  /**
86
   * Provides the default delegate ID for the given delegating validator ID.
87
   * 
88
   * @param targetID
89
   *          the delegating validator's ID.
90
   * @return a String with the ID of the default delegate.
91
   */
92
  public String getDefaultDelegate(String targetID)
93
  {
94
    Map delegates = getDelegateDescriptors(targetID);
95
96
    if (delegates == null)
97
    {
98
      return null;
99
    }
100
101
    // TODO: Implement a default attribute and use that to get the default?
102
    // What happens if two or more delegates claim to be the default one?
103
    // For now, just pick the first one in the list.
104
105
    Iterator delegatesIterator = delegates.values().iterator();
106
107
    if (!delegatesIterator.hasNext())
108
    {
109
      return null;
110
    }
111
112
    ValidatorDelegateDescriptor descriptor = (ValidatorDelegateDescriptor) delegatesIterator.next();
113
114
    return descriptor.getId();
115
  }
116
117
  /**
118
   * Retrieves a delegate instance based on the target and delegate IDs.
119
   * 
120
   * @param targetID
121
   *          the delegating validator's ID.
122
   * @param delegateID
123
   *          the delegate validator's ID.
124
   * @return an instance of the delegate validator or null if one cannot be
125
   *         found.
126
   */
127
  public IValidator getDelegate(String targetID, String delegateID) throws ValidationException
128
  {
129
    ValidatorDelegateDescriptor descriptor = getDescriptor(targetID, delegateID);
130
131
    if (descriptor == null)
132
    {
133
      return null;
134
    }
135
136
    IValidator delegate = descriptor.getValidator();
137
138
    return delegate;
139
  }
140
141
  /**
142
   * Provides a map with all delegates descriptors for the given target, keyed
143
   * by their ID.
144
   * 
145
   * @param targetID
146
   *          the target (delegating) validator id. Must not be null.
147
   * @return a Map <string, ValidatorDelegateDescriptor>. May be null if the ID
148
   *         passed in is not a delegating validator.
149
   */
150
  public Map getDelegateDescriptors(String targetID)
151
  {
152
    return (Map) delegatesByTarget.get(targetID);
153
  }
154
155
  /**
156
   * Finds a delegate descriptor based on the target id and delegate id.
157
   * 
158
   * @param targetID
159
   *          the delegating validator's id
160
   * @param delegateID
161
   *          the delegate id
162
   * @return a ValidatorDelegateDescriptor for the given target and id or null
163
   *         if one cannot be found.
164
   */
165
  public ValidatorDelegateDescriptor getDescriptor(String targetID, String delegateID)
166
  {
167
    Map delegates = (Map) delegatesByTarget.get(targetID);
168
169
    if (delegates == null)
170
    {
171
      // No delegates registered for this target.
172
173
      return null;
174
    }
175
176
    if (delegateID == null)
177
    {
178
      return null;
179
    }
180
    
181
    ValidatorDelegateDescriptor descriptor = (ValidatorDelegateDescriptor) delegates.get(delegateID);
182
183
    return descriptor;
184
  }
185
186
  /**
187
   * Determines if a given validator has delegates.
188
   * 
189
   * @param targetID
190
   *          the target validator id.
191
   * @return true if the target has registered delegates, false otherwise.
192
   */
193
  public boolean hasDelegates(String targetID)
194
  {
195
    Map delegatesByID = (Map) delegatesByTarget.get(targetID);
196
197
    boolean hasDelegates = (delegatesByID != null && !delegatesByID.isEmpty());
198
    return hasDelegates;
199
  }
200
}

Return to bug 132228