Class UpdateValueStrategy<S,​D>

    • Field Detail

      • POLICY_NEVER

        public static int POLICY_NEVER
        Policy constant denoting that the source observable's state should not be tracked and that the destination observable's value should never be updated.
      • POLICY_ON_REQUEST

        public static int POLICY_ON_REQUEST
        Policy constant denoting that the source observable's state should not be tracked, but that validation, conversion and updating the destination observable's value should be performed when explicitly requested.
      • POLICY_CONVERT

        public static int POLICY_CONVERT
        Policy constant denoting that the source observable's state should be tracked, including validating changes except for validateBeforeSet(Object), but that the destination observable's value should only be updated on request.
      • POLICY_UPDATE

        public static int POLICY_UPDATE
        Policy constant denoting that the source observable's state should be tracked, and that validation, conversion and updating the destination observable's value should be performed automatically on every change of the source observable value.
      • afterGetValidator

        protected IValidator<? super S> afterGetValidator
      • afterConvertValidator

        protected IValidator<? super D> afterConvertValidator
      • beforeSetValidator

        protected IValidator<? super D> beforeSetValidator
      • provideDefaults

        protected boolean provideDefaults
      • converter

        protected IConverter<? super S,​? extends D> converter
    • Constructor Detail

      • UpdateValueStrategy

        public UpdateValueStrategy()
        Creates a new update value strategy for automatically updating the destination observable value whenever the source observable value changes. Default validators and a default converter will be provided. The defaults can be changed by calling one of the setter methods.
      • UpdateValueStrategy

        public UpdateValueStrategy​(int updatePolicy)
        Creates a new update value strategy with a configurable update policy. Default validators and a default converter will be provided. The defaults can be changed by calling one of the setter methods.
        Parameters:
        updatePolicy - one of POLICY_NEVER, POLICY_ON_REQUEST, POLICY_CONVERT, or POLICY_UPDATE
      • UpdateValueStrategy

        public UpdateValueStrategy​(boolean provideDefaults,
                                   int updatePolicy)
        Creates a new update value strategy with a configurable update policy. Default validators and a default converter will be provided if provideDefaults is true. The defaults can be changed by calling one of the setter methods.
        Parameters:
        provideDefaults - if true, default validators and a default converter will be provided based on the observable value's type.
        updatePolicy - one of POLICY_NEVER, POLICY_ON_REQUEST, POLICY_CONVERT, or POLICY_UPDATE
    • Method Detail

      • createValidator

        protected IValidator<S> createValidator​(Object fromType,
                                                Object toType)
        Tries to create a validator that can validate values of type fromType. Returns null if no validator could be created. Either toType or modelDescription can be null, but not both.
        Parameters:
        fromType -
        toType -
        Returns:
        an IValidator, or null if unsuccessful
      • fillDefaults

        protected void fillDefaults​(IObservableValue<? extends S> source,
                                    IObservableValue<? super D> destination)
        Fills out default values based upon the provided source and destination. If the strategy is to default values it will attempt to default a converter. If the converter can be defaulted an attempt is made to default the after get validator. If a validator cannot be defaulted it will be null.
        Parameters:
        source -
        destination -
      • getUpdatePolicy

        public int getUpdatePolicy()
        Returns:
        the update policy
      • setAfterConvertValidator

        public UpdateValueStrategy<S,​D> setAfterConvertValidator​(IValidator<? super D> validator)
        Sets the validator to be invoked after the source value is converted to the type of the destination observable.
        Parameters:
        validator -
        Returns:
        the receiver, to enable method call chaining
      • setAfterGetValidator

        public UpdateValueStrategy<S,​D> setAfterGetValidator​(IValidator<? super S> validator)
        Sets the validator to be invoked after the source value is retrieved at the beginning of the synchronization process.
        Parameters:
        validator -
        Returns:
        the receiver, to enable method call chaining
      • setBeforeSetValidator

        public UpdateValueStrategy<S,​D> setBeforeSetValidator​(IValidator<? super D> validator)
        Sets the validator to be invoked before the value is to be set on the destination at the end of the synchronization process.
        Parameters:
        validator -
        Returns:
        the receiver, to enable method call chaining
      • setConverter

        public UpdateValueStrategy<S,​D> setConverter​(IConverter<? super S,​? extends D> converter)
        Sets the converter to be invoked when converting from the source type to the destination type.
        Parameters:
        converter -
        Returns:
        the receiver, to enable method call chaining
      • validateAfterConvert

        public IStatus validateAfterConvert​(D value)
        Validates the value after it is converted.

        Default implementation will use the validator if one exists. If one does not exist no validation will occur.

        Parameters:
        value -
        Returns:
        an ok status
      • validateAfterGet

        public IStatus validateAfterGet​(S value)
        Validates the value after it is retrieved from the source.

        Default implementation will use the validator if one exists. If one does not exist no validation will occur.

        Parameters:
        value -
        Returns:
        an ok status
      • validateBeforeSet

        public IStatus validateBeforeSet​(D value)
        Validates the value before it is set on the destination.

        Default implementation will use the validator if one exists. If one does not exist no validation will occur.

        Parameters:
        value -
        Returns:
        an ok status
      • doSet

        protected IStatus doSet​(IObservableValue<? super D> observableValue,
                                D value)
        Sets the current value of the given observable to the given value. Clients may extend but must call the super implementation.
        Parameters:
        observableValue -
        value -
        Returns:
        status
      • checkAssignable

        protected final void checkAssignable​(Object toType,
                                             Object fromType,
                                             String errorString)
      • createConverter

        protected IConverter<?,​?> createConverter​(Object fromType,
                                                        Object toType)
        Tries to create a converter that can convert from values of type fromType. Returns null if no converter could be created. Either toType or modelDescription can be null, but not both.
        Parameters:
        fromType -
        toType -
        Returns:
        an IConverter, or null if unsuccessful
      • isAssignableFromTo

        protected Boolean isAssignableFromTo​(Object fromType,
                                             Object toType)
        Returns Boolean.TRUE if the from type is assignable to the to type, or Boolean.FALSE if it not, or null if unknown.
        Parameters:
        fromType -
        toType -
        Returns:
        whether fromType is assignable to toType, or null if unknown
      • logErrorWhileSettingValue

        protected IStatus logErrorWhileSettingValue​(Exception ex)
        Parameters:
        ex - the exception, that was caught
        Returns:
        the validation status
      • convert

        public D convert​(S value)
        Converts the value from the source type to the destination type.

        Default implementation will use the setConverter(IConverter), if one exists. If no converter exists no conversion occurs.

        Parameters:
        value -
        Returns:
        the converted value