Hai..
I am new to GWT .When developing  GWT tree fill application ..unable
to set data to TreeNodes dynamically (Data Coming from database)

Here my code:

---------------------------------------------------------

package org.karishma.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.TreeListener;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.widgets.Panel;
import java.util.ArrayList;

/**
 *
 * @author veerraju
 */
public class TreeMainEntryPoint  implements
EntryPoint,TreeListener,FocusListener {
   public Tree tree ;

  class PendingItem extends TreeItem {
    public PendingItem() {
      super("Please wait...");
    }
  }
    class TreeNode {
    public TreeNode[] children;
    public TreeItem item;

    public String text;
    public String value;
    public String pgCode;
    public String level;
    public TreeNode(String text,String value,String pgCode,String
level) {
      this.text = text;
      this.value=value;
      this.pgCode=pgCode;
      this.level=level;
    }

    public TreeNode(String text,String value,String  pgCode,String
level, TreeNode[] children) {
      this(text,value,pgCode,level);
      this.children = children;
    }
  }
     TreeNode[] fTreeNode = new TreeNode[]{
    new TreeNode("group1","10","","0", new TreeNode[]{
      new TreeNode("A","20","10","1", new TreeNode[]{
        new TreeNode("1","30","20","2"),
        new TreeNode("2","40","20","2"),
        new TreeNode("3","50","20","2"),
        new TreeNode("4","60","20","2"),
        new TreeNode("5","70","20","2"),}),
      new TreeNode("B","80","10","1", new TreeNode[]{
        new TreeNode("B1","90","80","2"),
        new TreeNode("B2","100","80","2"),
        new TreeNode("B3","110","80","2"),}),
      new TreeNode("C","120","10","1", new TreeNode[]{
        new TreeNode("C1","130","120","2"),
        new TreeNode("C2","140","120","2"),}),
      new TreeNode("D","150","10","1", new TreeNode[]{
        new TreeNode("1","160","150","2"),
        new TreeNode("2","170","150","2"),
        new TreeNode("3","180","150","2"),}),}),
    new TreeNode("group2","190","","0", new TreeNode[]{
      new TreeNode("A","200","190","1", new TreeNode[]{
        new TreeNode("A1","210","200","2"),
        new TreeNode("A2","220","200","2"),
        new TreeNode("A3","230","200","2"),
        new TreeNode("A4","250","200","2"),}),
      new TreeNode("B","260","190","1",new TreeNode[]{
        new TreeNode("1","240","260","2"),
        new TreeNode("2","270","260","2"),
        new TreeNode("3","280","260","2")
        }),

      }),
    };

    /**
        The entry point method, called automatically by loading a
module
        that declares an implementing class as an entry-point
    */
    public void onModuleLoad() {
     tree = new Tree();
     for (int i = 0; i < fTreeNode.length; ++i) {
      createItem(fTreeNode[i]);
      tree.addItem(fTreeNode[i].item);
    }

   tree.addTreeListener(this);
   tree.addFocusListener(this);
    tree.setWidth("10px");
         Panel p1=new Panel();
         p1.add(tree);
         p1.setTitle("Tree Structure");
         p1.setBorder(true);
         p1.setPaddings(5);
         p1.setSize(250,500);
         p1.setAutoScroll(true);
         RootPanel.get().add(p1);
        // Create an asynchronous callback to handle the result.
       final AsyncCallback callback = new AsyncCallback() {
            public void onSuccess(Object result) {
            Window.alert(result.toString());
       ArrarList al1=(ArrayList)result;
            }
            public void onFailure(Throwable caught) {
             Window.alert("Communication failed....");
            }
        };

       getService().getTree(callback);

    }

      private void createItem(TreeNode TreeNode) {
    TreeNode.item = new TreeItem(TreeNode.text);
    TreeNode.item.setUserObject(TreeNode);
    TreeNode.item.setSelected(true);
    if (TreeNode.children != null) {
      TreeNode.item.addItem(new PendingItem());
    }
  }
  public void onTreeItemSelected(TreeItem item) {
    Window.alert("code:"+((TreeNode) item.getUserObject()).value
+";desc:"+((TreeNode) item.getUserObject()).text+";pgcode:"+
((TreeNode) item.getUserObject()).pgCode+";level:"+((TreeNode)
item.getUserObject()).level);
  }

  public void onTreeItemStateChanged(TreeItem item) {
    TreeItem child = item.getChild(0);
    if (child instanceof PendingItem) {
      item.removeItem(child);

      TreeNode tn = (TreeNode) item.getUserObject();

      for (int i = 0; i < tn.children.length; ++i) {
        createItem(tn.children[i]);
        item.addItem(tn.children[i].item);
      }
    }
  }


    public static TreeServiceAsync getService(){
        // Create the client proxy. Note that although you are
creating the
        // service interface proper, you cast the result to the
asynchronous
        // version of
        // the interface. The cast is always safe because the
generated proxy
        // implements the asynchronous interface automatically.
        TreeServiceAsync service = (TreeServiceAsync) GWT.create
(TreeService.class);
        // Specify the URL at which our service implementation is
running.
        // Note that the target URL must reside on the same domain and
port from
        // which the host page was served.
        //
        ServiceDefTarget endpoint = (ServiceDefTarget) service;
        String moduleRelativeURL = GWT.getModuleBaseURL() +
"treeservice";
        endpoint.setServiceEntryPoint(moduleRelativeURL);
        return service;
    }


    public void onLostFocus(Widget tree1) {
       this.tree=(Tree)tree1;


    }

    public void onFocus(Widget tree1) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}

------------------------------------------------------------------------------------------------

Any body can help me ...
thanks in advance....
Raju


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"GWT-Ext Developer Forum" 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/gwt-ext?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to