<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007 - 2009 Adobe
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->
<s:Application
width="100%" height="100%"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:example="example.*"
xmlns:spicefactory="http://www.spicefactory.org/parsley"
xmlns:cairngorm="http://ns.adobe.com/cairngorm">
<fx:Script>
<![CDATA[
import com.adobe.cairngorm.module.BasicLoadPolicy;
import com.adobe.cairngorm.module.ILoadPolicy;
import com.adobe.cairngorm.module.IModuleManager;
import com.adobe.cairngorm.module.ModuleViewLoader;
import com.adobe.cairngorm.module.ModuleViewLoaderSkin;
import example.api.BroadcastMessage;
import example.api.ClearLogMessage;
import example.api.PingMessage;
import example.api.PongMessage;
import mx.logging.LogEventLevel;
import mx.modules.IModuleInfo;
import spark.components.NavigatorContent;
[Bindable]
[Inject(id="moduleA")]
public var moduleA:IModuleManager;
[Bindable]
[Inject(id="moduleB")]
public var moduleB:IModuleManager;
[Bindable]
[Inject(id="moduleC")]
public var moduleC:IModuleManager;
[MessageDispatcher]
public var dispatcher:Function;
[Bindable]
[Inject(id="lazyLoadPolicy")]
public var lazyLoadPolicy:ILoadPolicy;
protected function dispatchPingMessage(moduleId:String = null):void
{
dispatcher(new PingMessage(moduleId));
}
protected function dispatchBroadcastMessage():void
{
dispatcher(new BroadcastMessage());
}
private var moduleCount:int = 50;
protected function button1_clickHandler(event:MouseEvent):void
{
var modulePod:ModulePod = new ModulePod();
modulePod.moduleId = "moduleA" + moduleCount++;
modulePod.percentWidth = 100;
modulePod.percentHeight = 100;
modulePod.label = modulePod.moduleId;
modulePod.moduleManager = moduleA;
tabNavStack.addElement(modulePod);
}
protected function button2_clickHandler(event:MouseEvent):void
{
var modulePod:ModulePod = new ModulePod();
modulePod.moduleId = "moduleB" + moduleCount++;
modulePod.percentWidth = 100;
modulePod.percentHeight = 100;
modulePod.label = modulePod.moduleId;
modulePod.moduleManager = moduleB;
tabNavStack.addElement(modulePod);
}
protected function button3_clickHandler(event:MouseEvent):void
{
var modulePod:ModulePod = new ModulePod();
modulePod.moduleId = "moduleC" + moduleCount++;
modulePod.percentWidth = 100;
modulePod.percentHeight = 100;
modulePod.label = modulePod.moduleId;
modulePod.moduleManager = moduleC;
tabNavStack.addElement(modulePod);
}
]]>
</fx:Script>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
.labelStyle
{
color:#000000
}
s|Label
{
color:#000000;
}
</fx:Style>
<fx:Declarations>
<spicefactory:ContextBuilder>
<cairngorm:CairngormModuleSupport/>
<spicefactory:FlexConfig type="{ CairngormModuleLibSampleContext }"/>
</spicefactory:ContextBuilder>
<mx:TraceTarget level="{ LogEventLevel.DEBUG }"
includeCategory="true">
<mx:filters>
<fx:Array>
<fx:String>com.adobe.cairngorm.*</fx:String>
<fx:String>org.spicefactory.*</fx:String>
</fx:Array>
</mx:filters>
</mx:TraceTarget>
<spicefactory:Configure/>
</fx:Declarations>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<mx:VBox width="100%">
<mx:HBox width="100%">
<mx:Button
label="Ping moduleId:moduleA"
click="dispatchPingMessage('moduleA')"/>
<mx:Button
label="Ping moduleId:moduleA2"
click="dispatchPingMessage('moduleA2')"/>
<mx:Button
label="Ping moduleId:moduleB"
click="dispatchPingMessage('moduleB')"/>
<mx:Button
label="Pong type:ModuleC"
click="dispatcher( new PongMessage() )"/>
<mx:Button
label="Ping all type:ModuleA"
click="dispatchBroadcastMessage()"/>
<mx:Spacer width="20"/>
<mx:Label text="moduleId:" />
<mx:TextInput id="moduleIdInput"
width="150"
text="moduleA2"/>
<mx:Button
label="Ping"
click="dispatchPingMessage(moduleIdInput.text)"/>
<mx:Spacer width="100%"/>
<mx:Button
label="CLEAR ALL LOGS"
click="dispatcher( new ClearLogMessage() )"/>
</mx:HBox>
<mx:HBox width="100%">
<!--<mx:Button label="hide"
click="testB.visible = !testB.visible"/>-->
<mx:Button
label="unload 'moduleA' (calling public method in the loader)"
click="testA.moduleLoader.unloadModule();"/>
<mx:Button
label="reload 'moduleA' (calling public method in the loader)"
click="testA.moduleLoader.loadModule();"/>
<mx:Button
label="unload 'moduleA' (by removing loader from stage)"
click="moduleContainer.removeChild(testA)"/>
<mx:Button
label="reload 'moduleA' (by adding loader back to stage)"
click="moduleContainer.addChildAt(testA,0)"/>
</mx:HBox>
<mx:HBox width="100%">
<mx:Button
label="remove 'moduleA' moduleManager from loader"
click="testA.moduleManager=null"/>
<mx:Button
label="adding 'moduleA' moduleManager to loader"
click="testA.moduleManager=moduleA"/>
</mx:HBox>
<mx:HBox width="100%">
<mx:Button
label="remove 'moduleA' loadPolicy from loader"
click="testA.moduleLoader.loadPolicy=null"/>
<mx:Button
label="adding 'moduleA' BasicLoadPolicy to loader"
click="testA.moduleLoader.loadPolicy=new BasicLoadPolicy()"/>
<mx:Button
label="adding 'moduleA' LazyModuleLoadPolicy to loader"
click="testA.moduleLoader.loadPolicy=lazyLoadPolicy"/>
</mx:HBox>
</mx:VBox>
<mx:HBox id="mainContainer"
width="100%" height="100%">
<mx:VBox id="moduleContainer"
width="350" height="100%">
<example:ModulePod id="testA"
width="100%" height="25%"
label="moduleA"
moduleId="moduleA"
moduleManager="{ moduleA }"/>
<example:LazyModulePod width="100%"
height="25%"
moduleId="moduleA2"
moduleManager="{ moduleA }"
label="moduleA2"/>
<example:Flex3ModulePod width="100%"
height="25%"
moduleId="moduleB"
moduleManager="{ moduleB }"
label="moduleB"/>
<mx:ViewStack id="moduleCStack"
width="100%" height="25%">
<mx:Canvas
width="100%" height="100%">
<mx:Button
horizontalCenter="0"
verticalCenter="0"
label="Instantiate ModuleC"
click="moduleCStack.selectedIndex=1"/>
</mx:Canvas>
<!-- Explicitely not setting the moduleId-->
<example:ModulePod
width="100%" height="100%"
label="moduleC"
moduleManager="{ moduleC }"/>
<!--
<mx:ModuleLoader url="example/moduleC/ModuleC.swf" />
-->
</mx:ViewStack>
</mx:VBox>
<mx:VBox
width="100%" height="100%" borderStyle="solid" borderColor="#000000" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:HBox horizontalAlign="right" width="100%">
<mx:Button
label="Add new instance of ModuleA"
click="button1_clickHandler(event)"/>
<mx:Button
label="Add new instance of ModuleB"
click="button2_clickHandler(event)"/>
<mx:Button
label="Add new instance of ModuleC"
click="button3_clickHandler(event)"/>
</mx:HBox>
<s:TabBar dataProvider="{tabNavStack}"/>
<mx:ViewStack id="tabNavStack"
width="100%" height="100%">
<example:ModulePod
width="100%" height="100%"
label="moduleA3"
moduleId="moduleA3"
moduleManager="{ moduleA }"/>
<example:ModulePod
width="100%" height="100%"
label="moduleA4"
moduleId="moduleA4"
moduleManager="{ moduleA }"/>
</mx:ViewStack>
</mx:VBox>
</mx:HBox>
</s:Application>