/*
* 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.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.HttpProxy;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.XmlLoadResultReader;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
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.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.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.impl.WindowImplIE.Resources;
import com.google.gwt.user.client.ui.RootPanel;
public class Hello implements EntryPoint {
public void onModuleLoad() {
RootPanel.get().add(new XmlGridExample());
}
}
class XmlGridExample extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout(10));
List columns = new ArrayList();
columns.add(new ColumnConfig("Sender", "Sender", 100));
columns.add(new ColumnConfig("Email", "Email", 165));
columns.add(new ColumnConfig("Phone", "Phone", 100));
columns.add(new ColumnConfig("State", "State", 50));
columns.add(new ColumnConfig("Zip", "Zip Code", 65));
// create the column model
ColumnModel cm = new ColumnModel(columns);
// defines the xml structure
ModelType type = new ModelType();
type.setRoot("records");
type.setRecordName("record");
type.addField("Sender", "Name");
type.addField("Email");
type.addField("Phone");
type.addField("State");
type.addField("Zip");
// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
GWT.getHostPageBaseURL() + "data/data.xml");
HttpProxy proxy = new HttpProxy(builder);
// need a loader, proxy, and reader
XmlLoadResultReader> reader = new XmlLoadResultReader>(
type);
final BaseListLoader> loader = new BaseListLoader>(
proxy, reader);
ListStore store = new ListStore(loader);
final Grid grid = new Grid(store, cm);
grid.setBorders(true);
grid.setLoadMask(true);
grid.getView().setEmptyText("Please hit the load button.");
grid.setAutoExpandColumn("Sender");
ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
//panel.setIcon(Resources.ICONS.table());
panel.setHeading("XML Table Demo");
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setSize(575, 350);
// add buttons
Button load = new Button("Load XML", new SelectionListener() {
public void componentSelected(ButtonEvent ce) {
loader.load();
}
});
panel.addButton(load);
add(panel);
}
}
Ext-GWT.zip( 4,297 k)