<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="0xf2f2f2"
    cornerRadius="10" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#BAD0FF, #E8F0FF]" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.utils.ArrayUtil;
    
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.collections.ArrayCollection;
    
    [Bindable]
    private var resultText:String = "| Results Text Here ]";
    [Bindable]
    private var results:ArrayCollection;
    private var rowStart:int = 0;
    
    private function callService():void
    {
        //roContactService.Echo("test test test test test");
        roContactService.GetContacts(rowStart, int(cbPageSize.text));
    }
    
    private function contactServiceHandler(event:ResultEvent):void
    {
        results = new ArrayCollection(ArrayUtil.toArray(event.result));
    }
    
    private function echoHandler(event:ResultEvent):void
    {
        resultText = event.result as String;
    }
    
    private function faultHandler(event:FaultEvent):void
    {
        Alert.show("Fault:  ", event.fault.toString());
    }
    
    ]]>

    </mx:Script>

    <mx:RemoteObject id="roContactService" source="Jon.Adventureworks.Fluorine.ContactService"
          destination="fluorine" fault="faultHandler(event)" showBusyCursor="true">
        <mx:method name="GetContacts" result="contactServiceHandler(event)" />
    </mx:RemoteObject>

    <mx:ApplicationControlBar width="100%">
        <mx:Label text="Page Size" fontWeight="bold" color="0x000000"/>
        <mx:ComboBox id="cbPageSize">
            <mx:dataProvider>
                <mx:String>100</mx:String>
                <mx:String>500</mx:String>
                <mx:String>1000</mx:String>
                <mx:String>10000</mx:String>
                <mx:String>25000</mx:String>
            </mx:dataProvider>
        </mx:ComboBox>
        <mx:Spacer width="25" />
        <mx:Label text="Search:" color="0x323232" />
        <mx:TextInput id="txtSearchFilter" width="100%" maxWidth="200" enabled="false" />
        <mx:Spacer width="100%" />
        <mx:Button id="btnSubmit" label="Submit" click="callService()" />
    </mx:ApplicationControlBar>

    <mx:ListCollectionView id="ListCollectionData" list="{results}" />

    <mx:RadioButtonGroup id="groupEmailPromotion" />
    <mx:AdvancedDataGrid id="adg1" dataProvider="{results}" width="100%" height="100%" editable="true">
        <mx:columns>
            <mx:AdvancedDataGridColumn headerText="G" width="50" editable="false">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:HBox width="100%" horizontalAlign="center">
                            <mx:RadioButton groupName="groupEmailPromotion" selected="{data.EmailPromotion == 0}"/>
                        </mx:HBox>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:AdvancedDataGridColumn>
            <mx:AdvancedDataGridColumn headerText="R" width="50" editable="false">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:HBox width="100%" horizontalAlign="center">
                            <mx:RadioButton groupName="groupEmailPromotion" selected="{data.EmailPromotion == 1}"/>
                        </mx:HBox>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:AdvancedDataGridColumn>
            <mx:AdvancedDataGridColumn headerText="B" width="50" editable="false">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:HBox width="100%" horizontalAlign="center">
                            <mx:RadioButton groupName="groupEmailPromotion" selected="{data.EmailPromotion == 2}"/>
                        </mx:HBox>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:AdvancedDataGridColumn>
            <mx:AdvancedDataGridColumn headerText="Id" dataField="ContactId" />
            <mx:AdvancedDataGridColumn headerText="Title" dataField="Title" />
            <mx:AdvancedDataGridColumn headerText="First Name" dataField="FirstName" />
            <mx:AdvancedDataGridColumn headerText="Middle Name" dataField="MiddleName" />
            <mx:AdvancedDataGridColumn headerText="Last Name" dataField="LastName" />
            <mx:AdvancedDataGridColumn headerText="Suffix" dataField="Suffix" width="80" />
            <mx:AdvancedDataGridColumn headerText="Email" dataField="EmailAddress" />
            <mx:AdvancedDataGridColumn headerText="Phone" dataField="Phone" />
        </mx:columns>
    </mx:AdvancedDataGrid>

</mx:Application>