<?xml version="1.0" encoding="utf-8"?>
<mc:ModuleTile xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="100%" height="150"
backgroundColor="#000000" backgroundAlpha="1.0"
backgroundImage="@Embed('./Assets/HubbleWallpaperB.jpg')"
backgroundSize="100%"
xmlns:mc="com.adobe.mosaic.core.*"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import com.adobe.mosaic.core.events.Message;
import com.adobe.mosaic.om.interfaces.*;
import com.adobe.mosaic.core.*;
import mx.collections.XMLListCollection;
import mx.events.*;
import mx.events.MenuEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable] private var viewArray:ArrayCollection;
[Bindable] private var panelArray:ArrayCollection;
[Bindable] private var catalogArray:ArrayCollection;
private var globalContext:IContext;
public var cascadeStyles:Dictionary;
[Bindable]
private var menuBarCollection:XMLListCollection;
[Bindable]
private var pingName:String = "";
private var newViews:int = 0;
private var newPanels:int = 0;
private var userViewsCount:int = 0;
// Use this for pointing the application to a new data server
private var defaultServer:String = "http://localhost:8080";
private var currServer:String;
// List of script tests to run; checked automatically on startup.
private var testCatalog:String = "/mosaic/catalogs/galaxy_catalog/resources/";
private var testBatchFile:String = "ScriptTests.xml";
private var testList:ArrayCollection;
private var testIndex:int;
[Bindable] private var currTestsURL:String;
private var menuData:XMLList =
<>
<menuitem label="Add Tiles">
<menuitem label="Ledger" data="Ledger"/>
<menuitem label="LedgerDetail" data="LedgerDetail"/>
<menuitem label="InvoiceDetail" data="InvoiceDetail"/>
<menuitem label="ExpenseReport" data="ExpenseReport"/>
<menuitem label="ExpenseDetail" data="ExpenseDetail"/>
</menuitem>
<menuitem label="Select Language">
<menuitem label="English" data="English" />
<menuitem label="Spanish" data="Spanish" />
<menuitem label="Chinese" data="Chinese" />
</menuitem>
<menuitem label="Select Style">
<menuitem label="iPhone" data="/IphoneStyles.swf" />
<menuitem label="Plain" data="/PlainStyles.swf" />
</menuitem>
<menuitem label="Select Month">
<menuitem label="Aug" data="August" />
<menuitem label="Sep" data="September" />
</menuitem>
<menuitem label="Info">
<menuitem label="About" data="About" />
<menuitem label="Views" data="Views" />
<menuitem label="Panels" data="Panels"/>
<menuitem label="Catalogs" data="Catalogs"/>
<menuitem label="User" data="User" />
<menuitem label="Stylesheets" data="Stylesheets" />
<menuitem label="Image Credits" data="ImageCredits" />
</menuitem>
<menuitem label="Add/Save">
<menuitem label="Add View" data="addView" />
<menuitem label="Add Panel" data="addPanel" />
<menuitem label="Save View" data="saveView1" />
<menuitem label="Save View GUI" data="saveView2" />
<menuitem label="Delete View" data="deleteView" />
</menuitem>
<menuitem label="TestLongMenu">
<menuitem label="item 1" data="test 1" />
<menuitem label="item 2" data="test 2" />
<menuitem label="item 3" data="test 3" />
<menuitem label="item 4" data="test 4" />
<menuitem label="item 5" data="test 5" />
<menuitem label="item 6" data="test 6" />
<menuitem label="item 7" data="test 7" />
<menuitem label="item 8" data="test 8" />
<menuitem label="item 9" data="test 9" />
<menuitem label="item 10" data="test 10" />
</menuitem>
<menuitem label="test" >
<menuitem label="Set Data Server" data="setDataServer" />
<menuitem label="Open DOM Crawler" data="openDOMcrawler" />
<menuitem label="Scripting" data="Scripting" />
</menuitem>
</>;
private function initApp():void {
var env:IEnvironment = this.mosaicApp.environment;
var server:String = env.url;
currServer = server;
menuBarCollection = new XMLListCollection(menuData);
// runtime.setGlobalContextAttribute("currMonth", "August");
var defaultStyle:String = "/IphoneStyles.swf";
globalContext = this.mosaicApp.context;
globalContext.setAttribute("currMonth", "August");
globalContext.setAttribute("currLanguage", "English");
globalContext.setAttribute("currGlobalStyle", defaultStyle);
globalContext.setAttribute("currGalaxyServer",currServer);
// To listen for ping replies...
mosaicApp.addMessageListener("com.adobe.mosaic","pingReply",onPingReply);
// To listen for script test completion...
mosaicApp.addMessageListener("com.adobe.mosaic","testReply",onTestReply);
// We need to check for any script tests in this catalog's resource
// folder. The file should be named "ScriptTests.xml"
//
// Extract each entry (a test script file) and send to Script tile
// We simply call the HTTPService to GET our test list; it's resulthandler
// will send the first message; subsequent tests (messages) are handled
// by the MessageListener "onTestReply"
// Later... we can add menu items to change the Test folder URL and to
// start a new sequence of tests.
// Last thing to do is start HTTPService request for XML data
currTestsURL = currServer + testCatalog + testBatchFile;
srv.send();
}
private function showUserInfo():void {
var uInfo:IUser = this.mosaicApp.user;
var uName:String = uInfo.username;
var uFullName:String = uInfo.fullname;
var uAuth:String = uInfo.authentication;
Alert.show("User Information:" + "\n"
+ "\tuser name:" + uName + "\n"
+ "\tfull name:" + uFullName + "\n"
+ "\tauthentication:" + uAuth, "User", 4, this);
}
private function showEnvironment():void {
var env:IEnvironment = this.mosaicApp.environment;
// env.url, env.version, env.build, env.copyright
Alert.show("Environment Information:" + "\n"
+ "\tURL:" + env.url + "\n"
+ "\tVersion:" + env.version + "\n"
+ "\tBuild:" + env.build + "\n"
+ "\tCopyright:" + env.copyright, "Environment", 4, this);
}
// If a Tile replies to ping, display the reply
// Later we can return more interesting reply data (e.g. what view/panel it is in)
// There are built-in means to find a tile, this is just to exercise the Message
// functionality.
private function onPingReply(message:Message):void {
pingName = message.payload;
}
// When a script test has completed, it signals back here.
// If there are more tests in the list of script files,
// create next URL and send it in another message to the Script tile.
private function onTestReply(message:Message):void {
testIndex++;
var tempStr:String = currServer + testCatalog;
if (testIndex < testList.length){
var obj:Object = testList.getItemAt(testIndex,0);
var testName:String = obj.file.toString();
if ((testName != null)||(testName != "")){
// now we can send a message to Scripting tile
tempStr += testName;
var stringMessage:Message = new Message("com.adobe.mosaic", "runTest", tempStr);
mosaicApp.sendMessage(stringMessage);
}
}
}
// Send a Ping to all active application tiles, if Tile is open it will reply.
// pingName is the id of the Bindable string used for TextArea
private function onPingRequest():void {
var stringData:String = "";
var pingMsg:String = "";
if (tileName.text != ""){
stringData = tileName.text;
pingName = " Pinging: " + stringData;
pingMsg = "ping" + stringData;
var stringMessage:Message = new Message("com.adobe.mosaic", pingMsg, stringData);
mosaicApp.sendMessage(stringMessage);
}
}
private function onMyClick(event:MenuEvent):void{
var menuData:String = event.item.@label;
var currView:IView = this.mosaicApp.activeView;
var currPanel:IPanel = this.mosaicApp.activePanel;
var strTemp:String = "";
var i:int = 0;
switch (menuData){
case "Ledger":
case "LedgerDetail":
case "InvoiceDetail":
case "ExpenseReport":
case "ExpenseDetail":
var c:ICatalog = this.mosaicApp.getCatalog("galaxy_catalog");
var t:ITile = c.getTile(event.item.@label);
mosaicApp.activePanel.addTile(t);
break;
case "English":
case "Spanish":
case "Chinese":
// set global appLanguage attribute for all Tiles to respond.
globalContext.setAttribute("currLanguage", event.item.@data);
break;
case "iPhone":
case "Plain":
// set global appStyle attribute for all Tiles to respond.
var newStyle:String = event.item.@data;
globalContext.setAttribute("currGlobalStyle", newStyle);
break;
case "Aug":
case "Sep":
globalContext.setAttribute("currMonth", event.item.@data);
break;
case "User":
showUserInfo();
break;
case "About":
showEnvironment();
break;
case "Views":
var appViews:Array = this.mosaicApp.views;
var viewsInfo:String = "Application views: \n";
for (i = 0; i < appViews.length; i++){
var view:IView = appViews[i];
viewsInfo += "\t " + view.nodeLabel +
", Num Panels: " + view.childrenNodes.length + "\n";
}
viewsInfo += "\t Active View: " + currView.nodeLabel;
viewsInfo += "\nUser Views: \n";
var userViews:Array = this.mosaicApp.userViews;
if (userViews == null) {
viewsInfo += "\t null user views";
Alert.show(viewsInfo, "Views", 4, this);
break;
}
if (userViews.length == 0){
viewsInfo += "\t user views length = 0";
Alert.show(viewsInfo, "Views", 4, this);
break;
}
for (i = 0; i <userViews.length; i++) {
var uView:IView = userViews[i];
viewsInfo += "\t " + uView.nodeLabel +
", Num Panels: " + uView.childrenNodes.length + "\n";
}
Alert.show(viewsInfo, "Views", 4, this);
break;
case "Panels":
var allPanels:Array = currView.panels;
var numTiles:int = 0;
var panelsInfo:String = "Current view Panels: \n";
for (i = 0; i < allPanels.length; i++){
var panel:IPanel = allPanels[i];
panelsInfo += "\t " + panel.nodeLabel +
", Num Tiles: " + panel.childrenNodes.length + "\n";
numTiles += panel.childrenNodes.length;
}
panelsInfo += "\t Active Panel: " + currPanel.nodeLabel + ", Total tiles: " + numTiles ;
Alert.show(panelsInfo, "Panels", 4, this);
break;
case "Catalogs":
var allCatalogs:Array = this.mosaicApp.catalogs;
var catInfo:String = "Application Catalogs: \n";
for (i = 0; i < allCatalogs.length; i++){
var cat:ICatalog = allCatalogs[i];
catInfo += "\t URI: " + cat.uri + "\n";
}
Alert.show(catInfo, "Catalogs", 4, this);
break;
case "Stylesheets":
var allStyles:Array = this.mosaicApp.stylesheets;
var styleInfo:String = "Application Stylesheets: \n";
for (i = 0; i < allStyles.length; i++){
styleInfo += "\t" + allStyles[i] + "\n";
}
Alert.show(styleInfo, "Stylesheets",4,this);
break;
case "Image Credits":
var imageInfo:String = " Images courtesy of STSci (hubblesite.org)\n";
imageInfo += "\nThe Tadpole Galaxy UGC 10214 \n";
imageInfo += " Credit:NASA, H. Ford (JHU), G. Illingworth (UCSC/LO),";
imageInfo += " M. Clampin (STSci), G. Hartig (STSci), ";
imageInfo += " The ASC Science Team, and ESA\n";
imageInfo += "\nCold Hydrogen Clouds in the Carina Nebula \n";
imageInfo += " Credit:NASA, ESA, N. Smith (University of California,";
imageInfo += " Berkeley) and The Hubble Heritage Team (STSci/AURA) ";
Alert.show(imageInfo, "Image Credits",4,this);
break;
case "Add View":
var vLabel:String;
if (tileName.text != ""){
vLabel = tileName.text + " " + newViews++;
}else {
vLabel = "New View " + newViews++;
}
var vView:Iview = this.mosaicApp.createBlankView();
vView.nodeLabel = vLabel;
this.mosaicApp.addView(vView);
break;
case "Add Panel":
var pLabel:String;
if (tileName.text != ""){
pLabel = tileName.text + " " + newPanels++;
}else {
pLabel = "New Panel " + newPanels++;
}
var pPanel:IPanel = this.mosaicApp.createBlankPanel();
pPanel.nodeLabel = pLabel;
this.mosaicApp.activeView.addPanel(pPanel);
break;
case "Save View" :
if (tileName.text != ""){
strTemp = tileName.text + userViewsCount++;
}else {
strTemp = "userView" + userViewsCount++;
}
currView.save(strTemp, "current view saved from menubar", onSaveUserViewOK, onSaveUserViewFail);
break;
case "Save View GUI" :
currView.requestSave();
break;
case "Delete View" :
var aView:IView;
var allUserViews:Array = this.mosaicApp.userViews;
// just pick first one for now
if (allUserViews.length > 0){
aView = allUserViews[0];
strTemp = aView.nodeLabel;
this.mosaicApp.deleteUserView(aView);
Alert.show("deleted user view: " + strTemp, "Result", 4, this);
} else {
Alert.show("no user views to delete", "Result", 4, this);
}
break;
case "Set Data Server" :
currServer = tileName.text;
globalContext.setAttribute("currGalaxyServer",currServer);
break;
case "Open DOM Crawler" :
var domCatalog:ICatalog = this.mosaicApp.getCatalog("galaxy_catalog");
var domTile:ITile = domCatalog.getTile("DOMCrawler");
mosaicApp.activePanel.addTile(domTile);
break;
case "Scripting" :
var c2:ICatalog = this.mosaicApp.getCatalog("galaxy_catalog");
var t2:ITile = c2.getTile("Scripting");
mosaicApp.activePanel.addTile(t2);
break;
}
}
private function onSaveUserViewOK(event:Event):void {
Alert.show("User View saved OK", "Result", 4, this);
}
private function onSaveUserViewFail(event:Event):void {
Alert.show("User View save FAILED", "Result", 4, this);
}
// get a Script test file (if exists) from catalog resources folder
private function resultHandler(event:ResultEvent):void
{
try {
testList = event.result.batch.test;
var str:String = testList.toString();
if (testList == null) return;
processList(testList);
// Format:
// <batch>
// <test>
// <file>Test1.xml</file>
// </test>
// </batch>
} catch (e:Error){
// Do nothing...
// If there is no batch file of tests, then there is
// nothing to do.
//Alert.show("Try-catch error " + e +" ", "HTTP Service", 4, this);
}
}
// extract first batch script file from the list
private function processList(list:ArrayCollection):void {
testIndex = 0; // keeps track of tests which have run
var tempStr:String = currServer + testCatalog;
var testName:String;
var obj:Object;
if (list.length > 0) {
obj = list.getItemAt(testIndex,0);
testName = obj.file.toString();
if ((testName != null)||(testName != "")){
// now we can send a message to Scripting tile
tempStr += testName;
var stringMessage:Message = new Message("com.adobe.mosaic", "runTest", tempStr);
mosaicApp.sendMessage(stringMessage);
}
}
}
]]>
</mx:Script>
<mx:Style source="Assets/IphoneStyles.css" />
<mx:HTTPService id="srv"
url="{currTestsURL}" result="resultHandler(event)"/>
<mx:VBox >
<mx:Canvas width="100%" height="60" >
<mx:Label text="Galaxy Reports" styleName="ledgerTitles" x="15" y="8" width="238"/>
<mx:MenuBar left="283" top="10" bottom="31" right="86"
labelField="@label" dataProvider="{menuBarCollection}"
cornerRadius="8" borderColor="#000000"
itemClick="{onMyClick(event)}" />
</mx:Canvas>
<mx:HBox>
<mx:Label/>
<mx:Button label="Ping..." click="onPingRequest()"
color="#000000" themeColor="#000000"/>
<mx:TextArea id="tileName" height="50"
editable="true" text="{pingName}" cornerRadius="4" width="180"/>
</mx:HBox>
</mx:VBox>
</mc:ModuleTile>