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:
009: package com.gwtext.sample.showcase2.client.tree;
010:
011: import com.google.gwt.user.client.Timer;
012: import com.gwtext.client.core.Connection;
013: import com.gwtext.client.core.Function;
014: import com.gwtext.client.core.Template;
015: import com.gwtext.client.data.SimpleStore;
016: import com.gwtext.client.data.Store;
017: import com.gwtext.client.widgets.Panel;
018: import com.gwtext.client.widgets.Tool;
019: import com.gwtext.client.widgets.form.ComboBox;
020: import com.gwtext.client.widgets.tree.AsyncTreeNode;
021: import com.gwtext.client.widgets.tree.TreeEditor;
022: import com.gwtext.client.widgets.tree.TreePanel;
023: import com.gwtext.client.widgets.tree.XMLTreeLoader;
024: import com.gwtext.sample.showcase2.client.SampleData;
025: import com.gwtext.sample.showcase2.client.ShowcasePanel;
026:
027: public class EditableTreePanel extends ShowcasePanel {
028:
029: public String getSourceUrl() {
030: return "source/tree/EditableTreePanel.java.html";
031: }
032:
033: public String getXmlDataUrl() {
034: return "source/tree/EditableTreePanel.xml.html";
035: }
036:
037: public Panel getViewPanel() {
038: if (panel == null) {
039: final Store store = new SimpleStore(new String[] { "abbr",
040: "country" }, SampleData.getCountries());
041: store.load();
042:
043: final Template template = new Template(
044: "<div class=\"x-combo-list-item\"><img src=\"images/flags/{abbr}.gif\"> "
045: + "{country}<div class=\"x-clear\"></div></div>");
046:
047: ComboBox cb = new ComboBox();
048: cb.setMinChars(1);
049: cb.setFieldLabel("Countries");
050: cb.setStore(store);
051: cb.setDisplayField("country");
052: cb.setMode(ComboBox.LOCAL);
053: cb.setTriggerAction(ComboBox.ALL);
054: cb.setEmptyText("Select Country");
055: cb.setTypeAhead(true);
056: cb.setSelectOnFocus(true);
057: cb.setWidth(60);
058: cb.setResizable(true);
059: cb.setTpl(template);
060: cb.setTitle("Countries");
061: cb.setAllowBlank(false);
062:
063: final TreePanel treePanel = new TreePanel();
064: treePanel.setWidth(240);
065: treePanel.setHeight(400);
066: treePanel.setTitle("Editable Tree");
067: treePanel.setAnimate(true);
068: treePanel.setEnableDD(true);
069: treePanel.setContainerScroll(true);
070: treePanel.setRootVisible(true);
071:
072: final XMLTreeLoader loader = new XMLTreeLoader();
073: loader.setDataUrl("data/countries.xml");
074: loader.setMethod(Connection.GET);
075: loader.setRootTag("countries");
076: loader.setFolderTitleMapping("@title");
077: loader.setFolderTag("team");
078: loader.setLeafTitleMapping("@title");
079: loader.setLeafTag("country");
080: loader.setQtipMapping("@qtip");
081: loader.setDisabledMapping("@disabled");
082: loader.setCheckedMapping("@checked");
083: loader.setIconMapping("@icon");
084: loader.setAttributeMappings(new String[] { "@rank" });
085:
086: final AsyncTreeNode root = new AsyncTreeNode("Countries",
087: loader);
088: treePanel.setRootNode(root);
089:
090: root.expand();
091: treePanel.expandAll();
092:
093: treePanel.addTool(new Tool(Tool.REFRESH, new Function() {
094: public void execute() {
095: treePanel.getEl().mask("Loading", "x-mask-loading");
096: root.reload();
097: root.collapse(true, false);
098: Timer timer = new Timer() {
099: public void run() {
100: treePanel.getEl().unmask();
101: root.expand(true, true);
102: }
103: };
104: timer.schedule(1000);
105: }
106: }, "Refresh"));
107:
108: TreeEditor treeEditor = new TreeEditor(treePanel, cb);
109:
110: panel = new Panel();
111: panel.setBorder(false);
112: panel.add(treePanel);
113: }
114: return panel;
115: }
116:
117: public String getIntro() {
118: return "<p>This example demonstrates an Editable Tree loaded from XML data. Double clicking on a node allows you to edit it. "
119: + "In this example a ComboBox editor is specified as the Editor.</p>";
120: }
121: }
|