Added IArrayList interface and updated associated classes.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/aa268ba6 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/aa268ba6 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/aa268ba6 Branch: refs/heads/spark Commit: aa268ba64ad74124f16ba5d001a480cd6d0429bf Parents: 0f744d3 Author: Peter Ent <[email protected]> Authored: Thu Feb 18 13:24:06 2016 -0500 Committer: Alex Harui <[email protected]> Committed: Tue Feb 23 21:44:21 2016 -0800 ---------------------------------------------------------------------- .../org/apache/flex/collections/ArrayList.as | 114 ++++++------ .../org/apache/flex/collections/IArrayList.as | 178 +++++++++++++++++++ .../DataItemRendererFactoryForArrayList.as | 27 ++- .../beads/models/ArrayListSelectionModel.as | 64 +++---- 4 files changed, 286 insertions(+), 97 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/aa268ba6/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as index 58d44e8..6f26e25 100644 --- a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as @@ -17,7 +17,7 @@ // //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.collections -{ +{ import org.apache.flex.core.IBead; import org.apache.flex.core.IStrand; import org.apache.flex.events.Event; @@ -25,67 +25,67 @@ package org.apache.flex.collections import org.apache.flex.events.IEventDispatcher; import org.apache.flex.collections.parsers.IInputParser; import org.apache.flex.collections.converters.IItemConverter; - + //-------------------------------------- // Events //-------------------------------------- - + /** * Dispatched when the collection's underlying source array * is changed. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ [Event(name="collectionChanged", type="org.apache.flex.events.Event")] - + /** * Dispatched when the collection has added an item. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ [Event(name="itemAdded", type="org.apache.flex.events.Event")] - + /** * Dispatched when the collection has removed an item. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ [Event(name="itemRemoved", type="org.apache.flex.events.Event")] - + /** * Dispatched when the collection has updated an item. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ [Event(name="itemUpdated", type="org.apache.flex.events.Event")] - + /** * The ArrayList class provides an event-driven wrapper for the * standard Array. Events are dispatched when items are added, removed, * or changed. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class ArrayList extends EventDispatcher implements IBead, ICollection + public class ArrayList extends EventDispatcher implements IBead, ICollection, IArrayList { /** * Constructor. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -99,10 +99,10 @@ package org.apache.flex.collections } private var _id:String; - + /** * @copy org.apache.flex.core.UIBase#id - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -124,12 +124,12 @@ package org.apache.flex.collections dispatchEvent(new Event("idChanged")); } } - + private var _strand:IStrand; - + /** * @copy org.apache.flex.core.UIBase#strand - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -140,12 +140,12 @@ package org.apache.flex.collections _strand = value; _source = new Array(); } - + private var _source:Array; - + /** * The array of raw data needing conversion. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -155,7 +155,7 @@ package org.apache.flex.collections { return _source; } - + public function set source(value:Array):void { if (_source != value) { @@ -164,10 +164,10 @@ package org.apache.flex.collections dispatchEvent(new Event("collectionChanged")); } } - + /** * Returns a copy of the source array. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -177,10 +177,10 @@ package org.apache.flex.collections { return _source.concat(); } - + /** * Fetches an item from the collection - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -189,11 +189,11 @@ package org.apache.flex.collections public function getItemAt(index:int):Object { return _source[index]; - } - + } + /** * Fetches an item from the collection given an index. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -208,10 +208,10 @@ package org.apache.flex.collections } return -1; } - + /** * Adds an item to the end of the array. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -221,10 +221,10 @@ package org.apache.flex.collections { addItemAt(item, length); } - + /** * Inserts an item to a specific location within the array. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -233,7 +233,7 @@ package org.apache.flex.collections public function addItemAt(item:Object, index:int):void { const spliceUpperBound:int = length; - + if (index < spliceUpperBound && index > 0) { source.splice(index, 0, item); @@ -246,19 +246,19 @@ package org.apache.flex.collections { source.unshift(item); } - else + else { // error return; } - + dispatchEvent(new Event("itemAdded")); } - + /** * Replaces the item at the given index with a new item and * returns the old item. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -268,7 +268,7 @@ package org.apache.flex.collections { const spliceUpperBound:int = length; var oldItem:Object; - + if (index >= 0 && index < spliceUpperBound) { oldItem = source[index]; source[index] = item; @@ -277,13 +277,13 @@ package org.apache.flex.collections else { // error } - + return oldItem; } - + /** * Removed an item from the array and returns it. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -298,11 +298,11 @@ package org.apache.flex.collections } return result; } - + /** * Removes an item from a specific location within the array and * returns it. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -312,7 +312,7 @@ package org.apache.flex.collections { const spliceUpperBound:int = length - 1; var removed:Object; - + if (index > 0 && index < spliceUpperBound) { removed = source.splice(index, 1)[0]; @@ -329,14 +329,14 @@ package org.apache.flex.collections // error return null; } - + dispatchEvent(new Event("itemRemoved")); return removed; } - + /** * Removes all of the items from the array. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -349,10 +349,10 @@ package org.apache.flex.collections dispatchEvent(new Event("itemRemoved")); } } - + /** * Signals that an item in the array has been updated. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -365,10 +365,10 @@ package org.apache.flex.collections dispatchEvent(new Event("itemUpdated")); } } - + /** * Signals that an item in the array has been updated. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -378,10 +378,10 @@ package org.apache.flex.collections { dispatchEvent(new Event("itemUpdated")); } - + /** * The number of items. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -389,8 +389,8 @@ package org.apache.flex.collections */ public function get length():int { - return _source ? _source.length : 0; + return _source ? _source.length : 0; } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/aa268ba6/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IArrayList.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IArrayList.as new file mode 100644 index 0000000..fbe8ed5 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IArrayList.as @@ -0,0 +1,178 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.collections +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.parsers.IInputParser; + import org.apache.flex.collections.converters.IItemConverter; + + //-------------------------------------- + + + /** + * The ArrayList class provides an event-driven wrapper for the + * standard Array. Events are dispatched when items are added, removed, + * or changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IArrayList + { + /** + * The array of raw data needing conversion. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function get source():Array; + function set source(value:Array):void; + + /** + * Returns a copy of the source array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function toArray():Array; + + /** + * Fetches an item from the collection + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getItemAt(index:int):Object; + + /** + * Fetches an item from the collection given an index. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getItemIndex(item:Object):int; + + /** + * Adds an item to the end of the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function addItem(item:Object):void; + + /** + * Inserts an item to a specific location within the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function addItemAt(item:Object, index:int):void; + + /** + * Replaces the item at the given index with a new item and + * returns the old item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function setItemAt(item:Object, index:int):Object; + + /** + * Removed an item from the array and returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function removeItem(item:Object):Boolean; + + /** + * Removes an item from a specific location within the array and + * returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function removeItemAt(index:int):Object; + + /** + * Removes all of the items from the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function removeAll():void; + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function itemUpdated(item:Object):void; + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function itemUpdatedAt(index:int):void; + + /** + * The number of items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function get length():int; + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/aa268ba6/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForArrayList.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForArrayList.as index 9895394..901b5f3 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForArrayList.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryForArrayList.as @@ -18,7 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads { - import org.apache.flex.collections.ArrayList; + import org.apache.flex.collections.IArrayList; import org.apache.flex.core.IBead; import org.apache.flex.core.IDataProviderItemRendererMapper; import org.apache.flex.core.IItemRendererClassFactory; @@ -61,9 +61,9 @@ package org.apache.flex.html.beads { } - private var selectionModel:ISelectionModel; + protected var selectionModel:ISelectionModel; - private var labelField:String; + protected var labelField:String; private var _strand:IStrand; @@ -138,9 +138,22 @@ package org.apache.flex.html.beads */ protected var dataGroup:IItemRendererParent; - private function dataProviderChangeHandler(event:Event):void + /** + * @private + */ + protected function setData(ir:ISelectableItemRenderer, data:Object, index:int):void { - var dp:ArrayList = selectionModel.dataProvider as ArrayList; + ir.index = index; + ir.labelField = labelField; + ir.data = data; + } + + /** + * @private + */ + protected function dataProviderChangeHandler(event:Event):void + { + var dp:IArrayList = selectionModel.dataProvider as IArrayList; if (!dp) return; @@ -153,8 +166,6 @@ package org.apache.flex.html.beads for (var i:int = 0; i < n; i++) { var ir:ISelectableItemRenderer = itemRendererFactory.createItemRenderer(dataGroup) as ISelectableItemRenderer; - ir.index = i; - ir.labelField = labelField; if (presentationModel) { UIBase(ir).height = presentationModel.rowHeight; @@ -165,7 +176,7 @@ package org.apache.flex.html.beads UIBase(ir).style = style; } dataGroup.addElement(ir); - ir.data = dp.getItemAt(i); + setData(ir, dp.getItemAt(i), i); } IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated")); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/aa268ba6/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ArrayListSelectionModel.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ArrayListSelectionModel.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ArrayListSelectionModel.as index 7366677..5c8a188 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ArrayListSelectionModel.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ArrayListSelectionModel.as @@ -18,18 +18,18 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.models { - import org.apache.flex.collections.ArrayList; + import org.apache.flex.collections.IArrayList; import org.apache.flex.core.IRollOverModel; import org.apache.flex.core.ISelectionModel; import org.apache.flex.core.IStrand; import org.apache.flex.events.Event; import org.apache.flex.events.EventDispatcher; - + /** * The ArrayListSelectionModel class is a selection model for * a dataProvider that is an ArrayList. It assumes that items * can be fetched from the dataProvider using dataProvider.getItemAt(index). - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -39,7 +39,7 @@ package org.apache.flex.html.beads.models { /** * Constructor. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -50,10 +50,10 @@ package org.apache.flex.html.beads.models } private var _strand:IStrand; - + /** * @copy org.apache.flex.core.IBead#strand - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -63,12 +63,12 @@ package org.apache.flex.html.beads.models { _strand = value; } - - private var _dataProvider:ArrayList; - + + private var _dataProvider:IArrayList; + /** * @copy org.apache.flex.core.ISelectionModel#dataProvider - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -85,10 +85,10 @@ package org.apache.flex.html.beads.models public function set dataProvider(value:Object):void { if (value === _dataProvider) return; - - _dataProvider = value as ArrayList; + + _dataProvider = value as IArrayList; if (_selectedIndex != -1) - _selectedItem = (_dataProvider == null || _selectedIndex >= _dataProvider.length) ? null : + _selectedItem = (_dataProvider == null || _selectedIndex >= _dataProvider.length) ? null : _dataProvider.getItemAt(_selectedIndex); dispatchEvent(new Event("dataProviderChanged")); } @@ -96,10 +96,10 @@ package org.apache.flex.html.beads.models private var _selectedIndex:int = -1; private var _rollOverIndex:int = -1; private var _labelField:String = null; - + /** * @copy org.apache.flex.core.ISelectionModel#labelField - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -120,10 +120,10 @@ package org.apache.flex.html.beads.models dispatchEvent(new Event("labelFieldChanged")); } } - + /** * @copy org.apache.flex.core.ISelectionModel#selectedIndex - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -140,15 +140,15 @@ package org.apache.flex.html.beads.models public function set selectedIndex(value:int):void { if (value === _selectedIndex) return; - + _selectedIndex = value; _selectedItem = (value == -1 || _dataProvider == null) ? null : (value < _dataProvider.length) ? _dataProvider.getItemAt(value) : null; - dispatchEvent(new Event("selectedIndexChanged")); + dispatchEvent(new Event("selectedIndexChanged")); } - + /** * @copy org.apache.flex.core.IRollOverModel#rollOverIndex - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -169,12 +169,12 @@ package org.apache.flex.html.beads.models dispatchEvent(new Event("rollOverIndexChanged")); } } - + private var _selectedItem:Object; - + /** * @copy org.apache.flex.core.ISelectionModel#selectedItem - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -191,8 +191,8 @@ package org.apache.flex.html.beads.models public function set selectedItem(value:Object):void { if (value === _selectedItem) return; - - _selectedItem = value; + + _selectedItem = value; var n:int = _dataProvider.length; for (var i:int = 0; i < n; i++) { @@ -202,16 +202,16 @@ package org.apache.flex.html.beads.models break; } } - dispatchEvent(new Event("selectedItemChanged")); + dispatchEvent(new Event("selectedItemChanged")); dispatchEvent(new Event("selectedIndexChanged")); } - + private var _selectedString:String; - + /** * An alternative to selectedItem for strongly typing the * the selectedItem if the Array is an Array of Strings. - * + * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 @@ -237,8 +237,8 @@ package org.apache.flex.html.beads.models break; } } - dispatchEvent(new Event("selectedItemChanged")); - dispatchEvent(new Event("selectedIndexChanged")); + dispatchEvent(new Event("selectedItemChanged")); + dispatchEvent(new Event("selectedIndexChanged")); } } }
