flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [09/50] [abbrv] git commit: [flex-asjs] [refs/heads/core_js_to_as] - labelfield in dropdownlist
Date Thu, 08 Oct 2015 18:51:11 GMT
labelfield in dropdownlist


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/b5a5a4eb
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/b5a5a4eb
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/b5a5a4eb

Branch: refs/heads/core_js_to_as
Commit: b5a5a4eb89e7de72c3c92fb03dcf634dca2ca1be
Parents: 00f22de
Author: Alex Harui <aharui@apache.org>
Authored: Thu Sep 10 14:11:54 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Sep 10 14:14:18 2015 -0700

----------------------------------------------------------------------
 .../apache/flex/flat/beads/DropDownListView.as  | 10 ++++--
 .../js/src/org/apache/flex/flat/DropDownList.js | 32 ++++++++++++++++++--
 .../as/src/org/apache/flex/html/DropDownList.as | 18 +++++++++++
 .../apache/flex/html/beads/DropDownListView.as  |  8 ++++-
 .../TextItemRendererFactoryForArrayData.as      |  5 ++-
 .../beads/controllers/DropDownListController.as |  1 +
 .../html/beads/models/ArraySelectionModel.as    |  4 ++-
 .../js/src/org/apache/flex/html/DropDownList.js | 22 ++++++++++++--
 .../html/beads/models/ArraySelectionModel.js    |  2 ++
 9 files changed, 92 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/Flat/as/src/org/apache/flex/flat/beads/DropDownListView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Flat/as/src/org/apache/flex/flat/beads/DropDownListView.as
b/frameworks/projects/Flat/as/src/org/apache/flex/flat/beads/DropDownListView.as
index 3d7d838..f7357b9 100644
--- a/frameworks/projects/Flat/as/src/org/apache/flex/flat/beads/DropDownListView.as
+++ b/frameworks/projects/Flat/as/src/org/apache/flex/flat/beads/DropDownListView.as
@@ -126,6 +126,7 @@ package org.apache.flex.flat.beads
 			super.strand = value;;
             selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel;
             selectionModel.addEventListener("selectedIndexChanged", selectionChangeHandler);
+            selectionModel.addEventListener("dataProviderChanged", selectionChangeHandler);
 			shape = new Shape();
 			shape.graphics.beginFill(0xCCCCCC);
 			shape.graphics.drawRect(0, 0, 10, 10);
@@ -135,7 +136,7 @@ package org.apache.flex.flat.beads
 			SimpleButton(value).overState = overSprite;
 			SimpleButton(value).hitTestState = shape;
 			if (selectionModel.selectedIndex !== -1)
-				text = selectionModel.selectedItem.toString();
+				selectionChangeHandler(null);
             else
                 text = "^W_";
             upTextField.height = upTextField.textHeight + 4;
@@ -151,7 +152,12 @@ package org.apache.flex.flat.beads
 		
 		private function selectionChangeHandler(event:Event):void
 		{
-			text = selectionModel.selectedItem.toString();
+            if (selectionModel.selectedItem == null)
+                text = "";
+            else if (selectionModel.labelField != null)
+                text = selectionModel.selectedItem[selectionModel.labelField].toString();
+            else
+    			text = selectionModel.selectedItem.toString();
 		}
 		
         private function changeHandler(event:Event):void

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/Flat/js/src/org/apache/flex/flat/DropDownList.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/Flat/js/src/org/apache/flex/flat/DropDownList.js b/frameworks/projects/Flat/js/src/org/apache/flex/flat/DropDownList.js
index 9f7614c..ef6d3f5 100644
--- a/frameworks/projects/Flat/js/src/org/apache/flex/flat/DropDownList.js
+++ b/frameworks/projects/Flat/js/src/org/apache/flex/flat/DropDownList.js
@@ -152,13 +152,17 @@ org.apache.flex.flat.DropDownList.prototype.buttonClicked =
   goog.events.listen(select, 'click', goog.bind(this.selectChanged, this));
   select.className = 'dropdown-menu';
 
+  var lf = this.labelField;
   dp = /** @type {Array.<string>} */ (this.dataProvider);
   n = dp.length;
   for (i = 0; i < n; i++) {
     opt = document.createElement('li');
     opt.style.backgroundColor = 'transparent';
     var ir = document.createElement('a');
-    ir.innerHTML = dp[i];
+    if (lf)
+      ir.innerHTML = dp[i][lf];
+    else
+      ir.innerHTML = dp[i];
     ir.id = i.toString();
     if (i == this.selectedIndex)
       ir.className = 'dropdown-menu-item-renderer-selected';
@@ -186,6 +190,20 @@ Object.defineProperties(org.apache.flex.flat.DropDownList.prototype,
{
         }
     },
     /** @export */
+    labelField: {
+        // TODO: (aharui) copied from ListBase because you
+        // can't just override the setter in a defineProps
+        // structure.
+        /** @this {org.apache.flex.flat.DropDownList} */
+        get: function() {
+            return this.model.labelField;
+        },
+        /** @this {org.apache.flex.flat.DropDownList} */
+        set: function(value) {
+            this.model.labelField = value;
+        }
+    },
+    /** @export */
     selectedIndex: {
         // TODO: (aharui) copied from ListBase because you
         // can't just override the setter in a defineProps
@@ -197,7 +215,11 @@ Object.defineProperties(org.apache.flex.flat.DropDownList.prototype,
{
         /** @this {org.apache.flex.flat.DropDownList} */
         set: function(value) {
             this.model.selectedIndex = value;
-            this.button.innerHTML = this.selectedItem + '<span class="dropdown-caret"/>';
+            var lf = this.labelField;
+            if (lf)
+              this.button.innerHTML = this.selectedItem[lf] + '<span class="dropdown-caret"/>';
+            else
+              this.button.innerHTML = this.selectedItem + '<span class="dropdown-caret"/>';
         }
     },
     /** @export */
@@ -212,7 +234,11 @@ Object.defineProperties(org.apache.flex.flat.DropDownList.prototype,
{
         /** @this {org.apache.flex.flat.DropDownList} */
         set: function(value) {
             this.model.selectedItem = value;
-            this.button.innerHTML = this.selectedItem + '<span class="dropdown-caret"/>';
+            var lf = this.labelField;
+            if (lf)
+              this.button.innerHTML = this.selectedItem[lf] + '<span class="dropdown-caret"/>';
+            else
+              this.button.innerHTML = this.selectedItem + '<span class="dropdown-caret"/>';
          }
     }
 });

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/as/src/org/apache/flex/html/DropDownList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/DropDownList.as b/frameworks/projects/HTML/as/src/org/apache/flex/html/DropDownList.as
index 43b34ea..25dcfc7 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/DropDownList.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/DropDownList.as
@@ -135,5 +135,23 @@ package org.apache.flex.html
             ISelectionModel(model).selectedItem = value;
         }
                         
+        /**
+         *  The name of field within the data used for display. Each item of the
+         *  data should have a property with this name.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function get labelField():String
+        {
+            return ISelectionModel(model).labelField;
+        }
+        public function set labelField(value:String):void
+        {
+            ISelectionModel(model).labelField = value;
+        }
+        
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/DropDownListView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/DropDownListView.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/DropDownListView.as
index e3f1a7e..1334227 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/DropDownListView.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/DropDownListView.as
@@ -114,6 +114,7 @@ package org.apache.flex.html.beads
 			super.strand = value;;
             selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel;
             selectionModel.addEventListener("selectedIndexChanged", selectionChangeHandler);
+            selectionModel.addEventListener("dataProviderChanged", selectionChangeHandler);
 			shape = new Shape();
 			shape.graphics.beginFill(0xCCCCCC);
 			shape.graphics.drawRect(0, 0, 10, 10);
@@ -139,7 +140,12 @@ package org.apache.flex.html.beads
 		
 		private function selectionChangeHandler(event:Event):void
 		{
-			text = selectionModel.selectedItem.toString();
+            if (selectionModel.selectedItem == null)
+                text = "";
+            else if (selectionModel.labelField != null)
+                text = selectionModel.selectedItem[selectionModel.labelField].toString();
+            else
+                text = selectionModel.selectedItem.toString();
 		}
 		
         private function changeHandler(event:Event):void

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as
index 635b851..f500094 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as
@@ -131,7 +131,10 @@ package org.apache.flex.html.beads
 				var tf:ITextItemRenderer = itemRendererFactory.createItemRenderer(dataGroup) as ITextItemRenderer;
                 tf.index = i;
                 dataGroup.addElement(tf);
-				tf.text = dp[i];
+                if (selectionModel.labelField)
+                    tf.text = dp[i][selectionModel.labelField];
+                else
+    				tf.text = dp[i];
 			}
 			
 			IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated"));

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/controllers/DropDownListController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/controllers/DropDownListController.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/controllers/DropDownListController.as
index 848eda5..17a4b64 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/controllers/DropDownListController.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/controllers/DropDownListController.as
@@ -81,6 +81,7 @@ package org.apache.flex.html.beads.controllers
             var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel;
             DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width;
             popUpModel.dataProvider = selectionModel.dataProvider;
+            popUpModel.labelField = selectionModel.labelField;
             viewBead.popUpVisible = true; // adds to display list as well
             popUpModel.selectedIndex = selectionModel.selectedIndex;
             var pt:Point = new Point(DisplayObject(_strand).x, DisplayObject(_strand).y +
DisplayObject(_strand).height);

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/models/ArraySelectionModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/models/ArraySelectionModel.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/models/ArraySelectionModel.as
index 2e655a4..a6c0a31 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/models/ArraySelectionModel.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/models/ArraySelectionModel.as
@@ -85,10 +85,12 @@ package org.apache.flex.html.beads.models
          */
 		public function set dataProvider(value:Object):void
 		{
+            if (value === _dataProvider) return;
+            
             _dataProvider = value;
             if (_selectedIndex != -1)
                 _selectedItem = (_dataProvider == null || _selectedIndex >= _dataProvider.length)
? null : 
-                    _dataProvider[value];
+                    _dataProvider[_selectedIndex];
 			dispatchEvent(new Event("dataProviderChanged"));
 		}
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/js/src/org/apache/flex/html/DropDownList.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/js/src/org/apache/flex/html/DropDownList.js b/frameworks/projects/HTML/js/src/org/apache/flex/html/DropDownList.js
index 1630d3a..2fb57a9 100644
--- a/frameworks/projects/HTML/js/src/org/apache/flex/html/DropDownList.js
+++ b/frameworks/projects/HTML/js/src/org/apache/flex/html/DropDownList.js
@@ -74,15 +74,33 @@ Object.defineProperties(org.apache.flex.html.DropDownList.prototype, {
               dp.remove(0);
             }
 
+            var lf = this.labelField;
             n = value.length;
             for (i = 0; i < n; i++) {
               opt = document.createElement('option');
-              opt.text = value[i];
+              if (lf)
+                opt.text = value[i][lf];
+              else
+                opt.text = value[i];
               dp.add(opt);
             }
         }
     },
     /** @export */
+    labelField: {
+        // TODO: (aharui) copied from ListBase because you
+        // can't just override the setter in a defineProps
+        // structure.
+        /** @this {org.apache.flex.html.DropDownList} */
+        get: function() {
+            return this.model.labelField;
+        },
+        /** @this {org.apache.flex.html.DropDownList} */
+        set: function(value) {
+            this.model.labelField = value;
+        }
+    },
+    /** @export */
     selectedIndex: {
         // TODO: (aharui) copied from ListBase because you
         // can't just override the setter in a defineProps
@@ -109,7 +127,7 @@ Object.defineProperties(org.apache.flex.html.DropDownList.prototype, {
         /** @this {org.apache.flex.html.DropDownList} */
         set: function(value) {
             this.model.selectedItem = value;
-            this.element.selectedIndex = this.selectedIndex;
+            this.element.selectedIndex = this.model.selectedIndex;
         }
     }
 });

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b5a5a4eb/frameworks/projects/HTML/js/src/org/apache/flex/html/beads/models/ArraySelectionModel.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/js/src/org/apache/flex/html/beads/models/ArraySelectionModel.js
b/frameworks/projects/HTML/js/src/org/apache/flex/html/beads/models/ArraySelectionModel.js
index 1b211ce..b22cf27 100644
--- a/frameworks/projects/HTML/js/src/org/apache/flex/html/beads/models/ArraySelectionModel.js
+++ b/frameworks/projects/HTML/js/src/org/apache/flex/html/beads/models/ArraySelectionModel.js
@@ -61,6 +61,7 @@ Object.defineProperties(org.apache.flex.html.beads.models.ArraySelectionModel.pr
         },
         /** @this {org.apache.flex.html.beads.models.ArraySelectionModel} */
         set: function(value) {
+            if (value === this.dataProvider_) return;
             this.dataProvider_ = value;
             this.dispatchEvent('dataProviderChanged');
         }
@@ -73,6 +74,7 @@ Object.defineProperties(org.apache.flex.html.beads.models.ArraySelectionModel.pr
         },
         /** @this {org.apache.flex.html.beads.models.ArraySelectionModel} */
         set: function(value) {
+            if (value === this.selectedIndex_) return;
             this.selectedIndex_ = value;
             this.dispatchEvent('selectedIndexChanged');
         }


Mime
View raw message