001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.form;
009:
010: import com.gwtext.client.core.Function;
011: import com.gwtext.client.core.Position;
012: import com.gwtext.client.data.Record;
013: import com.gwtext.client.widgets.PaddedPanel;
014: import com.gwtext.client.widgets.Panel;
015: import com.gwtext.client.widgets.form.DateField;
016: import com.gwtext.client.widgets.form.FieldSet;
017: import com.gwtext.client.widgets.form.FormPanel;
018: import com.gwtext.client.widgets.form.TextField;
019: import com.gwtext.client.widgets.grid.GridPanel;
020: import com.gwtext.client.widgets.grid.RowSelectionModel;
021: import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
022: import com.gwtext.client.widgets.layout.ColumnLayout;
023: import com.gwtext.client.widgets.layout.ColumnLayoutData;
024: import com.gwtext.client.widgets.layout.FitLayout;
025: import com.gwtext.sample.showcase2.client.SampleGrid;
026: import com.gwtext.sample.showcase2.client.ShowcasePanel;
027:
028: public class FormGridSample extends ShowcasePanel {
029:
030: public String getSourceUrl() {
031: return "source/form/FormGridSample.java.html";
032: }
033:
034: public Panel getViewPanel() {
035: if (panel == null) {
036: panel = new Panel();
037:
038: final FormPanel formPanel = new FormPanel();
039: formPanel.setFrame(true);
040: formPanel.setLabelAlign(Position.LEFT);
041: formPanel.setPaddings(5);
042: formPanel.setWidth(650);
043:
044: Panel inner = new Panel();
045: inner.setLayout(new ColumnLayout());
046:
047: Panel columnOne = new Panel();
048: columnOne.setLayout(new FitLayout());
049:
050: GridPanel gridPanel = new SampleGrid(false, new int[] { 0,
051: 1, 2, 3, 4 });
052: gridPanel.setHeight(300);
053: gridPanel.setTitle("Company Data");
054:
055: final RowSelectionModel sm = new RowSelectionModel(true);
056: sm.addListener(new RowSelectionListenerAdapter() {
057: public void onRowSelect(RowSelectionModel sm,
058: int rowIndex, Record record) {
059: formPanel.getForm().loadRecord(record);
060: }
061: });
062: gridPanel.setSelectionModel(sm);
063:
064: //select the first row after a little delay so that the rows are rendered
065: gridPanel.doOnRender(new Function() {
066: public void execute() {
067: sm.selectFirstRow();
068: }
069: }, 10);
070:
071: columnOne.add(gridPanel);
072: inner.add(columnOne, new ColumnLayoutData(0.6));
073:
074: FieldSet fieldSet = new FieldSet();
075: fieldSet.setLabelWidth(90);
076: fieldSet.setTitle("Company Details");
077: fieldSet.setAutoHeight(true);
078: fieldSet.setBorder(false);
079:
080: //the field names msut match the data field values from the Store
081: fieldSet.add(new TextField("Name", "company", 120));
082: fieldSet.add(new TextField("Price", "price", 120));
083: fieldSet.add(new TextField("% Change", "pctChange", 120));
084: fieldSet.add(new DateField("Last Updated", "lastChanged",
085: 120));
086: inner.add(new PaddedPanel(fieldSet, 0, 10, 0, 0),
087: new ColumnLayoutData(0.4));
088:
089: formPanel.add(inner);
090: panel.add(formPanel);
091: }
092:
093: return panel;
094: }
095:
096: public String getIntro() {
097: return "<p>This example edmonstrates the fact that by virtue of inheriting from the <b>Container</b>"
098: + " class, a FormPanel can contain any <b>Component</b>. This includes all the subclasses of Panel, "
099: + "including the GridPanel</p>"
100: + "<p>This example also demonstrates how data from a Store can be bound to a Grid and a Form.</p>";
101: }
102: }
|