/* * 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.TreeModelType; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSource; 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.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.LayoutSpacer; import com.smartgwt.client.widgets.tree.events.FolderClickEvent; import com.smartgwt.client.widgets.tree.events.FolderClickHandler; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS; import com.smartgwt.sample.showcase.client.data.ItemSupplyXmlDS; import com.google.gwt.core.client.EntryPoint; public class RecategorizeTreeSample implements EntryPoint { public void onModuleLoad() { DataSource supplyCategory = SupplyCategoryXmlDS.getInstance(); DataSource itemSupply = ItemSupplyXmlDS.getInstance(); final ListGrid itemList = new ListGrid(); itemList.setDataSource(itemSupply); itemList.setCanDragRecordsOut(true); itemList.setAutoFetchData(true); Criteria initialCriteria = new Criteria(); initialCriteria.setAttribute("capegory", "Washroom"); itemList.setInitialCriteria(initialCriteria); ListGridField itemName = new ListGridField("itemName"); itemName.setWidth(300); ListGridField sku = new ListGridField("SKU"); ListGridField units = new ListGridField("units"); itemList.setFields(itemName, sku, units); final Label labelCategory = new Label(); labelCategory.setHeight(20); labelCategory.setContents("Items in Category: Washroom"); TreeGrid categoryTree = new TreeGrid(); categoryTree.setDataSource(supplyCategory); categoryTree.setCanAcceptDroppedRecords(true); categoryTree.setCanReparentNodes(false); categoryTree.setAutoFetchData(true); categoryTree.addFolderClickHandler(new FolderClickHandler() { @Override public void onFolderClick(FolderClickEvent event) { String categoryName = event.getFolder().getAttributeAsString("categoryName"); labelCategory.setContents("Items in Category: " + categoryName); Criteria criteria = new Criteria(); criteria.addCriteria("category", categoryName); itemList.fetchData(criteria); } }); VLayout vLayoutItems = new VLayout(); vLayoutItems.setWidth("65%"); vLayoutItems.addMember(labelCategory); vLayoutItems.addMember(itemList); VLayout vLayoutCategory = new VLayout(); vLayoutCategory.setWidth("35%"); LayoutSpacer layoutSpacer = new LayoutSpacer(); layoutSpacer.setHeight(20); vLayoutCategory.addMember(layoutSpacer); vLayoutCategory.addMember(categoryTree); HLayout hLayout = new HLayout(); hLayout.setHeight(300); hLayout.setWidth(800); hLayout.setMembersMargin(10); hLayout.addMember(vLayoutCategory); hLayout.addMember(vLayoutItems); hLayout.draw(); } }