flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject [4/7] git commit: [flex-asjs] [refs/heads/feature/chart-work] - Data provider notifier changes: - Add DataProviderNotifierBase class which holds all common properties - Add DataProviderCollectionChangeNotifier which listen for "collectionChanged" event a
Date Sun, 09 Apr 2017 17:26:25 GMT
Data provider notifier changes:
- Add DataProviderNotifierBase class which holds all common properties
- Add DataProviderCollectionChangeNotifier which listen for "collectionChanged" event and
dispatch "dataProviderChanged" through model
- Rename DataProviderAddRemoveNotifier to DataProviderItemsChangeNotifier
- Add itemUpdated to DataProviderItemsChangeNotifier


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

Branch: refs/heads/feature/chart-work
Commit: b3cd50ebb1fd5799c48812b2db7cf787b907920e
Parents: 326d697
Author: piotrz <piotrz@apache.org>
Authored: Sun Apr 9 17:56:07 2017 +0200
Committer: piotrz <piotrz@apache.org>
Committed: Sun Apr 9 17:56:07 2017 +0200

----------------------------------------------------------------------
 .../html/beads/DataProviderAddRemoveNotifier.as | 183 -------------------
 .../html/beads/DataProviderChangeNotifier.as    | 163 +++--------------
 .../DataProviderCollectionChangeNotifier.as     |  71 +++++++
 .../beads/DataProviderItemsChangeNotifier.as    |  95 ++++++++++
 .../supportClasses/DataProviderNotifierBase.as  | 175 ++++++++++++++++++
 5 files changed, 364 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b3cd50eb/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderAddRemoveNotifier.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderAddRemoveNotifier.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderAddRemoveNotifier.as
deleted file mode 100644
index 81a80bb..0000000
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderAddRemoveNotifier.as
+++ /dev/null
@@ -1,183 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  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.html.beads
-{
-	import org.apache.flex.core.IBead;
-	import org.apache.flex.core.IBeadModel;
-	import org.apache.flex.core.IDocument;
-	import org.apache.flex.core.ISelectionModel;
-	import org.apache.flex.core.IStrand;
-	import org.apache.flex.core.UIBase;
-	import org.apache.flex.events.IEventDispatcher;
-	import org.apache.flex.events.Event;
-	import org.apache.flex.collections.ArrayList;
-	import org.apache.flex.events.CollectionEvent;
-	/**
-	 *  The DataProviderAddRemoveNotifier notifies listeners when a selection model's to
-	 *  ArrayList dataProvider has been added or removed item.
-	 *  
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public class DataProviderAddRemoveNotifier implements IBead, IDocument
-	{
-		/**
-		 *  constructor.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function DataProviderAddRemoveNotifier()
-		{
-		}
-		
-		protected var _dataProvider:ArrayList;
-		
-		private var _strand:IStrand;
-		
-		/**
-		 *  @copy org.apache.flex.core.IBead#strand
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function set strand(value:IStrand):void
-		{
-			_strand = value;
-			
-			if (_strand[destinationPropertyName] == null) {
-				var model:IBeadModel = UIBase(_strand).model as IBeadModel;
-				IEventDispatcher(model).addEventListener(changeEventName, destinationChangedHandler);
-			}
-			else {
-				destinationChangedHandler(null);
-			}
-		}
-		
-		private function destinationChangedHandler(event:Event):void
-		{
-			if (_dataProvider == null) {
-				var object:Object = document[sourceID];
-				_dataProvider = object[propertyName] as ArrayList;
-			}
-			else {
-				_dataProvider.removeEventListener(CollectionEvent.ITEM_ADDED, handleItemAdded);
-				_dataProvider.removeEventListener(CollectionEvent.ITEM_REMOVED, handleItemRemoved);
-			}
-			
-			_dataProvider.addEventListener(CollectionEvent.ITEM_ADDED, handleItemAdded);
-			_dataProvider.addEventListener(CollectionEvent.ITEM_REMOVED, handleItemRemoved);
-		}
-		
-		protected var document:Object;
-		
-		/**
-		 * @private
-		 */
-		public function setDocument(document:Object, id:String = null):void
-		{
-			this.document = document;
-		}
-		
-		private var _destinationPropertyName:String;
-		
-		public function get destinationPropertyName():String
-		{
-			return _destinationPropertyName;
-		}
-		public function set destinationPropertyName(value:String):void
-		{
-			_destinationPropertyName = value;
-		}
-		
-		private var _changeEventName:String;
-		
-		public function get changeEventName():String
-		{
-			return _changeEventName;
-		}
-		public function set changeEventName(value:String):void
-		{
-			_changeEventName = value;
-		}
-		
-		private var _sourceID:String;
-		
-		/**
-		 *  The ID of the object holding the ArrayList, usually a model.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function get sourceID():String
-		{
-			return _sourceID;
-		}
-		public function set sourceID(value:String):void
-		{
-			_sourceID = value;
-		}
-		
-		private var _propertyName:String;
-		
-		/**
-		 *  The property in the sourceID that is the ArrayList.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function get propertyName():String
-		{
-			return _propertyName;
-		}
-		
-		public function set propertyName(value:String):void
-		{
-			_propertyName = value;
-		}
-		
-		/**
-		 * @private
-		 */
-		private function handleItemAdded(event:CollectionEvent):void
-		{
-			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
-			selectionModel.dispatchEvent(event.cloneEvent() as CollectionEvent);
-		}
-		
-		/**
-		 * @private
-		 */
-		private function handleItemRemoved(event:CollectionEvent):void
-		{
-			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
-			selectionModel.dispatchEvent(event.cloneEvent() as CollectionEvent);
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b3cd50eb/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderChangeNotifier.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderChangeNotifier.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderChangeNotifier.as
index a24810b..e8c28bd 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderChangeNotifier.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderChangeNotifier.as
@@ -18,17 +18,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.html.beads
 {
-	import org.apache.flex.core.IBead;
-	import org.apache.flex.core.IBeadModel;
-	import org.apache.flex.core.IDocument;
 	import org.apache.flex.core.ISelectionModel;
-	import org.apache.flex.core.IStrand;
-	import org.apache.flex.core.UIBase;
 	import org.apache.flex.events.IEventDispatcher;
 	import org.apache.flex.events.Event;
 	import org.apache.flex.collections.ArrayList;
-	
-	/**
+    import org.apache.flex.html.supportClasses.DataProviderNotifierBase;
+
+    /**
 	 *  The DataProviderChangeNotifier notifies listeners when a selection model's
 	 *  ArrayList dataProvider has changed.
 	 *  
@@ -37,7 +33,7 @@ package org.apache.flex.html.beads
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	public class DataProviderChangeNotifier implements IBead, IDocument
+	public class DataProviderChangeNotifier extends DataProviderNotifierBase
 	{
 		/**
 		 *  constructor.
@@ -51,144 +47,31 @@ package org.apache.flex.html.beads
 		{
 		}
 		
-		protected var _dataProvider:ArrayList;
-		
-		private var _strand:IStrand;
-		
-		/**
-		 *  @copy org.apache.flex.core.IBead#strand
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function set strand(value:IStrand):void
+		override protected function destinationChangedHandler(event:Event):void
 		{
-			_strand = value;
-			
-			if (_strand[destinationPropertyName] == null) {
-				var model:IBeadModel = UIBase(_strand).model as IBeadModel;
-				IEventDispatcher(model).addEventListener(changeEventName, destinationChangedHandler);
-			}
-			else {
-				destinationChangedHandler(null);
-			}
-		}
-		
-		private function destinationChangedHandler(event:Event):void
-		{
-			if (_dataProvider == null) {
+			if (dataProvider == null)
+			{
 				var object:Object = document[sourceID];
-				_dataProvider = object[propertyName] as ArrayList;
+				dataProvider = object[propertyName] as ArrayList;
 			}
-			else {
-				_dataProvider.removeEventListener("itemAdded", handleItemAdded);
-				_dataProvider.removeEventListener("itemRemoved", handleItemRemoved);
-				_dataProvider.removeEventListener("itemUpdated", handleItemUpdated);
+			else
+			{
+                dataProvider.removeEventListener("itemAdded", handleDataProviderChanges);
+                dataProvider.removeEventListener("itemRemoved", handleDataProviderChanges);
+                dataProvider.removeEventListener("itemUpdated", handleDataProviderChanges);
+                dataProvider.removeEventListener("collectionChanged", handleDataProviderChanges);
 			}
-			
-			_dataProvider.addEventListener("itemAdded", handleItemAdded);
-			_dataProvider.addEventListener("itemRemoved", handleItemRemoved);
-			_dataProvider.addEventListener("itemUpdated", handleItemUpdated);
-		}
-		
-		protected var document:Object;
-		
-		/**
-		 * @private
-		 */
-		public function setDocument(document:Object, id:String = null):void
-		{
-			this.document = document;
-		}
-		
-		private var _destinationPropertyName:String;
-		
-		public function get destinationPropertyName():String
-		{
-			return _destinationPropertyName;
-		}
-		public function set destinationPropertyName(value:String):void
-		{
-			_destinationPropertyName = value;
-		}
-		
-		private var _changeEventName:String;
-		
-		public function get changeEventName():String
-		{
-			return _changeEventName;
-		}
-		public function set changeEventName(value:String):void
-		{
-			_changeEventName = value;
-		}
-		
-		private var _sourceID:String;
-		
-		/**
-		 *  The ID of the object holding the ArrayList, usually a model.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function get sourceID():String
-		{
-			return _sourceID;
-		}
-		public function set sourceID(value:String):void
-		{
-			_sourceID = value;
-		}
-		
-		private var _propertyName:String;
-		
-		/**
-		 *  The property in the sourceID that is the ArrayList.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function get propertyName():String
-		{
-			return _propertyName;
-		}
-		
-		public function set propertyName(value:String):void
-		{
-			_propertyName = value;
-		}
-		
-		/**
-		 * @private
-		 */
-		private function handleItemAdded(event:Event):void
-		{
-			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
-			selectionModel.dispatchEvent(new Event("dataProviderChanged"));
+
+            dataProvider.addEventListener("itemAdded", handleDataProviderChanges);
+            dataProvider.addEventListener("itemRemoved", handleDataProviderChanges);
+            dataProvider.addEventListener("itemUpdated", handleDataProviderChanges);
+            dataProvider.addEventListener("collectionChanged", handleDataProviderChanges);
 		}
-		
-		/**
-		 * @private
-		 */
-		private function handleItemRemoved(event:Event):void
-		{
-			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
-			selectionModel.dispatchEvent(new Event("dataProviderChanged"));
-		}
-		
-		/**
-		 * @private
-		 */
-		private function handleItemUpdated(event:Event):void
+
+		private function handleDataProviderChanges(event:Event):void
 		{
-			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
-			selectionModel.dispatchEvent(new Event("dataProviderChanged"));
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as
ISelectionModel;
+            selectionModel.dispatchEvent(new Event("dataProviderChanged"));
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b3cd50eb/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderCollectionChangeNotifier.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderCollectionChangeNotifier.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderCollectionChangeNotifier.as
new file mode 100644
index 0000000..2d58795
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderCollectionChangeNotifier.as
@@ -0,0 +1,71 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.html.beads
+{
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.collections.ArrayList;
+    import org.apache.flex.html.supportClasses.DataProviderNotifierBase;
+
+    /**
+	 *  The DataProviderCollectionChangeNotifier notifies listeners when a selection model's
+	 *  ArrayList dataProvider disptached collectionChanged event.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public class DataProviderCollectionChangeNotifier extends DataProviderNotifierBase
+	{
+		/**
+		 *  constructor.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function DataProviderCollectionChangeNotifier()
+		{
+		}
+		
+		override protected function destinationChangedHandler(event:Event):void
+		{
+			if (dataProvider == null)
+			{
+				var object:Object = document[sourceID];
+				dataProvider = object[propertyName] as ArrayList;
+			}
+			else
+			{
+                dataProvider.removeEventListener("collectionChanged", handleCollectionChanged);
+			}
+
+            dataProvider.addEventListener("collectionChanged", handleCollectionChanged);
+		}
+
+		private function handleCollectionChanged(event:Event):void
+		{
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as
ISelectionModel;
+            selectionModel.dispatchEvent(new Event("dataProviderChanged"));
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b3cd50eb/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderItemsChangeNotifier.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderItemsChangeNotifier.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderItemsChangeNotifier.as
new file mode 100644
index 0000000..eee1990
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderItemsChangeNotifier.as
@@ -0,0 +1,95 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.html.beads
+{
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.collections.ArrayList;
+	import org.apache.flex.events.CollectionEvent;
+    import org.apache.flex.html.supportClasses.DataProviderNotifierBase;
+
+    /**
+	 *  The DataProviderItemsChangeNotifier notifies listeners when to selection model's
+	 *  ArrayList dataProvider item has been added, removed or updated.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public class DataProviderItemsChangeNotifier extends DataProviderNotifierBase
+	{
+		/**
+		 *  constructor.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function DataProviderItemsChangeNotifier()
+		{
+		}
+
+		private function destinationChangedHandler(event:Event):void
+		{
+			if (dataProvider == null) {
+				var object:Object = document[sourceID];
+				dataProvider = object[propertyName] as ArrayList;
+			}
+			else {
+				dataProvider.removeEventListener(CollectionEvent.ITEM_ADDED, handleItemAdded);
+				dataProvider.removeEventListener(CollectionEvent.ITEM_REMOVED, handleItemRemoved);
+				dataProvider.removeEventListener(CollectionEvent.ITEM_UPDATED, handleItemUpdated);
+			}
+			
+			dataProvider.addEventListener(CollectionEvent.ITEM_ADDED, handleItemAdded);
+			dataProvider.addEventListener(CollectionEvent.ITEM_REMOVED, handleItemRemoved);
+            dataProvider.addEventListener(CollectionEvent.ITEM_UPDATED, handleItemUpdated);
+		}
+
+		/**
+		 * @private
+		 */
+		private function handleItemAdded(event:CollectionEvent):void
+		{
+			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+			selectionModel.dispatchEvent(event.cloneEvent() as CollectionEvent);
+		}
+		
+		/**
+		 * @private
+		 */
+		private function handleItemRemoved(event:CollectionEvent):void
+		{
+			var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+			selectionModel.dispatchEvent(event.cloneEvent() as CollectionEvent);
+		}
+
+        /**
+         * @private
+         */
+        private function handleItemUpdated(event:CollectionEvent):void
+        {
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as
ISelectionModel;
+            selectionModel.dispatchEvent(event.cloneEvent() as CollectionEvent);
+        }
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b3cd50eb/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataProviderNotifierBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataProviderNotifierBase.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataProviderNotifierBase.as
new file mode 100644
index 0000000..853fbb9
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataProviderNotifierBase.as
@@ -0,0 +1,175 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.html.beads
+{
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.IBeadModel;
+	import org.apache.flex.core.IDocument;
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.collections.ArrayList;
+	
+	/**
+	 *  The DataProviderChangeNotifier notifies listeners when a selection model's
+	 *  ArrayList dataProvider has changed.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public class DataProviderChangeNotifier implements IBead, IDocument
+	{
+		/**
+		 *  constructor.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function DataProviderChangeNotifier()
+		{
+		}
+		
+		protected var _dataProvider:ArrayList;
+		
+		private var _strand:IStrand;
+		
+		/**
+		 *  @copy org.apache.flex.core.IBead#strand
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			
+			if (_strand[destinationPropertyName] == null) {
+				var model:IBeadModel = UIBase(_strand).model as IBeadModel;
+				IEventDispatcher(model).addEventListener(changeEventName, destinationChangedHandler);
+			}
+			else {
+				destinationChangedHandler(null);
+			}
+		}
+		
+		private function destinationChangedHandler(event:Event):void
+		{
+			if (_dataProvider == null) {
+				var object:Object = document[sourceID];
+				_dataProvider = object[propertyName] as ArrayList;
+			}
+			else {
+				_dataProvider.removeEventListener("itemAdded", handleDataProviderChanges);
+				_dataProvider.removeEventListener("itemRemoved", handleDataProviderChanges);
+				_dataProvider.removeEventListener("itemUpdated", handleDataProviderChanges);
+                _dataProvider.removeEventListener("collectionChanged", handleDataProviderChanges);
+			}
+			
+			_dataProvider.addEventListener("itemAdded", handleDataProviderChanges);
+			_dataProvider.addEventListener("itemRemoved", handleDataProviderChanges);
+			_dataProvider.addEventListener("itemUpdated", handleDataProviderChanges);
+			_dataProvider.addEventListener("collectionChanged", handleDataProviderChanges);
+		}
+		
+		protected var document:Object;
+		
+		/**
+		 * @private
+		 */
+		public function setDocument(document:Object, id:String = null):void
+		{
+			this.document = document;
+		}
+		
+		private var _destinationPropertyName:String;
+		
+		public function get destinationPropertyName():String
+		{
+			return _destinationPropertyName;
+		}
+		public function set destinationPropertyName(value:String):void
+		{
+			_destinationPropertyName = value;
+		}
+		
+		private var _changeEventName:String;
+		
+		public function get changeEventName():String
+		{
+			return _changeEventName;
+		}
+		public function set changeEventName(value:String):void
+		{
+			_changeEventName = value;
+		}
+		
+		private var _sourceID:String;
+		
+		/**
+		 *  The ID of the object holding the ArrayList, usually a model.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get sourceID():String
+		{
+			return _sourceID;
+		}
+		public function set sourceID(value:String):void
+		{
+			_sourceID = value;
+		}
+		
+		private var _propertyName:String;
+		
+		/**
+		 *  The property in the sourceID that is the ArrayList.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get propertyName():String
+		{
+			return _propertyName;
+		}
+		
+		public function set propertyName(value:String):void
+		{
+			_propertyName = value;
+		}
+
+		private function handleDataProviderChanges(event:Event):void
+		{
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as
ISelectionModel;
+            selectionModel.dispatchEvent(new Event("dataProviderChanged"));
+		}
+	}
+}


Mime
View raw message