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.gwtext.client.core.Connection;
012: import com.gwtext.client.data.Node;
013: import com.gwtext.client.dd.DragData;
014: import com.gwtext.client.dd.DragDrop;
015: import com.gwtext.client.widgets.Component;
016: import com.gwtext.client.widgets.Panel;
017: import com.gwtext.client.widgets.form.FieldSet;
018: import com.gwtext.client.widgets.form.FormPanel;
019: import com.gwtext.client.widgets.form.Radio;
020: import com.gwtext.client.widgets.layout.HorizontalLayout;
021: import com.gwtext.client.widgets.layout.VerticalLayout;
022: import com.gwtext.client.widgets.tree.*;
023: import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
024: import com.gwtext.sample.showcase2.client.ShowcasePanel;
025:
026: public class TwoTreesSample extends ShowcasePanel {
027:
028: public String getSourceUrl() {
029: return "source/tree/TwoTreesSample.java.html";
030: }
031:
032: public String getXmlDataUrl() {
033: return "source/tree/TwoTreesSample.xml.html";
034: }
035:
036: public Panel getViewPanel() {
037: if (panel == null) {
038: panel = new Panel();
039:
040: //create form for nody drop style
041: FormPanel formPanel = new FormPanel();
042: formPanel.setBorder(false);
043: formPanel.setHideLabels(true);
044:
045: FieldSet fieldSet = new FieldSet("Drop style");
046: fieldSet.setWidth(420);
047: formPanel.add(fieldSet);
048:
049: final Radio moveRadio = new Radio();
050: moveRadio.setName("dropstyle");
051: moveRadio.setBoxLabel("Move");
052: moveRadio.setChecked(true);
053: fieldSet.add(moveRadio);
054:
055: final Radio copyRadio = new Radio();
056: copyRadio.setName("dropstyle");
057: copyRadio.setBoxLabel("Copy");
058: fieldSet.add(copyRadio);
059:
060: //create source countries tree
061: final TreePanel treePanel = new TreePanel();
062: treePanel.setTitle("Countries");
063: treePanel.setAnimate(true);
064: treePanel.setEnableDD(true);
065: treePanel.setContainerScroll(true);
066: treePanel.setRootVisible(true);
067: treePanel.setWidth(200);
068: treePanel.setHeight(400);
069: treePanel.setSelectionModel(new MultiSelectionModel());
070:
071: final XMLTreeLoader loader = new XMLTreeLoader();
072: loader.setDataUrl("data/countries-grouped.xml");
073: loader.setMethod(Connection.GET);
074: loader.setRootTag("countries");
075: loader.setFolderTitleMapping("@title");
076: loader.setFolderTag("continent");
077: loader.setLeafTitleMapping("@title");
078: loader.setLeafTag("country");
079: loader.setQtipMapping("@qtip");
080: loader.setIconMapping("@icon");
081:
082: AsyncTreeNode root = new AsyncTreeNode("Countries", loader);
083: treePanel.setRootNode(root);
084: root.expand();
085: treePanel.expandAll();
086:
087: //create target vacation tree
088: final TreePanel tripTreePanel = new TreePanel();
089: tripTreePanel.setTitle("Trip Planner");
090: tripTreePanel.setAnimate(true);
091: tripTreePanel.setEnableDD(true);
092: tripTreePanel.setContainerScroll(true);
093: tripTreePanel.setRootVisible(true);
094: tripTreePanel.setWidth(200);
095: tripTreePanel.setHeight(400);
096:
097: final XMLTreeLoader tripLoader = new XMLTreeLoader();
098: tripLoader.setDataUrl("data/trip.xml");
099: tripLoader.setMethod(Connection.GET);
100: tripLoader.setRootTag("vacations");
101: tripLoader.setFolderIdMapping("@title");
102: tripLoader.setFolderTag("trip");
103: tripLoader.setQtipMapping("@qtip");
104: tripLoader.setIconMapping("@icon");
105: tripLoader.setAttributeMappings(new String[] { "@trip" });
106:
107: final AsyncTreeNode tripRoot = new AsyncTreeNode(
108: "Places to Visit", tripLoader);
109:
110: tripTreePanel.setRootNode(tripRoot);
111:
112: //add trip tree listener that handles move / copy logic
113: tripTreePanel.addListener(new TreePanelListenerAdapter() {
114: public void onRender(Component component) {
115: tripRoot.expand();
116: tripTreePanel.expandAll();
117: }
118:
119: public boolean doBeforeNodeDrop(TreePanel treePanel,
120: TreeNode target, DragData dragData,
121: String point, DragDrop source,
122: TreeNode dropNode,
123: DropNodeCallback dropDropNodeCallback) {
124: if ("true".equals(target.getAttribute("trip"))) {
125: if (copyRadio.getValue()) {
126: TreeNode copyNode = dropNode.cloneNode();
127: Node[] children = copyNode.getChildNodes();
128: for (int i = 0; i < children.length; i++) {
129: Node child = children[i];
130: copyNode.removeChild(child);
131: }
132: dropDropNodeCallback.setDropNode(copyNode);
133: }
134: }
135: return true;
136: }
137: });
138:
139: Panel horizontalPanel = new Panel();
140: horizontalPanel.setLayout(new HorizontalLayout(20));
141: horizontalPanel.add(treePanel);
142: horizontalPanel.add(tripTreePanel);
143:
144: Panel verticalPanel = new Panel();
145: verticalPanel.setLayout(new VerticalLayout(15));
146:
147: verticalPanel.add(formPanel);
148: verticalPanel.add(horizontalPanel);
149:
150: panel.add(verticalPanel);
151: }
152: return panel;
153: }
154:
155: public String getIntro() {
156: return "This example demonstrates Drag & Drop nodes between trees. It also illustrates how to move a node on drop or make a copy.";
157: }
158: }
|