/* * SmartGWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * SmartGWT 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. SmartGWT 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.data.DataSource; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.sample.showcase.client.data.ItemSupplyXmlDS; import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS; public class NestedGridSample implements EntryPoint { private ListGridRecord lastOpenedRecord; public void onModuleLoad() { VLayout layout = new VLayout(20); final ItemSupplyXmlDS itemSupplyXmlDS = ItemSupplyXmlDS.getInstance(); final ListGrid categoryGrid = new ListGrid(); categoryGrid.setWidth(600); categoryGrid.setHeight(400); categoryGrid.setDataSource(SupplyCategoryXmlDS.getInstance()); categoryGrid.setAlternateRecordStyles(true); categoryGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { public void onRecordDoubleClick(RecordDoubleClickEvent event) { showDetailGrid(categoryGrid, itemSupplyXmlDS); } }); categoryGrid.fetchData(); layout.addMember(categoryGrid); IButton showDetail = new IButton("Show Detail Grid"); showDetail.setWidth(140); showDetail.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { showDetailGrid(categoryGrid, itemSupplyXmlDS); } }); layout.addMember(showDetail); IButton hideDetail = new IButton("Hide Detail Grid"); hideDetail.setWidth(140); hideDetail.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (lastOpenedRecord != null) { categoryGrid.closeRecord(lastOpenedRecord); lastOpenedRecord = null; } } }); layout.addMember(hideDetail); layout.draw(); } private void showDetailGrid(ListGrid categoryGrid, DataSource itemSupplyXmlDS) { ListGridRecord record = categoryGrid.getSelectedRecord(); if (record != null) { categoryGrid.openRecordDetailGrid(record, itemSupplyXmlDS); lastOpenedRecord = record; } } }