incubator-flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Kessler (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLEX-33190) GridEvent.GRID_DOUBLE_CLICK is dispatched even when two different cells are clicked
Date Tue, 25 Sep 2012 14:59:07 GMT

    [ https://issues.apache.org/jira/browse/FLEX-33190?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13462812#comment-13462812
] 

Mark Kessler commented on FLEX-33190:
-------------------------------------

Well I believe the value in the doubleclick event for a grid/datagrid would be best used for
an individual row or cell than the whole grid/datagrid.  So your last option is very reasonable
and a good compromise.  Having a property that dictates how the double click will be triggered
sounds great.  Sort of the way the selectionMode property can contain enumerated choices.
 Call it doubleClickMode or such to mirror the naming of the selectionMode.  Add it to the
grid and add convience pass-through functions to the datagrid.

Could use it something like this in the future...
myDataGrid.doubleClickMode = "row"; //or "cell" or "grid"

Here's somewhat of an example, I tried to keep the code style similar to what currently exists
in the files now.  Trying to match its support class style as well.  It would need to be tested/verified
as I tossed this together on my tablet.

-Create a new support class spark\components\gridClasses\GridDoubleClickMode.as

//package for class.
package spark.components.gridClasses
{
   //Class declaration.
   public final class GridDoubleClickMode
   {
      //Constructor.
      public function GridDoubleClickMode()
      {
      }

      //Delcare consts.
      public static const ROW:String = "row";
      public static const CELL:String = "cell";
      public static const GRID:String = "grid";
   }
}





-Modify the spark\components\Grid.as; Adding three new variables, added one getter/setter,
and modifying the dispatchGridClickEvents function.


//Import the class
import spark.components.gridClasses.GridDoubleClickMode;


//--------------------------------------------------------------------------
//
//  GridEvents
//
//--------------------------------------------------------------------------  
private var lastClickedColumnIndex:int = -1;
private var lastClickedRowIndex:int = -1;


//----------------------------------------
//  doubleClickMode
//----------------------------------------

//Declare _doubleClickMode variable setting a default value of ROW.
private var _doubleClickMode:String = GridDoubleClickMode.ROW;

//Getter for doubleClickMode.
public function get doubleClickMode():String
{
   return _doubleClickMode;
}

//Setter for doubleClickMode.
public function set doubleClickMode(value:String):void
{
   //Check if the new value and old value are the same.
   if (value == _doubleClickMode)
   {
      //No need to update.
      return;
   }

   //Switch to find allowed values. Ignoring anything not in a case.
   switch (value)
   {
      case GridDoubleClickMode.ROW:
      case GridDoubleClickMode.CELL:
      case GridDoubleClickMode.GRID:
      {
         //Store the new value.
         _doubleClickMode = value;

         //Dispatch an event showing the change. Optional to implement / event can be called.
//         dispatchChangeEvent("doubleclickModeChanged");

         break;
      }
   }

}


/**
 *  @private
 *  This method is called after we dispatch a GRID_MOUSE_UP.
 *  It determines whether to dispatch a GRID_CLICK or GRID_DOUBLE_CLICK
 *  event following a GRID_MOUSE_UP.
 * 
 *  A GRID_CLICK event is dispatched when the mouse up event happens in
 *  the same cell as the mouse down event.
 * 
 *  A GRID_DOUBLE_CLICK event is dispatched in place of the GRID_CLICK
 *  event when the last click event happened within DOUBLE_CLICK_TIME.
 */       

private function dispatchGridClickEvents(mouseEvent:MouseEvent, gridXY:Point, rowIndex:int,
columnIndex:int):void
{
   var dispatchGridClick:Boolean = (rowIndex == mouseDownRowIndex &&
                                    columnIndex == mouseDownColumnIndex);
   var newClickTime:Number = getTimer();

   //New bool to help verify the doubleclick.
   var isDoubleClick:Boolean = false;

   // In the case that we dispatched a click last time, check if we
   // should dispatch a double click this time.
   // This isn't stricly adequate, since the mouse might have been on a different cell for

   // the first click.  It's not clear that the extra checking would be worthwhile.
   if (doubleClickEnabled && dispatchGridClick && !isNaN(lastClickTime) &&
(newClickTime - lastClickTime <= DOUBLE_CLICK_TIME))
   {
      //Switch the _doubleClickMode variable.
      switch (_doubleClickMode)
      {
         //"row"
         case GridDoubleClickMode.ROW:
         {
            //Check if the row matches the previous row index.
            if (rowIndex == lastClickRowIndex)
            {
               //Mark it as a double click.
               isDoubleClick = true;
            }

            break;
         }

         //"cell"
         case GridDoubleClickMode.CELL:
         {
            //Check if the current row/column indexes matches the previous row/column indexes.
            if (rowIndex == lastClickRowIndex && columnIndex == lastClickColumnIndex)
            {
               //Mark it as a double click.
               isDoubleClick = true;
            }

            break;
         }

         //"grid"
         case GridDoubleClickMode.GRID:
         {
            //Mark it as a double click.
            isDoubleClick = true;

            break;
         }
      }

      //Check if a double click was verified.
      if (isDoubleClick == true)
      {
         dispatchGridEvent(mouseEvent, GridEvent.GRID_DOUBLE_CLICK, gridXY, rowIndex, columnIndex);
         lastClickTime = NaN;

         //Reset the last index variables.
         lastClickedColumnIndex = -1;
         lastClickedRowIndex = -1;
      }
      
   }

   // Otherwise, just dispatch the click event.
   if (dispatchGridClick)
   {
      dispatchGridEvent(mouseEvent, GridEvent.GRID_CLICK, gridXY, rowIndex, columnIndex);
      lastClickTime = newClickTime;
      
      //Store the indexes to use for comparison later.
      lastClickedColumnIndex = columnIndex;
      lastClickedRowIndex = rowIndex;
   }
}

                
> GridEvent.GRID_DOUBLE_CLICK is dispatched even when two different cells are clicked
> -----------------------------------------------------------------------------------
>
>                 Key: FLEX-33190
>                 URL: https://issues.apache.org/jira/browse/FLEX-33190
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: Spark: Grid
>    Affects Versions: Apache Flex 4.8 (parity release)
>            Reporter: Shigeru Nakagaki
>         Attachments: DataGridTest.mxml, Grid.as
>
>
> In dispatchGridClickEvents method of "s:Grid" class, GridEvent.GRID_DOUBLE_CLICK is dispatched.
But there is no check of whether the same cell was clicked.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message