/* * 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.data.Criteria; import com.smartgwt.client.util.Offline; 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.ListGridField; import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.sample.showcase.client.data.ItemSupplyXmlDS; import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS; import com.google.gwt.core.client.EntryPoint; public class OfflineDataSourceSupportSample implements EntryPoint { public void onModuleLoad() { // Enable offline storage for the two DataSources ItemSupplyXmlDS itemSupplyXmlDS = ItemSupplyXmlDS.getInstance(); itemSupplyXmlDS.setUseOfflineStorage(true); SupplyCategoryXmlDS supplyCategoryXmlDS = SupplyCategoryXmlDS.getInstance(); //supplyCategoryXmlDS.setUseOfflineStorage(true); final ListGrid itemListGrid = new ListGrid(); itemListGrid.setWidth(350); itemListGrid.setHeight(224); itemListGrid.setDataSource(itemSupplyXmlDS); ListGridField itemIdField = new ListGridField("itemID"); ListGridField itemNameField = new ListGridField("itemName"); ListGridField unitCostField = new ListGridField("unitCost"); ListGridField categoryField = new ListGridField("category"); itemListGrid.setFields(itemIdField, itemNameField, unitCostField, categoryField); TreeGrid categoryTree = new TreeGrid(); categoryTree.setWidth(250); categoryTree.setHeight(224); categoryTree.setDataSource(supplyCategoryXmlDS); categoryTree.setLoadDataOnDemand(true); categoryTree.setAutoFetchData(true); categoryTree.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { @Override public void onRecordDoubleClick(RecordDoubleClickEvent event) { final String categoryName = event.getRecord().getAttribute("categoryName"); Criteria criteria = new Criteria("category", categoryName); itemListGrid.filterData(criteria); } }); HLayout hLayout = new HLayout(10); hLayout.setMembers(categoryTree, itemListGrid); VLayout layout = new VLayout(10); final IButton button = new IButton("Go Offline", new ClickHandler() { @Override public void onClick(ClickEvent event) { final IButton source = (IButton) event.getSource(); if(source.getTitle().equals("Go Offline")) { Offline.goOffline(); source.setTitle("Go Online"); } else { Offline.goOnline(); source.setTitle("Go Offline"); } } }); layout.setMembers(hLayout, button); layout.setAutoHeight(); layout.draw(); } }