On Wed, Aug 4, 2010 at 12:23, danovics <[email protected]> wrote:

>
> In my table I have a column with checkboxes.
> I would like to achive that when I click on a cell with a checkbox the
> selection in the table won't change.
> On the selection change there are a lot of changes in my application gui.
> I would like to avoid these changes on a checkbox click.


I needed to do something similar when I implemented TreeVirtual. I wanted
the option for a click on the button that opens and closes a branch of the
tree to not select that row. It's the selection manager that handles such
things, so I implemented a custom selection manager for TreeVirtual that
looks at where the click occurred, and behaves different if the click was on
the open/close button. Here's the code that handles it in
qx.ui.treevirtual.SelectionManager:

    /**
     * Handles a select event.  First we determine if the click was on the
     * open/close button and toggle the opened/closed state as necessary.
     * Then, if the click was not on the open/close button or if the table's
     * "openCloseClickSelectsRow" property so indicates, call our superclass
to
     * handle the actual row selection.
     *
     * @param index {Integer} the index the event is pointing at.
     * @param evt {Map} the mouse event.
     * @return {void}
     */
    _handleSelectEvent : function(index, evt)
    {
      var _this = this;

      function handleButtonClick(tree, index, evt)
      {
        // Get the data model
        var dataModel = tree.getDataModel();

        // Determine the column containing the tree
        var treeCol = dataModel.getTreeColumn();

        // Get the focused column
        var focusedCol = tree.getFocusedColumn();

        // If the click is not in the tree column, ...
        if (focusedCol != treeCol)
        {
          // ... then let the Table selection manager deal with it
          return false;
        }

        // If the cell hasn't been focused automatically...
        if (evt instanceof qx.event.type.Mouse)
        {
          if (! tree.getFocusCellOnMouseMove())
          {
            // ... then focus it now so we can determine the node to
open/close
            var scrollers = tree._getPaneScrollerArr();

            for (var i=0; i<scrollers.length; i++)
            {
              scrollers[i]._focusCellAtPagePos(evt.getViewportLeft(),
                                               evt.getViewportTop());
            }
          }
        }

        // Get the node to which this event applies
        var node = dataModel.getNode(tree.getFocusedRow());

        if (!node) {
          return false;
        }

        // Was this a mouse event?
        if (evt instanceof qx.event.type.Mouse)
        {
          // Yup.  Get the order of the columns
          var tcm = tree.getTableColumnModel();
          var columnPositions = tcm._getColToXPosMap();

          // Calculate the position of the beginning of the tree column
          var left = qx.bom.element.Location.getLeft(
            tree.getContentElement().getDomElement());

          for (var i=0; i<columnPositions[treeCol].visX; i++) {
            left += tcm.getColumnWidth(columnPositions[i].visX);
          }

          // Was the click on the open/close button?  That button begins at
          // (node.level - 1) * 19 + 2 (the latter for padding), and has
width
          // 19.  We add a bit of latitude to that.
          var x = evt.getViewportLeft();
          var latitude = 2;

          var buttonPos = left + (node.level - 1) * 19 + 2;

          if (x >= buttonPos - latitude && x <= buttonPos + 19 + latitude)
          {
            // Yup.  Toggle the opened state for this node.
            dataModel.setState(node, { bOpened : ! node.bOpened });
            return tree.getOpenCloseClickSelectsRow() ? false : true;
          }
          else
          {
            return _this._handleExtendedClick(tree, evt, node, left);
          }
        }
        else
        {
          // See which key generated the event
          var identifier = evt.getKeyIdentifier();

          switch(identifier)
          {
            case "Space":
              // This should only select the row, not toggle the opened
state
              return false;

            case "Enter":
              // Toggle the open state if open/close is allowed
              if (!node.bHideOpenClose) {
                dataModel.setState(node, { bOpened : ! node.bOpened });
              }

              return tree.getOpenCloseClickSelectsRow() ? false : true;

            default:
              // Unrecognized key.  Ignore it.
              return true;
          }
        }
      }

      // Call our local method to toggle the open/close state, if necessary
      var bNoSelect = handleButtonClick(this.__table, index, evt);

      // If we haven't been told not to do the selection...
      if (!bNoSelect)
      {
        // then call the superclass to handle it.
        this.base(arguments, index, evt);
      }
    },

Derrell
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to