Use TreeListener : Tree « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Java » GWT » TreeScreenshots 
Use TreeListener
  

package com.java2s.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.TreeListener;

public class GWTClient implements EntryPoint,TreeListener {
  class PendingItem extends TreeItem {
    public PendingItem() {
      super("Please wait...");
    }
  }

  class TreeNode {
    public TreeNode[] children;
    public TreeItem item;
    public String text;

    public TreeNode(String text) {
      this.text = text;
    }

    public TreeNode(String text, TreeNode[] children) {
      this(text);
      this.children = children;
    }
  }

  TreeNode[] fTreeNode = new TreeNode[]{
    new TreeNode("A"new TreeNode[]{
      new TreeNode("B"new TreeNode[]{
        new TreeNode("1")
        new TreeNode("2"),
        new TreeNode("3")
        new TreeNode("4"),
        new TreeNode("5"),}),
      new TreeNode("B"new TreeNode[]{
        new TreeNode("B1")
        new TreeNode("B2"),
        new TreeNode("B3"),}),
      new TreeNode("C"new TreeNode[]{
        new TreeNode("C1")
        new TreeNode("C2"),}),
      new TreeNode("D"new TreeNode[]{
        new TreeNode("1")
        new TreeNode("2"),
        new TreeNode("3"),}),}),
    new TreeNode("AA"new TreeNode[]{
      new TreeNode("A"new TreeNode[]{
        new TreeNode("A1")
        new TreeNode("A2"),
        new TreeNode("A3"),
        new TreeNode("A4"),}),
      new TreeNode("B"new TreeNode[]{
        new TreeNode("1"),
        new TreeNode("2"),
        new TreeNode("3"),
        new TreeNode("4"),}),
      new TreeNode("C"new TreeNode[]{
        new TreeNode("F"),
        new TreeNode("E"),}),
      new TreeNode("G"new TreeNode[]{
        new TreeNode("C")
        new TreeNode("2"),
        new TreeNode("F")
        new TreeNode("E"),}),}),
    new TreeNode("M"new TreeNode[]{
        new TreeNode("C"new TreeNode[]{
      new TreeNode("P")
      new TreeNode("V"),}),}),};

  public void onModuleLoad() {
    Tree tree = new Tree();

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

    tree.addTreeListener(this);
    tree.setWidth("20em");

    RootPanel.get().add(tree);
  }
  private void createItem(TreeNode TreeNode) {
    TreeNode.item = new TreeItem(TreeNode.text);
    TreeNode.item.setUserObject(TreeNode);
    if (TreeNode.children != null) {
      TreeNode.item.addItem(new PendingItem());
    }
  }
  public void onTreeItemSelected(TreeItem item) {
    Window.alert(((TreeNodeitem.getUserObject()).text);
  }

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

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

  
}


           
         
    
  
GWT-useTreeListener.zip( 3 k)
Related examples in the same category
1.Create Tree With Pending Item
2.Tree node expanding and collapsing animation (Smart GWT)Tree node expanding and collapsing animation (Smart GWT)
3.Trees can show skinnable connector lines (Smart GWT)Trees can show skinnable connector lines (Smart GWT)
4.Tree with DataArrivedHandler (Smart GWT)Tree with DataArrivedHandler (Smart GWT)
5.Trees with multiple columns of data for each node. (Smart GWT)Trees with multiple columns of data for each node. (Smart GWT)
6.Sortable tree table (Smart GWT)Sortable tree table (Smart GWT)
7.Tree Editing Sample (Smart GWT)Tree Editing Sample (Smart GWT)
8.Parent Linking Tree Sample (Smart GWT)Parent Linking Tree Sample (Smart GWT)
9.Load tree data from a collection of local beans (Smart GWT)Load tree data from a collection of local beans (Smart GWT)
10.Tree data can be specified as a tree of nodes where each node lists its children (Smart GWT)Tree data can be specified as a tree of nodes where each node lists its children (Smart GWT)
11.Drag and drop to move parts and folders within and between the trees (Smart GWT)Drag and drop to move parts and folders within and between the trees (Smart GWT)
12.Tree Drag Reparent Sample (Smart GWT)Tree Drag Reparent Sample (Smart GWT)
13.Closed tree folders automatically open if you hover over them momentarily (Smart GWT)Closed tree folders automatically open if you hover over them momentarily (Smart GWT)
14.Load tree data from a collection of local beans (Smart GWT)Load tree data from a collection of local beans (Smart GWT)
15.Tree view dropdown (Smart GWT)Tree view dropdown (Smart GWT)
16.Trees sort per folder. (Smart GWT)Trees sort per folder. (Smart GWT)
17.Load On Demand Tree Sample (Smart GWT)Load On Demand Tree Sample (Smart GWT)
18.Basic TreePanel Example (Ext GWT)Basic TreePanel Example (Ext GWT)
19.CheckBox Tree Node (Ext GWT)CheckBox Tree Node (Ext GWT)
20.Adding Context Menu to Tree (Ext GWT)Adding Context Menu to Tree (Ext GWT)
21.Fast tree (Ext GWT)Fast tree (Ext GWT)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.