Fast tree (Ext GWT) : Tree « GWT « Java






Fast tree (Ext GWT)

Fast tree (Ext GWT)
 
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

package com.google.gwt.sample.hello.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelKeyProvider;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TreePanelEvent;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    RootPanel.get().add(new FastTreePanelExample());
  }
}
class FastTreePanelExample extends LayoutContainer {
  private int counter = 0;

  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FlowLayout(12));

    final Html html = new Html("This tree is handling 1 child. Expand to get more!");
    html.setStyleName("pad-text");

    LayoutContainer container = new LayoutContainer();
    container.setSize(300, 350);
    container.setBorders(true);
    container.setLayout(new FitLayout());

    TreeStore<ModelData> store = new TreeStore<ModelData>();
    final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
    tree.setTrackMouseOver(false);
    tree.setDisplayProperty("name");
    store.setKeyProvider(new ModelKeyProvider<ModelData>() {

      public String getKey(ModelData model) {
        return model.get("id");
      }

    });
    ModelData m = createModel("Fast Tree");
    store.add(m, false);

    tree.setLeaf(m, false);

    tree.addListener(Events.BeforeExpand, new Listener<TreePanelEvent<ModelData>>() {

      public void handleEvent(TreePanelEvent<ModelData> be) {
        if (be.getNode().getItemCount() != 0) {
          return;
        }
        List<ModelData> list = new ArrayList<ModelData>();
        for (int i = 0; i < 500; i++) {
          ModelData m = createModel("Tree Item " + i);
          list.add(m);
        }

        tree.getStore().insert(be.getNode().getModel(), list, 0, true);
        for (ModelData m : list) {
          tree.setLeaf(m, false);
        }
      }
    });

    tree.addListener(Events.Expand, new Listener<TreePanelEvent<ModelData>>() {

      public void handleEvent(TreePanelEvent<ModelData> be) {
        html.setHtml("<span>This tree is handling " + tree.getStore().getAllItems().size()
            + " children. Expand to get more!</span>");

      }

    });

    add(html);
    container.add(tree);
    add(container);
    
  }

  private ModelData createModel(String n) {
    ModelData m = new BaseModelData();
    m.set("name", n);
    m.set("id", String.valueOf(counter++));
    return m;
  }

}

   
  








Ext-GWT.zip( 4,297 k)

Related examples in the same category

1.Use TreeListener
2.Create Tree With Pending Item
3.Tree node expanding and collapsing animation (Smart GWT)Tree node expanding and collapsing animation (Smart GWT)
4.Trees can show skinnable connector lines (Smart GWT)Trees can show skinnable connector lines (Smart GWT)
5.Tree with DataArrivedHandler (Smart GWT)Tree with DataArrivedHandler (Smart GWT)
6.Trees with multiple columns of data for each node. (Smart GWT)Trees with multiple columns of data for each node. (Smart GWT)
7.Sortable tree table (Smart GWT)Sortable tree table (Smart GWT)
8.Tree Editing Sample (Smart GWT)Tree Editing Sample (Smart GWT)
9.Parent Linking Tree Sample (Smart GWT)Parent Linking Tree Sample (Smart GWT)
10.Load tree data from a collection of local beans (Smart GWT)Load tree data from a collection of local beans (Smart GWT)
11.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)
12.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)
13.Tree Drag Reparent Sample (Smart GWT)Tree Drag Reparent Sample (Smart GWT)
14.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)
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)