You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2020/09/11 15:43:41 UTC

[royale-asjs] branch develop updated: New bead to allow Jewel DataGrid to be sortable

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

carlosrovira 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 99ba677  New bead to allow Jewel DataGrid to be sortable
     new 8a4c21c  Merge pull request #908 from SolidSoft-Lda/develop
99ba677 is described below

commit 99ba677bab13e581bf56e6b92a9c788c201c94a5
Author: Hugo <hf...@solidsoft.pt>
AuthorDate: Thu Sep 10 10:15:21 2020 +0100

    New bead to allow Jewel DataGrid to be sortable
---
 .../Jewel/src/main/resources/jewel-manifest.xml    |  1 +
 .../beads/controls/datagrid/DataGridSortBead.as    | 89 ++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 374f26f..dcd9b15 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -54,6 +54,7 @@
     <component id="DataGridButtonBar" class="org.apache.royale.jewel.supportClasses.datagrid.DataGridButtonBar"/>
 
     <component id="DataGridColumnLabelsChange" class="org.apache.royale.jewel.beads.controls.datagrid.DataGridColumnLabelsChange"/>
+    <component id="DataGridSortBead" class="org.apache.royale.jewel.beads.controls.datagrid.DataGridSortBead"/>
 
     <component id="ButtonBarItemRenderer" class="org.apache.royale.jewel.itemRenderers.ButtonBarItemRenderer"/>
     <component id="IconButtonBarItemRenderer" class="org.apache.royale.jewel.itemRenderers.IconButtonBarItemRenderer"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datagrid/DataGridSortBead.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datagrid/DataGridSortBead.as
new file mode 100644
index 0000000..e5747d1
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datagrid/DataGridSortBead.as
@@ -0,0 +1,89 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.jewel.beads.controls.datagrid
+{
+	import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.jewel.beads.views.DataGridView;
+	import org.apache.royale.events.MouseEvent;
+	import org.apache.royale.jewel.supportClasses.datagrid.DataGridButtonBar;
+	import org.apache.royale.collections.Sort;
+	import org.apache.royale.collections.SortField;
+	import org.apache.royale.collections.IArrayListView;
+	import org.apache.royale.jewel.supportClasses.datagrid.DataGridColumn;
+
+	public class DataGridSortBead implements IBead
+	{
+		public function DataGridSortBead()
+		{
+			super();
+		}
+		
+        private var dg:DataGrid;
+
+		private var descending:Boolean;
+        
+		/**                         	
+		 *  @copy org.apache.royale.core.IBead#strand
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
+		 */
+		public function set strand(value:IStrand):void
+		{
+            dg = value as DataGrid;
+			(dg.view as DataGridView).header.addEventListener(MouseEvent.CLICK, mouseClickHandler, false);
+		}
+		
+		/**
+		 * @private
+		 */
+		private function mouseClickHandler(event:MouseEvent):void
+		{
+			var dgView:DataGridView = dg.view as DataGridView;
+            var buttonBar:DataGridButtonBar = (dgView.header as DataGridButtonBar);
+            // probably down on one button and up on another button
+            // so the ButtonBar won't change selection
+            if (event.target == buttonBar) return;
+			var column:DataGridColumn = event.target.data as DataGridColumn;
+			var collection:IArrayListView = dg.dataProvider as IArrayListView;
+			if (collection && collection.length)
+			{
+				if (collection.sort && collection.sort.fields[0].name == column.dataField)
+					descending = !descending;
+
+				var sort:Sort = new Sort();
+				var sortField:SortField = new SortField(column.dataField, false, descending);
+
+				sort.fields = [ sortField ];
+				collection.sort = sort;
+
+				(dgView.header as DataGridButtonBar).model.dispatchEvent(new Event("dataProviderChanged"));
+
+				// force redraw of column headers
+				collection.refresh();
+				dg.dataProvider = null;
+				dg.dataProvider = collection;
+			}
+		}
+	}
+}
\ No newline at end of file