flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik de Bruin <e...@ixsoftware.nl>
Subject Re: [2/2] git commit: [flex-sdk] [refs/heads/develop] - support mxml.children-as-data mainstream SDK
Date Sat, 06 Jul 2013 14:48:55 GMT
Daring move... what are you trying to achieve? Are you attempting to
get some kind of "vanilla SDK" support going for FlexJS?

EdB



On Sat, Jul 6, 2013 at 8:29 AM,  <aharui@apache.org> wrote:
> support mxml.children-as-data mainstream SDK
>
>
> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/6907ac09
> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/6907ac09
> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/6907ac09
>
> Branch: refs/heads/develop
> Commit: 6907ac09e43f1df07af558964946316dddefd829
> Parents: aeed464
> Author: Alex Harui <aharui@apache.org>
> Authored: Thu Jun 27 23:34:51 2013 -0700
> Committer: Alex Harui <aharui@apache.org>
> Committed: Fri Jul 5 23:29:02 2013 -0700
>
> ----------------------------------------------------------------------
>  .../framework/src/mx/core/UIComponent.as        | 256 ++++++++++++++++++-
>  .../framework/src/mx/states/AddItems.as         | 186 +++++++++++++-
>  .../projects/mx/src/mx/containers/ViewStack.as  |   9 +
>  frameworks/projects/mx/src/mx/core/Container.as |   6 +-
>  .../spark/src/spark/components/Group.as         |  10 +-
>  .../src/spark/components/SkinnableContainer.as  |  31 +++
>  6 files changed, 492 insertions(+), 6 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/framework/src/mx/core/UIComponent.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/framework/src/mx/core/UIComponent.as b/frameworks/projects/framework/src/mx/core/UIComponent.as
> index 8e46058..4eb4a6f 100644
> --- a/frameworks/projects/framework/src/mx/core/UIComponent.as
> +++ b/frameworks/projects/framework/src/mx/core/UIComponent.as
> @@ -1723,6 +1723,11 @@ public class UIComponent extends FlexSprite
>
>          _width = super.width;
>          _height = super.height;
> +
> +        var attributes:Array =  this.MXMLProperties;
> +        if (attributes)
> +            generateMXMLAttributes(attributes);
> +
>      }
>
>      //--------------------------------------------------------------------------
> @@ -4425,6 +4430,44 @@ public class UIComponent extends FlexSprite
>      {
>          return document == this;
>      }
> +
> +    //----------------------------------
> +    //  MXML Descriptor
> +    //----------------------------------
> +
> +    /**
> +     *  The descriptor of MXML children.
> +     */
> +    private var _MXMLDescriptor:Array;
> +
> +    public function get MXMLDescriptor():Array
> +    {
> +        return _MXMLDescriptor;
> +    }
> +
> +    public function setMXMLDescriptor(value:Array):void
> +    {
> +        _MXMLDescriptor = value;
> +    }
> +
> +    //----------------------------------
> +    //  MXML Properties
> +    //----------------------------------
> +
> +    /**
> +     *  The attributes of MXML top tag.
> +     */
> +    private var _MXMLProperties:Array;
> +
> +    public function get MXMLProperties():Array
> +    {
> +        return _MXMLProperties;
> +    }
> +
> +    public function setMXMLProperties(value:Array):void
> +    {
> +        _MXMLProperties = value;
> +    }
>
>      //----------------------------------
>      //  parentApplication
> @@ -7763,8 +7806,219 @@ public class UIComponent extends FlexSprite
>       */
>      protected function createChildren():void
>      {
> +        var children:Array =  this.MXMLDescriptor;
> +        if (children)
> +            generateMXMLInstances(document, children);
> +    }
> +
> +    protected function addMXMLChildren(comps:Array):void
> +    {
> +        for each (var i:DisplayObject in comps)
> +        {
> +            addChild(i);
> +        }
> +    }
> +
> +    protected function generateMXMLObject(document:Object, data:Array):Object
> +    {
> +        var i:int = 0;
> +        var cls:Class = data[i++];
> +        var comp:Object = new cls();
> +
> +        var m:int;
> +        var j:int;
> +        var name:String;
> +        var simple:*;
> +        var value:Object;
> +        var id:String;
> +
> +        m = data[i++]; // num props
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            simple = data[i++];
> +            value = data[i++];
> +            if (simple == null)
> +                value = generateMXMLArray(document, value as Array);
> +            else if (simple == false)
> +                value = generateMXMLObject(document, value as Array);
> +            if (name == "id")
> +            {
> +                document[value] = comp;
> +                id = value as String;
> +            }
> +            else if (name == "_id")
> +            {
> +                document[value] = comp;
> +                id = value as String;
> +                continue; // skip assignment to comp
> +            }
> +            comp[name] = value;
> +        }
> +        if (comp is IMXMLObject)
> +            comp.initialized(document, id);
> +        return comp;
> +    }
> +
> +    public function generateMXMLArray(document:Object, data:Array, recursive:Boolean
= true):Array
> +    {
> +        var comps:Array = [];
> +
> +        var n:int = data.length;
> +        var i:int = 0;
> +        while (i < n)
> +        {
> +            var cls:Class = data[i++];
> +            var comp:Object = new cls();
> +
> +            var m:int;
> +            var j:int;
> +            var name:String;
> +            var simple:*;
> +            var value:Object;
> +            var id:String = null;
> +
> +            m = data[i++]; // num props
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(document, value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(document, value as Array);
> +                if (name == "id")
> +                    id = value as String;
> +                if (name == "document" && !comp.document)
> +                    comp.document = document;
> +                else if (name == "_id")
> +                    id = value as String; // and don't assign to comp
> +                else
> +                    comp[name] = value;
> +            }
> +            m = data[i++]; // num styles
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(document, value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(document, value as Array);
> +                comp.setStyle(name, value);
> +            }
> +
> +            m = data[i++]; // num effects
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(document, value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(document, value as Array);
> +                comp.setStyle(name, value);
> +            }
> +
> +            m = data[i++]; // num events
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                value = data[i++];
> +                comp.addEventListener(name, value);
> +            }
> +
> +            var children:Array = data[i++];
> +            if (children)
> +            {
> +                if (recursive)
> +                    comp.generateMXMLInstances(document, children, recursive);
> +                else
> +                    comp.setMXMLDescriptor(children);
> +            }
> +
> +            if (id)
> +            {
> +                document[id] = comp;
> +                mx.binding.BindingManager.executeBindings(document, id, comp);
> +            }
> +            if (comp is IMXMLObject)
> +                comp.initialized(document, id);
> +            comps.push(comp);
> +        }
> +        return comps;
> +    }
> +
> +    protected function generateMXMLInstances(document:Object, data:Array, recursive:Boolean
= true):void
> +    {
> +        var comps:Array = generateMXMLArray(document, data, recursive);
> +        addMXMLChildren(comps);
> +    }
> +
> +    protected function generateMXMLAttributes(data:Array):void
> +    {
> +        var i:int = 0;
> +        var m:int;
> +        var j:int;
> +        var name:String;
> +        var simple:*;
> +        var value:Object;
> +        var id:String = null;
> +
> +        m = data[i++]; // num props
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            simple = data[i++];
> +            value = data[i++];
> +            if (simple == null)
> +                value = generateMXMLArray(this, value as Array, false);
> +            else if (simple == false)
> +                value = generateMXMLObject(this, value as Array);
> +            if (name == "id")
> +                id = value as String;
> +            if (name == "_id")
> +                id = value as String; // and don't assign
> +            else
> +                this[name] = value;
> +        }
> +        m = data[i++]; // num styles
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            simple = data[i++];
> +            value = data[i++];
> +            if (simple == null)
> +                value = generateMXMLArray(this, value as Array, false);
> +            else if (simple == false)
> +                value = generateMXMLObject(this, value as Array);
> +            this.setStyle(name, value);
> +        }
> +
> +        m = data[i++]; // num effects
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            simple = data[i++];
> +            value = data[i++];
> +            if (simple == null)
> +                value = generateMXMLArray(this, value as Array, false);
> +            else if (simple == false)
> +                value = generateMXMLObject(this, value as Array);
> +            this.setStyle(name, value);
> +        }
> +
> +        m = data[i++]; // num events
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            value = data[i++];
> +            this.addEventListener(name, value as Function);
> +        }
>      }
> -
>      /**
>       *  Performs any final processing after child objects are created.
>       *  This is an advanced method that you might override
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/framework/src/mx/states/AddItems.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/framework/src/mx/states/AddItems.as b/frameworks/projects/framework/src/mx/states/AddItems.as
> index 6fc388c..01fe514 100644
> --- a/frameworks/projects/framework/src/mx/states/AddItems.as
> +++ b/frameworks/projects/framework/src/mx/states/AddItems.as
> @@ -26,10 +26,12 @@ import mx.collections.IList;
>  import mx.core.ContainerCreationPolicy;
>  import mx.core.IChildList;
>  import mx.core.IDeferredContentOwner;
> +import mx.core.IMXMLObject;
>  import mx.core.ITransientDeferredInstance;
>  import mx.core.IVisualElement;
>  import mx.core.IVisualElementContainer;
>  import mx.core.UIComponent;
> +import mx.binding.BindingManager;
>
>  [DefaultProperty("itemsFactory")]
>
> @@ -41,7 +43,7 @@ import mx.core.UIComponent;
>   *  @playerversion AIR 1.5
>   *  @productversion Flex 4
>   */
> -public class AddItems extends OverrideBase
> +public class AddItems extends OverrideBase implements IMXMLObject
>  {
>      include "../core/Version.as";
>
> @@ -115,7 +117,9 @@ public class AddItems extends OverrideBase
>      //  Variables
>      //
>      //--------------------------------------------------------------------------
> -
> +
> +    private var document:Object;
> +
>      /**
>       *  @private
>       */
> @@ -308,6 +312,52 @@ public class AddItems extends OverrideBase
>      {
>          _items = value;
>      }
> +
> +    //------------------------------------
> +    //  itemsDescriptor
> +    //------------------------------------
> +
> +    /**
> +     *  @private
> +     *  Storage for the itemsDescriptor property.
> +     */
> +    private var _itemsDescriptor:Array;
> +
> +    [Inspectable(category="General")]
> +
> +    /**
> +     *
> +     * The descriptor that describes the items.
> +     *
> +     *  <p>If you set this property, the items are instantiated at the time
> +     *  determined by the <code>creationPolicy</code> property.</p>
> +     *
> +     *  <p>Do not set this property if you set the <code>items</code>
> +     *  property.
> +     *  This propety is the <code>AddItems</code> class default property.
> +     *  Setting this property with a <code>creationPolicy</code> of "all"
> +     *  is equivalent to setting a <code>items</code> property.</p>
> +     *
> +     *  @langversion 3.0
> +     *  @playerversion Flash 10
> +     *  @playerversion AIR 1.5
> +     *  @productversion Flex 4
> +     */
> +    public function get itemsDescriptor():Array
> +    {
> +        return _itemsDescriptor;
> +    }
> +
> +    /**
> +     *  @private
> +     */
> +    public function set itemsDescriptor(value:Array):void
> +    {
> +        _itemsDescriptor = value;
> +
> +        if (creationPolicy == ContainerCreationPolicy.ALL)
> +            createInstance();
> +    }
>
>      //------------------------------------
>      //  itemsFactory
> @@ -489,11 +539,132 @@ public class AddItems extends OverrideBase
>       */
>      public function createInstance():void
>      {
> -        if (!instanceCreated && !_items && itemsFactory)
> +        if (!instanceCreated && !_items && itemsFactory && !_itemsDescriptor)
>          {
>              instanceCreated = true;
>              items = itemsFactory.getInstance();
>          }
> +        else if (!instanceCreated && !_items && !itemsFactory &&
_itemsDescriptor)
> +        {
> +            instanceCreated = true;
> +            items = generateMXMLArray(itemsDescriptor, false);
> +        }
> +    }
> +
> +    protected function generateMXMLObject(data:Array):Object
> +    {
> +        var i:int = 0;
> +        var cls:Class = data[i++];
> +        var comp:Object = new cls();
> +
> +        var m:int;
> +        var j:int;
> +        var name:String;
> +        var simple:*;
> +        var value:Object;
> +        var id:String;
> +
> +        m = data[i++]; // num props
> +        for (j = 0; j < m; j++)
> +        {
> +            name = data[i++];
> +            simple = data[i++];
> +            value = data[i++];
> +            if (simple == null)
> +                value = generateMXMLArray(value as Array);
> +            else if (simple == false)
> +                value = generateMXMLObject(value as Array);
> +            comp[name] = value;
> +        }
> +        return comp;
> +    }
> +
> +    // varies slightly from version in UIComponent in how it handles documents
> +    public function generateMXMLArray(data:Array, recursive:Boolean = true):Array
> +    {
> +        var comps:Array = [];
> +
> +        var n:int = data.length;
> +        var i:int = 0;
> +        while (i < n)
> +        {
> +            var cls:Class = data[i++];
> +            var comp:Object = new cls();
> +
> +            var m:int;
> +            var j:int;
> +            var name:String;
> +            var simple:*;
> +            var value:Object;
> +            var id:String = null;
> +
> +            m = data[i++]; // num props
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(value as Array);
> +                if (name == "id")
> +                    id = value as String;
> +                if (name == "_id")
> +                    id = value as String; // and don't assign to comp
> +                else
> +                    comp[name] = value;
> +            }
> +            m = data[i++]; // num styles
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(value as Array);
> +                comp.setStyle(name, value);
> +            }
> +
> +            m = data[i++]; // num effects
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                simple = data[i++];
> +                value = data[i++];
> +                if (simple == null)
> +                    value = generateMXMLArray(value as Array, recursive);
> +                else if (simple == false)
> +                    value = generateMXMLObject(value as Array);
> +                comp.setStyle(name, value);
> +            }
> +
> +            m = data[i++]; // num events
> +            for (j = 0; j < m; j++)
> +            {
> +                name = data[i++];
> +                value = data[i++];
> +                comp.addEventListener(name, value);
> +            }
> +
> +            var children:Array = data[i++];
> +            if (children)
> +            {
> +                if (recursive)
> +                    comp.generateMXMLInstances(children, recursive);
> +                else
> +                    comp.setMXMLDescriptor(children);
> +            }
> +            if (id)
> +            {
> +                document[id] = comp;
> +                mx.binding.BindingManager.executeBindings(document, id, comp);
> +            }
> +            comps.push(comp);
> +        }
> +        return comps;
>      }
>
>      /**
> @@ -907,6 +1078,15 @@ public class AddItems extends OverrideBase
>              _waitingForDeferredContent = false;
>          }
>      }
> +
> +    /**
> +     *  IMXMLObject support
> +     */
> +    public function initialized(document:Object, id:String):void
> +    {
> +        this.document = document;
> +    }
> +
>  }
>
>  }
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/mx/src/mx/containers/ViewStack.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/mx/src/mx/containers/ViewStack.as b/frameworks/projects/mx/src/mx/containers/ViewStack.as
> index e2b97d5..bf462ca 100644
> --- a/frameworks/projects/mx/src/mx/containers/ViewStack.as
> +++ b/frameworks/projects/mx/src/mx/containers/ViewStack.as
> @@ -738,6 +738,15 @@ public class ViewStack extends Container implements IHistoryManagerClient,
ISele
>
>      /**
>       *  @private
> +     */
> +    override protected function generateMXMLInstances(document:Object, data:Array, recursive:Boolean
= true):void
> +    {
> +        // in theory, creationpolicy gets applied later
> +        super.generateMXMLInstances(document, data, false);
> +    }
> +
> +    /**
> +     *  @private
>       */
>      override protected function commitProperties():void
>      {
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/mx/src/mx/core/Container.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/mx/src/mx/core/Container.as b/frameworks/projects/mx/src/mx/core/Container.as
> index 635d8bc..c3f7d91 100644
> --- a/frameworks/projects/mx/src/mx/core/Container.as
> +++ b/frameworks/projects/mx/src/mx/core/Container.as
> @@ -4219,7 +4219,11 @@ public class Container extends UIComponent
>       */
>      public function createDeferredContent():void
>      {
> -        createComponentsFromDescriptors(true);
> +        var children:Array =  this.MXMLDescriptor;
> +        if (children)
> +            generateMXMLInstances(document, children);
> +        else
> +            createComponentsFromDescriptors(true);
>      }
>
>     /**
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/spark/src/spark/components/Group.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/spark/src/spark/components/Group.as b/frameworks/projects/spark/src/spark/components/Group.as
> index 7068fc5..f3a75fb 100644
> --- a/frameworks/projects/spark/src/spark/components/Group.as
> +++ b/frameworks/projects/spark/src/spark/components/Group.as
> @@ -546,7 +546,15 @@ public class Group extends GroupBase implements IVisualElementContainer,
>
>          }
>      }
> -
> +
> +    /**
> +     *  override setting of children
> +     */
> +    override protected function addMXMLChildren(comps:Array):void
> +    {
> +        mxmlContent = comps;
> +    }
> +
>      //----------------------------------
>      //  mxmlContent
>      //----------------------------------
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6907ac09/frameworks/projects/spark/src/spark/components/SkinnableContainer.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/spark/src/spark/components/SkinnableContainer.as b/frameworks/projects/spark/src/spark/components/SkinnableContainer.as
> index f011a01..edff9c6 100644
> --- a/frameworks/projects/spark/src/spark/components/SkinnableContainer.as
> +++ b/frameworks/projects/spark/src/spark/components/SkinnableContainer.as
> @@ -672,6 +672,14 @@ public class SkinnableContainer extends SkinnableContainerBase
>              _contentModified = true;
>      }
>
> +    /**
> +     *  override setting of children
> +     */
> +    override protected function addMXMLChildren(comps:Array):void
> +    {
> +        mxmlContent = comps;
> +    }
> +
>      //----------------------------------
>      //  mxmlContentFactory
>      //----------------------------------
> @@ -873,6 +881,17 @@ public class SkinnableContainer extends SkinnableContainerBase
>      //
>      //--------------------------------------------------------------------------
>
> +    private var creatingChildren:Boolean;
> +
> +    override protected function generateMXMLInstances(document:Object, data:Array, recursive:Boolean
= true):void
> +    {
> +        // don't generate children during super.createChildren
> +        if (creatingChildren)
> +            return;
> +
> +        super.generateMXMLInstances(document, data, recursive);
> +    }
> +
>      /**
>       *  Create content children, if the <code>creationPolicy</code> property
>       *  is not equal to <code>none</code>.
> @@ -884,7 +903,9 @@ public class SkinnableContainer extends SkinnableContainerBase
>       */
>      override protected function createChildren():void
>      {
> +        creatingChildren = true;
>          super.createChildren();
> +        creatingChildren = false;
>
>          // TODO (rfrishbe): When navigator support is added, this is where we would
>          // determine if content should be created now, or wait until
> @@ -1048,6 +1069,16 @@ public class SkinnableContainer extends SkinnableContainerBase
>       */
>      public function createDeferredContent():void
>      {
> +        var children:Array =  this.MXMLDescriptor;
> +        if (children)
> +        {
> +            generateMXMLInstances(document, children);
> +            mxmlContentCreated = true; // keep the code from recursing back into here.
> +            _deferredContentCreated = true;
> +            dispatchEvent(new FlexEvent(FlexEvent.CONTENT_CREATION_COMPLETE));
> +            return;
> +        }
> +
>          if (!mxmlContentCreated)
>          {
>              mxmlContentCreated = true;
>



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Mime
View raw message