[databinding] ControlDecorationSupport disposal seems not to work as expected [message #667654] |
Sat, 30 April 2011 16:52 |
Christophe Fondacci Messages: 95 Registered: July 2009 Location: Paris |
Member |
|
|
Hello all,
First, I need to say that I am new to the databinding framework.
Here is my problem :
* Using databinding to bind forms UI text fields with my POJO beans
* For some fields, I use a ControlDecorationSupport along with a conversion validator
Everything works fine so far.
Now, this form can change its input as it is following the MasterDetails pattern. When the input of my form changes, here is what I do (i am not sure that all steps are mandatory) :
* Explicitly dispose every binding from the data binding context
* Explicilty dispose every created ControlDecorationSupport (although I should not need this one as the jdoc says it is disposed when target binding is disposed)
* Dispose the data binding context, from a runnable called in the validation realm
* Then I rebind everything with the new model bean
This works perfectly, with one exception : when an error decoration is displayed, if I change the model every field is properly valued but the tiny error icon decoration stays in place.
This is very annoying as we think there is an error on the new edited element. One strange thing is that when I change the layout (for example, if I move a sash or resize the part), then the decoration disappear.
Is there something I am doing wrong ? What is the preferred method for changing the model of an editor with same control to ensure proper unbind / bind action ?
I suspect that I could force a "paint" of the part I am working in but I would appreciate a more elegant solution.
Any information would be very helpful !
Christophe.
http://www.nextep-softwares.com
|
|
|
|
Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #668565 is a reply to message #667785] |
Fri, 06 May 2011 09:02 |
Christophe Fondacci Messages: 95 Registered: July 2009 Location: Paris |
Member |
|
|
Very interesting, thank you very much for pointing me this.
However, I got some other problems when using the "out-of-the-box" master-detail binding. Everything works great with string values, but as soon as I try to bind integer values it does not work at all.
Here is what I was doing before using your suggestion :
widgetValue = WidgetProperties.text(SWT.Modify).observe(lengthText);
modelValue = PojoProperties.value(IBasicColumn.class, "datatype.length").observe(getModel()); //$NON-NLS-1$
updateStrategy = new UpdateValueStrategy();
updateStrategy.setConverter(StringToNumberConverter.toInteger(true));
boundValue = context.bindValue(widgetValue, modelValue, updateStrategy, null);
ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT);
And it worked great, except the decoration "refresh" bug when the model changed.
Now, I have switched to the following implementation :
IObservableValue selectionValue = ViewersObservables.observeSingleSelection(masterSelectionProvider);
widgetValue = WidgetProperties.text(SWT.Modify).observe(lengthText);
modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.length", int.class);
updateStrategy = new UpdateValueStrategy();
updateStrategy.setConverter(StringToNumberConverter.toInteger(false));
boundValue = context.bindValue(widgetValue, modelValue);
But nothing is never ever displayed in my lengthText field. I debugged a bit, and it seems that the value is properly fetched from my bean with the proper value. I tried adding a validator to find out what value was sent there, and it is always an empty string. I tried removing the converter but it does not change anything, I tried switching to Integer instead of primitive type... I am out of ideas, I don't know why it is not working and don't know where to look.
The other question which remains unanswered for me is the purpose of the propertyType class parameter of the observeDetailValue method : does it handle conversion automatically ? Is it redundant to define a number to string converter ?
It seems to me very difficult to debug the databinding framework because of the Realm execution, and I get lost between the observable and the binding section so any informaiton would be very very helpful to me. I think that binding an integer information in a Master/Details pattern is a relatively standard scenario so I am sure there is a simple way to make it work...
Thank you.
Christophe.
http://www.nextep-softwares.com
|
|
|
Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #668606 is a reply to message #668565] |
Fri, 06 May 2011 12:06 |
Carsten Habicht Messages: 14 Registered: January 2011 |
Junior Member |
|
|
I guess the updating doesn't happen because you use PojoObservables. If your model supports the Java Beans property change notification mechanism, it is probably better to use BeansObservables. Otherwise you might have to trigger updates of the target controls manually, e.g. when the selection changes.
I did a little test based on an "RCP Application with a view" code template (To create one, click "File -> New -> Other -> Plug-In Project -> (give it a name) -> Next -> Next -> RCP application with a view -> Finish). Youll find the view's code (lacking any sensible comments) there: http://pastebin.com/SREa6uCH .
The class parameter IMHO serves the purpose to tell the binding framework, which type the detail property is of. Don't know if it is used for validation or anything.
Best,
Carsten
P.S.: Most data binding fuck-ups (at least to me) happen because of some exception during conversion. Exception breakpoints (e.g. on NullPointerException) help a lot.
[Updated on: Fri, 06 May 2011 12:11] Report message to a moderator
|
|
|
|
Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #668635 is a reply to message #668625] |
Fri, 06 May 2011 14:09 |
Carsten Habicht Messages: 14 Registered: January 2011 |
Junior Member |
|
|
Aaaah. I missed that integer stuff. You have to convert the number to a string and vice versa, if you want to display it in a Text control.
ctx.bindValue(widgetValue, modelValue,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(StringToNumberConverter.toInteger(true)),
new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(IntegerToStringConverter.fromShort(true)));
Otherwise the binding attempt results in a ClassCastExcetpion being thrown (which might be the second-best guess for an exception breakpoint when debugging such stuff... ;o) ).
HTH
Carsten
[Updated on: Fri, 06 May 2011 14:11] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04245 seconds