Hi,
I think this one is for Martin, as author of the Tree controller.


I'm using a Tree controller to populate a Tree. I need to attach a context menu to some tree nodes, based on a property in the model of that tree node.

I'm trying to do this by using a configureItem delegate:

{
  configureItem : function(item) {
    if (item.getModel().getSomeProperty()) {
      item.setContextMenu(.......);
    }
  }
}

This doesn't work, because the configureItem delegate gets called before the model is attached to the tree node, so I can't access the model in configureItem.

I created a small patch (see attachment) that will call setModel() prior to the call configureItem, but still after the call to createItem. No API changes are needed. I think this makes much more sense, not to mention that it solves my issue ;)


Regards,
Marc
Index: qooxdoo/framework/source/class/qx/data/controller/Tree.js
===================================================================
--- qooxdoo/framework/source/class/qx/data/controller/Tree.js	(revision 27085)
+++ qooxdoo/framework/source/class/qx/data/controller/Tree.js	(working copy)
@@ -406,7 +406,7 @@
      *
      * @return {qx.ui.tree.core.AbstractTreeItem} The created and configured TreeFolder.
      */
-    _createItem: function() {
+    _createItem: function(model) {
       var delegate = this.getDelegate();
       // check if a delegate and a create method is set
       if (delegate != null && delegate.createItem != null) {
@@ -414,6 +414,7 @@
       } else {
         var item = new qx.ui.tree.TreeFolder();
       }
+      item.setModel(model);
 
       // check if a delegate is set and if the configure function is available
       if (delegate != null && delegate.configureItem != null) {
@@ -456,8 +457,7 @@
       // only build up a new tree if a model is given
       if (this.getModel() != null) {
         // add a new root node
-        var rootNode = this._createItem();
-        rootNode.setModel(this.getModel());
+        var rootNode = this._createItem(this.getModel());
         this.getTarget().setRoot(rootNode);
         // bind the root node
         this.__addBinding(this.getModel(), rootNode);
@@ -540,8 +540,7 @@
           // if the node is new
           } else {
             // add the child node
-            var treeNode = this._createItem();
-            treeNode.setModel(children.getItem(i));
+            var treeNode = this._createItem(children.getItem(i));
             rootNode.addAt(treeNode, i);
             this.__addBinding(children.getItem(i), treeNode);
 
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to