//////////////////////////////////////////////////////////////////////////////// // // 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. // //////////////////////////////////////////////////////////////////////////////// include "nameData.as"; import mx.collections.ArrayCollection; import mx.collections.XMLListCollection; import mx.collections.ListCollectionView; import mx.collections.IList; import mx.core.mx_internal; import mx.events.ListEvent; import mx.events.FlexEvent; import mx.collections.ArrayCollection; import mx.events.CollectionEvent; import mx.events.CollectionEventKind; import spark.components.DataGrid; import spark.components.gridClasses.GridSelection; import spark.components.gridClasses.GridSelectionMode; import spark.components.gridClasses.CellPosition; private var originalRowIndexHolder:ArrayList; private var originalColumnIndexHolder:ArrayList; public var keyword:String=""; public function randomArrayItem(a:Array):String { return (a.length == 0) ? "" : a[Math.round(Math.random() * (a.length - 1))]; } //debugging method public function displaySelectedCellIndices(v:Vector.):void { var n:int=v.length; var msg:String; for (var i:int=0;i):void { var n:int=v.length; for (var i:int=0;i=100) index=index-(int(index/100))*100; const firstName:String = humanNamesData[index]; const lastName:String = humanNamesData[index]; const food:String = foodNamesData[index]; const drink:String = drinkNamesData[index]; return {index:index, firstName: firstName, lastName: lastName, food: food, drink: drink}; } public function addItem(dataGrid:DataGrid,index:int):void { if (dataGrid.dataProvider is XMLListCollection) dataGrid.dataProvider.addItemAt(createXMLItem(dataGrid.dataProvider.length+1),index); else dataGrid.dataProvider.addItemAt(createItem(dataGrid.dataProvider.length+1),index); } public function removeItem(dataGrid:DataGrid,index:int):void { dataGrid.dataProvider.removeItemAt(index); } public function updateItem(dataGrid:DataGrid,index:int):void { if (dataGrid.dataProvider is XMLListCollection) dataGrid.dataProvider.setItemAt(createXMLItem(index),index); else dataGrid.dataProvider.itemUpdated(dataGrid.dataProvider.getItemAt(index),"firstName",dataGrid.dataProvider.getItemAt(index)['firstName'],"blablabla"); } public function insertColumns(dataGrid:DataGrid,index:int, count:int):void { for (var i:int=0;i"; return new XML(tmp); } public function createXMLListCollection(length:int):XMLListCollection { var tmp:String=""; var firstName:String,lastName:String, food:String, drink:String; var xmlStr:String=""; for (var i:int = 0; i < length; i++) { firstName= humanNamesData[i]; lastName= humanNamesData[i]; food= foodNamesData[i]; drink= drinkNamesData[i]; tmp=""; xmlStr+=tmp+"\n"; } return new XMLListCollection(new XMLList(xmlStr)); } public function applyFilter2(dataGrid:DataGrid):void { if (dataGrid.dataProvider is ListCollectionView) { ListCollectionView(dataGrid.dataProvider).filterFunction=excludeFirstNameContain; ListCollectionView(dataGrid.dataProvider).refresh(); } } public function excludeFirstNameContain( item:Object ):Boolean { if (item is XML) { var xmlList:XMLList=XML(item).attribute("firstName"); for each(item in xmlList) { if (item.toXMLString().indexOf(keyword)) return false; else return true; } return true; }else { if( String(item["firstName"]).indexOf(keyword)) return false; else return true; } } public function storeRowColumnIndices(rowIndices:Vector.,columnIndices:Vector.):void { originalRowIndexHolder=createArrayList(rowIndices); originalColumnIndexHolder=createArrayList(columnIndices); trace("originalRowIndexHolder="+originalRowIndexHolder); } public function createArrayList(v:Vector.):ArrayList { var arr:ArrayList=new ArrayList(); var n:int=v.length; for (var i:int=0;i):ArrayList { var n:int=newRowIndices.length; var arr:ArrayList=new ArrayList(); var obj:Object; var oldIndex:int; var columnVal:int; for (var i:int=0;i