You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cf...@apache.org on 2012/12/21 19:05:22 UTC
svn commit: r1425063 [7/13] - in /incubator/flex/sdk/branches/develop:
frameworks/ frameworks/projects/spark/ frameworks/projects/spark/src/
frameworks/projects/spark/src/spark/collections/
frameworks/projects/spark/src/spark/components/ frameworks/pro...
Modified: incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridSelection.as
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridSelection.as?rev=1425063&r1=1425062&r2=1425063&view=diff
==============================================================================
--- incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridSelection.as (original)
+++ incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridSelection.as Fri Dec 21 18:05:20 2012
@@ -476,12 +476,8 @@ public class GridSelection
*/
public function removeAll():Boolean
{
- var selectionChanged:Boolean = selectionLength > 0;
-
- removeSelection();
- selectionChanged = ensureRequiredSelection() || selectionChanged;
-
- return selectionChanged;
+ var selectionChanged:Boolean = removeSelection();
+ return ensureRequiredSelection() || selectionChanged;
}
//----------------------------------
@@ -1036,11 +1032,15 @@ public class GridSelection
* Remove any currently selected rows, cells and cached items. This
* disregards the requireSelection flag.
*/
- private function removeSelection():void
+ private function removeSelection():Boolean
{
+ const selectionChanged:Boolean = (selectionLength > 0);
+
cellRegions.length = 0;
_selectionLength = 0;
selectedItem = null;
+
+ return selectionChanged;
}
/**
@@ -1271,73 +1271,79 @@ public class GridSelection
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
- public function dataProviderCollectionChanged(event:CollectionEvent):void
+ public function dataProviderCollectionChanged(event:CollectionEvent):Boolean
{
+ var selectionChanged:Boolean = false;
+
inCollectionHandler = true;
switch (event.kind)
{
case CollectionEventKind.ADD:
{
- dataProviderCollectionAdd(event);
+ selectionChanged = dataProviderCollectionAdd(event);
break;
}
case CollectionEventKind.MOVE:
{
- dataProviderCollectionMove(event);
+ selectionChanged = dataProviderCollectionMove(event);
break;
}
case CollectionEventKind.REFRESH:
{
- dataProviderCollectionRefresh(event);
+ selectionChanged = dataProviderCollectionRefresh(event);
break;
}
case CollectionEventKind.REMOVE:
{
- dataProviderCollectionRemove(event);
+ selectionChanged = dataProviderCollectionRemove(event);
break;
}
case CollectionEventKind.REPLACE:
{
- dataProviderCollectionReplace(event);
+ selectionChanged = dataProviderCollectionReplace(event);
break;
}
case CollectionEventKind.RESET:
{
- dataProviderCollectionReset(event);
+ selectionChanged = dataProviderCollectionReset(event);
break;
}
case CollectionEventKind.UPDATE:
{
- dataProviderCollectionUpdate(event);
+ selectionChanged = dataProviderCollectionUpdate(event);
break;
}
}
inCollectionHandler = false;
+
+ return selectionChanged;
}
/**
* @private
* Add an item to the collection.
*/
- private function dataProviderCollectionAdd(event:CollectionEvent):void
+ private function dataProviderCollectionAdd(event:CollectionEvent):Boolean
{
- handleRowAdd(event.location, event.items.length);
- ensureRequiredSelection();
+ var selectionChanged:Boolean = handleRowAdd(event.location, event.items.length);
+ return ensureRequiredSelection() || selectionChanged;
}
/**
* @private
*/
- private function handleRowAdd(insertIndex:int, insertCount:int=1):void
+ private function handleRowAdd(insertIndex:int, insertCount:int=1):Boolean
{
+ var selectionChanged:Boolean = false;
+
for (var cnt:int = 0; cnt < insertCount; cnt++)
{
for (var crIndex:int = 0; crIndex < cellRegions.length; crIndex++)
@@ -1351,6 +1357,7 @@ public class GridSelection
if (insertIndex <= cr.y)
{
cr.y++;
+ selectionChanged = true;
}
else if (insertIndex < cr.bottom)
{
@@ -1364,37 +1371,42 @@ public class GridSelection
// insert newCR just after cr
cellRegions.splice(++crIndex, 0, newCR);
_selectionLength = -1; // recalculate
+ selectionChanged = true;
}
}
}
+
+ return selectionChanged;
}
/**
* @private
* The item has been moved from the oldLocation to location.
*/
- private function dataProviderCollectionMove(event:CollectionEvent):void
+ private function dataProviderCollectionMove(event:CollectionEvent):Boolean
{
+ var selectionChanged:Boolean = false;
+
const oldRowIndex:int = event.oldLocation;
- var newRowIndex:int = event.location;
+ const newRowIndex:int = event.location;
- handleRowRemove(oldRowIndex);
+ selectionChanged = handleRowRemove(oldRowIndex);
// If the row is removed before the newly added item
// then change index to account for this.
if (newRowIndex > oldRowIndex)
newRowIndex--;
- handleRowAdd(newRowIndex);
+ return handleRowAdd(newRowIndex) || selectionChanged;
}
/**
* @private
* The sort or filter on the collection changed.
*/
- private function dataProviderCollectionRefresh(event:CollectionEvent):void
+ private function dataProviderCollectionRefresh(event:CollectionEvent):Boolean
{
- handleRefreshAndReset(event);
+ return handleRefreshAndReset(event);
}
/**
@@ -1403,7 +1415,7 @@ public class GridSelection
* keep the item selected. Otherwise, clear the selection (or maintain one
* if requireSelection is true).
*/
- private function handleRefreshAndReset(event:CollectionEvent):void
+ private function handleRefreshAndReset(event:CollectionEvent):Boolean
{
// Is the selectedItem still in the collection?
if (selectedItem)
@@ -1422,38 +1434,36 @@ public class GridSelection
var oldSelectedCell:CellPosition = allCells()[0];
internalSetCellRegion(newRowIndex, oldSelectedCell.columnIndex);
}
- return;
+ return true;
}
}
// Not preserving selection or selection not in current view so remove
// selection.
- removeSelection();
- ensureRequiredSelection();
- return;
+ var selectionChanged:Boolean = removeSelection();
+ return ensureRequiredSelection() || selectionChanged;
}
/**
* @private
* An item has been removed from the collection.
*/
- private function dataProviderCollectionRemove(event:CollectionEvent):void
+ private function dataProviderCollectionRemove(event:CollectionEvent):Boolean
{
if (getGridDataProviderLength() == 0)
- {
- removeSelection();
- return;
- }
+ return removeSelection();
- handleRowRemove(event.location, event.items.length);
- ensureRequiredSelection();
+ var selectionChanged:Boolean = handleRowRemove(event.location, event.items.length);
+ return ensureRequiredSelection() || selectionChanged;
}
/**
* @private
*/
- private function handleRowRemove(removeIndex:int, removeCount:int=1):void
+ private function handleRowRemove(removeIndex:int, removeCount:int=1):Boolean
{
+ var selectionChanged:Boolean = false;
+
for (var cnt:int = 0; cnt < removeCount; cnt++)
{
var crIndex:int = 0
@@ -1466,10 +1476,12 @@ public class GridSelection
if (removeIndex < cr.y)
{
cr.y--;
+ selectionChanged = true;
}
else if (removeIndex >= cr.y && removeIndex < cr.bottom)
{
- _selectionLength = -1; // recalculate
+ _selectionLength = -1; // recalculate
+ selectionChanged = true;
cr.height--;
if (cr.height == 0)
{
@@ -1479,17 +1491,20 @@ public class GridSelection
}
crIndex++;
}
- }
+ }
+
+ return selectionChanged;
}
/**
* @private
* The item has been replaced.
*/
- private function dataProviderCollectionReplace(event:CollectionEvent):void
+ private function dataProviderCollectionReplace(event:CollectionEvent):Boolean
{
// Nothing to do here unless we're saving the data items to preserve
// the selection.
+ return false;
}
/**
@@ -1498,18 +1513,19 @@ public class GridSelection
* source. If there is a preserved selected item and it is in the new
* data source the selection will be maintained.
*/
- private function dataProviderCollectionReset(event:CollectionEvent):void
+ private function dataProviderCollectionReset(event:CollectionEvent):Boolean
{
- handleRefreshAndReset(event);
+ return handleRefreshAndReset(event);
}
/**
* @private
* One or more items in the collection have been updated.
*/
- private function dataProviderCollectionUpdate(event:CollectionEvent):void
+ private function dataProviderCollectionUpdate(event:CollectionEvent):Boolean
{
// Nothing to do.
+ return false;
}
//--------------------------------------------------------------------------
@@ -1529,27 +1545,29 @@ public class GridSelection
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
- public function columnsCollectionChanged(event:CollectionEvent):void
+ public function columnsCollectionChanged(event:CollectionEvent):Boolean
{
+ var selectionChanged:Boolean = false;
+
inCollectionHandler = true;
switch (event.kind)
{
case CollectionEventKind.ADD:
{
- columnsCollectionAdd(event);
+ selectionChanged = columnsCollectionAdd(event);
break;
}
case CollectionEventKind.MOVE:
{
- columnsCollectionMove(event);
+ selectionChanged = columnsCollectionMove(event);
break;
}
case CollectionEventKind.REMOVE:
{
- columnsCollectionRemove(event);
+ selectionChanged = columnsCollectionRemove(event);
break;
}
@@ -1561,38 +1579,43 @@ public class GridSelection
case CollectionEventKind.REFRESH:
{
- columnsCollectionRefresh(event);
+ selectionChanged = columnsCollectionRefresh(event);
break;
}
case CollectionEventKind.RESET:
{
- columnsCollectionReset(event);
+ selectionChanged = columnsCollectionReset(event);
break;
}
}
inCollectionHandler = false;
+
+ return selectionChanged;
}
/**
* @private
* Add an column to the columns collection.
*/
- private function columnsCollectionAdd(event:CollectionEvent):void
+ private function columnsCollectionAdd(event:CollectionEvent):Boolean
{
// If no selectionMode or a row-based selectionMode, nothing to do.
if (!isCellSelectionMode())
- return;
+ return false;
+
+ var selectionChanged:Boolean = handleColumnAdd(event.location, event.items.length);
- handleColumnAdd(event.location, event.items.length);
- ensureRequiredSelection();
+ return ensureRequiredSelection() || selectionChanged;
}
/**
* @private
*/
- private function handleColumnAdd(insertIndex:int, insertCount:int=1):void
+ private function handleColumnAdd(insertIndex:int, insertCount:int=1):Boolean
{
+ var selectionChanged:Boolean = false;
+
for (var cnt:int = 0; cnt < insertCount; cnt++)
{
for (var crIndex:int = 0; crIndex < cellRegions.length; crIndex++)
@@ -1606,6 +1629,7 @@ public class GridSelection
if (insertIndex <= cr.x)
{
cr.x++;
+ selectionChanged = true;
}
else if (insertIndex < cr.x)
{
@@ -1618,10 +1642,13 @@ public class GridSelection
// insert newCR just after cr
cellRegions.splice(++crIndex, 0, newCR);
- _selectionLength = -1; // recalculate
+ _selectionLength = -1; // recalculate
+ selectionChanged = true;
}
}
}
+
+ return selectionChanged;
}
/**
@@ -1629,50 +1656,49 @@ public class GridSelection
* The column has been moved from the oldLocation to location in the
* columns collection.
*/
- private function columnsCollectionMove(event:CollectionEvent):void
+ private function columnsCollectionMove(event:CollectionEvent):Boolean
{
// If no selectionMode or a row-based selectionMode, nothing to do.
if (!isCellSelectionMode())
- return;
+ return false;
const oldColumnIndex:int = event.oldLocation;
- var newColumnIndex:int = event.location;
+ const newColumnIndex:int = event.location;
- handleColumnRemove(oldColumnIndex);
+ var selectionChanged:Boolean = handleColumnRemove(oldColumnIndex);
// If the column is removed before the newly added column
// then change index to account for this.
if (newColumnIndex > oldColumnIndex)
newColumnIndex--;
- handleColumnAdd(newColumnIndex);
+ return handleColumnAdd(newColumnIndex) || selectionChanged;
}
/**
* @private
* A column has been removed from the columns collection.
*/
- private function columnsCollectionRemove(event:CollectionEvent):void
+ private function columnsCollectionRemove(event:CollectionEvent):Boolean
{
// If no selectionMode or a row-based selectionMode, nothing to do.
if (!isCellSelectionMode())
- return;
+ return false;
if (getGridColumnsLength() == 0)
- {
- removeSelection();
- return;
- }
+ return removeSelection();
- handleColumnRemove(event.location, event.items.length);
- ensureRequiredSelection();
+ var selectionChanged:Boolean = handleColumnRemove(event.location, event.items.length);
+ return ensureRequiredSelection() || selectionChanged;
}
/**
* @private
*/
- private function handleColumnRemove(removeIndex:int, removeCount:int=1):void
+ private function handleColumnRemove(removeIndex:int, removeCount:int=1):Boolean
{
+ var selectionChanged:Boolean = false;
+
for (var cnt:int = 0; cnt < removeCount; cnt++)
{
var crIndex:int = 0
@@ -1685,10 +1711,12 @@ public class GridSelection
if (removeIndex < cr.x)
{
cr.x--;
+ selectionChanged = true;
}
else if (removeIndex >= cr.x && removeIndex < cr.right)
{
- _selectionLength = -1; // recalculate
+ _selectionLength = -1; // recalculate
+ selectionChanged = true;
cr.width--;
if (cr.width == 0)
{
@@ -1698,7 +1726,9 @@ public class GridSelection
}
crIndex++;
}
- }
+ }
+
+ return selectionChanged;
}
/**
@@ -1706,9 +1736,9 @@ public class GridSelection
* The sort or filter on the collection changed. For columns, this is
* the same as a "reset" event.
*/
- private function columnsCollectionRefresh(event:CollectionEvent):void
+ private function columnsCollectionRefresh(event:CollectionEvent):Boolean
{
- columnsCollectionReset(event);
+ return columnsCollectionReset(event);
}
/**
@@ -1716,14 +1746,14 @@ public class GridSelection
* The columns changed. If the selectionMode is cell-based, don't preserve
* the selection.
*/
- private function columnsCollectionReset(event:CollectionEvent):void
+ private function columnsCollectionReset(event:CollectionEvent):Boolean
{
// If no selectionMode or a row-based selectionMode, nothing to do.
if (!isCellSelectionMode())
- return;
+ return false;
- removeSelection();
- ensureRequiredSelection();
+ var selectionChanged:Boolean = removeSelection();
+ return ensureRequiredSelection() || selectionChanged;
}
}
}
Added: incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as?rev=1425063&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as (added)
+++ incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as Fri Dec 21 18:05:20 2012
@@ -0,0 +1,162 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package spark.components.gridClasses
+{
+import flash.events.Event;
+import flash.events.MouseEvent;
+import flash.geom.Point;
+import flash.geom.Rectangle;
+
+import mx.collections.IList;
+import mx.core.LayoutDirection;
+import mx.core.mx_internal;
+import mx.events.FlexEvent;
+import mx.events.PropertyChangeEvent;
+
+import spark.collections.SubListView;
+import spark.components.Grid;
+import spark.components.Group;
+
+use namespace mx_internal;
+
+/**
+ * This class is internal to the DataGrid implementation.
+ *
+ * A Grid element (child) that displays a rectangular region within the Grid.
+ * The GridView's region is defined by four GridViewLayout properties: viewRowIndex and
+ * viewColumnIndex - the origin of the region, viewRowCount and viewColumnCount - the size
+ * of the region. The GridView contains GridLayers which contain all of the Grid's visual
+ * elements, the renderers, indicators, separators, etc.
+ *
+ * GridViews are created automatically by the Grid class, based on the values of
+ * the lockedRowCount and lockedColumnCount Grid properties.
+ */
+public class GridView extends Group
+{
+ private static const zeroPoint:Point = new Point(0, 0);
+
+ /**
+ * Creates a GridView group with its layout set to a private GridView specific value.
+ */
+ public function GridView()
+ {
+ super();
+ layout = new GridViewLayout();
+ layout.clipAndEnableScrolling = true;
+ }
+
+ /**
+ * Return this GridView's GridViewLayout.
+ */
+ public function get gridViewLayout():GridViewLayout
+ {
+ return layout as GridViewLayout;
+ }
+
+ /**
+ * True if this GridView's bounds contain the event.
+ *
+ * Currently this method does not account for the possibility that this GridView has been
+ * rotated or scaled.
+ */
+ public function containsMouseEvent(event:MouseEvent):Boolean
+ {
+ const eventStageX:Number = event.stageX;
+ const eventStageY:Number = event.stageY;
+ const origin:Point = localToGlobal(zeroPoint);
+
+ origin.x += horizontalScrollPosition;
+ if (layoutDirection == LayoutDirection.RTL)
+ origin.x -= width;
+
+ origin.y += verticalScrollPosition;
+
+ return (eventStageX >= origin.x) && (eventStageY >= origin.y) &&
+ (eventStageX < (origin.x + width)) && (eventStageY < (origin.y + height));
+ }
+
+ /**
+ * Returns the view-relative index of the next GridColumn.visible==true column
+ * after index.
+ * Returns -1 if there are no more visible columns.
+ * To find the first GridColumn.visible==true column index, use
+ * getNextVisibleColumnIndex(-1).
+ */
+ public function getNextVisibleColumnIndex(index:int=-1):int
+ {
+ if (index < -1)
+ return -1;
+
+ const columnsView:SubListView = this.gridViewLayout.columnsView;
+ const columnsLength:int = (columnsView) ? columnsView.length : 0;
+
+ for (var i:int = index + 1; i < columnsLength; i++)
+ {
+ var column:GridColumn = columnsView.getItemAt(i) as GridColumn;
+ if (column && column.visible)
+ return i;
+ }
+
+ return -1;
+ }
+
+ /**
+ * Returns the view-relative index of the previous GridColumn.visible==true column
+ * before index.
+ * Returns -1 if there are no more visible columns.
+ * To find the last GridColumn.visible==true column index, use
+ * getPreviousVisibleColumnIndex(columns.length).
+ */
+ public function getPreviousVisibleColumnIndex(index:int):int
+ {
+ const columnsView:SubListView = this.gridViewLayout.columnsView;
+ if (!columnsView || index > columnsView.length)
+ return -1;
+
+ for (var i:int = index - 1; i >= 0; i--)
+ {
+ var column:GridColumn = columnsView.getItemAt(i) as GridColumn;
+ if (column && column.visible)
+ return i;
+ }
+
+ return -1;
+ }
+
+ /**
+ * @private
+ */
+ override protected function dispatchPropertyChangeEvent(property:String, oldValue:*, newValue:*):void
+ {
+ switch(property)
+ {
+ case "contentWidth":
+ case "contentHeight":
+ const grid:Grid = parent as Grid;
+ if (grid)
+ {
+ const pce:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(grid, property, null, null);
+ grid.dispatchEvent(pce);
+ }
+ break;
+ }
+ }
+}
+}
\ No newline at end of file
Propchange: incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/gridClasses/GridView.as
------------------------------------------------------------------------------
svn:mime-type = text/plain