CellTree and RPC

661 views
Skip to first unread message

Jerome C.

unread,
Nov 16, 2010, 1:36:23 PM11/16/10
to Google Web Toolkit
Hi,

I don't know how to load datas for my CellTree via RPC.

The getNodeInfo is synchronous so how can I send a request to the
server and then (when the response comes back) update the CellTree ?

Or if we can't, how to load my tree in one request and after use this
structure in getNodeInfo ?

thanks

John LaBanca

unread,
Nov 16, 2010, 1:57:31 PM11/16/10
to google-we...@googlegroups.com
You can pass a ListDataProvider or AsyncDataProvider into DefaultNodeInfo.  Then you can return the NodeInfo synchronously, but populate the data provider asynchronously.

Thanks,
John LaBanca
jlab...@google.com



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


yeti

unread,
Dec 29, 2010, 2:02:27 AM12/29/10
to Google Web Toolkit
Could you please show me more details>?

Is it right when I return defaultNodeinfo , it will wait me to
populate the dataprovider?


thanks.

On 11月17日, 上午2时57分, John LaBanca <jlaba...@google.com> wrote:
> You can pass a ListDataProvider or AsyncDataProvider into DefaultNodeInfo.
> Then you can return the NodeInfo synchronously, but populate the data
> provider asynchronously.
>
> Thanks,
> John LaBanca
> jlaba...@google.com
>
>
>
>
>
>
>
> On Tue, Nov 16, 2010 at 1:36 PM, Jerome C. <jerome.ca...@gmail.com> wrote:
> > Hi,
>
> > I don't know how to load datas for my CellTree via RPC.
>
> > The getNodeInfo is synchronous so how can I send a request to the
> > server and then (when the response comes back) update the CellTree ?
>
> > Or if we can't, how to load my tree in one request and after use this
> > structure in getNodeInfo ?
>
> > thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsubs cr...@googlegroups.com>
> > .

Saket

unread,
Jan 2, 2011, 8:44:51 PM1/2/11
to Google Web Toolkit
i am also stuck in the same confusion.... please share your solution.

Regards,
Saket

ciosbel

unread,
Apr 14, 2011, 6:06:06 AM4/14/11
to google-we...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages