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

pent 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 6282e13  Added NestedStringItemRenderer which can handle dataFields 
such as: dataField=“record.address.city”
6282e13 is described below

commit 6282e138017e3336b2adf788a93f669243c3f922
Author: Peter Ent <[email protected]>
AuthorDate: Wed Feb 7 13:34:36 2018 -0500

    Added NestedStringItemRenderer which can handle dataFields such as: 
dataField=“record.address.city”
---
 .../projects/Basic/src/main/royale/BasicClasses.as |   1 +
 .../supportClasses/NestedStringItemRenderer.as     | 105 +++++++++++++++++++++
 2 files changed, 106 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as 
b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
index b8d4ea3..ad82d84 100644
--- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as
+++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
@@ -203,6 +203,7 @@ internal class BasicClasses
     import org.apache.royale.html.supportClasses.DateChooserList; 
DateChooserList;
     import org.apache.royale.html.supportClasses.DateItemRenderer; 
DateItemRenderer;
        import org.apache.royale.html.supportClasses.GraphicsItemRenderer; 
GraphicsItemRenderer;
+       import org.apache.royale.html.supportClasses.NestedStringItemRenderer; 
NestedStringItemRenderer;
 
     import org.apache.royale.html.beads.TitleBarView; TitleBarView;
     import org.apache.royale.html.beads.TitleBarMeasurementBead; 
TitleBarMeasurementBead;
diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/NestedStringItemRenderer.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/NestedStringItemRenderer.as
new file mode 100644
index 0000000..bf865c6
--- /dev/null
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/NestedStringItemRenderer.as
@@ -0,0 +1,105 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.supportClasses
+{
+
+       /**
+        * The NestedStringItemRenderer can be used with lists or 
DataGridColumns for
+        * items that are not at the top level of the data. For example, if the
+        * data is an Object having: {title: "Something", address:{street: 
"Main", zip: "02118"}}
+        * using NestedStringItemRenderer for the address field can extract any 
of
+        * its consitutents: labelField="address.zip". 
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+        */
+       public class NestedStringItemRenderer extends StringItemRenderer
+       {
+               /**
+                * Constructor
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+                */
+               public function NestedStringItemRenderer()
+               {
+                       super();
+               }
+               
+               /**
+                * Takes a labelField (or dataField) path (eg, "foo.bar.goo") 
and 
+                * returns the value associated with it from the data property 
by
+                * doing data[foo][bar][goo]. Returns null if the value cannot
+                * be determined.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+                */
+               public function getValueFromField(useField:String):Object
+               {
+                       if (data == null) return null;
+                       
+                       var currentValue:Object = data;
+                       
+                       var fn:Function = function(object:Object, index:int, 
array:Array):void {
+                               if (currentValue && 
currentValue.hasOwnProperty(object)) {
+                                       currentValue = currentValue[object];
+                               } else {
+                                       currentValue = null;
+                               }
+                       }
+                       var path:Array = useField.split(".");
+                       path.forEach(fn, this);
+                       return currentValue;
+               }
+               
+               private var _data:Object;
+               
+               /**
+                * @private
+                */
+               override public function set data(value:Object):void
+               {
+                       // cannot call super.data = value because that function
+                       // assumes the labelField is not a path
+                       _data = value;
+                       
+                       var text:String;
+                       if (value is String) text = value as String;
+                       else if (labelField) text = 
String(getValueFromField(labelField));
+                       else if (dataField) text = 
String(getValueFromField(dataField));
+                       else text = String(value);
+                       
+                       this.text = text;
+               }
+               
+               override public function get data():Object
+               {
+                       return _data;
+               }
+               
+               
+       }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to