/* * 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.types.Alignment; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.types.RecordComponentPoolingMode; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.sample.showcase.client.data.CountryData; import com.google.gwt.core.client.EntryPoint; public class RecordWidgetsSample implements EntryPoint { public void onModuleLoad() { ListGrid itemList = new ListGrid() { @Override protected Canvas createRecordComponent(ListGridRecord record, Integer colNum) { final ListGrid grid = this; Label editImg = new Label(); editImg.setLayoutAlign(Alignment.CENTER); editImg.setContents(record.getAttribute("background")); editImg.setWrap(true); editImg.setHeight(grid.getDrawnRowHeight(grid.getRowNum(record))); return editImg; } @Override public Canvas updateRecordComponent(ListGridRecord record, Integer colNum, Canvas component, boolean recordChanged) { final ListGrid grid = this; Label labelComponent = (Label)component; if (recordChanged) { labelComponent.setContents(record.getAttribute("background")); labelComponent.setHeight(grid.getDrawnRowHeight(grid.getRowNum(record))); } return labelComponent; } }; itemList.setWidth(750); itemList.setHeight(500); itemList.setCanResizeFields(true); itemList.setShowRecordComponents(true); itemList.setCanRemoveRecords(true); itemList.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE); itemList.setData(CountryData.getRecords()); ListGridField countryCodeField = new ListGridField(); countryCodeField.setName("countryCode"); countryCodeField.setType(ListGridFieldType.IMAGE); countryCodeField.setTitle("Flag"); countryCodeField.setWidth(40); countryCodeField.setAlign(Alignment.CENTER); countryCodeField.setImageURLPrefix("flags/16/"); countryCodeField.setImageURLSuffix(".png"); ListGridField countryNameField = new ListGridField(); countryNameField.setName("countryName"); countryNameField.setTitle("Country"); ListGridField capitalField = new ListGridField(); capitalField.setName("capital"); capitalField.setTitle("Capital"); ListGridField continentField = new ListGridField(); continentField.setName("continent"); continentField.setTitle("Continent"); itemList.setFields(countryCodeField,countryNameField,capitalField,continentField); itemList.draw(); itemList.draw(); } @Override protected boolean isTopIntro() { return true; } }