flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - - Add DataProviderAddRemoveNotifier bead - notifies about Add/Remove items to data provider
Date Wed, 01 Mar 2017 20:09:02 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 006d94b44 -> 1fb7bd604


- Add DataProviderAddRemoveNotifier bead - notifies about Add/Remove items to data provider


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

Branch: refs/heads/develop
Commit: 1fb7bd60403d0649baea4c93a647bd3dc597101b
Parents: 006d94b
Author: piotrz <piotrz@apache.org>
Authored: Wed Mar 1 21:08:59 2017 +0100
Committer: piotrz <piotrz@apache.org>
Committed: Wed Mar 1 21:08:59 2017 +0100

----------------------------------------------------------------------
 .../html/beads/DataProviderAddRemoveNotifier.as | 183 +++++++++++++++++++
 1 file changed, 183 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fb7bd60/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
new file mode 100644
index 0000000..81a80bb
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataProviderAddRemoveNotifier.as
@@ -0,0 +1,183 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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);
+		}
+	}
+}


Mime
View raw message