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 2013/01/09 20:56:29 UTC

svn commit: r1431034 - in /flex/sdk/branches/develop: frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as mustella/tests/gumbo/components/List/events/list_events_tester.mxml mustella/tests/gumbo/components/List/swfs/ListBasic.mxml

Author: cframpton
Date: Wed Jan  9 19:56:29 2013
New Revision: 1431034

URL: http://svn.apache.org/viewvc?rev=1431034&view=rev
Log:
FLEX-33163 - if a List's dataProvider receives a "reset" collection event, even if the selectedIndex doesn't change, the selectedItem does, so a "valueCommit" event must be dispatched to trigger bindings on selectedItem. 

Add new List_events_collectionKind_reset_bug test.

QE: Passed mustella tests for spark List, Spinner, ButtonBar, and TabBar.

Modified:
    flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as
    flex/sdk/branches/develop/mustella/tests/gumbo/components/List/events/list_events_tester.mxml
    flex/sdk/branches/develop/mustella/tests/gumbo/components/List/swfs/ListBasic.mxml

Modified: flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as
URL: http://svn.apache.org/viewvc/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as?rev=1431034&r1=1431033&r2=1431034&view=diff
==============================================================================
--- flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as (original)
+++ flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as Wed Jan  9 19:56:29 2013
@@ -625,15 +625,18 @@ public class ListBase extends SkinnableD
      */
     mx_internal var _proposedSelectedIndex:int = NO_PROPOSED_SELECTION;
     
-    /** 
-     *  @private
-     *  Flag that is set when the selectedIndex has been adjusted due to
-     *  items being added or removed. When this flag is true, the value
-     *  of the selectedIndex has changed, but the actual selected item
-     *  is the same. This flag is cleared in commitProperties().
-     */
-    mx_internal var selectedIndexAdjusted:Boolean = false;
-    
+	/** 
+	 *  @private
+	 *  Flag that is set when the selectedIndex has been adjusted due to
+	 *  items being added or removed. When this flag is true, the value
+	 *  of the selectedIndex has changed, but the actual selected item
+	 *  is the same. 
+     *  This flag can also be set if the selectedItem has changed to ensure
+     *  a valueCommit is dispatched even if the selectedIndex has not changed.
+     *  This flag is cleared in commitProperties().
+	 */
+	mx_internal var selectedIndexAdjusted:Boolean = false;
+	
     /** 
      *  @private
      *  Flag that is set when the caretIndex has been adjusted due to
@@ -822,7 +825,10 @@ public class ListBase extends SkinnableD
         
         if (dispatchChangeEvent)
             dispatchChangeAfterSelection = (dispatchChangeAfterSelection || dispatchChangeEvent);
-        
+		
+        // ensure that a "valueCommit" is dispatched even if the selectedIndex did not change.
+        selectedIndexAdjusted = true;
+	
         _pendingSelectedItem = value;
         invalidateProperties();
     }
@@ -947,8 +953,9 @@ public class ListBase extends SkinnableD
             changedSelection = commitSelection();
         
         // If the selectedIndex has been adjusted to account for items that
-        // have been added or removed, send out a "change" event 
-        // so any bindings to selectedIndex are updated correctly.
+        // have been added or removed, or the selectedItem has changed because of a dp collection
+        // event which didn't cause the selectedIndex to change, send out a "change" event so any 
+        // bindings to selectedIndex/selectedItem are updated correctly.
         if (selectedIndexAdjusted)
         {
             selectedIndexAdjusted = false;
@@ -1480,6 +1487,7 @@ public class ListBase extends SkinnableD
      */
     mx_internal function dataProviderRefreshed():void
     {
+        selectedItem = undefined;
         setSelectedIndex(NO_SELECTION, false);
         // TODO (rfrishbe): probably don't need the setCurrentCaretIndex below
         setCurrentCaretIndex(NO_CARET);
@@ -1666,7 +1674,9 @@ public class ListBase extends SkinnableD
             }
             else if (ce.kind == CollectionEventKind.RESET)
             {
-                // Data provider is being reset, clear out the selection
+                // Data provider is being reset, clear out the selection which includes the
+                // selectedItem so that any bindings on the selectedItem are triggered.
+                selectedItem = undefined;
                 if (dataProvider.length == 0)
                 {
                     setSelectedIndex(NO_SELECTION, false);

Modified: flex/sdk/branches/develop/mustella/tests/gumbo/components/List/events/list_events_tester.mxml
URL: http://svn.apache.org/viewvc/flex/sdk/branches/develop/mustella/tests/gumbo/components/List/events/list_events_tester.mxml?rev=1431034&r1=1431033&r2=1431034&view=diff
==============================================================================
--- flex/sdk/branches/develop/mustella/tests/gumbo/components/List/events/list_events_tester.mxml (original)
+++ flex/sdk/branches/develop/mustella/tests/gumbo/components/List/events/list_events_tester.mxml Wed Jan  9 19:56:29 2013
@@ -40,6 +40,7 @@
         import comps.*;
 
         import mx.collections.ArrayCollection;
+        import mx.collections.ListCollectionView;
         import spark.events.IndexChangeEvent;
         import spark.skins.spark.*;
         import mx.events.CollectionEventKind;
@@ -48,7 +49,7 @@
         import spark.utils.TextFlowUtil;
 
         public var data:ArrayCollection = new comps.SampleData();
-        var ti:TextFlow = TextFlowUtil.importFromString ("Maecenas tristique, velit aliquam faucibus ornare, justo erat porta elit, sed venenatis neque mi ac elit. Nullam enim metus, gravida ac euismod sit amet, commodo vitae elit. Quisque eget molestie ante. Nulla fermentum pretium augue non tristique. Praesent in orci eu diam ultrices sodales ac quis leo. Aliquam lobortis elit quis mi rutrum feugiat. Aenean sed elit turpis. Duis enim ligula, posuere sit amet semper a, pretium vel leo. Etiam mollis dolor nec elit suscipit imperdiet. Sed a est eros.");
+        private var ti:TextFlow = TextFlowUtil.importFromString ("Maecenas tristique, velit aliquam faucibus ornare, justo erat porta elit, sed venenatis neque mi ac elit. Nullam enim metus, gravida ac euismod sit amet, commodo vitae elit. Quisque eget molestie ante. Nulla fermentum pretium augue non tristique. Praesent in orci eu diam ultrices sodales ac quis leo. Aliquam lobortis elit quis mi rutrum feugiat. Aenean sed elit turpis. Duis enim ligula, posuere sit amet semper a, pretium vel leo. Etiam mollis dolor nec elit suscipit imperdiet. Sed a est eros.");
 
     ]]>
     </fx:Script>
@@ -220,6 +221,33 @@
         </body>
     </TestCase>
 
+    <TestCase testID="List_events_collectionKind_reset_bug" keywords="[List, change list, FLEX-33163]" description="Collection RESET event should reset selectedItem even if selectedIndex doesn't change">
+        <setup>
+            <ResetComponent target="list1" className="spark.components.List" waitEvent="updateComplete" />
+            <ResetComponent target="list2" className="spark.components.List" waitEvent="updateComplete" />
+            <ResetComponent target="lcvlist" className="spark.components.List" waitEvent="updateComplete" />
+            
+            <SetProperty target="list1" propertyName="dataProvider" valueExpression="value=new ArrayCollection(['A','B','C','D']);" waitEvent="updateComplete"/>
+            <SetProperty target="list2" propertyName="dataProvider" valueExpression="value=new ArrayCollection([1,2,3,4]);" waitEvent="updateComplete"/>
+            <SetProperty target="lcvlist" propertyName="dataProvider" valueExpression="value=new ListCollectionView(application.list1.dataProvider)"/>
+
+            <SetProperty target="lcvlist" propertyName="selectedIndex" value="1" waitEvent="updateComplete"/>
+            <AssertPropertyValue target="lcvlist_selectedItem" propertyName="text" value="B" />               
+        </setup>
+        <body>
+            <AssertPropertyValue target="lcvlist" propertyName="selectedItem" value="B" />
+            
+            <!-- Changing the ListCollectionView's list should generate a CollectionEventKind.RESET on the dataProvider. -->
+            <!-- The selectedItem should not change but the selectedItem should which should cause a valueCommit to be dispatched to update the bindings.  -->
+            <SetProperty target="lcvlist.dataProvider" propertyName="list" valueExpression="value=application.list2.dataProvider" waitTarget="lcvlist" waitEvent="valueCommit"/>
+
+            <AssertPropertyValue target="lcvlist" propertyName="selectedIndex" value="1" />
+            <!-- Ensure binding was triggered -->            
+            <AssertPropertyValue target="lcvlist_selectedItem" propertyName="text" value="2" />               
+            <AssertPropertyValue target="lcvlist" propertyName="selectedItem" value="2" /> 
+        </body>
+    </TestCase>
+
     <TestCase testID="List_events_collectionKind_update" keywords="[List, event, CollectionKind]" description="check that the dataProvider sends off CollectionEvents (update)">
         <setup>
             <ResetComponent target="list1" className="spark.components.List" waitEvent="updateComplete" waitTarget="list1" />

Modified: flex/sdk/branches/develop/mustella/tests/gumbo/components/List/swfs/ListBasic.mxml
URL: http://svn.apache.org/viewvc/flex/sdk/branches/develop/mustella/tests/gumbo/components/List/swfs/ListBasic.mxml?rev=1431034&r1=1431033&r2=1431034&view=diff
==============================================================================
--- flex/sdk/branches/develop/mustella/tests/gumbo/components/List/swfs/ListBasic.mxml (original)
+++ flex/sdk/branches/develop/mustella/tests/gumbo/components/List/swfs/ListBasic.mxml Wed Jan  9 19:56:29 2013
@@ -253,6 +253,10 @@
 
     <s:List id="list1" dataProvider="{new ArrayCollection([])}"  />
     <s:List id="list2" dataProvider="{new ArrayCollection([])}" itemRendererFunction="mixItemRendererFunction"/>
+    <s:HGroup>
+        <s:List id="lcvlist"/>
+        <s:Label id="lcvlist_selectedItem" text="{lcvlist.selectedItem}"/>
+    </s:HGroup>
     <comps:ItemRendRETComp id="list3" />
     <comps:ItemRendRETLabelComp id="list4" />
     <comps:ItemRendRETComp1 id="list5" />