flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bigosma...@apache.org
Subject [11/11] git commit: [flex-asjs] [refs/heads/develop] - Checking in Alex's example projects
Date Tue, 23 Jul 2013 21:48:09 GMT
Checking in Alex's example projects


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/a24f6122
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/a24f6122
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/a24f6122

Branch: refs/heads/develop
Commit: a24f61227df35f8577d370e184a46f2577154443
Parents: 9ab493a
Author: Om <bigosmallm@gmail.com>
Authored: Tue Jul 23 14:47:35 2013 -0700
Committer: Om <bigosmallm@gmail.com>
Committed: Tue Jul 23 14:47:35 2013 -0700

----------------------------------------------------------------------
 .../DataBindingTest/src/DataBindingTest.mxml    |  34 ++++
 examples/DataBindingTest/src/MyInitialView.mxml | 145 ++++++++++++++++
 .../src/StockDataJSONItemConverter.as           |  22 +++
 .../src/controllers/MyController.as             |  81 +++++++++
 examples/DataBindingTest/src/models/MyModel.as  | 126 ++++++++++++++
 examples/StatesTest/src/MyInitialView.mxml      | 164 +++++++++++++++++++
 examples/StatesTest/src/StatesTest.mxml         |  34 ++++
 .../src/StockDataJSONItemConverter.as           |  22 +++
 .../StatesTest/src/controllers/MyController.as  |  81 +++++++++
 examples/StatesTest/src/models/MyModel.as       | 126 ++++++++++++++
 10 files changed, 835 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/DataBindingTest/src/DataBindingTest.mxml
----------------------------------------------------------------------
diff --git a/examples/DataBindingTest/src/DataBindingTest.mxml b/examples/DataBindingTest/src/DataBindingTest.mxml
new file mode 100644
index 0000000..6a76b82
--- /dev/null
+++ b/examples/DataBindingTest/src/DataBindingTest.mxml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+                   xmlns:local="*"
+                   xmlns:basic="library://ns.apache.org/flexjs/basic" 
+                   xmlns:models="models.*" 
+                   xmlns:controllers="controllers.*"
+                   initialize="MyModel(model).stockSymbol='ADBE'"
+                   >
+    <basic:valuesImpl>
+        <basic:SimpleCSSValuesImpl />
+    </basic:valuesImpl>
+    <basic:initialView>
+        <local:MyInitialView />
+    </basic:initialView>
+    <basic:model>
+        <models:MyModel />
+    </basic:model>
+    <basic:controller>
+        <controllers:MyController />
+    </basic:controller>
+    <basic:beads>
+        <basic:HTTPService id="service">
+            <basic:LazyCollection id="collection">
+                <basic:inputParser>
+                    <basic:JSONInputParser />
+                </basic:inputParser>
+                <basic:itemConverter>
+                    <local:StockDataJSONItemConverter />
+                </basic:itemConverter> 
+            </basic:LazyCollection>
+        </basic:HTTPService>
+        <basic:ViewSourceContextMenuOption />
+    </basic:beads>
+</basic:Application>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/DataBindingTest/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/DataBindingTest/src/MyInitialView.mxml b/examples/DataBindingTest/src/MyInitialView.mxml
new file mode 100644
index 0000000..6656cca
--- /dev/null
+++ b/examples/DataBindingTest/src/MyInitialView.mxml
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+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.
+
+-->
+<basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
+				xmlns:basic="library://ns.apache.org/flexjs/basic"
+                xmlns:core="library://ns.apache.org/flexjs/core"
+			    initComplete="initControls()" xmlns:mx="library://ns.adobe.com/flex/mx">
+    <fx:Script>
+        <![CDATA[
+			import models.MyModel;
+			
+			import org.apache.flex.events.CustomEvent;
+			
+			private var _symbol:String;
+			
+            public function get symbol():String
+            {
+                return _symbol;
+            }
+			
+			public function get requestedField():String
+			{
+				return radio1.selectedValue as String;
+			}
+			
+            [Bindable]
+            public var fieldText:String;
+            
+			private function radioChanged(e:org.apache.flex.events.Event):void
+			{
+				dispatchEvent(new CustomEvent("radioClicked"));
+				fieldText = RadioButton(e.target).text;
+			}
+			
+			private function initControls():void
+			{
+				list.selectedItem = MyModel(applicationModel).stockSymbol;
+				radio1.selectedValue = MyModel(applicationModel).requestedField;
+				if (radio1.selected)
+					fieldText = radio1.text;
+				else if (radio2.selected)
+					fieldText = radio2.text;
+				else if (radio3.selected)
+					fieldText = radio3.text;
+				else if (radio4.selected)
+					fieldText = radio4.text;
+				
+			}
+            
+            private function setState():void
+            {
+                currentState = showAllData.selected ? "showAll" : "hideAll";    
+            }
+		]]>
+    </fx:Script>
+	<fx:Style>
+		@namespace basic "library://ns.apache.org/flexjs/basic";
+		
+		.output {
+			font-size: 20px;
+		}
+
+        .topContainer {
+            padding: 10px;
+            
+        }
+        .leftSide {
+            vertical-align: top;
+            margin-right: 10px;
+        }
+        
+        .rightSide {
+            vertical-align: top;
+            margin-left: 10px;
+            padding-left: 10px;
+        }
+        
+        .quoteButton {
+            margin-top: 10px;
+            margin-bottom: 10px;
+        }
+	</fx:Style>
+    <basic:states>
+        <mx:State name="hideAll" />        
+        <mx:State name="showAll" />        
+    </basic:states>
+    <basic:beads>
+        <basic:ViewBaseDataBinding />
+    </basic:beads>
+    <basic:Container x="0" y="0" className="topContainer" >
+        <basic:beads>
+            <basic:NonVirtualVerticalLayout />
+        </basic:beads>
+        <basic:Label width="300" text="Enter Stock Symbol or choose from list:" />
+        <basic:Container>
+            <basic:beads>
+                <basic:NonVirtualHorizontalLayout />
+            </basic:beads>
+            <basic:Container className="leftSide">
+                <basic:beads>
+                    <basic:NonVirtualVerticalLayout />
+                </basic:beads>
+                <basic:TextInput id="symbolTI" text="{MyModel(applicationModel).stockSymbol}"
/>
+                <basic:TextButton text="Get Quote" className="quoteButton" 
+                                  click="_symbol = symbolTI.text; dispatchEvent(new CustomEvent('buttonClicked'))"
/>
+                <basic:Label id="field" text="{fieldText}"/>
+                <basic:Label className="output" height="24" text="{MyModel(applicationModel).responseText}"
/>
+            </basic:Container>
+            <basic:Container className="rightSide">
+                <basic:beads>
+                    <basic:NonVirtualVerticalLayout />
+                </basic:beads>
+                <basic:DropDownList id="list" width="100" height="17"
+                                    change="_symbol = list.selectedItem as String; dispatchEvent(new
CustomEvent('listChanged'))"
+                                    dataProvider="{MyModel(applicationModel).strings}" />
+                <basic:RadioButton id="radio1" text="Price" value="Ask" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio2" text="Change" value="Change" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio3" text="Day's High" value="DaysHigh" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio4" text="Day's Low" value="DaysLow" groupName="group1"
change="radioChanged(event)"/>
+                <basic:CheckBox id="showAllData" text="Show All Data" change="setState()"
/>
+            </basic:Container>
+        </basic:Container>
+        <basic:Label id="bindtest" text="{fieldText + ' expression binding'}" />
+        <basic:Label width="300" text.showAll="110" includeIn="showAll" />
+        <basic:TextArea id="ta" width="300" height="100" height.showAll="110" 
+                        includeIn="showAll"
+                        text="{MyModel(applicationModel).allData}" />
+    </basic:Container>	
+</basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/DataBindingTest/src/StockDataJSONItemConverter.as
----------------------------------------------------------------------
diff --git a/examples/DataBindingTest/src/StockDataJSONItemConverter.as b/examples/DataBindingTest/src/StockDataJSONItemConverter.as
new file mode 100644
index 0000000..b2cb76d
--- /dev/null
+++ b/examples/DataBindingTest/src/StockDataJSONItemConverter.as
@@ -0,0 +1,22 @@
+package
+{
+    import org.apache.flex.net.JSONItemConverter;
+    
+    public class StockDataJSONItemConverter extends JSONItemConverter
+    {
+        public function StockDataJSONItemConverter()
+        {
+            super();
+        }
+        
+        override public function convertItem(data:String):Object
+        {
+            var obj:Object = super.convertItem(data);
+			if (obj["query"]["count"] == 0)
+				return "No Data";
+			
+			obj = obj["query"]["results"]["quote"];
+			return obj;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/DataBindingTest/src/controllers/MyController.as
----------------------------------------------------------------------
diff --git a/examples/DataBindingTest/src/controllers/MyController.as b/examples/DataBindingTest/src/controllers/MyController.as
new file mode 100644
index 0000000..83c2cd5
--- /dev/null
+++ b/examples/DataBindingTest/src/controllers/MyController.as
@@ -0,0 +1,81 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package controllers
+{
+	import org.apache.flex.events.Event;
+	
+	import org.apache.flex.core.Application;
+	import org.apache.flex.core.IDocument;
+    
+    import models.MyModel;
+    	
+	public class MyController implements IDocument
+	{
+		public function MyController(app:Application = null)
+		{
+			if (app)
+			{
+				this.app = app as DataBindingTest;
+				app.addEventListener("viewChanged", viewChangeHandler);
+			}
+		}
+		
+        private var queryBegin:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22";
+        private var queryEnd:String = "%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json";
+		private var app:DataBindingTest;
+		
+		private function viewChangeHandler(event:Event):void
+		{
+			app.initialView.addEventListener("buttonClicked", buttonClickHandler);
+			app.initialView.addEventListener("radioClicked", radioClickHandler);
+            app.initialView.addEventListener("listChanged", listChangedHandler);
+		}
+		
+        private function buttonClickHandler(event:Event):void
+        {
+            var sym:String = MyInitialView(app.initialView).symbol;
+            app.service.url = queryBegin + sym + queryEnd;
+            app.service.send();
+            app.service.addEventListener("complete", completeHandler);
+        }
+        
+		private function radioClickHandler(event:Event):void
+		{
+			var field:String = MyInitialView(app.initialView).requestedField;
+			MyModel(app.model).requestedField = field;
+		}
+		
+        private function completeHandler(event:Event):void
+        {
+			MyModel(app.model).responseData = app.collection.getItemAt(0);
+        }
+        
+        private function listChangedHandler(event:Event):void
+        {
+            MyModel(app.model).stockSymbol = MyInitialView(app.initialView).symbol;
+        }
+        
+		public function setDocument(document:Object, id:String = null):void
+		{
+			this.app = document as DataBindingTest;
+			app.addEventListener("viewChanged", viewChangeHandler);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/DataBindingTest/src/models/MyModel.as
----------------------------------------------------------------------
diff --git a/examples/DataBindingTest/src/models/MyModel.as b/examples/DataBindingTest/src/models/MyModel.as
new file mode 100644
index 0000000..c724f4b
--- /dev/null
+++ b/examples/DataBindingTest/src/models/MyModel.as
@@ -0,0 +1,126 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package models
+{
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	
+	public class MyModel extends EventDispatcher
+	{
+		public function MyModel()
+		{
+		}
+		
+		private var _requestedField:String = "Ask";
+		
+		[Bindable("requestedFieldChanged")]
+		public function get requestedField():String
+		{
+			return _requestedField;
+		}
+		
+		public function set requestedField(value:String):void
+		{
+			if (value != _requestedField)
+			{
+				_requestedField = value;
+				dispatchEvent(new Event("requestedFieldChanged"));
+				if (_responseData)
+					dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		private var _responseText:String;
+		
+		[Bindable("responseTextChanged")]
+		public function get responseText():String
+		{
+			if (_responseData == null)
+				return "";
+			if (_responseData == "No Data")
+				return _responseData as String;
+			var s:String = _responseData[_requestedField];
+			if (s == null)
+			{
+				if (_requestedField == "Ask")
+					s = _responseData["Bid"];
+			}
+			return s;
+		}
+		
+		private var _responseData:Object;
+		
+		[Bindable("responseDataChanged")]
+		public function get responseData():Object
+		{
+			return _responseData;
+		}
+		
+		public function set responseData(value:Object):void
+		{
+			if (value != _responseData)
+			{
+				_responseData = value;
+				_allData = "";
+				dispatchEvent(new Event("responseDataChanged"));
+				dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		private var _allData:String = "";
+		
+		[Bindable("responseDataChanged")]
+		public function get allData():String
+		{
+			if (_allData == "" && _responseData != null)
+			{
+				for (var p:String in _responseData)
+				{
+					_allData += p + ": " + _responseData[p] + "\n";
+				}
+			}
+			return _allData;
+		}
+		
+		
+		private var _stockSymbol:String;
+		
+		[Bindable("stockSymbolChanged")]
+		public function get stockSymbol():String
+		{
+			return _stockSymbol;
+		}
+		
+		public function set stockSymbol(value:String):void
+		{
+			if (value != _stockSymbol)
+			{
+				_stockSymbol = value;
+				dispatchEvent(new Event("stockSymbolChanged"));
+			}
+		}
+
+        private var _strings:Array = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
+        public function get strings():Array
+        {
+            return _strings;
+        }
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/StatesTest/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/StatesTest/src/MyInitialView.mxml b/examples/StatesTest/src/MyInitialView.mxml
new file mode 100644
index 0000000..c57c4ff
--- /dev/null
+++ b/examples/StatesTest/src/MyInitialView.mxml
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+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.
+
+-->
+<basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
+				xmlns:basic="library://ns.apache.org/flexjs/basic"
+                xmlns:core="library://ns.apache.org/flexjs/core"
+			    initComplete="initControls()" xmlns:mx="library://ns.adobe.com/flex/mx">
+    <fx:Script>
+        <![CDATA[
+			import models.MyModel;
+			
+			import org.apache.flex.events.CustomEvent;
+			
+			private var _symbol:String;
+			
+            public function get symbol():String
+            {
+                return _symbol;
+            }
+			
+			public function get requestedField():String
+			{
+				return radio1.selectedValue as String;
+			}
+			
+			private function radioChanged(e:org.apache.flex.events.Event):void
+			{
+				dispatchEvent(new CustomEvent("radioClicked"));
+				field.text = RadioButton(e.target).text;
+			}
+			
+			private function initControls():void
+			{
+				list.selectedItem = MyModel(applicationModel).stockSymbol;
+				radio1.selectedValue = MyModel(applicationModel).requestedField;
+				if (radio1.selected)
+					field.text = radio1.text;
+				else if (radio2.selected)
+					field.text = radio2.text;
+				else if (radio3.selected)
+					field.text = radio3.text;
+				else if (radio4.selected)
+					field.text = radio4.text;
+				
+			}
+            
+            private function setState():void
+            {
+                currentState = showAllData.selected ? "showAll" : "hideAll";    
+            }
+		]]>
+    </fx:Script>
+	<fx:Style>
+		@namespace basic "library://ns.apache.org/flexjs/basic";
+		
+		.output {
+			font-size: 20px;
+		}
+
+        .topContainer {
+            padding: 10px;
+            
+        }
+        .leftSide {
+            vertical-align: top;
+            margin-right: 10px;
+        }
+        
+        .rightSide {
+            vertical-align: top;
+            margin-left: 10px;
+            padding-left: 10px;
+        }
+        
+        .quoteButton {
+            margin-top: 10px;
+            margin-bottom: 10px;
+        }
+	</fx:Style>
+    <basic:states>
+        <mx:State name="hideAll" />        
+        <mx:State name="showAll" />        
+    </basic:states>
+    <basic:Container x="0" y="0" className="topContainer" >
+        <basic:beads>
+            <basic:NonVirtualVerticalLayout />
+        </basic:beads>
+        <basic:Label width="300" text="Enter Stock Symbol or choose from list:" />
+        <basic:Container>
+            <basic:beads>
+                <basic:NonVirtualHorizontalLayout />
+            </basic:beads>
+            <basic:Container className="leftSide">
+                <basic:beads>
+                    <basic:NonVirtualVerticalLayout />
+                </basic:beads>
+                <basic:TextInput id="symbolTI" >
+                    <basic:beads>
+                        <basic:SimpleBinding eventName="stockSymbolChanged"
+                                             sourceID="applicationModel"
+                                             sourcePropertyName="stockSymbol"
+                                             destinationPropertyName="text" />
+                    </basic:beads>
+                </basic:TextInput>
+                <basic:TextButton text="Get Quote" className="quoteButton" 
+                                  click="_symbol = symbolTI.text; dispatchEvent(new CustomEvent('buttonClicked'))"
/>
+                <basic:Label id="field" />
+                <basic:Label className="output" height="24">
+                    <basic:beads>
+                        <basic:SimpleBinding eventName="responseTextChanged"
+                                             sourceID="applicationModel"
+                                             sourcePropertyName="responseText"
+                                             destinationPropertyName="text" />
+                    </basic:beads>
+                </basic:Label>
+            </basic:Container>
+            <basic:Container className="rightSide">
+                <basic:beads>
+                    <basic:NonVirtualVerticalLayout />
+                </basic:beads>
+                <basic:DropDownList id="list" width="100" height="17"
+                                    change="_symbol = list.selectedItem as String; dispatchEvent(new
CustomEvent('listChanged'))">
+                    <basic:beads>
+                        <basic:ConstantBinding
+                            sourceID="applicationModel"
+                            sourcePropertyName="strings"
+                            destinationPropertyName="dataProvider" />
+                    </basic:beads>
+                </basic:DropDownList>
+                <basic:RadioButton id="radio1" text="Price" value="Ask" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio2" text="Change" value="Change" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio3" text="Day's High" value="DaysHigh" groupName="group1"
change="radioChanged(event)"/>
+                <basic:RadioButton id="radio4" text="Day's Low" value="DaysLow" groupName="group1"
change="radioChanged(event)"/>
+                <basic:CheckBox id="showAllData" text="Show All Data" change="setState()"
/>
+            </basic:Container>
+        </basic:Container>
+        <basic:Label width="300" text.showAll="110" includeIn="showAll" />
+        <basic:TextArea id="ta" width="300" height="100" height.showAll="110" 
+                        includeIn="showAll">
+            <basic:beads>
+                <basic:SimpleBinding eventName="responseDataChanged"
+                                     sourceID="applicationModel"
+                                     sourcePropertyName="allData"
+                                     destinationPropertyName="text" />
+            </basic:beads>
+        </basic:TextArea>
+    </basic:Container>	
+</basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/StatesTest/src/StatesTest.mxml
----------------------------------------------------------------------
diff --git a/examples/StatesTest/src/StatesTest.mxml b/examples/StatesTest/src/StatesTest.mxml
new file mode 100644
index 0000000..6a76b82
--- /dev/null
+++ b/examples/StatesTest/src/StatesTest.mxml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+                   xmlns:local="*"
+                   xmlns:basic="library://ns.apache.org/flexjs/basic" 
+                   xmlns:models="models.*" 
+                   xmlns:controllers="controllers.*"
+                   initialize="MyModel(model).stockSymbol='ADBE'"
+                   >
+    <basic:valuesImpl>
+        <basic:SimpleCSSValuesImpl />
+    </basic:valuesImpl>
+    <basic:initialView>
+        <local:MyInitialView />
+    </basic:initialView>
+    <basic:model>
+        <models:MyModel />
+    </basic:model>
+    <basic:controller>
+        <controllers:MyController />
+    </basic:controller>
+    <basic:beads>
+        <basic:HTTPService id="service">
+            <basic:LazyCollection id="collection">
+                <basic:inputParser>
+                    <basic:JSONInputParser />
+                </basic:inputParser>
+                <basic:itemConverter>
+                    <local:StockDataJSONItemConverter />
+                </basic:itemConverter> 
+            </basic:LazyCollection>
+        </basic:HTTPService>
+        <basic:ViewSourceContextMenuOption />
+    </basic:beads>
+</basic:Application>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/StatesTest/src/StockDataJSONItemConverter.as
----------------------------------------------------------------------
diff --git a/examples/StatesTest/src/StockDataJSONItemConverter.as b/examples/StatesTest/src/StockDataJSONItemConverter.as
new file mode 100644
index 0000000..b2cb76d
--- /dev/null
+++ b/examples/StatesTest/src/StockDataJSONItemConverter.as
@@ -0,0 +1,22 @@
+package
+{
+    import org.apache.flex.net.JSONItemConverter;
+    
+    public class StockDataJSONItemConverter extends JSONItemConverter
+    {
+        public function StockDataJSONItemConverter()
+        {
+            super();
+        }
+        
+        override public function convertItem(data:String):Object
+        {
+            var obj:Object = super.convertItem(data);
+			if (obj["query"]["count"] == 0)
+				return "No Data";
+			
+			obj = obj["query"]["results"]["quote"];
+			return obj;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/StatesTest/src/controllers/MyController.as
----------------------------------------------------------------------
diff --git a/examples/StatesTest/src/controllers/MyController.as b/examples/StatesTest/src/controllers/MyController.as
new file mode 100644
index 0000000..d6cae7d
--- /dev/null
+++ b/examples/StatesTest/src/controllers/MyController.as
@@ -0,0 +1,81 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package controllers
+{
+	import org.apache.flex.events.Event;
+	
+	import org.apache.flex.core.Application;
+	import org.apache.flex.core.IDocument;
+    
+    import models.MyModel;
+    	
+	public class MyController implements IDocument
+	{
+		public function MyController(app:Application = null)
+		{
+			if (app)
+			{
+				this.app = app as StatesTest;
+				app.addEventListener("viewChanged", viewChangeHandler);
+			}
+		}
+		
+        private var queryBegin:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22";
+        private var queryEnd:String = "%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json";
+		private var app:StatesTest;
+		
+		private function viewChangeHandler(event:Event):void
+		{
+			app.initialView.addEventListener("buttonClicked", buttonClickHandler);
+			app.initialView.addEventListener("radioClicked", radioClickHandler);
+            app.initialView.addEventListener("listChanged", listChangedHandler);
+		}
+		
+        private function buttonClickHandler(event:Event):void
+        {
+            var sym:String = MyInitialView(app.initialView).symbol;
+            app.service.url = queryBegin + sym + queryEnd;
+            app.service.send();
+            app.service.addEventListener("complete", completeHandler);
+        }
+        
+		private function radioClickHandler(event:Event):void
+		{
+			var field:String = MyInitialView(app.initialView).requestedField;
+			MyModel(app.model).requestedField = field;
+		}
+		
+        private function completeHandler(event:Event):void
+        {
+			MyModel(app.model).responseData = app.collection.getItemAt(0);
+        }
+        
+        private function listChangedHandler(event:Event):void
+        {
+            MyModel(app.model).stockSymbol = MyInitialView(app.initialView).symbol;
+        }
+        
+		public function setDocument(document:Object, id:String = null):void
+		{
+			this.app = document as StatesTest;
+			app.addEventListener("viewChanged", viewChangeHandler);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a24f6122/examples/StatesTest/src/models/MyModel.as
----------------------------------------------------------------------
diff --git a/examples/StatesTest/src/models/MyModel.as b/examples/StatesTest/src/models/MyModel.as
new file mode 100644
index 0000000..c724f4b
--- /dev/null
+++ b/examples/StatesTest/src/models/MyModel.as
@@ -0,0 +1,126 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package models
+{
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	
+	public class MyModel extends EventDispatcher
+	{
+		public function MyModel()
+		{
+		}
+		
+		private var _requestedField:String = "Ask";
+		
+		[Bindable("requestedFieldChanged")]
+		public function get requestedField():String
+		{
+			return _requestedField;
+		}
+		
+		public function set requestedField(value:String):void
+		{
+			if (value != _requestedField)
+			{
+				_requestedField = value;
+				dispatchEvent(new Event("requestedFieldChanged"));
+				if (_responseData)
+					dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		private var _responseText:String;
+		
+		[Bindable("responseTextChanged")]
+		public function get responseText():String
+		{
+			if (_responseData == null)
+				return "";
+			if (_responseData == "No Data")
+				return _responseData as String;
+			var s:String = _responseData[_requestedField];
+			if (s == null)
+			{
+				if (_requestedField == "Ask")
+					s = _responseData["Bid"];
+			}
+			return s;
+		}
+		
+		private var _responseData:Object;
+		
+		[Bindable("responseDataChanged")]
+		public function get responseData():Object
+		{
+			return _responseData;
+		}
+		
+		public function set responseData(value:Object):void
+		{
+			if (value != _responseData)
+			{
+				_responseData = value;
+				_allData = "";
+				dispatchEvent(new Event("responseDataChanged"));
+				dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		private var _allData:String = "";
+		
+		[Bindable("responseDataChanged")]
+		public function get allData():String
+		{
+			if (_allData == "" && _responseData != null)
+			{
+				for (var p:String in _responseData)
+				{
+					_allData += p + ": " + _responseData[p] + "\n";
+				}
+			}
+			return _allData;
+		}
+		
+		
+		private var _stockSymbol:String;
+		
+		[Bindable("stockSymbolChanged")]
+		public function get stockSymbol():String
+		{
+			return _stockSymbol;
+		}
+		
+		public function set stockSymbol(value:String):void
+		{
+			if (value != _stockSymbol)
+			{
+				_stockSymbol = value;
+				dispatchEvent(new Event("stockSymbolChanged"));
+			}
+		}
+
+        private var _strings:Array = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
+        public function get strings():Array
+        {
+            return _strings;
+        }
+
+	}
+}
\ No newline at end of file


Mime
View raw message