<?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: SelectOperationType.mxml 3913 2009-06-09 20:43:37Z alitokmen $
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
           horizontalScrollPolicy="off"
           width="100%"
           height="100%"
           creationComplete="registerEventHandlers()">

    <mx:Script>
        <![CDATA[

            import mx.states.*;
            import mx.controls.*;
            import mx.managers.*;
            import mx.events.*;
            import flash.events.*;
            import flash.net.*;
            import org.ow2.jasmine.jadort.client.flex.model.*;
            import org.ow2.jasmine.jadort.client.flex.event.*
            import com.adobe.cairngorm.control.CairngormEventDispatcher;
            import mx.core.UIComponent;
            import mx.collections.ArrayCollection;

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

            [Bindable]
            public var operationData : ArrayCollection = null;

            // initialization of data
            private function registerEventHandlers() : void {
                CairngormEventDispatcher.getInstance().addEventListener(
                    ProgressStateEvent.EVENT_PROGRESS_STATE, updateOperationTypes);

                // Call refresh to fill the list
                updateOperationTypes(null);
            }

            private function updateOperationTypes(evt : ProgressStateEvent) : void {
                var result : ArrayCollection = new ArrayCollection();

                var migrateObj:Object = new Object();
                migrateObj["action"] = "Migrate";
                migrateObj["operationType"] = "Migration";
                migrateObj["explanation"] = "The \"migration\" operation type is designed for deploying "
                    + "new applications (Java EE or OSGi bundles) or for migrating between versions of "
                    + "a given J2EE/Java EE application.\n\n"
                    + "Use this option in order to deploy new applications on this group of or deploy "
                    + "new versions of existing applications.";
                result.addItem(migrateObj);

                var maintainObj:Object = new Object();
                maintainObj["action"] = "Maintain";
                maintainObj["operationType"] = "Maintenance";
                maintainObj["explanation"] = "The \"maintenance\" operation type is designed for maintaining "
                    + "the application server itself (this may also include the applications running on the "
                    + "server). Use this option in order to upgrade your application server, do a physical "
                    + "maintenance on the server and/or change application server.\n\n";
                if (model.selectedGroup != null) {
                    if (model.selectedGroup.hasVms) {
                    maintainObj["explanation"] += "The group you have selected has associated VMs. "
                        + "JaDOrT will therefore be maintaining these VMs.";
                    } else {
                        maintainObj["explanation"] += "As your topology file doesn't specify any VMs for this "
                            + "group, the maintenance operation will be done on the application servers.";
                    }
                }
                result.addItem(maintainObj);

                operationData = result;
            }
        ]]>
    </mx:Script>

    <mx:Grid x="0" y="0" width="100%" height="100%">
        <mx:GridRow width="100%" height="30">
            <mx:GridItem width="100%" height="100%">
                <mx:Label width="100%" color="blue" text="The selected group is &quot;{model.selectedGroup.name}&quot;. Now, specify the operation type:" height="100%" fontSize="11" />
            </mx:GridItem>
        </mx:GridRow>
        <mx:GridRow width="100%" height="100%">
            <mx:GridItem width="100%" height="100%">
                <mx:DataGrid id="selectOperationTypeDG" width="100%"
                    height="{selectOperationTypeDG.measureHeightOfItems(0, operationData.length) + selectOperationTypeDG.headerHeight + 2}"
                    rowCount="{operationData.length}" dataProvider="{operationData}" variableRowHeight="true">
                    <mx:columns >
                        <mx:DataGridColumn width="150" dataField="operationType" headerText="Operation type" />
                        <mx:DataGridColumn dataField="explanation" headerText="Explanation" wordWrap="true" />
                        <mx:DataGridColumn width="100" sortable="false" itemRenderer="org.ow2.jasmine.jadort.client.flex.view.SelectOperationTypeRender" dataField="operationType" headerText="Action" editable="true" />
                    </mx:columns>
                </mx:DataGrid>
            </mx:GridItem>
        </mx:GridRow>
    </mx:Grid>
</mx:Canvas>
