flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [23/50] git commit: [flex-asjs] [refs/heads/master] - Added a new itemRenderer factory that extends EventDispatcher, allowing custom itemRenderers to intercept events from the itemRenderers and forward them.
Date Wed, 07 Sep 2016 22:33:58 GMT
Added a new itemRenderer factory that extends EventDispatcher, allowing custom itemRenderers
to intercept events from the itemRenderers and forward them.


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

Branch: refs/heads/master
Commit: eb11ac158183a3ee41e90a1f5ef0a027a5f8894f
Parents: 022fcd0
Author: Peter Ent <pent@apache.org>
Authored: Fri Aug 5 13:17:16 2016 -0400
Committer: Peter Ent <pent@apache.org>
Committed: Fri Aug 5 13:17:16 2016 -0400

----------------------------------------------------------------------
 .../projects/HTML/src/main/flex/HTMLClasses.as  |   1 +
 ...ererFactoryAndEventDispatcherForArrayData.as | 191 +++++++++++++++++++
 2 files changed, 192 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/eb11ac15/frameworks/projects/HTML/src/main/flex/HTMLClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as
index 51b5e48..f5c0f41 100644
--- a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as
+++ b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as
@@ -144,6 +144,7 @@ internal class HTMLClasses
     import org.apache.flex.html.beads.TextItemRendererFactoryForArrayData; TextItemRendererFactoryForArrayData;
 	import org.apache.flex.html.beads.DataItemRendererFactoryForArrayData; DataItemRendererFactoryForArrayData;
 	import org.apache.flex.html.beads.DataItemRendererFactoryForArrayList; DataItemRendererFactoryForArrayList;
+	import org.apache.flex.html.beads.DataItemRendererFactoryAndEventDispatcherForArrayData;
DataItemRendererFactoryAndEventDispatcherForArrayData;
 	import org.apache.flex.html.beads.DataItemRendererFactoryForHierarchicalData; DataItemRendererFactoryForHierarchicalData;
 	import org.apache.flex.html.supportClasses.DataGroup; DataGroup;
 	import org.apache.flex.html.supportClasses.Viewport; Viewport;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/eb11ac15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryAndEventDispatcherForArrayData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryAndEventDispatcherForArrayData.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryAndEventDispatcherForArrayData.as
new file mode 100644
index 0000000..3c55c60
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DataItemRendererFactoryAndEventDispatcherForArrayData.as
@@ -0,0 +1,191 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.IDataProviderItemRendererMapper;
+	import org.apache.flex.core.IItemRendererClassFactory;
+	import org.apache.flex.core.IItemRendererParent;
+	import org.apache.flex.core.IListPresentationModel;
+	import org.apache.flex.core.ISelectableItemRenderer;
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.IUIBase;
+	import org.apache.flex.core.SimpleCSSStyles;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.core.ValuesManager;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.html.List;
+
+    /**
+     *  The DataItemRendererFactoryAndEventDispatcherForArrayData class reads an
+     *  array of data and creates an item renderer for every
+     *  item in the array.  As each itemRenderer is created, a function is called
+	 *  that can be overridden in a subclass. Other implementations of
+     *  IDataProviderItemRendererMapper map different data
+     *  structures or manage a virtual set of renderers.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class DataItemRendererFactoryAndEventDispatcherForArrayData extends EventDispatcher
implements IBead, IDataProviderItemRendererMapper
+	{
+        /**
+         *  Constructor.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function DataItemRendererFactoryAndEventDispatcherForArrayData()
+		{
+			super()
+		}
+
+		private var selectionModel:ISelectionModel;
+
+		private var labelField:String;
+
+		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;
+			var listView:IListView = _strand.getBeadByType(IListView) as IListView;
+			if (listView == null) {
+				IEventDispatcher(_strand).addEventListener("viewChanged", completeSetup);
+			}
+			else {
+				completeSetup(null);
+			}
+		}
+
+		private function completeSetup(event:Event):void
+		{
+			selectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+			var listView:IListView = _strand.getBeadByType(IListView) as IListView;
+			dataGroup = listView.dataGroup;
+			selectionModel.addEventListener("dataProviderChanged", dataProviderChangeHandler);
+
+			labelField = (listView.host as List).labelField;
+
+			if (!itemRendererFactory)
+			{
+				_itemRendererFactory = new (ValuesManager.valuesImpl.getValue(_strand, "iItemRendererClassFactory"))
as IItemRendererClassFactory;
+				_strand.addBead(_itemRendererFactory);
+			}
+
+			dataProviderChangeHandler(null);
+		}
+
+		private var _itemRendererFactory:IItemRendererClassFactory;
+
+        /**
+         *  The org.apache.flex.core.IItemRendererClassFactory used
+         *  to generate instances of item renderers.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function get itemRendererFactory():IItemRendererClassFactory
+		{
+			return _itemRendererFactory;
+		}
+
+        /**
+         *  @private
+         */
+		public function set itemRendererFactory(value:IItemRendererClassFactory):void
+		{
+			_itemRendererFactory = value;
+		}
+
+        /**
+         *  The org.apache.flex.core.IItemRendererParent that will
+         *  parent the item renderers.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		protected var dataGroup:IItemRendererParent;
+
+		private function dataProviderChangeHandler(event:Event):void
+		{
+			var dp:Array = selectionModel.dataProvider as Array;
+			if (!dp)
+				return;
+
+			dataGroup.removeAllElements();
+
+			var listView:IListView = _strand.getBeadByType(IListView) as IListView;
+			var presentationModel:IListPresentationModel = _strand.getBeadByType(IListPresentationModel)
as IListPresentationModel;
+
+			var n:int = dp.length;
+			for (var i:int = 0; i < n; i++)
+			{
+				var ir:ISelectableItemRenderer = itemRendererFactory.createItemRenderer(dataGroup) as
ISelectableItemRenderer;
+				ir.index = i;
+				ir.labelField = labelField;
+				if (presentationModel) {
+					var style:SimpleCSSStyles = new SimpleCSSStyles();
+					style.marginBottom = presentationModel.separatorThickness;
+					UIBase(ir).style = style;
+					UIBase(ir).height = presentationModel.rowHeight;
+				}
+				dataGroup.addElement(ir);
+				ir.data = dp[i];
+
+				itemRendererCreated(ir);
+			}
+
+			IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated"));
+		}
+
+		/**
+		 * Override this function in a subclass to hook event listeners or other features into
+		 * the itemRenderer when it has been created and set.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+		 */
+		protected function itemRendererCreated(ir:ISelectableItemRenderer):void
+		{
+			// do something with this in a subclass
+		}
+	}
+}


Mime
View raw message