<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright 2010 Chet Haase
    
    Licensed 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.
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               viewSourceURL="srcview/index.html"
               width="300" height="250">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]private var results:ArrayCollection = new ArrayCollection([
                {name: "ketchup", latin:"splattis completus"},
                {name: "mustard", latin:"musto tardis"},
                {name: "mayonnaise", latin:"viscous raweggus"},
                {name: "hot sauce", latin:"hurtsogoodus"},
                {name: "pickle", latin:"gerkin entirus"},
                {name: "relish", latin:"gerkin destructus"},
                {name: "butter", latin:"fattus perfectus"},
                {name: "BBQ sauce", latin:"smokus weeatus"},
            ]);

            private function runSearch():void
            {
                currentState = "resultsScreen";
            }
        ]]>
    </fx:Script>
    <s:states>
        <s:State name="searchScreen"/>
        <s:State name="resultsScreen"/>
    </s:states>
    <s:Group includeIn="searchScreen">
        <s:Label x="107" y="66" text="Food Item" fontSize="18" fontWeight="bold"/>
        <s:TextInput id="searchInput" x="86" y="91"/>
        <s:Button x="115" y="121" label="Search" enabled="{searchInput.text != ''}"
                  click="runSearch()"/>
    </s:Group>
    <s:Group includeIn="resultsScreen">
        <mx:DataGrid x="10" y="10" width="280" height="201"
                     dataProvider="{results}">
            <mx:columns>
                <mx:DataGridColumn headerText="Common Name" 
                                   dataField="name"/>
                <mx:DataGridColumn headerText="Latin Name" 
                                   dataField="latin"/>
            </mx:columns>
        </mx:DataGrid>
        <s:Button x="104" y="219" label="Search Again"
                  click="currentState = 'searchScreen'"/>
    </s:Group>
</s:Application>