TreeGrid with Widget Example (Ext GWT) : Tree Table « 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 » Tree TableScreenshots 
TreeGrid with Widget Example (Ext GWT)
TreeGrid with Widget Example (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.io.Serializable;
import java.util.Arrays;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
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.treegrid.TreeGrid;
import com.extjs.gxt.ui.client.widget.treegrid.WidgetTreeGridCellRenderer;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;



public class Hello implements EntryPoint {

  public void onModuleLoad() {

    RootPanel.get().add(new WidgetTreeGridExample());

  }
}
class WidgetTreeGridExample extends LayoutContainer {

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

    Folder model = getTreeModel();

    TreeStore<ModelData> store = new TreeStore<ModelData>();
    store.add(model.getChildren()true);

    ColumnConfig name = new ColumnConfig("name""Name"100);
    name.setRenderer(new WidgetTreeGridCellRenderer<ModelData>(){
      @Override
      public Widget getWidget(ModelData model, String property, ColumnData config, int rowIndex, int colIndex,
          ListStore<ModelData> store, Grid<ModelData> grid) {
        Button b = new Button((String)model.get(property));
        b.setToolTip("Click for more information");
        return b;
      }
    });

    ColumnConfig date = new ColumnConfig("author""Author"100);
    ColumnConfig size = new ColumnConfig("genre""Genre"100);
    ColumnModel cm = new ColumnModel(Arrays.asList(name, date, size));

    ContentPanel cp = new ContentPanel();
    cp.setBodyBorder(false);
    cp.setHeading("Widget Renderer TreeGrid");
    cp.setButtonAlign(HorizontalAlignment.CENTER);
    cp.setLayout(new FitLayout());
    cp.setFrame(true);
    cp.setSize(600300);

    TreeGrid<ModelData> tree = new TreeGrid<ModelData>(store, cm);
    tree.setBorders(true);
    tree.setSize(400400);
    tree.setAutoExpandColumn("name");
    tree.getTreeView().setRowHeight(26);
    tree.getStyle().setLeafIcon(IconHelper.createStyle("icon-music"));
    
    cp.add(tree);

    add(cp);
  }

  public static Folder getTreeModel() {
    Folder[] folders = new Folder[] {
        new Folder("Beethoven",
            new Folder[] {

                new Folder("Quartets",
                    new Music[] {
                        new Music("Six String Quartets""Beethoven""Quartets"),
                        new Music("Three String Quartets""Beethoven""Quartets"),
                        new Music("Grosse Fugue for String Quartets""Beethoven",
                            "Quartets"),}),
                new Folder("Sonatas"new Music[] {
                    new Music("Sonata in A Minor""Beethoven""Sonatas"),
                    new Music("Sonata in F Major""Beethoven""Sonatas"),}),

                new Folder("Concertos"new Music[] {
                    new Music("No. 1 - C""Beethoven""Concertos"),
                    new Music("No. 2 - B-Flat Major""Beethoven""Concertos"),
                    new Music("No. 3 - C Minor""Beethoven""Concertos"),
                    new Music("No. 4 - G Major""Beethoven""Concertos"),
                    new Music("No. 5 - E-Flat Major""Beethoven""Concertos"),}),

                new Folder("Symphonies"new Music[] {
                    new Music("No. 1 - C Major""Beethoven""Symphonies"),
                    new Music("No. 2 - D Major""Beethoven""Symphonies"),
                    new Music("No. 3 - E-Flat Major""Beethoven""Symphonies"),
                    new Music("No. 4 - B-Flat Major""Beethoven""Symphonies"),
                    new Music("No. 5 - C Minor""Beethoven""Symphonies"),
                    new Music("No. 6 - F Major""Beethoven""Symphonies"),
                    new Music("No. 7 - A Major""Beethoven""Symphonies"),
                    new Music("No. 8 - F Major""Beethoven""Symphonies"),
                    new Music("No. 9 - D Minor""Beethoven""Symphonies"),}),}),
        new Folder("Brahms",
            new Folder[] {
                new Folder("Concertos"new Music[] {
                    new Music("Violin Concerto""Brahms""Concertos"),
                    new Music("Double Concerto - A Minor""Brahms""Concertos"),
                    new Music("Piano Concerto No. 1 - D Minor""Brahms""Concertos"),
                    new Music("Piano Concerto No. 2 - B-Flat Major""Brahms",
                        "Concertos"),}),
                new Folder("Quartets",
                    new Music[] {
                        new Music("Piano Quartet No. 1 - G Minor""Brahms""Quartets"),
                        new Music("Piano Quartet No. 2 - A Major""Brahms""Quartets"),
                        new Music("Piano Quartet No. 3 - C Minor""Brahms""Quartets"),
                        new Music("String Quartet No. 3 - B-Flat Minor""Brahms",
                            "Quartets"),}),
                new Folder("Sonatas"new Music[] {
                    new Music("Two Sonatas for Clarinet - F Minor""Brahms""Sonatas"),
                    new Music("Two Sonatas for Clarinet - E-Flat Major""Brahms",
                        "Sonatas"),}),
                new Folder("Symphonies"new Music[] {
                    new Music("No. 1 - C Minor""Brahms""Symphonies"),
                    new Music("No. 2 - D Minor""Brahms""Symphonies"),
                    new Music("No. 3 - F Major""Brahms""Symphonies"),
                    new Music("No. 4 - E Minor""Brahms""Symphonies"),}),}),
        new Folder("Mozart"new Folder[] {new Folder("Concertos"new Music[] {
            new Music("Piano Concerto No. 12""Mozart""Concertos"),
            new Music("Piano Concerto No. 17""Mozart""Concertos"),
            new Music("Clarinet Concerto""Mozart""Concertos"),
            new Music("Violin Concerto No. 5""Mozart""Concertos"),
            new Music("Violin Concerto No. 4""Mozart""Concertos"),}),}),};

    Folder root = new Folder("root");
    for (int i = 0; i < folders.length; i++) {
      root.add((Folderfolders[i]);
    }

    return root;
  }

}
class Music extends BaseTreeModel {

  public Music() {

  }

  public Music(String name) {
    set("name", name);
  }

  public Music(String name, String author, String genre) {
    set("name", name);
    set("author", author);
    set("genre", genre);
  }

  public String getName() {
    return (Stringget("name");
  }

  public String getAuthor() {
    return (Stringget("author");
  }

  public String getGenre() {
    return (Stringget("genre");
  }

  public String toString() {
    return getName();
  }
}

class Folder extends BaseTreeModel implements Serializable {

  private static int ID = 0;
  
  public Folder() {
    set("id", ID++);
  }

  public Folder(String name) {
    set("id", ID++);
    set("name", name);
  }

  public Folder(String name, BaseTreeModel[] children) {
    this(name);
    for (int i = 0; i < children.length; i++) {
      add(children[i]);
    }
  }

  public Integer getId() {
    return (Integerget("id");
  }

  public String getName() {
    return (Stringget("name");
  }

  public String toString() {
    return getName();
  }

}

   
  
Ext-GWT.zip( 4,297 k)
Related examples in the same category
1.A Tree Table
2.Tree, table and detail panel (Smart GWT)Tree, table and detail panel (Smart GWT)
3.Tree in a grid (Smart GWT)Tree in a grid (Smart GWT)
4.Tree table with Frozen Columns Sample (Smart GWT)Tree table with Frozen Columns Sample (Smart GWT)
5.TreeGrid and TreeGridField (Smart GWT)TreeGrid and TreeGridField (Smart GWT)
6.Tree with Multiple Columns Sample (Smart GWT)Tree with Multiple Columns Sample (Smart GWT)
7.ColumnTree provides an alternate navigation paradigm for Tree data (Smart GWT)ColumnTree provides an alternate navigation paradigm for Tree data (Smart GWT)
8.Formatter interfaces allow you to add custom tree titles (Smart GWT)Formatter interfaces allow you to add custom tree titles (Smart GWT)
9.TreeTable editing (Ext GWT)TreeTable editing (Ext GWT)
10.Double click to edit a table tree (Ext GWT)Double click to edit a table tree (Ext GWT)
11.TreeGrid example (Ext GWT)TreeGrid example (Ext GWT)
12.TreeGrid with Row Editor (Ext GWT)TreeGrid with Row Editor (Ext GWT)
13.Adding row number to TreeGrid (Ext GWT)Adding row number to TreeGrid (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.