Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Multivalidator fires validate method twice
Multivalidator fires validate method twice [message #892868] Sat, 30 June 2012 16:17 Go to next message
Roman Smushkevich is currently offline Roman Smushkevich
Messages: 4
Registered: June 2012
Junior Member
Hi everybody,

During programming investigations I met really uncomfortable behaviour of anonymous class descended from MultiValidator. Its validate method is fired twice every time the SWTWidget is changed.

Particularly I placed 2 DateTime widgets onto the form and assigned observablevalue to each of them. Afterwards I introduced an anonymous class descended from MultiValidator and used those 2 observable values to check constraints according to the shared examples.

So, after implementation I recognized the uncommon behaviour of my backed class. The valid method fires twice on each change of the date in any of the DateTime widgets . If I insert a call to JPA or whatever else, its behaviour could lead to a performance regression.

If I had made a mistake in a code snippet or if this is due to a bug in a JFace binding mechanism - let me know or please make a suggestion about such "misbehaviour".


DataBindingContext bindingContext = new DataBindingContext();
final IObservableValue getDishIDObserveValue = PojoObservables.observeValue(getDish(), "id");
//
final IObservableValue dteStartDateObserveSelectionObserveWidget = SWTObservables.observeSelection(dteStartDate);
final IObservableValue dteEndDateObserveSelectionObserveWidget = SWTObservables.observeSelection(dteEndDate);
//
MultiValidator dateValidator = new MultiValidator() {

@Override
protected IStatus validate() {
Integer id = (Integer)getDishIDObserveValue.getValue();
if (id == null)
id = -1;
Date startDate = (Date)dteStartDateObserveSelectionObserveWidget.getValue();
Date endDate = (Date)dteEndDateObserveSelectionObserveWidget.getValue();
return Status.OK_STATUS;
}
};
bindingContext.addValidationStatusProvider(dateValidator);
//
return bindingContext;
Re: Multivalidator fires validate method twice [message #892911 is a reply to message #892868] Sun, 01 July 2012 15:57 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 402
Registered: December 2009
Location: Prague
Senior Member
Hi Roman,

I'm not really sure about the databinding since I don't use it so often, but AFAIK the multivalidator registers itself into every observable value you call inside the validate method and then its is called every time an observable value is changed.

Take a look at this article
http://eclipsesource.com/blogs/2009/02/27/databinding-crossvalidation-with-a-multivalidator/

[Updated on: Sun, 01 July 2012 15:58]

Report message to a moderator

Re: Multivalidator fires validate method twice [message #892948 is a reply to message #892911] Mon, 02 July 2012 02:32 Go to previous message
Roman Smushkevich is currently offline Roman Smushkevich
Messages: 4
Registered: June 2012
Junior Member
Hi Jan,

Before posting my question in this thread I searched for a solvation in Internet. Thanks for the link any way, but it doesn't answer my question.

From the other side you are right. Multivalidator registers itself. BUT the validate method fires twice for each value change in each validator. This means, that when I'm shifting a date only in DateTimeWidget "dteStartDate" it occures 2 runs through valid method.

But anyway, thanks for your help!
Previous Topic:Scroll Bar in JFace Dialog
Next Topic:JFace Table: cell editing does not work when SWT.FULL_SELECTION is used
Goto Forum:
  


Current Time: Sun May 19 06:53:35 EDT 2013

Powered by FUDForum. Page generated in 0.01757 seconds