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.DefaultSelectionModelListener;
014:
015: /**
016: * Default Tree selection model. Using this selection model only a single node can be selected.
017: * To enable selection of multiple nodes, use {@link com.gwtext.client.widgets.tree.MultiSelectionModel}.
018: *
019: * @see com.gwtext.client.widgets.tree.MultiSelectionModel
020: */
021: public class DefaultSelectionModel extends JsObject implements
022: TreeSelectionModel {
023:
024: /**
025: * Construct a DefaultSelectionModel.
026: */
027: public DefaultSelectionModel() {
028: jsObj = create();
029: }
030:
031: private native JavaScriptObject create() /*-{
032: return new $wnd.Ext.tree.DefaultSelectionModel();
033: }-*/;
034:
035: public DefaultSelectionModel(JavaScriptObject jsObj) {
036: super (jsObj);
037: }
038:
039: private static DefaultSelectionModel instance(JavaScriptObject jsObj) {
040: return new DefaultSelectionModel(jsObj);
041: }
042:
043: public native void clearSelections() /*-{
044: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
045: sm.clearSelections();
046: }-*/;
047:
048: public native TreeNode getSelectedNode() /*-{
049: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
050: var treeNode = sm.getSelectedNode();
051: if(treeNode == null || treeNode === undefined) {
052: return null;
053: } else {
054: return @com.gwtext.client.widgets.tree.TreeNode::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(treeNode);
055: }
056: }-*/;
057:
058: public native boolean isSelected(TreeNode treeNode) /*-{
059: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
060: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
061: return sm.isSelected(tn);
062: }-*/;
063:
064: public native void select(TreeNode treeNode) /*-{
065: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
066: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
067: return sm.select(tn);
068: }-*/;
069:
070: public native void selectNext() /*-{
071: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
072: sm.selectNext();
073: }-*/;
074:
075: public native void selectPrevious() /*-{
076: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
077: sm.selectPrevious();
078: }-*/;
079:
080: public native void unselect(TreeNode treeNode) /*-{
081: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
082: var tn = treeNode.@com.gwtext.client.core.JsObject::getJsObj()();
083: return sm.unselect(tn);
084: }-*/;
085:
086: public native void addSelectionModelListener(
087: DefaultSelectionModelListener listener)/*-{
088: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
089: var smJ = this;
090: sm.addListener('beforeselect',
091: function(self, newNode, oldNode) {
092: var newNodeJ = @com.gwtext.client.widgets.tree.TreeNode::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(newNode);
093: var oldNodeJ = @com.gwtext.client.widgets.tree.TreeNode::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(oldNode);
094: return listener.@com.gwtext.client.widgets.tree.event.DefaultSelectionModelListener::doBeforeSelect(Lcom/gwtext/client/widgets/tree/DefaultSelectionModel;Lcom/gwtext/client/widgets/tree/TreeNode;Lcom/gwtext/client/widgets/tree/TreeNode;)(smJ, newNodeJ, oldNodeJ);
095: }
096: );
097:
098: sm.addListener('selectionchange',
099: function(self, node) {
100: var nodeJ = node == null ? null : @com.gwtext.client.widgets.tree.TreeNode::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(node);
101: listener.@com.gwtext.client.widgets.tree.event.DefaultSelectionModelListener::onSelectionChange(Lcom/gwtext/client/widgets/tree/DefaultSelectionModel;Lcom/gwtext/client/widgets/tree/TreeNode;)(smJ, nodeJ);
102: }
103: );
104: }-*/;
105: }
|