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.widgets.*;
012: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
013: import com.gwtext.client.widgets.form.FormPanel;
014: import com.gwtext.client.widgets.form.TextField;
015: import com.gwtext.sample.showcase2.client.ShowcasePanel;
016: import com.gwtextux.client.widgets.form.ItemSelector;
017:
018: public class ItemSelectorSample extends ShowcasePanel {
019:
020: public String getSourceUrl() {
021: return "source/form/ItemSelectorSample.java.html";
022: }
023:
024: public Panel getViewPanel() {
025: if (panel == null) {
026: panel = new Panel();
027:
028: final FormPanel formPanel = new FormPanel();
029: formPanel.setTitle("Team Selection");
030: formPanel.setFrame(true);
031: formPanel.setPaddings(5, 0, 5, 5);
032: formPanel.setWidth(520);
033: formPanel.setLabelWidth(75);
034: formPanel.add(new TextField("Team", "team", 230));
035:
036: final ItemSelector itemSelector = new ItemSelector();
037: itemSelector.setFieldLabel("Players");
038: itemSelector.setName("players");
039: itemSelector.setDataFields(new String[] { "playerID",
040: "name" });
041: itemSelector.setFromData(new Object[][] {
042: new Object[] { "1", "Player One" },
043: new Object[] { "2", "Player Two" },
044: new Object[] { "3", "Player Three" },
045: new Object[] { "4", "Player Four" },
046: new Object[] { "5", "Player Five" } });
047: itemSelector.setToData(new Object[][] { new Object[] { "6",
048: "Player Six" } });
049: itemSelector.setMsWidth(160);
050: itemSelector.setMsHeight(200);
051:
052: itemSelector.setValueField("playerID");
053: itemSelector.setDisplayField("name");
054:
055: //can also assign legends
056: //itemSelector.setToLegend("Selected");
057: //itemSelector.setFromLegend("Available");
058:
059: Toolbar fromToolbar = new Toolbar();
060: ToolbarButton addButton = new ToolbarButton();
061: addButton.setDisabled(true);
062: addButton.setIconCls("user-add-icon");
063: fromToolbar.addButton(addButton);
064: fromToolbar.addSpacer();
065: fromToolbar.addItem(new ToolbarTextItem("Available"));
066: itemSelector.setFromToolbar(fromToolbar);
067:
068: Toolbar toToolbar = new Toolbar();
069: ToolbarButton clearButton = new ToolbarButton("Clear");
070: clearButton.setIconCls("user-delete-icon");
071: clearButton.addListener(new ButtonListenerAdapter() {
072: public void onClick(Button button, EventObject e) {
073: itemSelector.reset();
074: }
075: });
076: toToolbar.addButton(clearButton);
077: itemSelector.setToToolbar(toToolbar);
078:
079: formPanel.add(itemSelector);
080:
081: Button values = new Button("Get Value",
082: new ButtonListenerAdapter() {
083: public void onClick(Button button, EventObject e) {
084: super .onClick(button, e);
085:
086: String values = formPanel.getForm()
087: .getValues();
088: log(MESSAGE, "Form data : " + values);
089: }
090: });
091: formPanel.addButton(values);
092:
093: Button markInvalid = new Button("Mark Invalid",
094: new ButtonListenerAdapter() {
095: public void onClick(Button button, EventObject e) {
096: itemSelector.markInvalid("Invalid");
097: }
098: });
099:
100: formPanel.addButton(markInvalid);
101:
102: panel.add(formPanel);
103: }
104: return panel;
105: }
106:
107: protected boolean showEvents() {
108: return true;
109: }
110:
111: public String getIntro() {
112: return "This is an example of a dual column Item selector.";
113: }
114: }
|