Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » databinding validates on initial dialog display
databinding validates on initial dialog display [message #467223] Tue, 01 May 2007 15:55 Go to next message
Eclipse UserFriend
Originally posted by: slorenc.infogix.com

I downloaded the 04/30/2007 intergration build in order to get around a bug
in ValueBinding class present in 3.3.M6 implementation of SWT databinding.
I'm using databinding to validate a few controls on a dialog. Below is a
snippet initializing databinding. I have an errorLabel control which
displays the current error taken from the status object returned by
validators. This works OK.

However, I would like the databinding NOT to validate when initially
displaying the dialog because I expect users to enter some fields which are
initially empty. For example the name field is initially empty as well as a
location field (path to a file).

My question is.

Is there a way to tell databinding to not perform checking when transferring
from model (my data values) to target (my controls) intially?

Thanks,

Swavek

private void bindData () {

bindingContext = new DataBindingContext();

IValidator sourceNameValidator = new IValidator () {


public IStatus validate(Object value) {

IStatus status = Status.OK_STATUS;

if (value != null && ((String)value).length () == 0) {

status = ValidationStatus.error ("Name cannot be empty");

} else if (((String)value).startsWith("_")) {

status = ValidationStatus.error ("Name must start with a letter");

}

return status;

}

};

bindingContext.bindValue(SWTObservables.observeText(nameFiel d,

SWT.Modify), BeansObservables.observeValue(this, "nameValue"),

new UpdateValueStrategy().setAfterConvertValidator(sourceNameVal idator),

new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));


IValidator fileExistsValidator = new IValidator () {


public IStatus validate(Object value) {

IStatus status = Status.OK_STATUS;

if (value != null && ((String)value).length () > 0) {

File fileExists = new File((String) value);

if (!fileExists.exists()) {

status = ValidationStatus.error ("Can't find specified Excel file");

} else if (!fileExists.getAbsolutePath().endsWith(".xls")) {

status = ValidationStatus.error ("Specified file must be .xls file");

}

} else {

status = ValidationStatus.error ("Excel file location must be specified");

}

return status;

}


};

bindingContext.bindValue(SWTObservables.observeText(location Field,

SWT.Modify), BeansObservables.observeValue(this, "locationValue"),

new UpdateValueStrategy().setAfterConvertValidator(fileExistsVal idator),

new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));


// Bind the error label to the validation error on the context.

bindingContext.bindValue(SWTObservables.observeText(errorMes sage),

new AggregateValidationStatus(bindingContext.getBindings(),

AggregateValidationStatus.MAX_SEVERITY), null,

null);

}
Re: databinding validates on initial dialog display [message #467252 is a reply to message #467223] Wed, 02 May 2007 06:55 Go to previous message
Marko Topolnik is currently offline Marko TopolnikFriend
Messages: 42
Registered: July 2009
Member
In my project I use validators that always pass for empty strings and
have a separate mechanism to verify that all mandatory fields are filled
in. I think it is more user-friendly to treat the case of empty field
differently from the case of an invalid field.

P.S. You should post databinding-related stuff to eclipse.platform and
prefix the subject with [Databinding].

Marko Topolnik, Ph.D.
CROZ d.o.o.
mtopolnik@croz.net


Swavek Lorenc wrote:
> I downloaded the 04/30/2007 intergration build in order to get around a bug
> in ValueBinding class present in 3.3.M6 implementation of SWT databinding.
> I'm using databinding to validate a few controls on a dialog. Below is a
> snippet initializing databinding. I have an errorLabel control which
> displays the current error taken from the status object returned by
> validators. This works OK.
>
> However, I would like the databinding NOT to validate when initially
> displaying the dialog because I expect users to enter some fields which are
> initially empty. For example the name field is initially empty as well as a
> location field (path to a file).
>
> My question is.
>
> Is there a way to tell databinding to not perform checking when transferring
> from model (my data values) to target (my controls) intially?
>
> Thanks,
>
> Swavek
>
> private void bindData () {
>
> bindingContext = new DataBindingContext();
>
> IValidator sourceNameValidator = new IValidator () {
>
>
> public IStatus validate(Object value) {
>
> IStatus status = Status.OK_STATUS;
>
> if (value != null && ((String)value).length () == 0) {
>
> status = ValidationStatus.error ("Name cannot be empty");
>
> } else if (((String)value).startsWith("_")) {
>
> status = ValidationStatus.error ("Name must start with a letter");
>
> }
>
> return status;
>
> }
>
> };
>
> bindingContext.bindValue(SWTObservables.observeText(nameFiel d,
>
> SWT.Modify), BeansObservables.observeValue(this, "nameValue"),
>
> new UpdateValueStrategy().setAfterConvertValidator(sourceNameVal idator),
>
> new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
>
>
> IValidator fileExistsValidator = new IValidator () {
>
>
> public IStatus validate(Object value) {
>
> IStatus status = Status.OK_STATUS;
>
> if (value != null && ((String)value).length () > 0) {
>
> File fileExists = new File((String) value);
>
> if (!fileExists.exists()) {
>
> status = ValidationStatus.error ("Can't find specified Excel file");
>
> } else if (!fileExists.getAbsolutePath().endsWith(".xls")) {
>
> status = ValidationStatus.error ("Specified file must be .xls file");
>
> }
>
> } else {
>
> status = ValidationStatus.error ("Excel file location must be specified");
>
> }
>
> return status;
>
> }
>
>
> };
>
> bindingContext.bindValue(SWTObservables.observeText(location Field,
>
> SWT.Modify), BeansObservables.observeValue(this, "locationValue"),
>
> new UpdateValueStrategy().setAfterConvertValidator(fileExistsVal idator),
>
> new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
>
>
> // Bind the error label to the validation error on the context.
>
> bindingContext.bindValue(SWTObservables.observeText(errorMes sage),
>
> new AggregateValidationStatus(bindingContext.getBindings(),
>
> AggregateValidationStatus.MAX_SEVERITY), null,
>
> null);
>
> }
>
>
Previous Topic:Field Editors layout problem
Next Topic:Adding a jar to an RCP application
Goto Forum:
  


Current Time: Fri Apr 26 09:53:58 GMT 2024

Powered by FUDForum. Page generated in 0.03474 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top