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.core.EventObject;
011: import com.gwtext.client.data.Record;
012: import com.gwtext.client.data.SimpleStore;
013: import com.gwtext.client.data.Store;
014: import com.gwtext.client.widgets.Panel;
015: import com.gwtext.client.widgets.form.ComboBox;
016: import com.gwtext.client.widgets.form.Field;
017: import com.gwtext.client.widgets.form.FormPanel;
018: import com.gwtext.client.widgets.form.event.ComboBoxCallback;
019: import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
020: import com.gwtext.sample.showcase2.client.SampleData;
021: import com.gwtext.sample.showcase2.client.ShowcasePanel;
022:
023: /**
024: * Basic ComboBox.
025: */
026: public class BasicComboBoxSample extends ShowcasePanel {
027:
028: public String getSourceUrl() {
029: return "source/combo/BasicComboBoxSample.java.html";
030: }
031:
032: public Panel getViewPanel() {
033: if (panel == null) {
034:
035: panel = new Panel();
036:
037: FormPanel form = new FormPanel();
038: form.setLabelWidth(35);
039: form.setBorder(false);
040: //create a Store using local array data
041: final Store store = new SimpleStore(new String[] { "abbr",
042: "state", "nick" }, SampleData.getStates());
043: store.load();
044:
045: final ComboBox cb = new ComboBox();
046: cb.setForceSelection(true);
047: cb.setMinChars(1);
048: cb.setFieldLabel("State");
049: cb.setStore(store);
050: cb.setDisplayField("state");
051: cb.setMode(ComboBox.LOCAL);
052: cb.setTriggerAction(ComboBox.ALL);
053: cb.setEmptyText("Enter state");
054: cb.setLoadingText("Searching...");
055: cb.setTypeAhead(true);
056: cb.setSelectOnFocus(true);
057: cb.setWidth(200);
058: cb.setValueField("abbr");
059: //cb.setTpl("<tpl for=\".\"><div ext:qtip=\"{state}. {nick}\" class=\"x-combo-list-item\">{state}</div></tpl>");
060:
061: //this hides the dropdown besides the ComboBox field
062: cb.setHideTrigger(false);
063:
064: cb.addListener(new ComboBoxListenerAdapter() {
065: public boolean doBeforeQuery(ComboBox comboBox,
066: ComboBoxCallback cb) {
067: log(EVENT, "ComboBox::doBeforeQuery()");
068: return true;
069: }
070:
071: public boolean doBeforeSelect(ComboBox comboBox,
072: Record record, int index) {
073: log(EVENT, "ComboBox::doBeforeSelect('"
074: + record.getAsString("states") + "')");
075: return super
076: .doBeforeSelect(comboBox, record, index);
077: }
078:
079: public void onCollapse(ComboBox comboBox) {
080: log(EVENT, "ComboBox::onCollapse()");
081: }
082:
083: public void onExpand(ComboBox comboBox) {
084: log(EVENT, "ComboBox::onExpand()");
085: }
086:
087: public void onSelect(ComboBox comboBox, Record record,
088: int index) {
089: log(EVENT, "ComboBox::onSelect('"
090: + record.getAsString("states") + "')");
091: }
092:
093: public void onBlur(Field field) {
094: log(EVENT, "ComboBox::onBlur()");
095: }
096:
097: public void onChange(Field field, Object newVal,
098: Object oldVal) {
099: log(EVENT, "ComboBox::onChange(" + oldVal + "-->"
100: + newVal + ")");
101: }
102:
103: public void onFocus(Field field) {
104: log(EVENT, "ComboBox::onFocus()");
105: }
106:
107: public void onInvalid(Field field, String msg) {
108: super .onInvalid(field, msg);
109: }
110:
111: public void onSpecialKey(Field field, EventObject e) {
112: log(EVENT, "ComboBox::onSpecialKey(key code "
113: + e.getKey() + ")");
114: }
115: });
116:
117: form.add(cb);
118: panel.add(form);
119: }
120: return panel;
121: }
122:
123: protected boolean showEvents() {
124: return true;
125: }
126:
127: public String getIntro() {
128: return "<p>This example shows a basic ComboBox populated with data from a Store. It also associates a custom tooltip based on a template for each ComboBox item.</p> "
129: + "<p>A Store can be populated from a wide varierty of data sources like XML or Json data from your webserver, Json data from another server using cross "
130: + "domain script loading or local array data. GWT-Plus supports populating a Store with Javabeans returned using GWT-RPC.</p>"
131: + "<p>This particular example loads data into the Store using local array data.</p>";
132: }
133: }
|