You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by yi...@apache.org on 2019/08/18 14:13:50 UTC

[royale-asjs] branch develop updated: Fixes #444

This is an automated email from the ASF dual-hosted git repository.

yishayw pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9504cb1  Fixes #444
9504cb1 is described below

commit 9504cb196f8ea8863bec2b0d2085d343dbf5efc8
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Sun Aug 18 17:13:36 2019 +0300

    Fixes #444
---
 .../MXRoyale/src/main/resources/defaults.css       |   1 +
 .../MXRoyale/src/main/royale/MXRoyaleClasses.as    |   1 +
 .../controls/beads/DataProviderChangeNotifier.as   | 102 +++++++++++++++++++++
 .../mx/controls/listClasses/AdvancedListBase.as    |  30 ++++++
 4 files changed, 134 insertions(+)

diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index e8c6631..a6dce8a 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -82,6 +82,7 @@ AdvancedDataGrid
 	IBeadView: ClassReference("mx.controls.beads.AdvancedDataGridView");
 	IBeadModel: ClassReference("mx.controls.beads.models.DataGridICollectionViewModel");
 	IBeadLayout: ClassReference("mx.controls.beads.layouts.DataGridLayout");
+	IDataProviderNotifier: ClassReference("mx.controls.beads.DataProviderChangeNotifier");
 	columnClass: ClassReference("mx.controls.advancedDataGridClasses.AdvancedDataGridColumnList");
 	
 	background-color: #FFFFFF;
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index cbe0646..74bad4a 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -205,6 +205,7 @@ internal class MXRoyaleClasses
 	import mx.messaging.channels.URLVariables; URLVariables;
 	import mx.controls.Menu; Menu;
 	import mx.events.NumericStepperEvent; NumericStepperEvent;
+	import mx.controls.beads.DataProviderChangeNotifier; DataProviderChangeNotifier;
 	
 	import mx.controls.PopUpButton; PopUpButton;
 	import mx.controls.PopUpMenuButton; PopUpMenuButton;
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/DataProviderChangeNotifier.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/DataProviderChangeNotifier.as
new file mode 100644
index 0000000..4a2b445
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/DataProviderChangeNotifier.as
@@ -0,0 +1,102 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 mx.controls.beads
+{
+	import org.apache.royale.core.ISelectionModel;
+	import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.events.Event;
+    import org.apache.royale.core.IDataProviderNotifier;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.core.IStrandWithModel;
+
+    /**
+	 *  The DataProviderChangeNotifier notifies listeners when a selection model's
+	 *  dataProvider has changed.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.6
+	 */
+	public class DataProviderChangeNotifier implements IDataProviderNotifier
+	{
+		/**
+		 *  constructor.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
+		 */
+		private var _strand:IStrand;
+		protected var dataProvider:IEventDispatcher;
+
+		public function DataProviderChangeNotifier()
+		{
+		}
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			if (model.dataProvider == null)
+			{
+				model.addEventListener("dataProviderChanged", dataProviderChangedHandler);
+			} else
+			{
+				dataProviderChangedHandler(null);
+			}
+		}
+
+		protected function dataProviderChangedHandler(event:Event):void
+		{
+			dataProvider = model.dataProvider as IEventDispatcher;
+			if (dataProvider)
+			{
+				detachEventListeners();
+			}
+			attachEventListeners();
+		}
+
+		private function get model():ISelectionModel
+		{
+			return IStrandWithModel(_strand).model as ISelectionModel;
+		}
+
+		private function handleDataProviderChanges(event:Event):void
+		{
+            model.dispatchEvent(new Event("dataProviderChanged"));
+		}
+		
+		protected function attachEventListeners():void
+		{
+			dataProvider.addEventListener("collectionChanged", handleDataProviderChanges);
+			dataProvider.addEventListener("filterFunctionChanged", handleDataProviderChanges);
+			dataProvider.addEventListener("sortChanged", handleDataProviderChanges);
+			dataProvider.addEventListener("collectionChange", handleDataProviderChanges);
+		}
+		
+		protected function detachEventListeners():void
+		{
+			dataProvider.removeEventListener("collectionChanged", handleDataProviderChanges);
+			dataProvider.removeEventListener("filterFunctionChanged", handleDataProviderChanges);
+			dataProvider.removeEventListener("sortChanged", handleDataProviderChanges);
+			dataProvider.removeEventListener("collectionChange", handleDataProviderChanges);
+		}
+	}
+}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
index d9ea289..067dc21 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
@@ -91,6 +91,8 @@ import mx.core.IFactory;
 import mx.core.UIComponent; 
 import mx.core.ScrollControlBase;
 import mx.core.mx_internal;
+import org.apache.royale.core.IDataProviderNotifier;
+import org.apache.royale.utils.loadBeadFromValuesManager;
 use namespace mx_internal;
 
 
@@ -579,7 +581,35 @@ public class AdvancedListBase extends ListBase /* extends UIComponent
         super.dataProvider = value;
         collection = super.dataProvider as ICollectionView;
     }
+
+    override public function addedToParent():void
+    {
+        if (!dataNotifier) {
+            dataNotifier = loadBeadFromValuesManager(IDataProviderNotifier, "iDataProviderNotifier", this) as IDataProviderNotifier;
+        }
+        super.addedToParent();
+    }
+
+    private var _dataNotifier:IDataProviderNotifier;
+    /**
+     *  The IDataProviderNotifier that will watch for data
+     *  provider changes.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.6
+     */
+    public function get dataNotifier():IDataProviderNotifier
+    {
+        return _dataNotifier;
+    }
+    public function set dataNotifier(value:IDataProviderNotifier):void
+    {
+        _dataNotifier = value;
+    }
     
+
     //--------------------------------------------------------------------------
     //
     //  Variables