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/11/17 10:05:14 UTC

[royale-asjs] branch multi_select created (now fda1a7d)

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

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


      at fda1a7d  Added array multi selection model

This branch includes the following new commits:

     new fda1a7d  Added array multi selection model

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[royale-asjs] 01/01: Added array multi selection model

Posted by yi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fda1a7d2a664871a09ee2f891b0ddec06939c3fb
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Sun Nov 17 11:57:02 2019 +0200

    Added array multi selection model
---
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 .../html/beads/models/ArrayMultiSelectionModel.as  | 232 +++++++++++++++++++++
 .../projects/Core/src/main/royale/CoreClasses.as   |   1 +
 .../org/apache/royale/core/IMultiSelectionModel.as |  65 ++++++
 4 files changed, 299 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 26cf36f..d383b60 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -83,6 +83,7 @@
     <component id="TitleBarTitle" class="org.apache.royale.html.beads.TitleBarTitle"/>
     <component id="ImageModel" class="org.apache.royale.html.beads.models.ImageModel"/>
     <component id="ArraySelectionModel" class="org.apache.royale.html.beads.models.ArraySelectionModel"/>
+    <component id="ArrayMultiSelectionModel" class="org.apache.royale.html.beads.models.ArrayMultiSelectionModel"/>
     <component id="ArrayColorSelectionModel" class="org.apache.royale.html.beads.models.ArrayColorSelectionModel"/>
     <component id="TitleBarModel" class="org.apache.royale.html.beads.models.TitleBarModel"/>
     <component id="ToolTip" class="org.apache.royale.html.ToolTip"/>
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/models/ArrayMultiSelectionModel.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/models/ArrayMultiSelectionModel.as
new file mode 100644
index 0000000..0c794ac
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/models/ArrayMultiSelectionModel.as
@@ -0,0 +1,232 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads.models
+{
+	import org.apache.royale.core.IRollOverModel;
+	import org.apache.royale.core.IMultiSelectionModel;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.events.Event;
+	import org.apache.royale.events.EventDispatcher;
+			
+    /**
+     *  The ArraySelectionModel class is a selection model for
+     *  a dataProvider that is an array. It assumes that items
+     *  can be fetched from the dataProvider
+     *  dataProvider[index].  Other selection models
+     *  would support other kinds of data providers.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion 0.9.7
+     */
+	public class ArrayMultiSelectionModel extends EventDispatcher implements IMultiSelectionModel, IRollOverModel
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function ArrayMultiSelectionModel()
+		{
+		}
+
+		private var _strand:IStrand;
+		
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+		}
+		
+		private var _dataProvider:Object;
+        
+        /**
+         *  @copy org.apache.royale.core.IMultiSelectionModel#dataProvider
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function get dataProvider():Object
+		{
+			return _dataProvider;
+		}
+
+        /**
+         *  @private
+         */
+		public function set dataProvider(value:Object):void
+		{
+			if (value == _dataProvider) return;
+			_dataProvider = value;
+			if(_dataProvider && _selectedIndices)
+			{
+				var indices:Array = [];
+				var length:int = (value as Array).length;
+				for (var i:int = 0; i < _selectedIndices.length; i++)
+				{
+					if (_selectedIndices[i] < length)
+					{
+						indices.push(value[_selectedIndices[i]]);
+					}
+					_selectedIndices = indices;
+					syncItemsAndIndices();
+				}
+			}
+			dispatchEvent(new Event("dataProviderChanged"));
+		}
+
+		private var _selectedIndices:Array = null;
+		private var _rollOverIndex:int = -1;
+		private var _labelField:String = null;
+		
+        /**
+         *  @copy org.apache.royale.core.IMultiSelectionModel#labelField
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function get labelField():String
+		{
+			return _labelField;
+		}
+
+        /**
+         *  @private
+         */
+		public function set labelField(value:String):void
+		{
+			if (value != _labelField) {
+				_labelField = value;
+				dispatchEvent(new Event("labelFieldChanged"));
+			}
+		}
+		
+        /**
+         *  @copy org.apache.royale.core.IMultiSelectionModel#selectedIndices
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function get selectedIndices():Array
+		{
+			return _selectedIndices;
+		}
+
+        /**
+         *  @private
+         */
+		public function set selectedIndices(value:Array):void
+		{
+            if (value == _selectedIndices) return;
+			_selectedIndices = value;
+			if (value == null || dataProvider == null)
+			{
+				_selectedItems = null;
+			} else
+			{
+				syncItemsAndIndices();
+			}
+			dispatchEvent(new Event("selectedItemsChanged"));			
+			dispatchEvent(new Event("selectedIndicesChanged"));
+		}
+		
+        /**
+         *  @copy org.apache.royale.core.IRollOverModel#rollOverIndex
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function get rollOverIndex():int
+		{
+			return _rollOverIndex;
+		}
+
+        /**
+         *  @private
+         */
+		public function set rollOverIndex(value:int):void
+		{
+			_rollOverIndex = value;
+			dispatchEvent(new Event("rollOverIndexChanged"));			
+		}
+		
+		private var _selectedItems:Array;
+		
+        /**
+         *  @copy org.apache.royale.core.IMultiSelectionModel#selectedItems
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+		public function get selectedItems():Array
+		{
+			return _selectedItems;
+		}
+
+        /**
+         *  @private
+         */
+		public function set selectedItems(value:Array):void
+		{
+            if (value == _selectedItems) return;
+            
+			_selectedItems = value;	
+			_selectedIndices = [];
+			var dp:Array = _dataProvider as Array;
+			for (var i:int = 0; i < value.length; i++)
+			{
+				_selectedIndices.push(dp.indexOf(value[i]));
+			}
+			dispatchEvent(new Event("selectedItemsChanged"));			
+			dispatchEvent(new Event("selectedIndicesChanged"));
+		}
+		
+
+		private function syncItemsAndIndices():void
+		{
+				var items:Array = [];
+				for (var i:int = 0; i < _selectedIndices.length; i++)
+				{
+					items.push(dataProvider[_selectedIndices[i]]);
+				}
+				_selectedItems = items;
+		}
+	}
+}
diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index ce4785b..2c17dc7 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -134,6 +134,7 @@ internal class CoreClasses
     import org.apache.royale.core.ISelectableItemRenderer; ISelectableItemRenderer;
     import org.apache.royale.core.ISelectable; ISelectable;
     import org.apache.royale.core.ISelectionModel; ISelectionModel;
+    import org.apache.royale.core.IMultiSelectionModel; IMultiSelectionModel;
     import org.apache.royale.core.IStrand; IStrand;
 	import org.apache.royale.core.IContainerBaseStrandChildrenHost; IContainerBaseStrandChildrenHost;
     import org.apache.royale.core.IStrandWithModel; IStrandWithModel;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IMultiSelectionModel.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IMultiSelectionModel.as
new file mode 100644
index 0000000..d69e8a5
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IMultiSelectionModel.as
@@ -0,0 +1,65 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.core
+{
+    /**
+     *  The IMultiSelectionModel interface describes the minimum set of properties
+     *  available to control that let the user select one or more items from within a
+     *  set of items in a dataProvider.  A more sophisticated model would
+     *  support multiple selection.
+     * 
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.7
+     */
+	public interface IMultiSelectionModel extends IDataProviderModel
+	{
+        /**
+         *  The indices of the selected items in the
+         *  dataProvider.  Null can
+         *  have specific meanings but generally means
+         *  that no item is selected because the
+         *  user has typed in a custom entry or has
+         *  yet to make a choice.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+        function get selectedIndices():Array;
+        function set selectedIndices(value:Array):void;
+        
+        /**
+         *  The data items selected in the
+         *  dataProvider.  null usually means
+         *  that the user has not selected any value
+         *  and has typed in a custom entry.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.7
+         */
+        function get selectedItems():Array;
+        function set selectedItems(value:Array):void;
+
+	}
+}