/* * 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.Criterion; import com.smartgwt.client.data.DateRange; import com.smartgwt.client.data.RelativeDate; import com.smartgwt.client.types.TitleOrientation; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.events.DrawEvent; import com.smartgwt.client.widgets.events.DrawHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.DateRangeItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.sample.showcase.client.data.WorldXmlDS; import com.google.gwt.core.client.EntryPoint; public class GridDateRangeFilterSample implements EntryPoint { public void onModuleLoad() { VLayout layout = new VLayout(8); // --------------------------------------------------------------------------------------- // Seperate DynamicForm Example (DateRangeItem) Label dateRangeLabel = new Label(); dateRangeLabel.setWidth(595); dateRangeLabel.setHeight(25); dateRangeLabel.setContents("External DynamicForm (DateRangeItem)"); dateRangeLabel.setBaseStyle("exampleSeparator"); layout.addMember(dateRangeLabel); DynamicForm form = new DynamicForm(); form.setWidth(500); form.setHeight(22); form.setTitleOrientation(TitleOrientation.TOP); final DateRangeItem rangeItem = new DateRangeItem("independence"); rangeItem.setWidth("*"); rangeItem.setShowTitle(false); rangeItem.setAllowRelativeDates(true); DateRange dateRange = new DateRange(); dateRange.setRelativeStartDate(new RelativeDate("-1200m")); dateRange.setRelativeEndDate(new RelativeDate("-1000m")); rangeItem.setValue(dateRange); form.setItems(rangeItem); layout.addMember(form); // Create a ListGrid displaying data from the worldDS final ListGrid grid1 = new ListGrid(); grid1.setWidth(595); grid1.setHeight(200); grid1.setDataSource(WorldXmlDS.getInstance()); IButton searchButton = new IButton("Filter"); searchButton.setAutoFit(true); searchButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Criterion criteria = rangeItem.getCriterion(); grid1.fetchData(criteria); } }); layout.addMember(searchButton); layout.addMember(grid1); // --------------------------------------------------------------------------------------- // Inline FilterEditor Example (MiniDateRangeItem) Label filterEditorLabel = new Label("FilterEditor (MiniDateRangeItem)"); filterEditorLabel.setWidth(595); filterEditorLabel.setBaseStyle("exampleSeparator"); filterEditorLabel.setHeight(25); layout.addMember(filterEditorLabel); // Create a ListGrid displaying data from the worldDS and also displaying a FilterEditor final ListGrid grid2 = new ListGrid(); grid2.setWidth(595); grid2.setHeight(200); grid2.setDataSource(WorldXmlDS.getInstance()); grid2.setAutoFetchData(true); grid2.setShowFilterEditor(true); layout.addMember(grid2); layout.addDrawHandler(new DrawHandler() { @Override public void onDraw(DrawEvent event) { Criterion criteria = rangeItem.getCriterion(); grid1.fetchData(criteria); } }); layout.draw(); } }