Ok, this is old, but for future related questions, here is how i did.
Define an AsyncDataProvider of your own, like:
public class MyDataProvider extends AsyncDataProvider<MyType> {
protected void onRangeChanged(final HasData<MyType> display) {
// calling my RPC method to obtain inner elements
myService.randomMethod(param1, new AsyncCallback<MyReturnType>() {
public void onSuccess(MyReturnType result) {
// do something
Range range = display.getVisibleRange();
int start = range.getStart();
updateRowData(start, result);
}
});
}
}
Then inside getNodeInfo(T value) of your TreeViewModel just return a new
DeafultNodeInfo with a new MyDataProvider. In this way your NodeInfo is
returned syncronously, but the data provider updates itself asyncronously.
For exampe:
public <T> NodeInfo<?> getNodeInfo(T value) {
// do something with the value and return the right DefaultNodeInfo
if(value instanceof MyType1) {
return new DefaultNodeInfo<SectionDTO>(
new SectionDataProvider([pass here value if you want the data
provider knows about the selected node]),
new MyCustomCellOrADefaultOne());
}
else if ...
}
This will retrieve inner elements asynchronously. If you want to do
something else when a leaf (or a non-leaf) is clicked (or selected), define
a SelectionModel (it could be a SingleSelectionModel, or a more complex one)
inside your TreeViewModel and pass it to DefaultNodeInfo. Example:
// defining
private SingleSelectionModel<MyType> selectionModel =
new SingleSelectionModel<MyType>();
// inside TreeViewModel ctor (or in a better place)
selectionModel.addSelectionChangeHandler(new
SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
// fire rpc, a place change or something else
// event.getSelectedObject() contains the selected element
}
});
// return the DefaultNodeInfo with info about the selection strategy
public <T> NodeInfo<?> getNodeInfo(T value) {
// do something with the value and return the right DefaultNodeInfo
if(value instanceof MyType1) {
return new DefaultNodeInfo<SectionDTO>(
new SectionDataProvider(),
new MyCustomCellOrADefaultOne(),
selectionModel,
null);
}
else if ...
}
Hope that helps,
Andrew.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.