Filter Tree in GWT

702 views
Skip to first unread message

Qrunk

unread,
Apr 3, 2012, 6:09:20 AM4/3/12
to google-we...@googlegroups.com
Hi
How to create a filter tree in GWT using CellTree, a filter tree is some Tree which has an filter(TextBox) where we can enter values for the leaf node. Once we start entering values we get the tree branches along with leaf nodes reflected on the Tree panel(we have our tree inside a panel). For reference : http://www.sencha.com/examples/explorer.html#filtertree

We can develop such FilterTree easily in GXT, but we have an requirement to develop it in GWT, not in GXT. Can I have some replies with a short and simple sample code on FilterTree in GWT, or at least any links to refer to.

Qrunk

unread,
Apr 3, 2012, 2:10:19 PM4/3/12
to google-we...@googlegroups.com
Can some one refer the below link and let us know about FilterTree

http://stackoverflow.com/questions/9991133/getting-all-suggestions-from-the-suggestbox-in-gwt/9993597#9993597

Thanks

Qrunk

unread,
Apr 4, 2012, 11:44:17 AM4/4/12
to google-we...@googlegroups.com
Can some one please put some light on this issue ?? if GXT  has already done it cant it be done now in GWT ??


On Tuesday, 3 April 2012 15:39:20 UTC+5:30, Qrunk wrote:

Patrick Tucker

unread,
Apr 5, 2012, 9:29:01 AM4/5/12
to google-we...@googlegroups.com
CellTree uses a list...
 
After your GUI component works, custom header with textbox, you just need to filter the list??

Qrunk

unread,
Apr 9, 2012, 2:32:10 AM4/9/12
to google-we...@googlegroups.com

Hi Patrick,

Sorry for late reply, I didnt understood what you meant by filtering of list, as in a tree I might be having so many lists, even nested lists.

Can you please let me know how would I do filtering , as in any sample code snippet would do the perfect job, can you provide that please.

Thanks

Jens

unread,
Apr 9, 2012, 10:53:54 AM4/9/12
to google-we...@googlegroups.com
Using CellTree you have to provide a TreeViewModel. For each node in the tree you will create a ListDataProvider that contains the child elements of a given node. If you want to filter your tree you have to filter all these ListDataProviders. To do so you should create a sub class of ListDataProvider and add filter capabilities to it. Maybe something like:

FilterListDataProvider<T> extends ListDataProvider<T> {

  void setFilter(Filter<T> filter) {
    //store it
  }

  public List<T> getOriginalList() {
    return super.getList();
  }

  @Override
  public List<T> getList() {
    List<T> originalData = super.getList();
    if(filter == null) {
       return originalData;
    }
    //filter.apply() should return a new list. Do not modify originalData.
    return filter.apply(originalData);
  }

}

After you have setup the filter you have to call ListDataProvider.refresh() to update the CellTree (which hopefully causes getList() to be called). Maybe you also have to overwrite other methods of ListDataProvider to make the filtered behavior correct.

Also I think CellTree won't open up itself upon refreshing ListDataProviders. So you have to do it yourself using CellTree.getRootTreeNode().setChildOpen(). Note that setChildOpen() returns the child node if its successfully opened so you can walk through the tree nodes.

I haven't implemented all of this myself, but I think thats the way I would try it.

-- J.
Reply all
Reply to author
Forward
0 new messages