Created
November 29, 2010 16:17
-
-
Save edeustace/720141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" | |
creationComplete="init()" | |
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> | |
<fx:Script> | |
<![CDATA[ | |
protected function button1_clickHandler(event:MouseEvent):void | |
{ | |
// TODO Auto-generated method stub | |
} | |
]]> | |
</fx:Script> | |
<fx:Declarations> | |
<!-- Place non-visual elements (e.g., services, value objects) here --> | |
</fx:Declarations> | |
<fx:Script> | |
<![CDATA[ | |
import com.adobe.ps.mobius.documents.model.Document; | |
import com.adobe.ps.mobius.documents.model.MiniDocument; | |
import mx.collections.ArrayCollection; | |
import mx.collections.Sort; | |
import mx.collections.SortField; | |
import mx.controls.dataGridClasses.DataGridColumn; | |
import mx.events.DataGridEvent; | |
[Bindable] | |
private var collection:ArrayCollection = new ArrayCollection(); | |
private var dates:Array = [ new Date(2010, 5, 1), new Date(2010, 4, 2), new Date(2010, 5, 3) ]; | |
private var labels:Array = [ "Apple", "Banana", "Carrot", "Grape", "Orange" ]; | |
private var tabNames:Array = [ "Correspondance", "A and E" ]; | |
protected function datagrid1_headerReleaseHandler(event:DataGridEvent):void | |
{ | |
} | |
private function createDocument(counter:int):MiniDocument | |
{ | |
var mini:MiniDocument = new MiniDocument(); | |
mini.startDate = dates[counter % dates.length]; | |
mini.tabName = tabNames[counter % tabNames.length]; | |
mini.label = labels[counter % labels.length]; | |
return mini; | |
} | |
private function init():void | |
{ | |
for (var i:int = 0; i < 10; i++) | |
{ | |
collection.addItem(createDocument(i)); | |
} | |
} | |
private function printCollection(collection:ArrayCollection):void | |
{ | |
textArea.text = ""; | |
for each (var doc:MiniDocument in collection) | |
{ | |
textArea.text += (doc + "\n"); | |
} | |
} | |
private function sortAsc() : void | |
{ | |
setSort(false); | |
} | |
private function sortDesc() : void | |
{ | |
setSort(true); | |
} | |
private function setSort( isDescending: Boolean = false ) : void | |
{ | |
collection.sort = new Sort(); | |
var startDateField : SortField = new SortField("startDate",true,isDescending); | |
startDateField.compareFunction = compareStartDate; | |
collection.sort.fields = [ startDateField ]; | |
collection.refresh(); | |
printCollection(collection); | |
} | |
private function compareStartDate(obj1:Object,obj2:Object, fields : Array = null) : int | |
{ | |
return compareDates(obj1.startDate,obj2.startDate); | |
} | |
public static function compareDates(d1:Date, d2:Date):int | |
{ | |
var d1ms:Number = d1.getTime(); | |
var d2ms:Number = d2.getTime(); | |
if (d1ms > d2ms) | |
{ | |
return -1; | |
} | |
else if (d1ms < d2ms) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
]]> | |
</fx:Script> | |
<s:layout> | |
<s:VerticalLayout/> | |
</s:layout> | |
<s:Button label="sort by date ASC" click="sortAsc()"/> | |
<s:Button label="sort by date DESC" click="sortDesc()"/> | |
<s:TextArea id="textArea" width="500" height="500"> | |
</s:TextArea> | |
</s:Application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment