/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.google.gwt.core.client.EntryPoint; public class GridDataBindingInlineDataSample implements EntryPoint { public void onModuleLoad() { final ListGrid countryGrid = new ListGrid(); countryGrid.setWidth(350); countryGrid.setHeight(224); countryGrid.setShowAllRecords(true); ListGridField countryCodeField = new ListGridField("countryCode", "Code", 50); ListGridField nameField = new ListGridField("countryName", "Country", 120); ListGridField capitalField = new ListGridField("capital", "Capital"); countryGrid.setFields(countryCodeField, nameField, capitalField); countryGrid.setCanResizeFields(true); countryGrid.setData(createListGridRecords(countryRecords)); countryGrid.draw(); } private static final String[] countryRecords = new String[] { "countryCode;countryName;capital", "US;United States;Washington, DC", "CH;China;Beijing", "JA;Japan;Tokyo", "IN;India;New Delhi", "GM;Germany;Berlin", "UK;United Kingdom;London", "FR;France;Paris", "IT;Italy;Rome", "RS;Russia;Moscow", "BR;Brazil;Brasilia", "CA;Canada;Ottawa", "MX;Mexico;Mexico (Distrito Federal)", "SP;Spain;Madrid", "KS;South Korea;Seoul", "ID;Indonesia;Jakarta"}; /** * Creates an array of
ListGridRecord
objects from an array of
String
* values. The first string in the array contains the names of the fields in the *
ListGridRecord
s; the remaining strings in the supplied array contain the data. * The field names and data values are separated by semicolons. * @param records An array of strings containing the field names (in the first string of the * array) and the data values to be used in creating the resulting list grid records. * @return An array of list grid records representing the data. */ public ListGridRecord[] createListGridRecords(String[] records) { ListGridRecord[] result = new ListGridRecord[records.length - 1]; String[] fieldNames = records[0].split(";"); for (int recordIndex = 1; recordIndex < records.length; ++recordIndex) { String[] fieldValues = records[recordIndex].split(";"); result[recordIndex - 1] = new ListGridRecord(); for (int fieldIndex = 0; fieldIndex < fieldValues.length; ++fieldIndex) { result[recordIndex - 1].setAttribute(fieldNames[fieldIndex], fieldValues[fieldIndex]); } } return result; } // createListGridRecords() }