Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 127381 - [DataBinding] NestedProperty new constructor
Summary: [DataBinding] NestedProperty new constructor
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 17:31 EST by Sébastien Letélié CLA
Modified: 2009-08-30 02:15 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sébastien Letélié CLA 2006-02-11 17:31:47 EST
I propose to add a new constructor to NestedProperty for writing : new NestedProperty(myObject, "member.lastName")
What do you think about ?

    public NestedProperty(Object object, String propertiesPath) throws BindException {
        try {
            if (propertiesPath.indexOf('.') != -1) {
                List<String> l_properties = new ArrayList<String>();
                List<Class> l_classes = new ArrayList<Class>();
                StringTokenizer l_tokenizer = new StringTokenizer(propertiesPath, ".");
                Class l_class = object.getClass();
                while (l_tokenizer.hasMoreTokens()) {
                    String l_token = l_tokenizer.nextToken();
                    l_properties.add(l_token);
                    l_class = getType(l_class, l_token);
                    l_classes.add(l_class);
                }
                String[] l_propertiesParam = new String[l_properties.size()];
                l_properties.toArray(l_propertiesParam);
                Class[] l_classesParam = new Class[l_classes.size()];
                l_classes.toArray(l_classesParam);
                return new NestedProperty(object, l_propertiesParam, l_classesParam);
            } else {
                return new Property(object, propertiesPath);
            }
        } catch (IntrospectionException e) {
            throw new BindException(e.getMessage());
        }
    }
Comment 1 Kim Horne CLA 2006-02-13 09:14:49 EST
I believe this is for databinding - we have several Property classes.  If it isn't please punt back to me.
Comment 2 Boris Bokowski CLA 2006-02-13 09:36:35 EST
Thanks for the suggestion. However, for now, we are shying away from defining our own string-based language for object paths. Feel free to use this code in your application if your property identifiers are strings, it's just that we won't add this to the framework at this point.

Closing as LATER.
Comment 3 Peter Centgraf CLA 2007-02-27 16:51:49 EST
The 3.3M5 API includes most of what's needed to solve this.  This snippet should get you the rest of the way.  I'm using Java 5 regex support, but you could trivially re-implement the call to split() if you need to run on older JVMs.

import static org.eclipse.core.databinding.beans.BeansObservables.*;

public static IObservableValue observeNestedValue(Object bean, String property) {
	Realm realm = Realm.getDefault();
	
	// JSTL EL uses a simple period-delimited list of property names
	String[] parts = property.split("\\.");
	
	// Start out with a simple property
	IObservableValue lastPart = observeValue(realm, bean, parts[0]);
	for (int i = 1; i < parts.length; i++) {
		String part = parts[i];
		
		// Each additional part should listen to changes on both host and value
		lastPart = observeDetailValue(realm, lastPart, part, null);
	}
	return lastPart;
}
Comment 4 Frank Gerhardt CLA 2007-07-17 06:06:52 EDT
Note: Tom Schindl posted a similar solution in bug #195222
Comment 5 Denis Roy CLA 2009-08-30 02:15:08 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.