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

(-)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/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.
(-)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.ValidationRegistryReader;
21
import org.eclipse.wst.validation.internal.ValidatorMetaData;
22
import org.eclipse.wst.validation.internal.core.ValidationException;
23
import org.eclipse.wst.validation.internal.operations.LocalizedMessage;
24
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
25
import org.eclipse.wst.validation.internal.provisional.core.IProjectValidationContext;
26
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
27
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
28
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
29
30
/**
31
 * This class is to be used as a base class by clients who want to provide
32
 * alternate validator implementations for a given validator type.
33
 * 
34
 * It locates the currently configured delegate for this validator and calls its
35
 * validate method.
36
 * 
37
 * @see IValidator
38
 * @see IDelegatingValidator
39
 * 
40
 * <p>
41
 * <b>Note:</b> This class/interface is part of an interim API that is still
42
 * under development and expected to change significantly before reaching
43
 * stability. It is being made available at this early stage to solicit feedback
44
 * from pioneering adopters on the understanding that any code that uses this
45
 * API will almost certainly be broken (repeatedly) as the API evolves.
46
 * </p>
47
 */
48
public class DelegatingValidator implements IDelegatingValidator
49
{
50
  /**
51
   * Default constructor.
52
   */
53
  public DelegatingValidator()
54
  {
55
  }
56
57
  /*
58
   * (non-Javadoc)
59
   * 
60
   * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#cleanup(org.eclipse.wst.validation.internal.provisional.core.IReporter)
61
   */
62
  public void cleanup(IReporter reporter)
63
  {
64
    // [Issue] This method does not get passed the validation context. How are
65
    // going
66
    // to know what is the delegate in order to invoke its cleanup method?
67
  }
68
69
  /*
70
   * (non-Javadoc)
71
   * 
72
   * @see org.eclipse.wst.validation.internal.provisional.core.IValidator#validate(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
73
   *      org.eclipse.wst.validation.internal.provisional.core.IReporter)
74
   */
75
  public void validate(IValidationContext helper, IReporter reporter) throws ValidationException
76
  {
77
    // We need to ensure that the context is an IProjectValidationContext. The
78
    // limitation of using an IValidationContext is that it does not readily
79
    // provide the project the validator is being invoked upon.
80
81
    if (!(helper instanceof IProjectValidationContext))
82
    {
83
      // [Issue] Since this message goes to the user, do we need a less
84
      // technical message text? Maybe we should log instead and send a
85
      // generic message to the user.
86
      throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, "The validation context is not an IProjectValidationContext."));
87
    }
88
89
    IProjectValidationContext projectContext = (IProjectValidationContext) helper;
90
    IProject project = projectContext.getProject();
91
92
    ValidatorDelegateDescriptor delegateDescriptor = null;
93
94
    try
95
    {
96
      ProjectConfiguration projectConfig = ConfigurationManager.getManager().getProjectConfiguration(project);
97
98
      if (projectConfig == null)
99
      {
100
        throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, "Unable to read the project validation configuration."));
101
      }
102
103
      ValidatorMetaData vmd = ValidationRegistryReader.getReader().getValidatorMetaData(this);
104
105
      delegateDescriptor = projectConfig.getDelegateDescriptor(vmd);
106
    }
107
    catch (InvocationTargetException e)
108
    {
109
      throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, "Error retrieving the project validation configuration."));
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 (+129 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.provisional.core.IValidator;
17
18
/**
19
 * ValidatorDelegateDescriptor stores information about a delegate validator.
20
 * 
21
 * It is also used to store the instance of the validator it describes. To
22
 * obtain the instance call getValidator().
23
 */
24
public class ValidatorDelegateDescriptor
25
{
26
  /**
27
   * The instance of the validator refered to by this descriptor.
28
   */
29
  private IValidator delegate;
30
31
  /**
32
   * The platform configuration element describing this delegate.
33
   */
34
  private IConfigurationElement delegateConfiguration;
35
36
  /**
37
   * The delegating validator's ID.
38
   */
39
  private String delegatingValidatorID;
40
41
  /**
42
   * The delegate's ID.
43
   */
44
  private String id;
45
46
  /**
47
   * The delegate's display name.
48
   */
49
  private String name;
50
51
  /**
52
   * Constructs a descriptor.
53
   * 
54
   * @param id
55
   *          the delegate's uniques id. Must be unique in the context of a
56
   *          delegating validator.
57
   * @param delegateConfiguration
58
   *          the delegates configuration element
59
   * @param delegateName
60
   *          the delegate's display name.
61
   * @param targetValidatorID
62
   *          the target validator's unique id.
63
   */
64
  public ValidatorDelegateDescriptor(String id, IConfigurationElement delegateConfiguration, String delegateName, String targetValidatorID)
65
  {
66
    this.id = id;
67
    this.delegateConfiguration = delegateConfiguration;
68
    this.name = delegateName;
69
    this.delegatingValidatorID = targetValidatorID;
70
  }
71
72
  /**
73
   * Provides the delegate's ID.
74
   * 
75
   * @return a string with the fully qualified class name of this validator
76
   *         implementation.
77
   */
78
  public String getId()
79
  {
80
    return id;
81
  }
82
83
  /**
84
   * Provides the delegate's name.
85
   * 
86
   * @return a String with the validator's display name.
87
   */
88
  public String getName()
89
  {
90
    return name;
91
  }
92
93
  /**
94
   * Retrieves the target validator's ID.
95
   * 
96
   * @return a String with the fully qualified class name of the delegating
97
   *         validator who will delegate its implementation to the validator
98
   *         described by this descriptor.
99
   */
100
  public String getTargetID()
101
  {
102
    return delegatingValidatorID;
103
  }
104
105
  /**
106
   * Provides the instance of the validator delegate pointed to by this
107
   * descriptor.
108
   * 
109
   * @return an IValidator instance.
110
   */
111
  public IValidator getValidator()
112
  {
113
    if (delegate != null)
114
    {
115
      return delegate;
116
    }
117
118
    try
119
    {
120
      delegate = (IValidator) delegateConfiguration.createExecutableExtension(ValidatorDelegatesRegistryReader.CLASS_ATTRIBUTE);
121
    }
122
    catch (CoreException e)
123
    {
124
      e.printStackTrace();
125
    }
126
127
    return delegate;
128
  }
129
}
(-)validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java (+194 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.provisional.core.IValidator;
19
20
/**
21
 * ValidatorDelegatesRegistry is a singleton used to store validator delegate
22
 * descriptors for each delegating validator.
23
 */
24
public class ValidatorDelegatesRegistry
25
{
26
  /**
27
   * The one and only instance of this registry.
28
   */
29
  private static ValidatorDelegatesRegistry instance;
30
31
  /**
32
   * Provides the one and only instance of this class.
33
   * 
34
   * The actual platform extension registry reading happens at this time.
35
   * 
36
   * @see ValidatorDelegatesRegistryReader
37
   * 
38
   * @return the validator delegates registry singleton instance.
39
   */
40
  public static ValidatorDelegatesRegistry getInstance()
41
  {
42
    if (instance == null)
43
    {
44
      instance = new ValidatorDelegatesRegistry();
45
46
      ValidatorDelegatesRegistryReader reader = new ValidatorDelegatesRegistryReader(instance);
47
      reader.readRegistry();
48
    }
49
50
    return instance;
51
  }
52
53
  /**
54
   * The map of target validator id to Map of delegates by id.
55
   */
56
  private Map delegatesByTarget = new HashMap();
57
58
  /**
59
   * Adds a descriptor to the registry.
60
   * 
61
   * @param descriptor
62
   *          the descriptor to add. Must not be null.
63
   */
64
  void add(ValidatorDelegateDescriptor descriptor)
65
  {
66
    if (descriptor == null)
67
    {
68
      return;
69
    }
70
71
    String targetID = descriptor.getTargetID();
72
73
    Map delegates = (Map) delegatesByTarget.get(targetID);
74
75
    if (delegates == null)
76
    {
77
      delegates = new HashMap();
78
      delegatesByTarget.put(targetID, delegates);
79
    }
80
81
    delegates.put(descriptor.getId(), descriptor);
82
  }
83
84
  /**
85
   * Provides the default delegate ID for the given delegating validator ID.
86
   * 
87
   * @param targetID
88
   *          the delegating validator's ID.
89
   * @return a String with the ID of the default delegate.
90
   */
91
  public String getDefaultDelegate(String targetID)
92
  {
93
    Map delegates = getDelegateDescriptors(targetID);
94
95
    if (delegates == null)
96
    {
97
      return null;
98
    }
99
100
    // TODO: Implement a default attribute and use that to get the default?
101
    // What happens if two or more delegates claim to be the default one?
102
    // For now, just pick the first one in the list.
103
104
    Iterator delegatesIterator = delegates.values().iterator();
105
106
    if (!delegatesIterator.hasNext())
107
    {
108
      return null;
109
    }
110
111
    ValidatorDelegateDescriptor descriptor = (ValidatorDelegateDescriptor) delegatesIterator.next();
112
113
    return descriptor.getId();
114
  }
115
116
  /**
117
   * Retrieves a delegate instance based on the target and delegate IDs.
118
   * 
119
   * @param targetID
120
   *          the delegating validator's ID.
121
   * @param delegateID
122
   *          the delegate validator's ID.
123
   * @return an instance of the delegate validator or null if one cannot be
124
   *         found.
125
   */
126
  public IValidator getDelegate(String targetID, String delegateID)
127
  {
128
    ValidatorDelegateDescriptor descriptor = getDescriptor(targetID, delegateID);
129
130
    if (descriptor == null)
131
    {
132
      return null;
133
    }
134
135
    IValidator delegate = descriptor.getValidator();
136
137
    return delegate;
138
  }
139
140
  /**
141
   * Provides a map with all delegates descriptors for the given target, keyed
142
   * by their ID.
143
   * 
144
   * @param targetID
145
   *          the target (delegating) validator id. Must not be null.
146
   * @return a Map <string, ValidatorDelegateDescriptor>. May be null if the ID
147
   *         passed in is not a delegating validator.
148
   */
149
  public Map getDelegateDescriptors(String targetID)
150
  {
151
    return (Map) delegatesByTarget.get(targetID);
152
  }
153
154
  /**
155
   * Finds a delegate descriptor based on the target id and delegate id.
156
   * 
157
   * @param targetID
158
   *          the delegating validator's id
159
   * @param delegateID
160
   *          the delegate id
161
   * @return a ValidatorDelegateDescriptor for the given target and id or null
162
   *         if one cannot be found.
163
   */
164
  public ValidatorDelegateDescriptor getDescriptor(String targetID, String delegateID)
165
  {
166
    Map delegates = (Map) delegatesByTarget.get(targetID);
167
168
    if (delegates == null)
169
    {
170
      // No delegates registered for this target.
171
172
      return null;
173
    }
174
175
    ValidatorDelegateDescriptor descriptor = (ValidatorDelegateDescriptor) delegates.get(delegateID);
176
177
    return descriptor;
178
  }
179
180
  /**
181
   * Determines if a given validator has delegates.
182
   * 
183
   * @param targetID
184
   *          the target validator id.
185
   * @return true if the target has registered delegates, false otherwise.
186
   */
187
  public boolean hasDelegates(String targetID)
188
  {
189
    Map delegatesByID = (Map) delegatesByTarget.get(targetID);
190
191
    boolean hasDelegates = (delegatesByID != null);
192
    return hasDelegates;
193
  }
194
}
(-)validateui/org/eclipse/wst/validation/internal/ui/ValidationPreferencePage.java (-9 / +73 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 57-63 Link Here
57
import org.eclipse.wst.validation.internal.GlobalConfiguration;
62
import org.eclipse.wst.validation.internal.GlobalConfiguration;
58
import org.eclipse.wst.validation.internal.ProjectConfiguration;
63
import org.eclipse.wst.validation.internal.ProjectConfiguration;
59
import org.eclipse.wst.validation.internal.ValidatorMetaData;
64
import org.eclipse.wst.validation.internal.ValidatorMetaData;
65
import org.eclipse.wst.validation.internal.delegates.IDelegatingValidator;
60
import org.eclipse.wst.validation.internal.operations.ValidatorManager;
66
import org.eclipse.wst.validation.internal.operations.ValidatorManager;
67
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
61
import org.eclipse.wst.validation.internal.ui.plugin.ValidationUIPlugin;
68
import org.eclipse.wst.validation.internal.ui.plugin.ValidationUIPlugin;
62
69
63
/**
70
/**
Lines 250-255 Link Here
250
	// order to access this field)
257
	// order to access this field)
251
	//private boolean _isAutoBuildEnabled; // initialized in the constructor
258
	//private boolean _isAutoBuildEnabled; // initialized in the constructor
252
	private ValidatorMetaData[] _oldVmd = null; // Cache the enabled validators so that, if
259
	private ValidatorMetaData[] _oldVmd = null; // Cache the enabled validators so that, if
260
  private Map _oldDelegates = null; // Cache the validator delegates.
253
	// there is no change to this list, the
261
	// there is no change to this list, the
254
	// expensive task list update can be avoided
262
	// expensive task list update can be avoided
255
	private boolean _allow = false; // Cache the value of the prefence "allow projects to
263
	private boolean _allow = false; // Cache the value of the prefence "allow projects to
Lines 336-351 Link Here
336
			}
344
			}
337
		}
345
		}
338
346
347
    private Image getImage(String imageName) {
348
      boolean isDisabled = !validatorsTable.isEnabled();
349
      if (isDisabled) {
350
          imageName = imageName + "_disabled";  //$NON-NLS-N$
351
      }
352
      Image image = ValidationUIPlugin.getPlugin().getImage(imageName);
353
      return image;
354
    }
355
    
339
		public Image getColumnImage(Object element, int columnIndex) {
356
		public Image getColumnImage(Object element, int columnIndex) {
340
			if(columnIndex == 1) {
357
			if(columnIndex == 1) {
341
				if(((ValidatorMetaData)element).isManualValidation())
358
				if(((ValidatorMetaData)element).isManualValidation())
342
					return  ValidationUIPlugin.getPlugin().getImage("ok_tbl");
359
					return  getImage("ok_tbl");
343
				return ValidationUIPlugin.getPlugin().getImage("fail_tbl");
360
				return getImage("fail_tbl");
344
			} else if(columnIndex == 2) {
361
			} 
362
      else if(columnIndex == 2) {
345
				if(((ValidatorMetaData)element).isBuildValidation())
363
				if(((ValidatorMetaData)element).isBuildValidation())
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
			}
366
			}
367
      else if (columnIndex == 3)
368
      {
369
        ValidatorMetaData vmd = (ValidatorMetaData)element;
370
        IValidator validator = null;
371
        try
372
        {
373
          validator = vmd.getValidator();
374
        }
375
        catch (InstantiationException e)
376
        {
377
          e.printStackTrace();
378
        }
379
        if (validator instanceof IDelegatingValidator)
380
        {
381
          return getImage("settings");          
382
        }
383
      }
349
			return null;
384
			return null;
350
		
385
		
351
		}
386
		}
Lines 409-415 Link Here
409
		// that, if there is no change to this
444
		// that, if there is no change to this
410
		// list, the expensive task list
445
		// list, the expensive task list
411
		// update can be avoided
446
		// update can be avoided
412
		_allow = pagePreferences.canProjectsOverride();
447
448
    _oldDelegates =  new HashMap(pagePreferences.getDelegatingValidators());
449
		
450
    _allow = pagePreferences.canProjectsOverride();
413
451
414
		page = createPage(parent);
452
		page = createPage(parent);
415
	}
453
	}
Lines 427-432 Link Here
427
        buildColumn.setText("Build");
465
        buildColumn.setText("Build");
428
        buildColumn.setResizable(false);
466
        buildColumn.setResizable(false);
429
        buildColumn.setWidth(30);
467
        buildColumn.setWidth(30);
468
        TableColumn settingsColumn = new TableColumn(table, SWT.NONE);
469
        settingsColumn.setText("Settings");
470
        settingsColumn.setResizable(false);
471
        settingsColumn.setWidth(40);
430
    }
472
    }
431
	
473
	
432
	public Composite createPage(Composite parent) throws InvocationTargetException {
474
	public Composite createPage(Composite parent) throws InvocationTargetException {
Lines 484-489 Link Here
484
				validatorsTable.setEnabled(!disableAllValidation.getSelection());
526
				validatorsTable.setEnabled(!disableAllValidation.getSelection());
485
				enableAllButton.setEnabled(!disableAllValidation.getSelection());
527
				enableAllButton.setEnabled(!disableAllValidation.getSelection());
486
				disableAllButton.setEnabled(!disableAllValidation.getSelection());
528
				disableAllButton.setEnabled(!disableAllValidation.getSelection());
529
        validatorList.refresh();
487
			}
530
			}
488
		});
531
		});
489
		
532
		
Lines 499-506 Link Here
499
		validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
542
		validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
500
		TableLayout tableLayout = new TableLayout();
543
		TableLayout tableLayout = new TableLayout();
501
		tableLayout.addColumnData(new ColumnWeightData(160, true));
544
		tableLayout.addColumnData(new ColumnWeightData(160, true));
502
        tableLayout.addColumnData(new ColumnWeightData(40, true));
545
    tableLayout.addColumnData(new ColumnWeightData(40, true));
503
        tableLayout.addColumnData(new ColumnWeightData(30, true));
546
    tableLayout.addColumnData(new ColumnWeightData(30, true));
547
    tableLayout.addColumnData(new ColumnWeightData(40, true));
548
    
504
		validatorsTable.setHeaderVisible(true);
549
		validatorsTable.setHeaderVisible(true);
505
		validatorsTable.setLinesVisible(true);
550
		validatorsTable.setLinesVisible(true);
506
        validatorsTable.setLayout(tableLayout);
551
        validatorsTable.setLayout(tableLayout);
Lines 613-618 Link Here
613
    case 2:
658
    case 2:
614
      vmd.setBuildValidation(!vmd.isBuildValidation());
659
      vmd.setBuildValidation(!vmd.isBuildValidation());
615
      break;
660
      break;
661
    case 3:
662
      {
663
        String delegateID = pagePreferences.getDelegateUniqueName(vmd);
664
  
665
        Shell shell = Display.getCurrent().getActiveShell();
666
        DelegatingValidatorPreferencesDialog dialog = new DelegatingValidatorPreferencesDialog(shell, vmd, delegateID);
667
  
668
        dialog.setBlockOnOpen(true);
669
        dialog.create();
670
  
671
        int result = dialog.open();
672
  
673
        if (result == Window.OK)
674
        {
675
          pagePreferences.setDelegateUniqueName(vmd, dialog.getDelegateID());
676
        }
677
      }
678
      break;
616
    default:
679
    default:
617
      break;
680
      break;
618
    }
681
    }
Lines 840-846 Link Here
840
			try {
903
			try {
841
				if (project.isOpen()) {
904
				if (project.isOpen()) {
842
					ProjectConfiguration prjp = ConfigurationManager.getManager().getProjectConfiguration(project);
905
					ProjectConfiguration prjp = ConfigurationManager.getManager().getProjectConfiguration(project);
843
					if (!prjp.doesProjectOverride() && (prjp.hasEnabledValidatorsChanged(_oldVmd, allowChanged) || true)) {
906
					if (!prjp.doesProjectOverride() && (prjp.hasEnabledValidatorsChanged(_oldVmd, allowChanged) || true) && 
907
              (prjp.haveDelegatesChanged(_oldDelegates, allowChanged) || true)) {
844
						// If the project used to override the preferences, and the preferences
908
						// If the project used to override the preferences, and the preferences
845
						// make that impossible now, then update the task list.
909
						// make that impossible now, then update the task list.
846
						//
910
						//
(-)validateui/org/eclipse/wst/validation/internal/ui/ValidationPropertiesPage.java (-12 / +78 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
          IValidator validator = null;
375
          try
376
          {
377
            validator = vmd.getValidator();
378
          }
379
          catch (InstantiationException e)
380
          {
381
            e.printStackTrace();
382
          }
383
          if (validator instanceof IDelegatingValidator)
384
          {
385
            return getImage("settings");          
386
          }
387
        }
353
				return null;
388
				return null;
354
			
355
			}
389
			}
356
		}
390
		}
357
391
Lines 401-409 Link Here
401
			//isAutoBuildEnabled = vMgr.isGlobalAutoBuildEnabled();
435
			//isAutoBuildEnabled = vMgr.isGlobalAutoBuildEnabled();
402
			//isBuilderConfigured = ValidatorManager.doesProjectSupportBuildValidation(getProject());
436
			//isBuilderConfigured = ValidatorManager.doesProjectSupportBuildValidation(getProject());
403
			oldVmd = pagePreferences.getEnabledValidators(); // Cache the enabled validators so
437
			oldVmd = pagePreferences.getEnabledValidators(); // Cache the enabled validators so
404
			// that, if there is no change to this
438
      // that, if there is no change to this
405
			// list, the expensive task list update
439
      // list, the expensive task list update
406
			// can be avoided
440
      // can be avoided
441
442
      oldDelegates =  new HashMap(pagePreferences.getDelegatingValidators());
407
443
408
			createPage(parent);
444
			createPage(parent);
409
		}
445
		}
Lines 421-426 Link Here
421
	        buildColumn.setText("Build");
457
	        buildColumn.setText("Build");
422
	        buildColumn.setResizable(false);
458
	        buildColumn.setResizable(false);
423
	        buildColumn.setWidth(30);
459
	        buildColumn.setWidth(30);
460
          TableColumn settingsColumn = new TableColumn(table, SWT.NONE);
461
          settingsColumn.setText("Settings");
462
          settingsColumn.setResizable(false);
463
          settingsColumn.setWidth(40);
424
	    }
464
	    }
425
465
426
		/**
466
		/**
Lines 506-511 Link Here
506
					validatorsTable.setEnabled(!disableAllValidation.getSelection());
546
					validatorsTable.setEnabled(!disableAllValidation.getSelection());
507
					enableAllButton.setEnabled(!disableAllValidation.getSelection());
547
					enableAllButton.setEnabled(!disableAllValidation.getSelection());
508
					disableAllButton.setEnabled(!disableAllValidation.getSelection());
548
					disableAllButton.setEnabled(!disableAllValidation.getSelection());
549
          try {
550
            updateWidgets();
551
          } catch (InvocationTargetException exc) {
552
            displayAndLogError(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_INTERNAL_TITLE), ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_INTERNAL_PAGE), exc);
553
          }
509
				}
554
				}
510
			});
555
			});
511
			
556
			
Lines 523-530 Link Here
523
			validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
568
			validatorsTable = new Table(validatorGroup,SWT.BORDER | SWT.FULL_SELECTION);
524
			TableLayout tableLayout = new TableLayout();
569
			TableLayout tableLayout = new TableLayout();
525
			tableLayout.addColumnData(new ColumnWeightData(160, true));
570
			tableLayout.addColumnData(new ColumnWeightData(160, true));
526
	        tableLayout.addColumnData(new ColumnWeightData(40, true));
571
	    tableLayout.addColumnData(new ColumnWeightData(40, true));
527
	        tableLayout.addColumnData(new ColumnWeightData(30, true));
572
	    tableLayout.addColumnData(new ColumnWeightData(30, true));
573
      tableLayout.addColumnData(new ColumnWeightData(40, true));
528
			validatorsTable.setHeaderVisible(true);
574
			validatorsTable.setHeaderVisible(true);
529
			validatorsTable.setLinesVisible(true);
575
			validatorsTable.setLinesVisible(true);
530
	        validatorsTable.setLayout(tableLayout);
576
	        validatorsTable.setLayout(tableLayout);
Lines 756-761 Link Here
756
      case 2:
802
      case 2:
757
        vmd.setBuildValidation(!vmd.isBuildValidation());
803
        vmd.setBuildValidation(!vmd.isBuildValidation());
758
        break;
804
        break;
805
      case 3:
806
      {
807
        String delegateID = pagePreferences.getDelegateUniqueName(vmd);
808
  
809
        Shell shell = Display.getCurrent().getActiveShell();
810
        DelegatingValidatorPreferencesDialog dialog = new DelegatingValidatorPreferencesDialog(shell, vmd, delegateID);
811
  
812
        dialog.setBlockOnOpen(true);
813
        dialog.create();
814
  
815
        int result = dialog.open();
816
  
817
        if (result == Window.OK)
818
        {
819
          pagePreferences.setDelegateUniqueName(vmd, dialog.getDelegateID());
820
        }
821
      }
759
      default:
822
      default:
760
        break;
823
        break;
761
      }
824
      }
Lines 816-823 Link Here
816
		 */
879
		 */
817
		private void enableDependentControls(boolean overridePreferences) {
880
		private void enableDependentControls(boolean overridePreferences) {
818
			validatorsTable.setEnabled(overridePreferences);
881
			validatorsTable.setEnabled(overridePreferences);
882
      validatorList.refresh();
819
			enableAllButton.setEnabled(overridePreferences); // since help messsage isn't
883
			enableAllButton.setEnabled(overridePreferences); // since help messsage isn't
820
			disableAllButton.setEnabled(overridePreferences);
884
			disableAllButton.setEnabled(overridePreferences);
885
      
821
		}
886
		}
822
887
823
		protected void updateHelp() throws InvocationTargetException {
888
		protected void updateHelp() throws InvocationTargetException {
Lines 939-945 Link Here
939
			// Persist the values.
1004
			// Persist the values.
940
			storeValues();
1005
			storeValues();
941
1006
942
			if (pagePreferences.hasEnabledValidatorsChanged(oldVmd, false)) { 
1007
			if (pagePreferences.hasEnabledValidatorsChanged(oldVmd, false) ||
1008
          pagePreferences.haveDelegatesChanged(oldDelegates, false)) { 
943
				// false means that the preference "allow" value hasn't changed
1009
				// false means that the preference "allow" value hasn't changed
944
				ValidatorManager.getManager().updateTaskList(getProject()); 
1010
				ValidatorManager.getManager().updateTaskList(getProject()); 
945
			}
1011
			}
(-)validateui/org/eclipse/wst/validation/internal/ui/ResourceConstants.java (-1 / +5 lines)
Lines 61-66 Link Here
61
61
62
	public static final String VBF_UI_POPUP_RUNVALIDATION = "%VBF_UI_POPUP_RUNVALIDATION"; //$NON-NLS-1$
62
	public static final String VBF_UI_POPUP_RUNVALIDATION = "%VBF_UI_POPUP_RUNVALIDATION"; //$NON-NLS-1$
63
63
64
  /* package */static final String PREF_BUTTON_ADVANCED = "PREF_BUTTON_ADVANCED"; //$NON-NLS-1$
64
	/* package */static final String PREF_BUTTON_ENABLEALL = "PREF_BUTTON_ENABLEALL"; //$NON-NLS-1$
65
	/* package */static final String PREF_BUTTON_ENABLEALL = "PREF_BUTTON_ENABLEALL"; //$NON-NLS-1$
65
	/* package */static final String PREF_BUTTON_DISABLEALL = "PREF_BUTTON_DISABLEALL"; //$NON-NLS-1$
66
	/* package */static final String PREF_BUTTON_DISABLEALL = "PREF_BUTTON_DISABLEALL"; //$NON-NLS-1$
66
	/* package */static final String PREF_VALLIST_TITLE = "PREF_VALLIST_TITLE"; //$NON-NLS-1$
67
	/* package */static final String PREF_VALLIST_TITLE = "PREF_VALLIST_TITLE"; //$NON-NLS-1$
Lines 89-92 Link Here
89
	
90
	
90
	/* package */static final String DISABLE_VALIDATION = "DISABLE_VALIDATION"; //$NON-NLS-1$
91
	/* package */static final String DISABLE_VALIDATION = "DISABLE_VALIDATION"; //$NON-NLS-1$
91
	static final String INFO = "INFO"; //$NON-NLS-1$
92
	static final String INFO = "INFO"; //$NON-NLS-1$
92
}
93
  
94
  String DELEGATES_DIALOG_TITLE = "DELEGATES_DIALOG_TITLE"; //$NON-NLS-1$
95
  String DELEGATES_COMBO_LABEL = "DELEGATES_COMBO_LABEL"; //$NON-NLS-1$
96
 }
(-)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 (+260 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.Collection;
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
   * The selected validator delegate ID.
51
   */
52
  private String delegateID;
53
54
  /**
55
   * Constructs the dialog on the given shell.
56
   * 
57
   * @param parentShell
58
   *          the dialog's parent. Must not be null.
59
   * @param targetID
60
   *          the delegating validator's id
61
   * 
62
   * @param delegateID
63
   *          the ID of the currently selected validator delegate.
64
   */
65
  protected DelegatingValidatorPreferencesDialog(Shell parentShell, ValidatorMetaData vmd, String delegateID)
66
  {
67
    super(parentShell);
68
69
    delegatingValidatorDescriptor = vmd;
70
    this.delegateID = delegateID;
71
  }
72
73
  /*
74
   * (non-Javadoc)
75
   * 
76
   * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
77
   */
78
  protected Control createDialogArea(Composite parent)
79
  {
80
    super.createDialogArea(parent);
81
82
    getShell().setText(ResourceHandler.getExternalizedMessage(ResourceConstants.DELEGATES_DIALOG_TITLE));
83
84
    GridLayout layout = new GridLayout();
85
    parent.setLayout(layout);
86
87
    Label label = new Label(parent, SWT.NONE);
88
    GridData labelData = new GridData(SWT.FILL, SWT.CENTER, true, false);
89
    labelData.widthHint = 250;
90
    label.setLayoutData(labelData);
91
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.TEXT_FONT));
92
    String delegatingValidatorName = delegatingValidatorDescriptor.getValidatorDisplayName();
93
    label.setText(delegatingValidatorName);
94
95
    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
96
    GridData separatorData = new GridData(SWT.FILL, SWT.CENTER, true, false);
97
    separator.setLayoutData(separatorData);
98
99
    Composite group = new Composite(parent, SWT.NONE);
100
    GridData groupGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
101
    group.setLayoutData(groupGridData);
102
    GridLayout groupLayout = new GridLayout(2, false);
103
    group.setLayout(groupLayout);
104
105
    Label comboLabel = new Label(group, SWT.NONE);
106
    comboLabel.setLayoutData(new GridData());
107
    comboLabel.setText(ResourceHandler.getExternalizedMessage(ResourceConstants.DELEGATES_COMBO_LABEL));
108
    
109
    Combo combo = new Combo(group, SWT.NONE);
110
    GridData comboGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
111
    combo.setLayoutData(comboGridData);
112
113
    final ComboViewer comboViewer = new ComboViewer(combo);
114
    comboViewer.setContentProvider(new DelegatesContentProvider());
115
    comboViewer.setLabelProvider(new DelegatesLabelProvider());
116
    String targetID = delegatingValidatorDescriptor.getValidatorUniqueName();
117
118
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener()
119
    {
120
121
      public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
122
      {
123
        IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection();
124
        setDelegateID(((ValidatorDelegateDescriptor) selection.getFirstElement()).getId());
125
      }
126
    });
127
128
    comboViewer.setInput(targetID);
129
130
    ValidatorDelegateDescriptor selected = ValidatorDelegatesRegistry.getInstance().getDescriptor(targetID, delegateID);
131
132
    if (selected != null)
133
    {
134
      comboViewer.setSelection(new StructuredSelection(new Object[] { selected }));
135
    }
136
137
    Label endSeparator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
138
    GridData endSeparatorData = new GridData(SWT.FILL, SWT.CENTER, true, false); 
139
    endSeparator.setLayoutData(endSeparatorData);
140
    
141
    return parent;
142
  }
143
144
  /**
145
   * Provides contents for the delegate validators combo box.
146
   */
147
  private final class DelegatesContentProvider implements IStructuredContentProvider
148
  {
149
    public void dispose()
150
    {
151
    }
152
153
    /*
154
     * (non-Javadoc)
155
     * 
156
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
157
     */
158
    public Object[] getElements(Object inputElement)
159
    {
160
      String targetID = (String) inputElement;
161
      Collection delegates = ValidatorDelegatesRegistry.getInstance().getDelegateDescriptors(targetID).values();
162
      return delegates.toArray();
163
    }
164
165
    /*
166
     * (non-Javadoc)
167
     * 
168
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
169
     *      java.lang.Object, java.lang.Object)
170
     */
171
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
172
    {
173
    }
174
  }
175
176
  /**
177
   * Provides the labels/images for the delegate validator combo box
178
   * 
179
   * @author vbaciul
180
   * 
181
   */
182
  private final class DelegatesLabelProvider implements ILabelProvider
183
  {
184
    /*
185
     * (non-Javadoc)
186
     * 
187
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
188
     */
189
    public void addListener(ILabelProviderListener listener)
190
    {
191
    }
192
193
    /*
194
     * (non-Javadoc)
195
     * 
196
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
197
     */
198
    public void dispose()
199
    {
200
    }
201
202
    /*
203
     * (non-Javadoc)
204
     * 
205
     * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
206
     */
207
    public Image getImage(Object element)
208
    {
209
      return null;
210
    }
211
212
    /*
213
     * (non-Javadoc)
214
     * 
215
     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
216
     */
217
    public String getText(Object element)
218
    {
219
      return ((ValidatorDelegateDescriptor) element).getName();
220
    }
221
222
    /*
223
     * (non-Javadoc)
224
     * 
225
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
226
     *      java.lang.String)
227
     */
228
    public boolean isLabelProperty(Object element, String property)
229
    {
230
      return false;
231
    }
232
233
    /*
234
     * (non-Javadoc)
235
     * 
236
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
237
     */
238
    public void removeListener(ILabelProviderListener listener)
239
    {
240
    }
241
  }
242
243
  /*
244
   * Provides the ID of the currently selected validator delegate ID.
245
   */
246
  public String getDelegateID()
247
  {
248
    return delegateID;
249
  }
250
251
  /**
252
   * Sets the currently selected validator delegate ID.
253
   * 
254
   * @param delegateID
255
   */
256
  private void setDelegateID(String delegateID)
257
  {
258
    this.delegateID = delegateID;
259
  }
260
}

Return to bug 132228