001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.combo;
009:
010: import com.gwtext.client.data.Record;
011: import com.gwtext.client.data.SimpleStore;
012: import com.gwtext.client.data.Store;
013: import com.gwtext.client.widgets.Panel;
014: import com.gwtext.client.widgets.form.ComboBox;
015: import com.gwtext.client.widgets.form.FormPanel;
016: import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
017: import com.gwtext.sample.showcase2.client.ShowcasePanel;
018:
019: /**
020: * An example of a Linked ComboBox.
021: */
022:
023: //credit to Jozef Sakalos for original Ext tutorial
024: //http://extjs.com/learn/Tutorial:Linked_Combos_Tutorial_for_Ext_2
025: public class LinkedComboBoxSample extends ShowcasePanel {
026:
027: public String getSourceUrl() {
028: return "source/combo/LinkedComboBoxSample.java.html";
029: }
030:
031: public Panel getViewPanel() {
032: if (panel == null) {
033:
034: panel = new Panel();
035:
036: FormPanel form = new FormPanel();
037: form.setTitle("Linked ComboBox");
038: form.setFrame(true);
039: form.setWidth(350);
040:
041: // countries store
042: Object[][] countries = new Object[][] {
043: new Object[] { "USA", "United States of America" },
044: new Object[] { "D", "Germany" },
045: new Object[] { "F", "France" },
046: new Object[] { "GB", "Great Britain" }, };
047:
048: final Store countriesStore = new SimpleStore(new String[] {
049: "cid", "country" }, countries);
050: countriesStore.load();
051:
052: //cities store
053: Object[][] cities = new Object[][] {
054: new Object[] { new Integer(1), "USA", "New York" },
055: new Object[] { new Integer(2), "USA", "Cleveland" },
056: new Object[] { new Integer(3), "USA", "Austin" },
057: new Object[] { new Integer(4), "USA", "Los Angeles" },
058: new Object[] { new Integer(5), "D", "Munich" },
059: new Object[] { new Integer(6), "D", "Bonn" },
060: new Object[] { new Integer(7), "F", "Paris" },
061: new Object[] { new Integer(8), "F", "Nice" },
062: new Object[] { new Integer(9), "GB", "London" },
063: new Object[] { new Integer(10), "GB", "Glasgow" },
064: new Object[] { new Integer(11), "GB", "Liverpool" } };
065:
066: final Store citiesStore = new SimpleStore(new String[] {
067: "id", "cid", "city" }, cities);
068: citiesStore.load();
069:
070: final ComboBox countryCB = new ComboBox();
071: countryCB.setFieldLabel("Select Country");
072: countryCB.setStore(countriesStore);
073: countryCB.setDisplayField("country");
074: countryCB.setMode(ComboBox.LOCAL);
075: countryCB.setTriggerAction(ComboBox.ALL);
076: countryCB.setForceSelection(true);
077: countryCB.setValueField("cid");
078: countryCB.setReadOnly(true);
079:
080: final ComboBox cityCB = new ComboBox();
081: cityCB.setFieldLabel("Select City");
082: cityCB.setStore(citiesStore);
083: cityCB.setDisplayField("city");
084: cityCB.setValueField("id");
085: cityCB.setMode(ComboBox.LOCAL);
086: cityCB.setTriggerAction(ComboBox.ALL);
087: cityCB.setLinked(true);
088: cityCB.setForceSelection(true);
089: cityCB.setReadOnly(true);
090:
091: countryCB.addListener(new ComboBoxListenerAdapter() {
092:
093: public void onSelect(ComboBox comboBox, Record record,
094: int index) {
095: cityCB.setValue("");
096: citiesStore.filter("cid", comboBox.getValue());
097: }
098: });
099:
100: form.add(countryCB);
101: form.add(cityCB);
102:
103: panel.add(form);
104: }
105: return panel;
106: }
107:
108: public String getIntro() {
109: return "<p>This example demonstrates a linked ComboBox where the available options in the second ComboBox depend on"
110: + "the selection in the first ComboBox.</p>";
111: }
112: }
|