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.form;
009:
010: import com.gwtext.client.core.EventObject;
011: import com.gwtext.client.core.Position;
012: import com.gwtext.client.widgets.Button;
013: import com.gwtext.client.widgets.MessageBox;
014: import com.gwtext.client.widgets.Panel;
015: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
016: import com.gwtext.client.widgets.form.FormPanel;
017: import com.gwtext.client.widgets.form.TextField;
018: import com.gwtext.sample.showcase2.client.ShowcasePanel;
019: import com.gwtextux.client.widgets.form.MultiSelect;
020:
021: public class MultiSelectSample extends ShowcasePanel {
022:
023: public Panel getViewPanel() {
024: if (panel == null) {
025: panel = new Panel();
026:
027: final FormPanel formPanel = new FormPanel();
028: formPanel.setFrame(true);
029: formPanel.setLabelAlign(Position.RIGHT);
030: formPanel.setTitle("Multi Select Form");
031: formPanel.setWidth(320);
032: formPanel.setLabelWidth(75);
033:
034: formPanel.add(new TextField("Team", "team"));
035:
036: final MultiSelect multiSelect = new MultiSelect();
037: multiSelect.setName("players");
038: multiSelect
039: .setDataFields(new String[] { "playerID", "name" });
040: multiSelect.setData(new Object[][] {
041: new Object[] { "1", "One" },
042: new Object[] { "2", "Two" },
043: new Object[] { "3", "Three" },
044: new Object[] { "4", "Four" },
045: new Object[] { "5", "Five" },
046: new Object[] { "6", "Six" },
047: new Object[] { "7", "Seven" },
048: new Object[] { "8", "Eight" },
049: new Object[] { "9", "Nine" } });
050: multiSelect.setValueField("playerID");
051: multiSelect.setDisplayField("name");
052: multiSelect.setWidth(160);
053: multiSelect.setHeight(180);
054: multiSelect.setAllowBlank(true);
055: multiSelect.setLegend("Players");
056: multiSelect.setFieldLabel("Players");
057:
058: formPanel.add(multiSelect);
059:
060: formPanel.addButton(new Button("Get Value",
061: new ButtonListenerAdapter() {
062: public void onClick(Button button, EventObject e) {
063: super .onClick(button, e);
064:
065: String values = formPanel.getForm()
066: .getValues();
067: MessageBox.alert("Values", values);
068: }
069: }));
070:
071: formPanel.addButton(new Button("Set Value (2,3)",
072: new ButtonListenerAdapter() {
073: public void onClick(Button button, EventObject e) {
074: multiSelect.setValue("2,3");
075: }
076: }));
077:
078: formPanel.addButton(new Button("Mark Invalid",
079: new ButtonListenerAdapter() {
080:
081: public void onClick(Button button, EventObject e) {
082: multiSelect.markInvalid("Invalid");
083: }
084: }));
085:
086: formPanel.addButton(new Button("Toggle Enabled",
087: new ButtonListenerAdapter() {
088:
089: public void onClick(Button button, EventObject e) {
090: if (multiSelect.isDisabled()) {
091: multiSelect.enable();
092: } else {
093: multiSelect.enable();
094: }
095: }
096: }));
097:
098: panel.add(formPanel);
099: }
100: return panel;
101: }
102: }
|