Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 258192 - [DataBinding] Observable for objects the use JFace's IPropertyChangeListener
Summary: [DataBinding] Observable for objects the use JFace's IPropertyChangeListener
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-09 16:55 EST by Michael Valenta CLA
Modified: 2009-03-08 12:45 EDT (History)
3 users (show)

See Also:


Attachments
Patch to add IProperyChangeListener based observable value (8.88 KB, patch)
2008-12-09 16:57 EST, Michael Valenta CLA
no flags Details | Diff
Updated patch with proper copyrights and a snippet (15.28 KB, patch)
2008-12-10 13:00 EST, Michael Valenta CLA
no flags Details | Diff
updated patch (14.00 KB, patch)
2009-03-06 23:05 EST, Boris Bokowski CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Valenta CLA 2008-12-09 16:55:57 EST
I have written an observable for objects that fire events to IPropertyChangeListeners. This is useful for those clients that may already have objects that fire those types of events and want to try out the databinding framework. I will attach a patch
Comment 1 Michael Valenta CLA 2008-12-09 16:57:38 EST
Created attachment 119973 [details]
Patch to add IProperyChangeListener based observable value
Comment 2 Michael Valenta CLA 2008-12-09 17:37:03 EST
Oops, wrong copyright. I'll resubmit the patch the next chance I get.
Comment 3 Michael Valenta CLA 2008-12-10 13:00:00 EST
Created attachment 120086 [details]
Updated patch with proper copyrights and a snippet

I've attached another patch for your consideration. I'm happy to incorporate any suggestions and release the fix myself but I don't want to do so without the eyes of a databinding person on this (since I don't play around much in the databinding framework). If you prefer to release the patch yourself, that's great too.
Comment 4 Matthew Hall CLA 2008-12-10 18:48:25 EST
A few comments:
* ObservableJFacePropertyValue should be named JFacePropertyObservableValue to align with existing naming conventions.
* The above class should register a listener on the model in firstListenerAdded(), not in the constructor.  It should remove the listener in lastListenerRemoved().
* In some cases the value type may be known to be more specific than the return type of the getter method.  For this reason there should be an option to specify the value type in the observeProperty method.  Overloading is an option.
* Since the observable is in an internal package, the getFieldName() method will never be seen.
Comment 5 Matthew Hall CLA 2009-02-18 14:06:59 EST
Boris, I can't make an objective evaluation of this patch since I'm not familiar with IPropertyChangeListener or how it is supposed to work with JFace.

Please review this patch and, if you +1 the current observable implementation, send it back to me so I can convert it over to a property implementation.
Comment 6 Michael Valenta CLA 2009-02-18 15:38:27 EST
Boris and Matthew, sorry about the lack of activity on my part on this. I haven't had much time to devote to this, I'm currently developing against Eclipse 3.3 and I've moved on to other areas so I haven't had a chance to revisit the patch. 
Comment 7 Matthew Hall CLA 2009-02-18 16:09:57 EST
I guess what I'm wondering is if the field name vs property name dichotomy is a common, standardized pattern in the platform.  Specifically, can we reliably expect that the source object will have get[Field] / set[Field] methods (i.e. standard property method names) given a field name?  Is this an established standard or just a convention?  Is it common for the property name in the PropertyChangeEvent to disagree with the getter/setter method names as your patch implies?
Comment 8 Michael Valenta CLA 2009-02-19 09:06:53 EST
There are no "standards" when it comes to objects that notify IPropertyChangeListeners of events. In most of the cases I've seen, most source objects have get[Field] / set[Field] methods but the property name does not correspond to the field name.
Comment 9 Matthew Hall CLA 2009-02-19 18:13:35 EST
Boris, your call.  I'm not familiar enough with IPropertyChangeListener to make an informed decision.

If you +1, send it back to me and I'll port the patch over to the IProperty API.
Comment 10 Boris Bokowski CLA 2009-03-06 23:05:49 EST
Created attachment 127899 [details]
updated patch

This time using the new properties API. Matthew, could you have a look at this to hopefully catch any stupid mistakes I made?
Comment 11 Boris Bokowski CLA 2009-03-06 23:14:17 EST
Example:

JFaceProperties.property("text", IAction.TEXT, Action.class)
Comment 12 Matthew Hall CLA 2009-03-07 01:57:27 EST
Two things:
* Let's rename JFaceProperties.property() to JFaceProperties.value()
* To be consistent with the methods in BeanProperties let's change the order of arguments to (Class clazz, String fieldName, String propertyName)
Comment 13 Matthew Hall CLA 2009-03-07 02:02:35 EST
Other than the above items, +1
Comment 14 Boris Bokowski CLA 2009-03-07 08:29:43 EST
done, thanks for the review.

Example is now:

JFaceProperties.value(Action.class, "text", IAction.TEXT).observe(someAction)
Comment 15 Ovidio Mallo CLA 2009-03-08 11:07:18 EDT
Boris, I was just wondering whether it was intentional to put the class JFaceProperties in the package "org.eclipse.jface.util" which does not include the "databinding" part?
Comment 16 Boris Bokowski CLA 2009-03-08 12:34:26 EDT
Good catch!
Comment 17 Boris Bokowski CLA 2009-03-08 12:45:18 EDT
moved into package org.eclipse.jface.databinding.util. Ovidio, I owe you a beer (or something else, if you don't drink alcohol)!
Comment 18 Boris Bokowski CLA 2009-03-08 12:45:44 EDT
see comment 17