flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/2] git commit: [flex-asjs] [refs/heads/develop] - Changes to support databinding
Date Wed, 26 Jun 2013 05:46:51 GMT
Updated Branches:
  refs/heads/develop b48c8d480 -> 286147c15


Changes to support databinding


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

Branch: refs/heads/develop
Commit: 132a29b8ec96589711a846e0a26dd4759b784add
Parents: b48c8d4
Author: Alex Harui <aharui@apache.org>
Authored: Tue Jun 25 07:57:26 2013 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Jun 25 22:46:39 2013 -0700

----------------------------------------------------------------------
 frameworks/as/basic-manifest.xml                |   1 +
 .../org/apache/flex/core/ViewBaseDataBinding.as | 179 +++++++++++++++
 .../org/apache/flex/events/ValueChangeEvent.as  |  10 +
 .../org/apache/flex/core/SimpleStatesImpl.js    |   2 +-
 .../org/apache/flex/core/ViewBaseDataBinding.js | 225 +++++++++++++++++++
 5 files changed, 416 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/132a29b8/frameworks/as/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/basic-manifest.xml b/frameworks/as/basic-manifest.xml
index 92238a7..e4744aa 100644
--- a/frameworks/as/basic-manifest.xml
+++ b/frameworks/as/basic-manifest.xml
@@ -55,5 +55,6 @@
     <component id="SimpleAlert" class="org.apache.flex.html.staticControls.SimpleAlert"/>
     <component id="Alert" class="org.apache.flex.html.staticControls.Alert"/>
     <component id="Spinner" class="org.apache.flex.html.staticControls.Spinner"/>
+    <component id="ViewBaseDataBinding" class="org.apache.flex.core.ViewBaseDataBinding"/>
 
 </componentPackage>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/132a29b8/frameworks/as/src/org/apache/flex/core/ViewBaseDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/ViewBaseDataBinding.as b/frameworks/as/src/org/apache/flex/core/ViewBaseDataBinding.as
new file mode 100644
index 0000000..0d5b876
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/core/ViewBaseDataBinding.as
@@ -0,0 +1,179 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.flex.core
+{
+    import org.apache.flex.binding.ConstantBinding;
+    import org.apache.flex.binding.SimpleBinding;
+    import org.apache.flex.core.IBead;
+    import org.apache.flex.core.IStrand;
+    import org.apache.flex.events.Event;
+    import org.apache.flex.events.IEventDispatcher;
+    
+	public class ViewBaseDataBinding implements IBead
+	{
+		public function ViewBaseDataBinding()
+		{
+			super();
+		}
+        
+        private var _strand:IStrand;
+        public function set strand(value:IStrand):void
+        {
+            _strand = value;
+            IEventDispatcher(_strand).addEventListener("initComplete", initCompleteHandler);
+        }    
+
+        private function initCompleteHandler(event:Event):void
+        {
+            var bindingData:Array = _strand["_bindings"];
+            var n:int = bindingData[0];
+            var bindings:Array = [];
+            var i:int;
+            var index:int = 1;
+            for (i = 0; i < n; i++)
+            {
+                var binding:Object = {};
+                binding.source = bindingData[index++];
+                binding.destination = bindingData[index++];
+                bindings.push(binding);
+            }
+            var watchers:Object = decodeWatcher(bindingData.slice(index));
+            for (i = 0; i < n; i++)
+            {
+                binding = bindings[i];
+                if (binding.source != null)
+                {
+                    if (binding.source is Array)
+                    {
+                        if (binding.source[0] == "applicationModel")
+                        {
+                            if (binding.source.length == 2 && binding.destination.length
== 2)
+                            {
+                                var destination:IStrand;
+                                // can be simplebinding or constantbinding
+                                var modelWatcher:Object = watchers.watcherMap["applicationModel"];
+                                var fieldWatcher:Object = modelWatcher.children.watcherMap[binding.source[1]];
+                                if (fieldWatcher.eventNames is String)
+                                {
+                                    var sb:SimpleBinding = new SimpleBinding();
+                                    sb.destinationPropertyName = binding.destination[1];
+                                    sb.eventName = fieldWatcher.eventNames as String;
+                                    sb.sourceID = binding.source[0];
+                                    sb.sourcePropertyName = binding.source[1];
+                                    sb.setDocument(_strand);
+                                    destination = _strand[binding.destination[0]] as IStrand;
+                                    if (destination)
+                                        destination.addBead(sb);
+                                    else
+                                    {
+                                        deferredBindings[binding.destination[0]] = sb;
+                                        IEventDispatcher(_strand).addEventListener("propertyChange",
deferredBindingsHandler);
+                                    }
+                                }
+                                else if (fieldWatcher.eventNames == null)
+                                {
+                                    var cb:ConstantBinding = new ConstantBinding();
+                                    cb.destinationPropertyName = binding.destination[1];
+                                    cb.sourceID = binding.source[0];
+                                    cb.sourcePropertyName = binding.source[1];
+                                    cb.setDocument(_strand);
+                                    destination = _strand[binding.destination[0]] as IStrand;
+                                    if (destination)
+                                        destination.addBead(cb);
+                                    else
+                                    {
+                                        deferredBindings[binding.destination[0]] = cb;
+                                        IEventDispatcher(_strand).addEventListener("propertyChange",
deferredBindingsHandler);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        
+        private function decodeWatcher(bindingData:Array):Object
+        {
+            var watcherMap:Object = {};
+            var watchers:Array = [];
+            var n:int = bindingData.length;
+            var index:int = 0;
+            var watcherData:Object;
+            while (index < n)
+            {
+                var watcherIndex:int = bindingData[index++];
+                var type:int = bindingData[index++];
+                switch (type)
+                {
+                    case 0:
+                    {
+                        watcherData = { type: "function" };
+                        watcherData.functionName = bindingData[index++];
+                        watcherData.eventNames = bindingData[index++];
+                        watcherData.bindings = bindingData[index++];
+                        break;
+                    }
+                    case 1:
+                    case 2:
+                    {
+                        watcherData = { type: type == 1 ? "static" : "property" };
+                        watcherData.propertyName = bindingData[index++];
+                        watcherData.eventNames = bindingData[index++];
+                        watcherData.bindings = bindingData[index++];
+                        watcherData.getterFunction = bindingData[index++];
+                        watcherMap[watcherData.propertyName] = watcherData;
+                        break;
+                    }
+                    case 3:
+                    {
+                        watcherData = { type: "xml" };
+                        watcherData.propertyName = bindingData[index++];
+                        watcherData.bindings = bindingData[index++];
+                        watcherMap[watcherData.propertyName] = watcherData;
+                        break;
+                    }
+                }
+                watcherData.children = bindingData[index++];
+                if (watcherData.children != null)
+                {
+                    watcherData.children = decodeWatcher(watcherData.children);
+                }
+                watcherData.index = watcherIndex;
+                watchers.push(watcherData);
+            }            
+            return { watchers: watchers, watcherMap: watcherMap };
+        }
+        
+        private var deferredBindings:Object = {};
+        private function deferredBindingsHandler(event:Event):void
+        {
+            for (var p:String in deferredBindings)
+            {
+                if (_strand[p] != null)
+                {
+                    var destination:IStrand = _strand[p] as IStrand;
+                    destination.addBead(deferredBindings[p]);
+                    delete deferredBindings[p];
+                }
+            }
+        }
+        
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/132a29b8/frameworks/as/src/org/apache/flex/events/ValueChangeEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/events/ValueChangeEvent.as b/frameworks/as/src/org/apache/flex/events/ValueChangeEvent.as
index 88e7463..4a759f7 100644
--- a/frameworks/as/src/org/apache/flex/events/ValueChangeEvent.as
+++ b/frameworks/as/src/org/apache/flex/events/ValueChangeEvent.as
@@ -30,7 +30,17 @@ package org.apache.flex.events
 		
 		public var oldValue:Object;
 		public var newValue:Object;
+        public var propertyName:String;
+        public var source:Object;
 		
 		public static const VALUE_CHANGE:String = "valueChange";
+        
+        public static function createUpdateEvent(source:Object, name:String, oldValue:Object,
newValue:Object):ValueChangeEvent
+        {
+            var event:ValueChangeEvent = new ValueChangeEvent(VALUE_CHANGE, false, false,
oldValue, newValue);
+            event.propertyName = name;
+            event.source = source;
+            return event;
+        }
 	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/132a29b8/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
index 4392257..5817de4 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
@@ -34,7 +34,7 @@ goog.inherits(org.apache.flex.core.SimpleStatesImpl,
 
 /**
  * @expose
- * @this {org.apache.flex.net.dataConverters.LazyCollection}
+ * @this {org.apache.flex.core.SimpleStatesImpl}
  * @param {Object} value The new host.
  */
 org.apache.flex.core.SimpleStatesImpl.prototype.set_strand =

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/132a29b8/frameworks/js/FlexJS/src/org/apache/flex/core/ViewBaseDataBinding.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/ViewBaseDataBinding.js b/frameworks/js/FlexJS/src/org/apache/flex/core/ViewBaseDataBinding.js
new file mode 100644
index 0000000..5f7b5d0
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/ViewBaseDataBinding.js
@@ -0,0 +1,225 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.core.ViewBaseDataBinding');
+
+goog.require('org.apache.flex.binding.ConstantBinding');
+goog.require('org.apache.flex.binding.SimpleBinding');
+goog.require('org.apache.flex.events.Event');
+
+    
+/**
+ * @constructor
+ */
+org.apache.flex.core.ViewBaseDataBinding = function() {
+
+  /**
+   * @private
+   * @type {Object}
+   */
+  this.strand_ = null;
+
+  /**
+   * @private
+   * @type {Object}
+   */
+  this.deferredBindings = {};
+
+};
+        
+/**
+ * @expose
+ * @this {org.apache.flex.core.ViewBaseDataBinding}
+ * @param {Object} value The new host.
+ */
+org.apache.flex.core.ViewBaseDataBinding.prototype.set_strand =
+    function(value) {
+  if (this.strand_ !== value) {
+    this.strand_ = value;
+    this.strand_.addEventListener('initComplete',
+        goog.bind(this.initCompleteHandler, this));
+  }
+};
+
+
+/**
+ * @protected
+ * @this {org.apache.flex.core.ViewBaseDataBinding}
+ * @param {Object} event The event.
+ */
+org.apache.flex.core.ViewBaseDataBinding.prototype.initCompleteHandler =
+    function(event) {
+
+    var bindingData = this.strand_["_bindings"];
+    var n = bindingData[0];
+    var bindings = [];
+    var i;
+    var index = 1;
+    for (i = 0; i < n; i++)
+    {
+        var binding = {};
+        binding.source = bindingData[index++];
+        binding.destination = bindingData[index++];
+        bindings.push(binding);
+    }
+    var watchers = this.decodeWatcher(bindingData.slice(index));
+    for (i = 0; i < n; i++)
+    {
+        binding = bindings[i];
+        if (binding.source != null)
+        {
+            // try to determine if it is an array
+            if (typeof(binding.source) == "object" &&
+                typeof(binding.source.slice) == "function")
+            {
+                if (binding.source[0] == "applicationModel")
+                {
+                    if (binding.source.length == 2 &&
+                        binding.destination.length == 2)
+                    {
+                        var destination;
+                        // can be simplebinding or constantbinding
+                        var modelWatcher = 
+                            watchers.watcherMap["applicationModel"];
+                        var childMap = modelWatcher.children.watcherMap
+                        var fieldWatcher = childMap[binding.source[1]];
+                        if (typeof(fieldWatcher.eventNames) == "string")
+                        {
+                          var sb;
+                          sb = new org.apache.flex.binding.SimpleBinding();
+                          sb.destinationPropertyName = 
+                                    binding.destination[1];
+                          sb.eventName = fieldWatcher.eventNames;
+                          sb.sourceID = binding.source[0];
+                          sb.sourcePropertyName = binding.source[1];
+                          sb.setDocument(this.strand_);
+                          destination = this.strand_[
+                                            binding.destination[0]];
+                          if (destination)
+                              destination.addBead(sb);
+                          else
+                          {
+                            this.deferredBindings[binding.destination[0]] =
+                                    sb;
+                            this.strand_.addEventListener("propertyChange",
+                                    this.deferredBindingsHandler);
+                          }
+                        }
+                        else if (fieldWatcher.eventNames == null)
+                        {
+                          var cb;
+                          cb = org.apache.flex.binding.ConstantBinding;
+                          cb = new cb();
+                          cb.destinationPropertyName = 
+                                binding.destination[1];
+                          cb.sourceID = binding.source[0];
+                          cb.sourcePropertyName = binding.source[1];
+                          cb.setDocument(this.strand_);
+                          destination = this.strand_[
+                                            binding.destination[0]];
+                          if (destination)
+                                destination.addBead(cb);
+                          else
+                          {
+                            this.deferredBindings[binding.destination[0]] =
+                                cb;
+                            this.strand_.addEventListener("propertyChange",
+                                this.deferredBindingsHandler);
+                          }
+                        }
+                    }
+                }
+            }
+        }
+    }
+};
+        
+/**
+ * @protected
+ * @this {org.apache.flex.core.ViewBaseDataBinding}
+ * @param {Object} bindingData The watcher data to decode.
+ * @return {Object} The watcher tree structure.
+ */
+org.apache.flex.core.ViewBaseDataBinding.prototype.decodeWatcher =
+    function(bindingData) {
+    var watcherMap = {};
+    var watchers = [];
+    var n = bindingData.length - 1; // there is an extra null because
+                                    // it is easier for the compiler
+    var index = 0;
+    var watcherData;
+    while (index < n)
+    {
+        var watcherIndex = bindingData[index++];
+        var type = bindingData[index++];
+        switch (type)
+        {
+            case 0:
+            {
+                watcherData = { type: "function" };
+                watcherData.functionName = bindingData[index++];
+                watcherData.eventNames = bindingData[index++];
+                watcherData.bindings = bindingData[index++];
+                break;
+            }
+            case 1:
+            case 2:
+            {
+                watcherData = { type: type == 1 ? "static" : "property" };
+                watcherData.propertyName = bindingData[index++];
+                watcherData.eventNames = bindingData[index++];
+                watcherData.bindings = bindingData[index++];
+                watcherData.getterFunction = bindingData[index++];
+                watcherMap[watcherData.propertyName] = watcherData;
+                break;
+            }
+            case 3:
+            {
+                watcherData = { type: "xml" };
+                watcherData.propertyName = bindingData[index++];
+                watcherData.bindings = bindingData[index++];
+                watcherMap[watcherData.propertyName] = watcherData;
+                break;
+            }
+        }
+        watcherData.children = bindingData[index++];
+        if (watcherData.children != null)
+        {
+            watcherData.children = this.decodeWatcher(watcherData.children);
+        }
+        watcherData.index = watcherIndex;
+        watchers.push(watcherData);
+    }            
+    return { watchers: watchers, watcherMap: watcherMap };
+};
+        
+/**
+ * @protected
+ * @this {org.apache.flex.core.ViewBaseDataBinding}
+ * @param {Object} event The event.
+ */
+org.apache.flex.core.ViewBaseDataBinding.prototype.deferredBindingsHandler =
+function(event) {
+    var p;
+    for (p in this.deferredBindings)
+    {
+        if (this.strand_[p] != null)
+        {
+            var destination = this.strand_[p];
+            destination.addBead(this.deferredBindings[p]);
+            delete deferredBindings[p];
+        }
+    }
+};
+


Mime
View raw message