royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: fix index position in table component when add and remove
Date Wed, 29 Aug 2018 07:53:52 GMT
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 340bdf7  fix index position in table component when add and remove
340bdf7 is described below

commit 340bdf7fb0085c22c4917b2d78053a7d3ee50573
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Wed Aug 29 09:53:48 2018 +0200

    fix index position in table component when add and remove
---
 .../src/main/royale/TablePlayGround.mxml           |  8 ++++
 .../TableCellCloseIconItemRenderer.mxml            |  8 +++-
 .../AddTableItemRendererForArrayListData.as        | 43 +++++++++++++---------
 .../RemoveTableItemRendererForArrayListData.as     | 21 +++++++----
 .../jewel/supportClasses/table/TBodyContentArea.as |  2 +
 5 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/examples/royale/JewelExample/src/main/royale/TablePlayGround.mxml b/examples/royale/JewelExample/src/main/royale/TablePlayGround.mxml
index 72acba0..0a4a2c8 100644
--- a/examples/royale/JewelExample/src/main/royale/TablePlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/TablePlayGround.mxml
@@ -205,6 +205,14 @@ limitations under the License.
 						<j:Button text="Remove first item" click="removeItemAt()"/>
 						<j:Button text="Update first item" click="updateFirstItem()"/>
 						<j:Button text="Remove all data" click="removeAllData()"/>
+						<j:HGroup gap="3" itemsVerticalAlign="itemsCentered">
+							<j:Label text="Select table by index: "/>
+							<j:NumericStepper valueChange="table.selectedIndex = event.target.value" minimum="0"/>
+						</j:HGroup>
+						<!-- <j:HGroup gap="3" itemsVerticalAlign="itemsCentered">
+							<j:Label text="Select table by item: "/>
+							<j:NumericStepper valueChange="table.selectedItemProperty = table.dataProvider.getItemAt(event.target.value)"
minimum="0"/>
+						</j:HGroup> -->
 					</j:VGroup>
 				</j:HGroup>
 			</j:Card>
diff --git a/examples/royale/JewelExample/src/main/royale/itemRenderers/TableCellCloseIconItemRenderer.mxml
b/examples/royale/JewelExample/src/main/royale/itemRenderers/TableCellCloseIconItemRenderer.mxml
index b5897ce..4c03e1a 100644
--- a/examples/royale/JewelExample/src/main/royale/itemRenderers/TableCellCloseIconItemRenderer.mxml
+++ b/examples/royale/JewelExample/src/main/royale/itemRenderers/TableCellCloseIconItemRenderer.mxml
@@ -27,9 +27,13 @@ limitations under the License.
     
     <fx:Script>
 		<![CDATA[
+            import org.apache.royale.jewel.Table;
+            import org.apache.royale.collections.ArrayList;
+            
             private function clickCloseButton():void
 			{
-                trace("hello!");
+                var table:Table = itemRendererParent as Table;
+                (table.dataProvider as ArrayList).removeItemAt(rowIndex);
             }
         ]]>
 	</fx:Script>
@@ -40,7 +44,7 @@ limitations under the License.
     
     <j:IconButton emphasis="primary" width="24" height="24" style="padding: 0px; border-radius:
50%" click="clickCloseButton()">
         <j:icon>
-            <js:FontIcon text="{data.icon}" material="true" size="18"/>
+            <js:FontIcon text="{MaterialIconType.CLOSE}" material="true" size="18"/>
         </j:icon>
     </j:IconButton>
     
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/AddTableItemRendererForArrayListData.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/AddTableItemRendererForArrayListData.as
index c826e5c..45bbf73 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/AddTableItemRendererForArrayListData.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/AddTableItemRendererForArrayListData.as
@@ -23,7 +23,6 @@ package org.apache.royale.jewel.beads.itemRenderers
 	import org.apache.royale.core.IItemRendererParent;
 	import org.apache.royale.core.IList;
 	import org.apache.royale.core.IListPresentationModel;
-	import org.apache.royale.core.ISelectableItemRenderer;
 	import org.apache.royale.core.ISelectionModel;
 	import org.apache.royale.core.IStrand;
 	import org.apache.royale.core.SimpleCSSStyles;
@@ -31,10 +30,11 @@ package org.apache.royale.jewel.beads.itemRenderers
 	import org.apache.royale.events.CollectionEvent;
 	import org.apache.royale.events.Event;
 	import org.apache.royale.events.IEventDispatcher;
-	import org.apache.royale.html.supportClasses.DataItemRenderer;
-	import org.apache.royale.jewel.beads.itemRenderers.ITextItemRenderer;
 	import org.apache.royale.jewel.beads.models.TableModel;
+	import org.apache.royale.jewel.itemRenderers.TableItemRenderer;
+	import org.apache.royale.jewel.supportClasses.table.TableCell;
 	import org.apache.royale.jewel.supportClasses.table.TableColumn;
+	import org.apache.royale.jewel.supportClasses.table.TableRow;
 	import org.apache.royale.utils.loadBeadFromValuesManager;
 
     /**
@@ -130,7 +130,7 @@ package org.apache.royale.jewel.beads.itemRenderers
 		{
             var presentationModel:IListPresentationModel = _strand.getBeadByType(IListPresentationModel)
as IListPresentationModel;
 			var column:TableColumn;
-			var ir:ITextItemRenderer;
+			var ir:TableItemRenderer;
 
 			var index:int = event.index * model.columns.length;
 			for(var j:int = 0; j < model.columns.length; j++)
@@ -139,19 +139,19 @@ package org.apache.royale.jewel.beads.itemRenderers
 				
 				if(column.itemRenderer != null)
 				{
-					ir = column.itemRenderer.newInstance() as ITextItemRenderer;
+					ir = column.itemRenderer.newInstance() as TableItemRenderer;
 				} else
 				{
-					ir = itemRendererFactory.createItemRenderer(itemRendererParent) as ITextItemRenderer;
+					ir = itemRendererFactory.createItemRenderer(itemRendererParent) as TableItemRenderer;
 				}
 
 				labelField =  column.dataField;
 		
-				(ir as DataItemRenderer).dataField = labelField;
-				(ir as DataItemRenderer).rowIndex = event.index;
-				(ir as DataItemRenderer).columnIndex = j;
+				ir.dataField = labelField;
+				ir.rowIndex = event.index;
+				ir.columnIndex = j;
 		
-				fillRenderer(index++, event.item, (ir as ISelectableItemRenderer), presentationModel);
+				fillRenderer(index++, event.item, ir, presentationModel);
 				
 				if(column.align != "")
 				{
@@ -160,12 +160,21 @@ package org.apache.royale.jewel.beads.itemRenderers
 			}
 
 			// update the index values in the itemRenderers to correspond to their shifted positions.
-			var n:int = itemRendererParent.numElements;
-			var d:DataItemRenderer;
-			for (var i:int = event.index; i < n; i++)
+			// adjust the itemRenderers' index to adjust for the shift
+			var cell:TableCell;
+			var processedRow:TableRow;
+			var len:int = itemRendererParent.numElements;
+			for (var i:int = event.index; i < len; i++)
 			{
-				d = itemRendererParent.getItemRendererForIndex(i) as DataItemRenderer;
-				d.index = i;
+				processedRow = itemRendererParent.getElementAt(i) as TableRow;
+				var n:int = processedRow.numElements;
+				for (j = 0; j < n; j++)
+				{
+					cell = processedRow.getElementAt(j) as TableCell;
+					ir = cell.getElementAt(0) as TableItemRenderer;
+					ir.index = i;
+					ir.rowIndex = i;
+				}
 			}
 
 			(_strand as IEventDispatcher).dispatchEvent(new Event("layoutNeeded"));
@@ -215,7 +224,7 @@ package org.apache.royale.jewel.beads.itemRenderers
          */
         protected function fillRenderer(index:int,
                                         item:Object,
-                                        itemRenderer:ISelectableItemRenderer,
+                                        itemRenderer:TableItemRenderer,
                                         presentationModel:IListPresentationModel):void
         {
             itemRendererParent.addItemRendererAt(itemRenderer, index);
@@ -236,7 +245,7 @@ package org.apache.royale.jewel.beads.itemRenderers
         /**
          * @private
          */
-        protected function setData(itemRenderer:ISelectableItemRenderer, data:Object, index:int):void
+        protected function setData(itemRenderer:TableItemRenderer, data:Object, index:int):void
         {
             itemRenderer.index = index;
             itemRenderer.data = data;
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/RemoveTableItemRendererForArrayListData.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/RemoveTableItemRendererForArrayListData.as
index 06685ba..52c21be 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/RemoveTableItemRendererForArrayListData.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/itemRenderers/RemoveTableItemRendererForArrayListData.as
@@ -21,12 +21,12 @@ package org.apache.royale.jewel.beads.itemRenderers
 	import org.apache.royale.core.IBead;
 	import org.apache.royale.core.IItemRendererParent;
 	import org.apache.royale.core.IList;
-	import org.apache.royale.core.ISelectableItemRenderer;
 	import org.apache.royale.core.ISelectionModel;
 	import org.apache.royale.core.IStrand;
 	import org.apache.royale.events.CollectionEvent;
 	import org.apache.royale.events.Event;
 	import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.html.supportClasses.DataItemRenderer;
 	import org.apache.royale.jewel.beads.models.TableModel;
 	import org.apache.royale.jewel.supportClasses.table.TableCell;
 	import org.apache.royale.jewel.supportClasses.table.TableRow;
@@ -122,12 +122,12 @@ package org.apache.royale.jewel.beads.itemRenderers
 		 */
 		protected function handleItemRemoved(event:CollectionEvent):void
 		{
-			var ir:ISelectableItemRenderer;
+			var ir:DataItemRenderer;
 			var cell:TableCell;
 			var processedRow:TableRow = itemRendererParent.getElementAt(event.index) as TableRow;
 			while (processedRow.numElements > 0) {
 				cell = processedRow.getElementAt(0) as TableCell;
-				ir = cell.getElementAt(0) as ISelectableItemRenderer;
+				ir = cell.getElementAt(0) as DataItemRenderer;
 				itemRendererParent.removeItemRenderer(ir);
 				cell.removeElement(ir);
 				processedRow.removeElement(cell);
@@ -135,11 +135,18 @@ package org.apache.royale.jewel.beads.itemRenderers
 			itemRendererParent.removeElement(processedRow);
 
 			// adjust the itemRenderers' index to adjust for the shift
-			var n:int = itemRendererParent.numElements;
-			for (var i:int = event.index; i < n; i++)
+			var len:int = itemRendererParent.numElements;
+			for (var i:int = event.index; i < len; i++)
 			{
-				ir = itemRendererParent.getElementAt(i) as ISelectableItemRenderer;
-				ir.index = i;
+				processedRow = itemRendererParent.getElementAt(i) as TableRow;
+				var n:int = processedRow.numElements;
+				for (var j:int = 0; j < n; j++)
+				{
+					cell = processedRow.getElementAt(j) as TableCell;
+					ir = cell.getElementAt(0) as DataItemRenderer;
+					ir.index = i;
+					ir.rowIndex = i;
+				}
 			}
 
 			(_strand as IEventDispatcher).dispatchEvent(new Event("layoutNeeded"));
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/table/TBodyContentArea.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/table/TBodyContentArea.as
index 9463d2f..afe0b2c 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/table/TBodyContentArea.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/table/TBodyContentArea.as
@@ -91,6 +91,7 @@ package org.apache.royale.jewel.supportClasses.table
 		{
 			// this method is not used for now, so it needs to be tested to see if it's correctly
implemented
 			var r:DataItemRenderer = renderer as DataItemRenderer;
+			r.itemRendererParent = host; // easy access from renderer to table
 			var tableCell:TableCell = new TableCell();
 			tableCell.addElement(r);
 
@@ -123,6 +124,7 @@ package org.apache.royale.jewel.supportClasses.table
 		public function addItemRendererAt(renderer:IItemRenderer, index:int):void
 		{
 			var r:DataItemRenderer = renderer as DataItemRenderer;
+			r.itemRendererParent = host; // easy access from renderer to table
 			var tableCell:TableCell = new TableCell();
 			tableCell.addElement(r);
 


Mime
View raw message