This is an automated email from the ASF dual-hosted git repository.

piotrz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 23c00b3  Add DynamicRemoveAllItemRendererForArrayListData
23c00b3 is described below

commit 23c00b33bb5c6cb3019a50b265dd165d3e8ce78f
Author: Piotr Zarzycki <piotrzarzyck...@gmail.com>
AuthorDate: Wed Dec 13 22:57:42 2017 +0100

    Add DynamicRemoveAllItemRendererForArrayListData
    
    - Add DynamicRemoveAllItemRendererForArrayListData which helps to handle 
scenario where all items has been removed from ArrayList
    - Introduce ALL_ITEMS_REMOVED (allItemsRemoved) event type in 
CollectionEvent
    - Update MDLDynamicTableExample to reflect changes
---
 .../MDLDynamicTableExample/src/MainView.mxml       |   9 ++
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 ...DynamicRemoveAllItemRendererForArrayListData.as | 164 +++++++++++++++++++++
 .../org/apache/royale/collections/ArrayList.as     |  13 +-
 .../org/apache/royale/events/CollectionEvent.as    |   1 +
 5 files changed, 187 insertions(+), 1 deletion(-)

diff --git a/examples/royale/MDLDynamicTableExample/src/MainView.mxml 
b/examples/royale/MDLDynamicTableExample/src/MainView.mxml
index e7234d8..e484cac 100644
--- a/examples/royale/MDLDynamicTableExample/src/MainView.mxml
+++ b/examples/royale/MDLDynamicTableExample/src/MainView.mxml
@@ -35,6 +35,11 @@ limitations under the License.
                        
usersListModel.users.removeItemAt(usersListModel.users.length - 1);
                }               
                
+               private function onRemoveAllClick(event:MouseEvent):void
+               {
+                       usersListModel.users.removeAll();       
+               }               
+               
                private function onTblChange(event:Event):void
                {
                        var selIndex:int = tblUsers.selectedIndex;
@@ -63,6 +68,7 @@ limitations under the License.
                        <mdl:beads>
                                <js:DynamicItemsRendererFactoryForArrayListData 
/>
                                <js:DynamicRemoveItemRendererForArrayListData />
+                               
<js:DynamicRemoveAllItemRendererForArrayListData />
                        </mdl:beads>
                </mdl:Table>
        </mdl:GridCell>
@@ -72,4 +78,7 @@ limitations under the License.
        <mdl:GridCell>
                <mdl:Button text="Remove Last Employee" width="100" 
click="onRemoveEmployeeClick(event)"/>
        </mdl:GridCell>
+       <mdl:GridCell>
+               <mdl:Button text="Remove All" width="130" 
click="onRemoveAllClick(event)"/>
+       </mdl:GridCell>
 </mdl:Grid>
diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml 
b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 81ad5b3..d0bf629 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -153,6 +153,7 @@
     <component id="DynamicItemsRendererFactoryForArrayListData" 
class="org.apache.royale.html.beads.DynamicItemsRendererFactoryForArrayListData"
 />
     <component id="DynamicRemoveItemRendererForArrayListData" 
class="org.apache.royale.html.beads.DynamicRemoveItemRendererForArrayListData" 
/>
     <component id="DataItemRendererFactoryForHierarchicalData" 
class="org.apache.royale.html.beads.DataItemRendererFactoryForHierarchicalData" 
/>
+    <component id="DynamicRemoveAllItemRendererForArrayListData" 
class="org.apache.royale.html.beads.DynamicRemoveAllItemRendererForArrayListData"
 />
     <component id="TextItemRendererFactoryForArrayData" 
class="org.apache.royale.html.beads.TextItemRendererFactoryForArrayData" />
     <component id="TextItemRendererFactoryForStringVectorData" 
class="org.apache.royale.html.beads.TextItemRendererFactoryForStringVectorData" 
/>
 
diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DynamicRemoveAllItemRendererForArrayListData.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DynamicRemoveAllItemRendererForArrayListData.as
new file mode 100644
index 0000000..5111037
--- /dev/null
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DynamicRemoveAllItemRendererForArrayListData.as
@@ -0,0 +1,164 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads
+{
+       import org.apache.royale.core.IBead;
+       import org.apache.royale.core.IDataProviderModel;
+       import org.apache.royale.core.IItemRendererParent;
+       import org.apache.royale.core.IList;
+       import org.apache.royale.core.ISelectionModel;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.core.UIBase;
+       import org.apache.royale.events.CollectionEvent;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.events.IEventDispatcher;
+
+       /**
+        * Handles the removal of all itemRenderers once the corresponding 
datum has been removed
+        * from the IDataProviderModel.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.0
+        */
+       public class DynamicRemoveAllItemRendererForArrayListData implements 
IBead
+       {
+               /**
+                * Constructor
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.0
+                */
+               public function DynamicRemoveAllItemRendererForArrayListData()
+               {
+               }
+
+               private var _strand:IStrand;
+
+               /**
+                * @copy org.apache.royale.core.IStrand
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.0
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       
IEventDispatcher(value).addEventListener("initComplete", initComplete);
+               }
+               
+               /**
+                *  finish setup
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.8
+                */
+               protected function initComplete(event:Event):void
+               {
+                       
IEventDispatcher(_strand).removeEventListener("initComplete", initComplete);
+                       
+                       _dataProviderModel = 
_strand.getBeadByType(ISelectionModel) as ISelectionModel;
+                       
dataProviderModel.addEventListener("dataProviderChanged", 
dataProviderChangeHandler);   
+                       
+                       // invoke now in case "dataProviderChanged" has already 
been dispatched.
+                       dataProviderChangeHandler(null);
+               }
+               
+               /**
+                * @private
+                */
+               protected function dataProviderChangeHandler(event:Event):void
+               {
+                       var dp:IEventDispatcher = 
dataProviderModel.dataProvider as IEventDispatcher;
+                       if (!dp)
+                               return;
+                       
+                       // listen for all items being removed in the future.
+                       dp.addEventListener(CollectionEvent.ALL_ITEMS_REMOVED, 
handleAllItemsRemoved);
+               }
+
+               /**
+                * Handles the itemRemoved event by removing the item.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.0
+                */
+               protected function 
handleAllItemsRemoved(event:CollectionEvent):void
+               {
+                       if (dataProviderModel is ISelectionModel)
+                       {
+                               var model:ISelectionModel = dataProviderModel 
as ISelectionModel;
+                               model.selectedIndex = -1;
+                               model.selectedItem = null;
+                       }
+                       var parent:UIBase = itemRendererParent as UIBase;
+                       itemRendererParent.removeAllItemRenderers();
+
+                       (_strand as IEventDispatcher).dispatchEvent(new 
Event("layoutNeeded"));
+               }
+
+               private var _dataProviderModel: IDataProviderModel;
+
+               /**
+                *  The org.apache.royale.core.IDataProviderModel that contains 
the
+                *  data source.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.0
+                */
+               public function get dataProviderModel(): IDataProviderModel
+               {
+                       if (_dataProviderModel == null) {
+                               _dataProviderModel = 
_strand.getBeadByType(IDataProviderModel) as IDataProviderModel;
+                       }
+                       return _dataProviderModel;
+               }
+
+               private var _itemRendererParent: IItemRendererParent;
+
+               /**
+                *  The org.apache.royale.core.IItemRendererParent used
+                *  to generate instances of item renderers.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.0
+                */
+               public function get itemRendererParent():IItemRendererParent
+               {
+                       if (_itemRendererParent == null) {
+                               var list:IList = _strand as IList;
+                               _itemRendererParent = list.dataGroup;
+                       }
+                       return _itemRendererParent;
+               }
+       }
+}
diff --git 
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ArrayList.as
 
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ArrayList.as
index b7f1b98..9bf19f2 100644
--- 
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ArrayList.as
+++ 
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ArrayList.as
@@ -60,6 +60,16 @@ package org.apache.royale.collections
         */
        [Event(name="itemRemoved", 
type="org.apache.royale.events.CollectionEvent")]
 
+    /**
+     *  Dispatched when the collection has updated an item.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+    [Event(name="allItemsRemoved", 
type="org.apache.royale.events.CollectionEvent")]
+
        /**
         *  Dispatched when the collection has updated an item.
         *
@@ -358,8 +368,9 @@ package org.apache.royale.collections
                {
                        if (length > 0)
                        {
-                var collectionEvent:CollectionEvent = new 
CollectionEvent(CollectionEvent.ITEM_REMOVED);
+                var collectionEvent:CollectionEvent = new 
CollectionEvent(CollectionEvent.ALL_ITEMS_REMOVED);
                 collectionEvent.items = source.splice(0, length);
+                               collectionEvent.index = -1;
                 dispatchEvent(collectionEvent);
                        }
                }
diff --git 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/CollectionEvent.as
 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/CollectionEvent.as
index 844fc9d..6831ca5 100644
--- 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/CollectionEvent.as
+++ 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/CollectionEvent.as
@@ -31,6 +31,7 @@ package org.apache.royale.events
        {
                public static const ITEM_ADDED:String = "itemAdded";
                public static const ITEM_REMOVED:String = "itemRemoved";
+        public static const ALL_ITEMS_REMOVED:String = "allItemsRemoved";
                public static const ITEM_UPDATED:String = "itemUpdated";
                public static const COLLECTION_CHANGED:String = 
"collectionChanged";
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@royale.apache.org" <commits@royale.apache.org>'].

Reply via email to