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.client.data;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.gwtext.client.core.JsObject;
013: import com.gwtext.client.data.event.TreeListener;
014:
015: /**
016: * Represents a tree data structure and bubbles all the events for its nodes. The nodes in the tree have most standard
017: * DOM functionality.
018: */
019: public class Tree extends JsObject {
020: /**
021: * Create a new Tree instance.
022: */
023: public Tree() {
024: jsObj = create();
025: }
026:
027: Tree(JavaScriptObject jsObj) {
028: super (jsObj);
029: }
030:
031: private static Tree instance(JavaScriptObject treeJS) {
032: return new Tree(treeJS);
033: }
034:
035: private native JavaScriptObject create()/*-{
036: return new $wnd.Ext.data.Tree();
037: }-*/;
038:
039: /**
040: * Gets a node in this tree by its id.
041: *
042: * @param id the mode ID
043: * @return the node, or null if not found
044: */
045: public Node getNodeById(String id) {
046: JavaScriptObject node = getNodeById(jsObj, id);
047: return node == null ? null : new Node(node);
048: }
049:
050: private native JavaScriptObject getNodeById(JavaScriptObject tree,
051: String id) /*-{
052: return tree.getNodeById(id);
053: }-*/;
054:
055: /**
056: * Returns the root node.
057: *
058: * @return the root node
059: */
060: public Node getRootNode() {
061: JavaScriptObject root = getRootNode(jsObj);
062: return root == null ? null : new Node(root);
063: }
064:
065: private native JavaScriptObject getRootNode(JavaScriptObject tree) /*-{
066: return tree.getRootNode();
067: }-*/;
068:
069: /**
070: * Set the root node.
071: *
072: * @param node the root node
073: */
074: public native void setRootNode(Node node) /*-{
075: var tree = this.@com.gwtext.client.core.JsObject::getJsObj()();
076: var nodeJS = node.@com.gwtext.client.core.JsObject::getJsObj()();
077: tree.setRootNode(nodeJS);
078: }-*/;
079:
080: /**
081: * Add a Tree listener.
082: *
083: * @param listener the listener
084: */
085: public native void addNodeListener(TreeListener listener) /*-{
086: var tree = this.@com.gwtext.client.core.JsObject::getJsObj()();
087: var treeJ = this;
088:
089: tree.addListener('append',
090: function(tree, parent, node, index) {
091: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
092: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
093: listener.@com.gwtext.client.data.event.TreeListener::onAppend(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;I)(treeJ, parentJ, nodeJ, index);
094: }
095: );
096:
097: tree.addListener('beforeappend',
098: function(tree, parent, node) {
099: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
100: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
101: return listener.@com.gwtext.client.data.event.TreeListener::doBeforeAppend(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;)(treeJ, parentJ, nodeJ);
102: }
103: );
104:
105: tree.addListener('beforeinsert',
106: function(tree, parent, node, refNode) {
107: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
108: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
109: var refNodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(refNode);
110: return listener.@com.gwtext.client.data.event.TreeListener::doBeforeInsert(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;)(treeJ, parentJ, nodeJ, refNodeJ);
111: }
112: );
113:
114: tree.addListener('beforemove',
115: function(tree, node, oldParent, newParent, index) {
116: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
117: var oldParentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(oldParent);
118: var newParentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(newParent);
119:
120: return listener.@com.gwtext.client.data.event.TreeListener::doBeforeMove(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;I)(treeJ, nodeJ, oldParentJ, newParentJ, index);
121: }
122: );
123:
124: tree.addListener('beforeremove',
125: function(tree, parent, node) {
126: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
127: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
128: return listener.@com.gwtext.client.data.event.TreeListener::doBeforeRemove(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;)(treeJ, parentJ, nodeJ);
129: }
130: );
131:
132: tree.addListener('insert',
133: function(tree, parent, node, refNode) {
134: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
135: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
136: var refNodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(refNode);
137: listener.@com.gwtext.client.data.event.TreeListener::onInsert(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;)(treeJ, parentJ, nodeJ, refNodeJ);
138: }
139: );
140:
141: tree.addListener('move',
142: function(tree, node, oldParent, newParent, index) {
143: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
144: var oldParentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(oldParent);
145: var newParentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(newParent);
146:
147: listener.@com.gwtext.client.data.event.TreeListener::onMove(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;I)(treeJ, nodeJ, oldParentJ, newParentJ, index);
148: }
149: );
150:
151: tree.addListener('remove',
152: function(tree, parent, node) {
153: var parentJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(parent);
154: var nodeJ = @com.gwtext.client.data.Node::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
155: listener.@com.gwtext.client.data.event.TreeListener::onRemove(Lcom/gwtext/client/data/Tree;Lcom/gwtext/client/data/Node;Lcom/gwtext/client/data/Node;)(treeJ, parentJ, nodeJ);
156: }
157: );
158: }-*/;
159: }
|