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.widgets.tree;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.gwtext.client.core.JsObject;
013: import com.gwtext.client.widgets.tree.event.MultiSelectionModelListener;
014:
015: /**
016: * Selection model for multi selecting tree nodes.
017: *
018: * @see com.gwtext.client.widgets.tree.DefaultSelectionModel
019: */
020: public class MultiSelectionModel extends JsObject implements
021: TreeSelectionModel {
022:
023: public MultiSelectionModel() {
024: jsObj = create();
025: }
026:
027: private native JavaScriptObject create() /*-{
028: return new $wnd.Ext.tree.MultiSelectionModel();
029: }-*/;
030:
031: public MultiSelectionModel(JavaScriptObject jsObj) {
032: super (jsObj);
033: }
034:
035: public static MultiSelectionModel instance(JavaScriptObject jsObj) {
036: return new MultiSelectionModel(jsObj);
037: }
038:
039: public native void clearSelections() /*-{
040: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
041: sm.clearSelections();
042: }-*/;
043:
044: public native void clearSelections(boolean suppressEvent) /*-{
045: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
046: sm.clearSelections(suppressEvent);
047: }-*/;
048:
049: public TreeNode[] getSelectedNodes() {
050: JavaScriptObject nativeArray = getSelectedNodes(jsObj);
051: return TreePanel.convertFromNativeTreeNodeArray(nativeArray);
052: }
053:
054: private native JavaScriptObject getSelectedNodes(JavaScriptObject sm) /*-{
055: var treeNodes = sm.getSelectedNodes();
056: return (treeNodes === undefined) ? null : treeNodes;
057: }-*/;
058:
059: public native boolean isSelected(TreeNode treeNode) /*-{
060: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
061: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
062: return sm.isSelected(tn);
063: }-*/;
064:
065: public native void select(TreeNode treeNode) /*-{
066: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
067: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
068: return sm.select(tn);
069: }-*/;
070:
071: public native void select(TreeNode treeNode, boolean keepExisting) /*-{
072: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
073: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
074: return sm.select(tn, null, keepExisting);
075: }-*/;
076:
077: public native void selectNext() /*-{
078: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
079: sm.selectNext();
080: }-*/;
081:
082: public native void selectPrevious() /*-{
083: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
084: sm.selectPrevious();
085: }-*/;
086:
087: public native void unselect(TreeNode treeNode) /*-{
088: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
089: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
090: return sm.unselect(tn);
091: }-*/;
092:
093: public native void addSelectionModelListener(
094: MultiSelectionModelListener listener)/*-{
095: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
096: var smJ = this;
097:
098: sm.addListener('selectionchange',
099: function(self, nodes) {
100: if(nodes === undefined) nodes = null;
101: var nodesJ = @com.gwtext.client.widgets.tree.TreePanel::convertFromNativeTreeNodeArray(Lcom/google/gwt/core/client/JavaScriptObject;)(nodes);
102: listener.@com.gwtext.client.widgets.tree.event.MultiSelectionModelListener::onSelectionChange(Lcom/gwtext/client/widgets/tree/MultiSelectionModel;[Lcom/gwtext/client/widgets/tree/TreeNode;)(smJ, nodesJ);
103: }
104: );
105: }-*/;
106: }
|