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.EventObject;
014: import com.gwtext.client.core.Function;
015: import com.gwtext.client.widgets.Button;
016: import com.gwtext.client.widgets.Panel;
017: import com.gwtext.client.widgets.Tool;
018: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
019: import com.gwtext.client.widgets.tree.AsyncTreeNode;
020: import com.gwtext.client.widgets.tree.TreeNode;
021: import com.gwtext.client.widgets.tree.TreePanel;
022: import com.gwtext.client.widgets.tree.XMLTreeLoader;
023: import com.gwtext.sample.showcase2.client.Showcase2;
024: import com.gwtext.sample.showcase2.client.ShowcasePanel;
025:
026: public class CheckboxTreePanel extends ShowcasePanel {
027:
028: public String getSourceUrl() {
029: return "source/tree/CheckboxTreePanel.java.html";
030: }
031:
032: public String getXmlDataUrl() {
033: return "source/tree/CheckboxTreePanel.xml.html";
034: }
035:
036: public String getCssUrl() {
037: return "source/tree/CheckboxTreePanel.css.html";
038: }
039:
040: public Panel getViewPanel() {
041: if (panel == null) {
042: panel = new Panel();
043: final TreePanel treePanel = new TreePanel();
044: treePanel.setTitle("Checkbox Tree");
045: treePanel.setCollapsible(true);
046: treePanel.setIconCls("world-icon");
047: treePanel.setHeight(400);
048: treePanel.setWidth(200);
049: treePanel.setAnimate(true);
050: treePanel.setEnableDD(true);
051: treePanel.setContainerScroll(true);
052: treePanel.setAutoScroll(true);
053: treePanel.setRootVisible(true);
054: treePanel.setFrame(true);
055:
056: XMLTreeLoader loader = new XMLTreeLoader();
057: loader.setDataUrl("countries-cb.xml");
058: loader.setMethod(Connection.GET);
059: loader.setRootTag("countries");
060: loader.setFolderIdMapping("@id");
061: loader.setLeafIdMapping("@id");
062: loader.setFolderTitleMapping("@title");
063: loader.setFolderTag("team");
064: loader.setLeafTitleMapping("@title");
065: loader.setLeafTag("country");
066: loader.setQtipMapping("@qtip");
067: loader.setDisabledMapping("@disabled");
068: loader.setCheckedMapping("@checked");
069: loader.setIconMapping("@icon");
070: loader.setAttributeMappings(new String[] { "@rank" });
071:
072: final AsyncTreeNode root = new AsyncTreeNode("Countries",
073: loader);
074: treePanel.setRootNode(root);
075:
076: root.expand();
077:
078: treePanel.addTool(new Tool(Tool.REFRESH, new Function() {
079: public void execute() {
080: treePanel.getEl().mask("Loading", "x-mask-loading");
081: root.reload();
082: root.collapse(true, false);
083: Timer timer = new Timer() {
084: public void run() {
085: treePanel.getEl().unmask();
086: root.expand(true, true);
087: }
088: };
089: timer.schedule(1000);
090: }
091: }, "Refresh"));
092:
093: treePanel.expandAll();
094:
095: Button button = new Button("Show Checked",
096: new ButtonListenerAdapter() {
097: public void onClick(Button button, EventObject e) {
098: TreeNode[] checkedNodes = treePanel
099: .getChecked();
100: String checkedNodesString = "";
101: for (int i = 0; i < checkedNodes.length; i++) {
102: TreeNode checkedNode = checkedNodes[i];
103: checkedNodesString += "<br>"
104: + checkedNode.getText();
105: }
106: Showcase2.showMessage("Checked Nodes",
107: checkedNodesString);
108: }
109: });
110:
111: Button toggle = new Button("Toggle Team A",
112: new ButtonListenerAdapter() {
113: public void onClick(Button button, EventObject e) {
114: treePanel.getNodeById("team-a").getUI()
115: .toggleCheck();
116: }
117: });
118:
119: treePanel.addButton(button);
120: treePanel.addButton(toggle);
121:
122: panel.add(treePanel);
123: }
124: return panel;
125:
126: }
127:
128: public String getIntro() {
129: return "This example demonstrates TreeNodes with Checkboxes.";
130: }
131: }
|