GWT 2.0.3 + Tree widget + get tree level of selected TreeItem - Problem

2010-06-02 Thread junior
Hejsan,
I am building dynamic Tree Widget. First Level I done with no problem
so it look like:

+ Atletics
+ Ice Hockey
+ Chess
+ Footbal
+ Golf

Functionality must be like when you click on sport must roll up/show
off list of countries like:

+ Atletics
+ Ice Hockey
+ Canada
+ USA
+ Russia
+ Chess
+ Footbal
+ Golf

and when click to some country then show off League like

+ Atletics
+ Ice Hockey
+ Canada
   + Tournaments
   + Extra league
   + 1.league
   + 2.league
+ USA
+ Russia
+ Chess
+ Footbal
+ Golf


PROBLEM is that I need get level of selected TreeItem to for each
different level will fire up different query so for example for
selected  Ice Hockey need get information that it's 1 level of tree so
use databases select to find out all countries for Ice hockey.
When click to Canada TreeItem, it's level 2 I call select to find
out all leagues level for Canada.

I create handler for Tree like:
// Add a handler that automatically generates some children
statTree.addOpenHandler(new OpenHandlerTreeItem() {

public void onOpen(OpenEventTreeItem event) {
// tree item that was clicked
TreeItem itemSelected = event.getTarget();

if (itemSelected.getChildCount() == 1) {
// Close item immediately
itemSelected.setState(false, false);

// Add a random number of children to 
the item
String itemText = 
itemSelected.getText();

// request to database according 
selected tree item level

// dummy data
for (int i = 0; i  numChildren; i++) {
// tree item to be added
TreeItem childDescendant = 
itemSelected

.addItem(itemText + . + i);

System.out.println(\ncildDescendant index: 
+ 
itemSelected.getChildIndex(childDescendant));
childDescendant.addItem();
}

// Remove the temporary item when we 
finish loading
itemSelected.getChild(0).remove();

// Reopen the item
itemSelected.setState(true, false);
}
}
});

Please help me some one I'll do appreciate it.
Thank you

-- 
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-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



GWT 2.0.3 + Tree widget + get tree level of selected TreeItem - Problem

2010-06-02 Thread junior
Hejsan
I am building GWT Tree and need to get information about level of
current opened TreeItem. Let me describe more detail.
I build up first level(Sport List) of tree so it looks like:
+ Athletics
+ Ice Hockey
+ Footbal

Second level(Countries List) must looks like:
+ Athletics
+ Ice Hockey
   + Canada
   + USA
   + Russia
+ Footbal

Third level(League List) must looks like:
+ Athletics
+ Ice Hockey
   + Canada
  + Tournament
  + 1.League
  + 2.League
  + AAA League
   + USA
   + Russia
+ Footbal

Why I need info abou opened TreeItem? By level of opened TreeItem fire
up different SELECT of database so if I open up + Ice Hockey - it's
first level, then I fire up SELECT on database to get list of
countries for sport Ice Hockey. Next if I open up country + Canada
then fire up SELECT on databases to get list of all leagues at country
Canada for sport Ice Hockey.

I call open handler for Tree for TreeItem like this:

// Add a handler that automatically generates some children
statTree.addOpenHandler(new OpenHandlerTreeItem() {

public void onOpen(OpenEventTreeItem event) {
// tree item that was clicked
TreeItem itemSelected = event.getTarget();
if (itemSelected.getChildCount() == 1) {
// Close item immediately
itemSelected.setState(false, false);

// Add a random number of children to 
the item
String itemText = 
itemSelected.getText();

// different request to database, 
according level of TreeItem
// ??

// just temporary dummy data
of subtree items
int numChildren = Random.nextInt(5) + 2;
for (int i = 0; i  numChildren; i++) {
// tree item to be added
TreeItem childDescendant = 
itemSelected

.addItem(itemText + . + i);

System.out.println(\ncildDescendant index: 
+ 
itemSelected.getChildIndex(childDescendant));
childDescendant.addItem();
}

// Remove the temporary item when we 
finish loading
itemSelected.getChild(0).remove();

// Reopen the item
itemSelected.setState(true, false);
}
}
});


Please help me with this problem, I'd appreciate it.
junior

-- 
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-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: GWT 2.0.3 + Tree widget + get tree level of selected TreeItem - Problem

2010-06-02 Thread Jim Douglas
Follow the chain of getParentItem() until it returns null.

http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/ui/TreeItem.html#getParentItem()

On Jun 2, 3:25 am, junior kubinca...@gmail.com wrote:
 Hejsan
 I am building GWT Tree and need to get information about level of
 current opened TreeItem. Let me describe more detail.
 I build up first level(Sport List) of tree so it looks like:
 + Athletics
 + Ice Hockey
 + Footbal

 Second level(Countries List) must looks like:
 + Athletics
 + Ice Hockey
    + Canada
    + USA
    + Russia
 + Footbal

 Third level(League List) must looks like:
 + Athletics
 + Ice Hockey
    + Canada
       + Tournament
       + 1.League
       + 2.League
       + AAA League
    + USA
    + Russia
 + Footbal

 Why I need info abou opened TreeItem? By level of opened TreeItem fire
 up different SELECT of database so if I open up + Ice Hockey - it's
 first level, then I fire up SELECT on database to get list of
 countries for sport Ice Hockey. Next if I open up country + Canada
 then fire up SELECT on databases to get list of all leagues at country
 Canada for sport Ice Hockey.

 I call open handler for Tree for TreeItem like this:

 // Add a handler that automatically generates some children
                 statTree.addOpenHandler(new OpenHandlerTreeItem() {

                         public void onOpen(OpenEventTreeItem event) {
                                 // tree item that was clicked
                                 TreeItem itemSelected = event.getTarget();
                                 if (itemSelected.getChildCount() == 1) {
                                         // Close item immediately
                                         itemSelected.setState(false, false);

                                         // Add a random number of children to 
 the item
                                         String itemText = 
 itemSelected.getText();

                                         // different request to database, 
 according level of TreeItem
                                         // ??

                                         // just temporary dummy data
 of subtree items
                                         int numChildren = Random.nextInt(5) + 
 2;
                                         for (int i = 0; i  numChildren; i++) 
 {
                                                 // tree item to be added
                                                 TreeItem childDescendant = 
 itemSelected
                                                                 
 .addItem(itemText + . + i);
                                                 
 System.out.println(\ncildDescendant index: 
                                                                 + 
 itemSelected.getChildIndex(childDescendant));
                                                 childDescendant.addItem();
                                         }

                                         // Remove the temporary item when we 
 finish loading
                                         itemSelected.getChild(0).remove();

                                         // Reopen the item
                                         itemSelected.setState(true, false);
                                 }
                         }
                 });

 Please help me with this problem, I'd appreciate it.
 junior

-- 
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-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.