Skip to main content



      Home
Home » Eclipse Projects » JFace » [databinding] ObservableListTreeContentProvider with IObservableList in different realm
[databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #17709] Tue, 30 June 2009 18:00 Go to next message
Eclipse UserFriend
ObservableListTreeContentProvider documentation is clear that its
IObservableFactory must create lists on the realm of the current display.
In my case, I have an IObservableList for the root of the tree that is not
necessarily on the display realm. Is there a simple way to proxy from one
realm to another?

I guess I could create a new WritableList on the display realm and bind the
two together with a DataBindingContext. In this case, however, I just need
updates to propagate one way - from the source model list to the display
realm proxy.

-Will
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #18545 is a reply to message #17709] Wed, 01 July 2009 12:19 Go to previous messageGo to next message
Eclipse UserFriend
I would use a binding for this as you mentioned.

Matthew

Will Horn wrote:
> ObservableListTreeContentProvider documentation is clear that its
> IObservableFactory must create lists on the realm of the current
> display. In my case, I have an IObservableList for the root of the tree
> that is not necessarily on the display realm. Is there a simple way to
> proxy from one realm to another?
>
> I guess I could create a new WritableList on the display realm and bind
> the two together with a DataBindingContext. In this case, however, I
> just need updates to propagate one way - from the source model list to
> the display realm proxy.
>
> -Will
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #19324 is a reply to message #18545] Tue, 07 July 2009 20:57 Go to previous messageGo to next message
Eclipse UserFriend
"Matthew Hall" <matthall@woodcraftmill.com> wrote in message
news:h2g2av$i55$1@build.eclipse.org...
>I would use a binding for this as you mentioned.

How about this:

public class ProxyList extends WritableList {

public static IObservableList create(IObservableList original) {
return create(Realm.getDefault(), original);
}

public static IObservableList create(Realm realm, IObservableList
original) {
if (realm.equals(original.getRealm())) {
return original;
}
ProxyList list = new ProxyList(realm, original);
list.init();
return list;
}

private final DataBindingContext mDataBindingContext;
private IObservableList mOriginal;

private ProxyList(Realm realm, IObservableList original) {
super(new ArrayList<Object>(), original.getElementType());
mOriginal = original;
mDataBindingContext = new DataBindingContext();
}

private void init() {
mDataBindingContext.bindList(this, mOriginal);
}

@Override
public synchronized void dispose() {
mDataBindingContext.dispose();
super.dispose();
}
}
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #19507 is a reply to message #19324] Wed, 08 July 2009 14:41 Go to previous messageGo to next message
Eclipse UserFriend
You will get an NPE in ProxyList.create(IObservableList) if
Realm.getDefault() == null. Other than that it looks good.

Another option is to just create a WritableList and add a dispose
listener that disposes the binding context, rather than subclassing:

public static IObservableList create(Realm realm, IObservableList list) {
if (realm.equals(original.getRealm())) return list;
IObservableList proxy = new WritableList(realm);
final DataBindingContext bindingContext = new DataBindingContext();
bindingContext.bindList(proxy, original);
proxy.addDisposeListener(new IDisposeListener() {
public void handleDispose(DisposeEvent) {
bindingContext.dispose();
}
} );
return proxy;
}

Matthew

Will Horn wrote:
> "Matthew Hall" <matthall@woodcraftmill.com> wrote in message
> news:h2g2av$i55$1@build.eclipse.org...
>> I would use a binding for this as you mentioned.
>
> How about this:
>
> public class ProxyList extends WritableList {
>
> public static IObservableList create(IObservableList original) {
> return create(Realm.getDefault(), original);
> }
>
> public static IObservableList create(Realm realm, IObservableList
> original) {
> if (realm.equals(original.getRealm())) {
> return original;
> }
> ProxyList list = new ProxyList(realm, original);
> list.init();
> return list;
> }
>
> private final DataBindingContext mDataBindingContext;
> private IObservableList mOriginal;
>
> private ProxyList(Realm realm, IObservableList original) {
> super(new ArrayList<Object>(), original.getElementType());
> mOriginal = original;
> mDataBindingContext = new DataBindingContext();
> }
>
> private void init() {
> mDataBindingContext.bindList(this, mOriginal);
> }
>
> @Override
> public synchronized void dispose() {
> mDataBindingContext.dispose();
> super.dispose();
> }
> }
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #20510 is a reply to message #19507] Sun, 12 July 2009 19:54 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the tips. One more question: is it necessary/good to dispose the
WritableList too?, e.g.

public static IObservableList proxyList(Realm realm, IObservableList
original) {
if (original.getRealm().equals(realm)) {
return original;
}
final WritableList list = new WritableList(realm);
final DataBindingContext dbc = new DataBindingContext();
original.addDisposeListener(new IDisposeListener() {
@Override
public void handleDispose(DisposeEvent staleEvent) {
list.dispose();
dbc.dispose();
}
});
dbc.bindList(list, original);
return list;
}


"Matthew Hall" <matthall@woodcraftmill.com> wrote in message
news:h32p8q$rp$1@build.eclipse.org...
> You will get an NPE in ProxyList.create(IObservableList) if
> Realm.getDefault() == null. Other than that it looks good.
>
> Another option is to just create a WritableList and add a dispose listener
> that disposes the binding context, rather than subclassing:
>
> public static IObservableList create(Realm realm, IObservableList list) {
> if (realm.equals(original.getRealm())) return list;
> IObservableList proxy = new WritableList(realm);
> final DataBindingContext bindingContext = new DataBindingContext();
> bindingContext.bindList(proxy, original);
> proxy.addDisposeListener(new IDisposeListener() {
> public void handleDispose(DisposeEvent) {
> bindingContext.dispose();
> }
> } );
> return proxy;
> }
>
> Matthew
>
> Will Horn wrote:
>> "Matthew Hall" <matthall@woodcraftmill.com> wrote in message
>> news:h2g2av$i55$1@build.eclipse.org...
>>> I would use a binding for this as you mentioned.
>>
>> How about this:
>>
>> public class ProxyList extends WritableList {
>>
>> public static IObservableList create(IObservableList original) {
>> return create(Realm.getDefault(), original);
>> }
>>
>> public static IObservableList create(Realm realm, IObservableList
>> original) {
>> if (realm.equals(original.getRealm())) {
>> return original;
>> }
>> ProxyList list = new ProxyList(realm, original);
>> list.init();
>> return list;
>> }
>>
>> private final DataBindingContext mDataBindingContext;
>> private IObservableList mOriginal;
>>
>> private ProxyList(Realm realm, IObservableList original) {
>> super(new ArrayList<Object>(), original.getElementType());
>> mOriginal = original;
>> mDataBindingContext = new DataBindingContext();
>> }
>>
>> private void init() {
>> mDataBindingContext.bindList(this, mOriginal);
>> }
>>
>> @Override
>> public synchronized void dispose() {
>> mDataBindingContext.dispose();
>> super.dispose();
>> }
>> }
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #20544 is a reply to message #20510] Mon, 13 July 2009 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Will Horn wrote:
> Thanks for the tips. One more question: is it necessary/good to dispose
> the WritableList too?

Yes, it is considered best practice.

Matthew
Re: [databinding] ObservableListTreeContentProvider with IObservableList in different realm [message #20632 is a reply to message #20544] Tue, 14 July 2009 15:17 Go to previous message
Eclipse UserFriend
For future readers of this thread, here is the code I have ended up with.
Similar stuff should work for ObservableValue.

/**
* Returns an observable list that proxies on the current realm for the
list
* passed in. The original list will be returned if its realm is the
current
* realm.
*
* @param original
* the list to proxy
* @return the proxy list
* @throws IllegalArgumentException
* if original is null
* @throws IllegalStateException
* if this thread has no default realm
* @throws IllegalStateException
* if the default realm is not the current realm
*/
public static IObservableList proxyList(IObservableList original) {
Realm realm = Realm.getDefault();
if (realm == null) {
throw new IllegalStateException(
"this method requires a default realm"); //$NON-NLS-1$
}
return proxyList(realm, original);
}

/**
* Returns an observable list that proxies on the given realm for the
list
* passed in. The original list will be returned if its realm is the
alread
* the provided realm.
*
* @param original
* the list to proxy
* @return the proxy list
* @throws IllegalArgumentException
* if realm is null
* @throws IllegalArgumentException
* if original is null
* @throws IllegalStateException
* if the provided realm is not the current realm
*/
public static IObservableList proxyList(Realm realm,
IObservableList original) {
if (realm == null) {
throw new IllegalArgumentException("the realm cannot be null");
//$NON-NLS-1$
}
if (original == null) {
throw new IllegalArgumentException("the original list cannot be
null"); //$NON-NLS-1$
}
if (!realm.isCurrent()) {
throw new IllegalStateException(
"must be called from the proxy realm"); //$NON-NLS-1$
}
if (realm.equals(original.getRealm())) {
return original;
}
final WritableList list = new WritableList(realm,
new ArrayList<Object>(), original.getElementType());
final DataBindingContext dbc = new DataBindingContext(realm);
original.addDisposeListener(new IDisposeListener() {
@Override
public void handleDispose(DisposeEvent staleEvent) {
list.dispose();
dbc.dispose();
}
});
dbc.bindList(list, original);
return list;
}
Previous Topic:TreeViewer find node
Next Topic:[DataBinding] master-detail binding with non-String properties
Goto Forum:
  


Current Time: Thu May 08 15:26:41 EDT 2025

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

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

Back to the top