Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [databinding] ControlDecorationSupport disposal seems not to work as expected
[databinding] ControlDecorationSupport disposal seems not to work as expected [message #667654] Sat, 30 April 2011 16:52 Go to next message
Christophe Fondacci is currently offline Christophe FondacciFriend
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 #667785 is a reply to message #667654] Mon, 02 May 2011 08:51 Go to previous messageGo to next message
Carsten Habicht is currently offline Carsten HabichtFriend
Messages: 14
Registered: January 2011
Junior Member
Hey Christophe,

what you'd probably want is master detail binding. It looks a bit complicated at first, but addresses that sort of scenario.
http://wiki.eclipse.org/JFace_Data_Binding/Master_Detail
http://wiki.eclipse.org/JFace_Data_Binding/Snippets#Master_D etail

Cheers
Carsten
Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #668565 is a reply to message #667785] Fri, 06 May 2011 09:02 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe FondacciFriend
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 Go to previous messageGo to next message
Carsten Habicht is currently offline Carsten HabichtFriend
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 #668625 is a reply to message #668606] Fri, 06 May 2011 13:31 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe FondacciFriend
Messages: 95
Registered: July 2009
Location: Paris
Member
Thanks for the feedback.

I don't think it has anything to do with the use of PojoObservables since everything is working fine with String-based properties. I understand that the UI will not be aware of changes from the model unless I implement this explicitly.

But when the bean changes or when the binding is first made, it should work.

I looked at your snippet (thanks for writing it !) and noticed you were not using any "integer" field. So I altered it a bit to add a numeric property to your Model2 bean and added a binding of this property to a new Text control...

...and faced the exact same problem : while string value is properly refreshed, the integer value is always empty. I can notice that the value is properly fetched with the proper value from the bean...don't know what's going on after that.

I tried to add runtime exception breakpoint (this seems indeed a very effective way to debug databinding problems) but cannot see anything. You will find the updated snippet here :
http://pastebin.com/Tbibi5Qx

Is there anything I am doing wrong in the snippet ?
Thank you very much.
Christophe
http://www.nextep-softwares.com
Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #668635 is a reply to message #668625] Fri, 06 May 2011 14:09 Go to previous messageGo to next message
Carsten Habicht is currently offline Carsten HabichtFriend
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

Re: [databinding] ControlDecorationSupport disposal seems not to work as expected [message #675674 is a reply to message #668635] Wed, 01 June 2011 07:33 Go to previous message
Christophe Fondacci is currently offline Christophe FondacciFriend
Messages: 95
Registered: July 2009
Location: Paris
Member
Excellent, I forgot to tell you that it works great now that I added the target to model converter in addition to the model to target one.
Thank you very much for your help.

Christophe.
http://www.nextep-softwares.com
Previous Topic:Finding a view from another perspective
Next Topic:how on earth do i bind comboVIewer to CellEditor?
Goto Forum:
  


Current Time: Thu Apr 25 22:30:35 GMT 2024

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

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

Back to the top