/* * 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.DataSource; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.types.TextMatchStyle; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.FormItemCriterionGetter; import com.smartgwt.client.widgets.form.SearchForm; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.RadioGroupItem; import com.smartgwt.client.widgets.form.events.ItemChangedEvent; import com.smartgwt.client.widgets.form.events.ItemChangedHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.VStack; import com.smartgwt.sample.showcase.client.data.WorldXmlDS; import com.google.gwt.core.client.EntryPoint; public class TieredFilteringSample implements EntryPoint { public void onModuleLoad() { SearchForm specializedForm = new SearchForm(); specializedForm.setNumCols(4); specializedForm.setWidth(800); RadioGroupItem radioGroupHemisphere = new RadioGroupItem(); radioGroupHemisphere.setName("hemisphere"); radioGroupHemisphere.setTitle("Hemisphere"); radioGroupHemisphere.setValueMap("Any", "Northern", "Southern"); radioGroupHemisphere.setDefaultValue("Any"); radioGroupHemisphere.setVertical(false); radioGroupHemisphere.setCriterionGetter(new FormItemCriterionGetter() { @Override public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) { return null; } @Override public Criterion getCriterion(DynamicForm form, FormItem item) { final Criterion criterionHemisphere = new Criterion(); String[] southernCountries = {"Indonesia", "Argentina", "Bolivia", "Australia", "Brasil", "Chile", "Paraguay", "Ecuador","Mauritius", "Somalia", "Tanzania", "Zambia", "Peru", "Uruguay", "Angola", "Botswana", "Burundi", "Madagascar", "South Africa", "Kenya", "Malawi", "Mozambique", "Namibia", "Nauru", "New Zeland", "Congo"}; String value = (String)item.getValue(); if (value != null && !value.equals("Any")) { if (value.equals("Northern")) { criterionHemisphere.setFieldName("countryName"); criterionHemisphere.setOperator(OperatorId.NOT_IN_SET); criterionHemisphere.setAttribute("value", southernCountries); } else { criterionHemisphere.setFieldName("countryName"); criterionHemisphere.setOperator(OperatorId.IN_SET); criterionHemisphere.setAttribute("value", southernCountries); } } return criterionHemisphere; } }); RadioGroupItem radioGroupPopulation= new RadioGroupItem(); radioGroupPopulation.setName("population"); radioGroupPopulation.setTitle("Population"); radioGroupPopulation.setValueMap("Any", "Dense", "Normal", "Sparse"); radioGroupPopulation.setDefaultValue("Any"); radioGroupPopulation.setVertical(false); radioGroupPopulation.setCriterionGetter(new FormItemCriterionGetter() { @Override public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) { return null; } @Override public Criterion getCriterion(DynamicForm form, FormItem item) { final Criterion criterionPopulation = new Criterion(); String value = (String)item.getValue(); if (value != null && !value.equals("Any")) { if (value.equals("Dense")) { criterionPopulation.setFieldName("population"); criterionPopulation.setOperator(OperatorId.LESS_THAN); criterionPopulation.setAttribute("value", 1000000); } else if (value.equals("Normal")) { criterionPopulation.setFieldName("population"); criterionPopulation.setOperator(OperatorId.BETWEEN); criterionPopulation.setAttribute("start", 1000001); criterionPopulation.setAttribute("end", 6500000); } else { criterionPopulation.setFieldName("population"); criterionPopulation.setOperator(OperatorId.GREATER_THAN); criterionPopulation.setAttribute("value", 6500001); } } return criterionPopulation; } }); specializedForm.setFields(radioGroupHemisphere, radioGroupPopulation); specializedForm.setDataSource(WorldXmlDS.getInstance()); specializedForm.setColWidths(120, "*", 100); specializedForm.addItemChangedHandler(new ItemChangedHandler() { @Override public void onItemChanged(ItemChangedEvent event) { specializedForm.submit(); } }); ListGrid countryList = new ListGrid(); countryList.setWidth(800); countryList.setHeight(224); countryList.setAlternateRecordStyles(true); countryList.setAutoFetchData(true); countryList.setCanShowFilterEditor(true); countryList.setDataSource(WorldXmlDS.getInstance()); countryList.setSearchForm(specializedForm); countryList.setAllowFilterOperators(true); countryList.setAlwaysShowOperatorIcon(true); ListGridField countryNameField = new ListGridField("countryName", "Country Name"); ListGridField continentField = new ListGridField("continent", "Continent"); ListGridField populationField = new ListGridField("population", "Population"); populationField.setType(ListGridFieldType.INTEGER); ListGridField areaField = new ListGridField("area", "Area"); areaField.setType(ListGridFieldType.FLOAT); ListGridField independenceField = new ListGridField("independence", "Independence"); independenceField.setType(ListGridFieldType.DATE); independenceField.setWidth(150); countryList.setFields(countryNameField, continentField, populationField, areaField, independenceField); VStack vStack = new VStack(); vStack.setWidth100(); vStack.setMembersMargin(10); vStack.setMembers(specializedForm, countryList); vStack.draw(); } protected boolean isTopIntro() { return true; } }