<?xml version="1.0" encoding="utf-8"?>
<!--
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  - JaDOrT: JASMINe Deployment Orchestration Tool
  - Copyright (C) 2008-2009 Bull S.A.S.
  - Copyright (C) 2008-2009 France Telecom R&D
  - Contact: jasmine@ow2.org
  -
  - This library is free software; you can redistribute it and/or
  - modify it under the terms of the GNU Lesser General Public
  - License as published by the Free Software Foundation; either
  - version 2.1 of the License, or any later version.
  -
  - This library is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  - Lesser General Public License for more details.
  -
  - You should have received a copy of the GNU Lesser General Public
  - License along with this library; if not, write to the Free Software
  - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  - USA
  -
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  - $Id: ExecuteMaintenanceCluster.mxml 3663 2009-05-11 15:57:35Z chahinem $
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
           horizontalScrollPolicy="off"
           width="100%"
           height="100%"
           creationComplete="initApp()">

    <mx:Script>
        <![CDATA[
            import org.ow2.jasmine.jadort.client.flex.event.*;
            import org.ow2.jasmine.jadort.client.flex.model.*;
            import com.adobe.cairngorm.control.CairngormEventDispatcher;

            [Bindable]
            public var model : JadortModelLocator = JadortModelLocator.getInstance();

            // initialization of data
            private function initApp() : void {
                CairngormEventDispatcher.getInstance().addEventListener(
                    ServerWorkerProgressEvent.EVENT_SERVER_WORKER_PROGRESS, progressBar);

                // Send the event once in order to refresh the progress bars
                var serverWorkerProgressEvent : ServerWorkerProgressEvent = new ServerWorkerProgressEvent();
                CairngormEventDispatcher.getInstance().dispatchEvent(serverWorkerProgressEvent);
            }

            // progress the global progress bar
            private function progressBar(evt : ServerWorkerProgressEvent) : void {
                if (evt.progressPercent <= 20) {
                    if (evt.progressError) {
                        prog1.setStyle("themeColor", "#ff1a1a");
                    } else {
                        prog1.setStyle("themeColor", "#009dff");
                    }

                    prog1.setProgress(evt.progressPercent*5+1, 100);
                    prog2.setProgress(0, 100);
                    prog3.setProgress(0, 100);
                    prog4.setProgress(0, 100);
                    prog5.setProgress(0, 100);
                } else if (evt.progressPercent <= 40) {
                    if (evt.progressError) {
                        prog2.setStyle("themeColor", "#ff1a1a");
                    } else {
                        prog2.setStyle("themeColor", "#009dff");
                    }

                    prog1.setProgress(100, 100);
                    prog2.setProgress(evt.progressPercent*5-98, 100);
                    prog3.setProgress(0, 100);
                    prog4.setProgress(0, 100);
                    prog5.setProgress(0, 100);
                } else if (evt.progressPercent <= 60) {
                    if (evt.progressError) {
                        prog3.setStyle("themeColor", "#ff1a1a");
                    } else {
                        prog3.setStyle("themeColor", "#009dff");
                    }

                    prog1.setProgress(100, 100);
                    prog2.setProgress(100, 100);
                    prog3.setProgress((evt.progressPercent*5-200), 100);
                    prog4.setProgress(0, 100);
                    prog5.setProgress(0, 100);
                } else if (evt.progressPercent <= 80) {
                    if (evt.progressError) {
                        prog4.setStyle("themeColor", "#ff1a1a");
                    } else {
                        prog4.setStyle("themeColor", "#009dff");
                    }

                    prog1.setProgress(100, 100);
                    prog2.setProgress(100, 100);
                    prog3.setProgress(100, 100);
                    prog4.setProgress((evt.progressPercent*5-300), 100);
                    prog5.setProgress(0, 100);
                } else if (evt.progressPercent <= 100) {
                    if (evt.progressError) {
                        prog5.setStyle("themeColor", "#ff1a1a");
                    } else {
                        prog5.setStyle("themeColor", "#009dff");
                    }

                    prog1.setProgress(100, 100);
                    prog2.setProgress(100, 100);
                    prog3.setProgress(100, 100);
                    prog4.setProgress(100, 100);
                    prog5.setProgress((evt.progressPercent*5-400), 100);
                }
            }
        ]]>
    </mx:Script>

    <mx:Canvas id="progressCanvas" horizontalCenter="3" width="700" y="2" height="74">
        <mx:ProgressBar id="prog1" labelPlacement="center" height="56" width="135" label="" horizontalCenter="-270" verticalCenter="-1" mode="manual" />
        <mx:Label text="Disable Worker" width="113" height="32" textAlign="center" horizontalCenter="-274" verticalCenter="-2" fontWeight="bold" />
        <mx:ProgressBar id="prog2" labelPlacement="center" height="56" width="135" label="" horizontalCenter="-136" verticalCenter="-1" mode="manual" />
        <mx:Label text="Stop Server" width="151" height="32" textAlign="center" horizontalCenter="-139" verticalCenter="-2" fontWeight="bold" />
        <mx:ProgressBar id="prog3" labelPlacement="center" height="56" width="135" label="" horizontalCenter="-2" verticalCenter="-1" mode="manual" />
        <mx:Label text="Maintain Server" width="103" height="32" textAlign="center" horizontalCenter="-4" verticalCenter="-2" fontWeight="bold" />
        <mx:ProgressBar id="prog4" labelPlacement="center" height="56" width="135" label="" horizontalCenter="132" verticalCenter="-1" mode="manual" />
        <mx:Label text="Start Server" width="113" height="32" textAlign="center" horizontalCenter="130" verticalCenter="-2" fontWeight="bold" />
        <mx:ProgressBar id="prog5" labelPlacement="center" height="56" width="135" label="" horizontalCenter="266" verticalCenter="-1" mode="manual" />
        <mx:Label text="Enable Worker" width="113" height="32" textAlign="center" horizontalCenter="260" verticalCenter="-2" fontWeight="bold" />
    </mx:Canvas>
    <mx:DataGrid id="serversCanvas" width="100%" rowCount="{model.serverProgressList.length}" dataProvider="{model.serverProgressList}" textAlign="center" x="0" y="{progressCanvas.height + 20}">
        <mx:columns>
            <mx:DataGridColumn dataField="name" headerText="Server Name" width="100" />
            <mx:DataGridColumn dataField="state" headerText="Status" width="60" />
            <mx:DataGridColumn width="110" dataField="progress" itemRenderer="org.ow2.jasmine.jadort.client.flex.view.ServerWorkerProgressbarItemRenderer" headerText="Progress" />
            <mx:DataGridColumn dataField="state" itemRenderer="org.ow2.jasmine.jadort.client.flex.view.ServerErrorItemRenderer" headerText="Action" editable="true" />
        </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid width="100%" rowCount="{model.workerProgressList.length}" dataProvider="{model.workerProgressList}" textAlign="center" x="0" y="{serversCanvas.y + serversCanvas.height + 20}">
        <mx:columns>
            <mx:DataGridColumn dataField="name" headerText="Worker Name" width="100" />
            <mx:DataGridColumn dataField="state" headerText="Status" width="60" />
            <mx:DataGridColumn width="110" dataField="progress" itemRenderer="org.ow2.jasmine.jadort.client.flex.view.ServerWorkerProgressbarItemRenderer" headerText="Progress" />
            <mx:DataGridColumn dataField="state" itemRenderer="org.ow2.jasmine.jadort.client.flex.view.WorkerErrorItemRenderer" headerText="Action" editable="true" />
        </mx:columns>
    </mx:DataGrid>
</mx:Canvas>
