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.client.widgets.tree;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011: import com.gwtext.client.core.JsObject;
012:
013: /**
014: * Supports filtering of TreePanel nodes.
015: */
016: public class TreeFilter extends JsObject {
017:
018: /**
019: * Create a new TreeFilter.
020: *
021: * @param treePanel the tree panel to filter
022: */
023: public TreeFilter(TreePanel treePanel) {
024: jsObj = create(treePanel.getOrCreateJsObj(), null);
025: }
026:
027: /**
028: * Create a new TreeFilter.
029: *
030: * @param treePanel the tree panel to filter
031: * @param config the TreePanelFilter config
032: */
033: public TreeFilter(TreePanel treePanel, TreeFilterConfig config) {
034: jsObj = create(treePanel.getOrCreateJsObj(),
035: config == null ? null : config.getJsObj());
036: }
037:
038: protected native JavaScriptObject create(
039: JavaScriptObject treePanel, JavaScriptObject config)/*-{
040: return new $wnd.Ext.tree.TreeFilter(treePanel, config);
041: }-*/;
042:
043: /**
044: * Clears the current filter. Note: with the "remove" TreeFilterConfig option set a filter cannot be cleared.
045: */
046: public native void clear() /*-{
047: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
048: filter.clear();
049: }-*/;
050:
051: //TODO filter based on specific node attributes
052: /**
053: * Filter the data.
054: *
055: * @param value the node's text value
056: */
057: public native void filter(String value) /*-{
058: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
059: filter.filter(value);
060: }-*/;
061:
062: /**
063: * Filter the data.
064: *
065: * @param value the node's text
066: * @param startNode the node to start filtering from
067: */
068: public native void filter(String value, TreeNode startNode) /*-{
069: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
070: var node = startNode.@com.gwtext.client.core.JsObject::getJsObj()();
071: filter.filter(value, null, node);
072: }-*/;
073:
074: /**
075: * Filter the data.
076: *
077: * @param regexp regexp to test the node value against
078: */
079: public native void filterRe(String regexp) /*-{
080: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
081: filter.filter(new $wnd.RegExp(regexp));
082: }-*/;
083:
084: /**
085: * Filter the data.
086: *
087: * @param regexp regexp to test the node value against
088: * @param startNode the node to start filtering from
089: */
090: public native void filterRe(String regexp, TreeNode startNode) /*-{
091: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
092: var node = startNode.@com.gwtext.client.core.JsObject::getJsObj()();
093: filter.filter(new $wnd.RegExp(regexp), null, node);
094: }-*/;
095:
096: /**
097: * Filter by a callback function. The passed function will be called with each node in the tree (or from the startNode).
098: * If the callback returns true, the node is kept otherwise it is filtered. If a node is filtered, its children are also
099: * filtered.
100: *
101: * @param callback the filter callback
102: */
103: public native void filterBy(TreeTraversalCallback callback) /*-{
104: var filter = this.@com.gwtext.client.core.JsObject::getJsObj()();
105: filter.filterBy(function(node) {
106: var nodeJ = @com.gwtext.client.widgets.tree.TreeNode::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
107: return callback.@com.gwtext.client.widgets.tree.TreeTraversalCallback::execute(Lcom/gwtext/client/widgets/tree/TreeNode;)(nodeJ);
108: });
109: }-*/;
110: }
|