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 3fa7503 Spark DropDownList: Fix selectedIndex/selectedItem properties
3fa7503 is described below
commit 3fa7503383d61ef43c56efd919ed097c2ec28288
Author: Piotr Zarzycki <[email protected]>
AuthorDate: Tue Oct 1 12:03:29 2019 +0200
Spark DropDownList: Fix selectedIndex/selectedItem properties
(reference #474 )
---
.../models/SingleSelectionICollectionViewModel.as | 36 ++-
.../spark/components/beads/DropDownListView.as | 286 +++++++++++----------
.../components/supportClasses/DropDownListBase.as | 59 ++++-
.../spark/components/supportClasses/ListBase.as | 4 +-
4 files changed, 231 insertions(+), 154 deletions(-)
diff --git
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
index 9a79fb8..ea4538d 100644
---
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
+++
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
@@ -106,17 +106,28 @@ package mx.controls.beads.models
if (index == 0)
{
if (lastIndex == 1)
- _cursor.movePrevious();
+ {
+ _cursor.movePrevious();
+ }
else
- _cursor.seek(CursorBookmark.FIRST);
+ {
+ _cursor.seek(CursorBookmark.FIRST);
+ }
lastIndex = 0;
}
else if (index + 1 == lastIndex)
- _cursor.movePrevious();
+ {
+ _cursor.movePrevious();
+ }
else if (lastIndex + 1 == index)
- _cursor.moveNext();
+ {
+ _cursor.moveNext();
+ }
else
- _cursor.seek(CursorBookmark.FIRST, index);
+ {
+ _cursor.seek(CursorBookmark.FIRST, index);
+ }
+
return _cursor.current;
}
@@ -168,8 +179,21 @@ package mx.controls.beads.models
{
if (value == _selectedIndex) return;
+ lastIndex = _selectedIndex;
_selectedIndex = value;
- _selectedItem = (value == -1 || _dataProvider == null)
? null : (value < _dataProvider.length) ? getItemAt(value) : null;
+ if (value == -1 || dataProvider == null)
+ {
+ _selectedItem = null;
+ }
+ else if (value < dataProvider.length)
+ {
+ _selectedItem = getItemAt(value);
+ }
+ else
+ {
+ _selectedItem = null;
+ }
+
dispatchEvent(new Event("selectedIndexChanged"));
}
diff --git
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
index 46713d2..d35d878 100644
---
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
+++
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
@@ -20,166 +20,172 @@
package spark.components.beads
{
-import mx.core.IFlexDisplayObject;
-import mx.core.IUIComponent;
-import mx.managers.PopUpManager;
-
-import spark.components.Button;
-import spark.components.DropDownList;
-
-import org.apache.royale.core.IBead;
-import org.apache.royale.core.IChild;
-import org.apache.royale.core.IContainer;
-import org.apache.royale.core.ILayoutChild;
-import org.apache.royale.core.IPopUpHost;
-import org.apache.royale.core.ISelectionModel;
-import org.apache.royale.core.IStrand;
-import org.apache.royale.core.IStrandWithModel;
-import org.apache.royale.core.IStyleableObject;
-import org.apache.royale.core.IUIBase;
-import org.apache.royale.events.Event;
-import org.apache.royale.events.IEventDispatcher;
-import org.apache.royale.html.beads.IDropDownListView;
-
-/**
- * @private
- * The DropDownListView for emulation.
- */
-public class DropDownListView extends SkinnableContainerView implements
IDropDownListView
-{
-
//--------------------------------------------------------------------------
- //
- // Constructor
- //
-
//--------------------------------------------------------------------------
-
- /**
- * Constructor.
- *
- * @langversion 3.0
- * @playerversion Flash 9
- * @playerversion AIR 1.1
- * @productversion Flex 3
- */
- public function DropDownListView()
- {
- super();
- }
+ import mx.core.IFlexDisplayObject;
+ import mx.core.IUIComponent;
+ import mx.managers.PopUpManager;
- /**
- * @royalesuppresspublicvarwarning
- */
- public var label:Button;
-
- private var selectionModel:ISelectionModel;
+ import spark.components.Button;
+ import spark.components.DropDownList;
+
+ import org.apache.royale.core.IBead;
+ import org.apache.royale.core.IChild;
+ import org.apache.royale.core.IContainer;
+ import org.apache.royale.core.ILayoutChild;
+ import org.apache.royale.core.IPopUpHost;
+ import org.apache.royale.core.ISelectionModel;
+ import org.apache.royale.core.IStrand;
+ import org.apache.royale.core.IStrandWithModel;
+ import org.apache.royale.core.IStyleableObject;
+ import org.apache.royale.core.IUIBase;
+ import org.apache.royale.events.Event;
+ import org.apache.royale.events.IEventDispatcher;
+ import org.apache.royale.html.beads.IDropDownListView;
- /**
- */
- override public function set strand(value:IStrand):void
- {
- super.strand = value;
-
- selectionModel = (value as IStrandWithModel).model as ISelectionModel;
- selectionModel.addEventListener("selectedIndexChanged",
selectionChangeHandler);
- selectionModel.addEventListener("dataProviderChanged",
selectionChangeHandler);
-
- (value as IEventDispatcher).addEventListener("initComplete",
selectionChangeHandler);
-
- // remove the DataGroup. It will be the dropdown
- var chost:IContainer = host as IContainer;
- chost.strandChildren.removeElement(viewport.contentView);
-
- label = new Button();
- if (selectionModel.selectedIndex == -1)
- label.label = (host as DropDownList).prompt;
- chost.strandChildren.addElement(label);
-
-
- value.addBead(new DropDownListLayout());
-
- }
-
- private function selectionChangeHandler(event:Event):void
- {
- if (selectionModel.selectedItem == null)
- label.label = (host as DropDownList).prompt;
- else if (selectionModel.labelField != null)
- label.label =
selectionModel.selectedItem[selectionModel.labelField].toString();
- else
- label.label = selectionModel.selectedItem.toString();
- }
-
- /**
- * The dropdown/popup that displays the set of choices.
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function get popUp():IStrand
- {
- return viewport.contentView as IStrand;
- }
-
- private var _popUpVisible:Boolean;
-
- /**
- * A flag that indicates whether the dropdown/popup is
- * visible.
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function get popUpVisible():Boolean
- {
- return _popUpVisible;
- }
-
/**
* @private
+ * The DropDownListView for emulation.
*/
- public function set popUpVisible(value:Boolean):void
+ public class DropDownListView extends SkinnableContainerView implements
IDropDownListView
{
- if (value != _popUpVisible)
+
//--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+
//--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function DropDownListView()
+ {
+ super();
+ }
+
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public var label:Button;
+
+ private var selectionModel:ISelectionModel;
+
+ /**
+ */
+ override public function set strand(value:IStrand):void
+ {
+ super.strand = value;
+
+ selectionModel = (value as IStrandWithModel).model as
ISelectionModel;
+ selectionModel.addEventListener("selectedIndexChanged",
selectionChangeHandler);
+ selectionModel.addEventListener("dataProviderChanged",
selectionChangeHandler);
+
+ (value as IEventDispatcher).addEventListener("initComplete",
selectionChangeHandler);
+
+ // remove the DataGroup. It will be the dropdown
+ var chost:IContainer = host as IContainer;
+ chost.strandChildren.removeElement(viewport.contentView);
+
+ label = new Button();
+ if (selectionModel.selectedIndex == -1)
+ label.label = (host as DropDownList).prompt;
+ chost.strandChildren.addElement(label);
+
+
+ value.addBead(new DropDownListLayout());
+
+ }
+
+ private function selectionChangeHandler(event:Event):void
{
- _popUpVisible = value;
- var popUpDisplayObject:IFlexDisplayObject = popUp as
IFlexDisplayObject;
- if (value)
+ if (selectionModel.selectedItem == null)
{
- PopUpManager.addPopUp(popUpDisplayObject, _strand);
- (popUpDisplayObject as IStyleableObject).className =
"DropDownDataGroup";
- (popUp as IUIComponent).setActualSize((popUp as
IUIComponent).width, 100);
+ label.label = (host as DropDownList).prompt;
+ }
+ else if (selectionModel.labelField != null)
+ {
+ label.label =
selectionModel.selectedItem[selectionModel.labelField].toString();
}
else
{
- PopUpManager.removePopUp(popUpDisplayObject);
+ label.label = selectionModel.selectedItem.toString();
+ }
+ }
+
+ /**
+ * The dropdown/popup that displays the set of choices.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function get popUp():IStrand
+ {
+ return viewport.contentView as IStrand;
+ }
+
+ private var _popUpVisible:Boolean;
+
+ /**
+ * A flag that indicates whether the dropdown/popup is
+ * visible.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function get popUpVisible():Boolean
+ {
+ return _popUpVisible;
+ }
+
+ /**
+ * @private
+ */
+ public function set popUpVisible(value:Boolean):void
+ {
+ if (value != _popUpVisible)
+ {
+ _popUpVisible = value;
+ var popUpDisplayObject:IFlexDisplayObject = popUp as
IFlexDisplayObject;
+ if (value)
+ {
+ PopUpManager.addPopUp(popUpDisplayObject, _strand);
+ (popUpDisplayObject as IStyleableObject).className =
"DropDownDataGroup";
+ (popUp as IUIComponent).setActualSize((popUp as
IUIComponent).width, 100);
+ }
+ else
+ {
+ PopUpManager.removePopUp(popUpDisplayObject);
+ }
}
}
}
-}
}
-import spark.components.Button;
-import spark.components.DropDownList;
-import spark.components.beads.DropDownListView;
+ import spark.components.Button;
+ import spark.components.DropDownList;
+ import spark.components.beads.DropDownListView;
-import org.apache.royale.core.LayoutBase;
+ import org.apache.royale.core.LayoutBase;
-// this layouts out the one Label/Button.
-class DropDownListLayout extends LayoutBase
-{
- override public function layout():Boolean
+ // this layouts out the one Label/Button.
+ class DropDownListLayout extends LayoutBase
{
- var list:DropDownList = host as DropDownList;
- var view:DropDownListView = list.view as DropDownListView;
- view.label.setActualSize(list.width, list.height);
-
- return false;
+ override public function layout():Boolean
+ {
+ var list:DropDownList = host as DropDownList;
+ var view:DropDownListView = list.view as DropDownListView;
+ view.label.setActualSize(list.width, list.height);
+
+ return false;
+ }
}
-}
diff --git
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
index 5ee368a..c607a5c 100644
---
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
+++
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
@@ -307,9 +307,14 @@ public class DropDownListBase extends List
//----------------------------------
// dataProvider
//----------------------------------
-
+
+ [Bindable("dataProviderChanged")]
[Inspectable(category="Data")]
-
+ override public function get dataProvider():IList
+ {
+ return (model as ISelectionModel).dataProvider as IList;
+ }
+
/**
* @private
* Update the label if the dataProvider has changed
@@ -367,19 +372,61 @@ public class DropDownListBase extends List
//----------------------------------
//[Inspectable(category="Data", defaultValue="label")]
-
+
+ override public function get labelField():String
+ {
+ return (model as ISelectionModel).labelField;
+ }
+
/**
* @private
*/
override public function set labelField(value:String):void
{
- super.labelField = value; // this passes it to DataGroup
-
(model as ISelectionModel).labelField = value;
+ super.labelField = value; // this passes it to DataGroup
+
//labelChanged = true;
//invalidateProperties();
}
-
+
+ [Bindable("change")]
+ [Bindable("valueCommit")]
+ [Inspectable(category="General", defaultValue="-1")]
+ override public function get selectedIndex():int
+ {
+ /* if (_proposedSelectedIndex != NO_PROPOSED_SELECTION)
+ return _proposedSelectedIndex; */
+
+ return (model as ISelectionModel).selectedIndex;
+ }
+
+ /**
+ * @private
+ */
+ override public function set selectedIndex(value:int):void
+ {
+ (model as ISelectionModel).selectedIndex = value;
+ super.selectedIndex = value;
+ /* setSelectedIndex(value, false); */
+ }
+
+ [Bindable("change")]
+ [Bindable("valueCommit")]
+ [Inspectable(category="General", defaultValue="null")]
+ override public function get selectedItem():*
+ {
+ return (model as ISelectionModel).selectedItem;
+ }
+
+ /**
+ * @private
+ */
+ override public function set selectedItem(value:*):void
+ {
+ (model as ISelectionModel).selectedItem = value;
+ super.selectedItem = value;
+ }
//----------------------------------
// labelFunction
//----------------------------------
diff --git
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/ListBase.as
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/ListBase.as
index 68ff7d0..edbb211 100644
---
a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/ListBase.as
+++
b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/ListBase.as
@@ -49,7 +49,7 @@ import spark.components.DataGroup;
import spark.components.SkinnableContainer;
import spark.components.beads.SkinnableContainerView;
-import org.apache.royale.core.IBeadLayout;
+import org.apache.royale.core.IBeadLayout;
import org.apache.royale.core.ISelectionModel;
import org.apache.royale.core.ItemRendererClassFactory;
import org.apache.royale.events.Event;
@@ -665,7 +665,7 @@ public class ListBase extends SkinnableContainer
* @playerversion AIR 1.5
* @productversion Royale 0.9.4
*/
- public function get labelField():String
+ public function get labelField():String
{
return (((view as SkinnableContainerView).contentView as
DataGroup).model as ISelectionModel).labelField;
}