<?xml version="1.0" encoding="UTF-8"?>
<!--
    DO NOT ALTER OR REMOVE COPYRIGHT NOTICE OR THIS HEADER.

    Copyright 2006, 2007 Sun Microsystems, Inc. All rights reserved.
    Use is subject to license terms.

    The contents of this file are subject to the terms of the Common Development
    and Distribution License("CDDL") (the "License"). You may not use this file
    except in compliance with the License.

    You can obtain a copy of the License at https://openinstaller.dev.java.net/license.html
    or http://openinstaller.dev.java.net/license.txt . See the License for the
    specific language governing permissions and limitations under the License.

    When distributing the Covered Code, include this CDDL Header Notice in each
    file and include the License file at http://openinstaller.dev.java.net/license.txt .
    If applicable, add the following below this CDDL Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyrighted [year] [name of copyright owner]"

    ident "@(#)%Name% %Revision% %Date% SMI"

    This file declares the UI for the Upgrade page.
-->
<apt:template apt:name="Upgrade" xmlns:apt="http://www.sun.com/jds/apoc/2004/template"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:oor="http://openoffice.org/2001/registry"
  xsi:schemaLocation="http://www.sun.com/jds/apoc/2004/template ../../../consumables/schemas/config/apoc/policytemplate.xsd">
 <apt:category apt:name="Upgrade" apt:label="Upgrade page" >

 <apt:page apt:name="Upgrade" apt:label="Upgrade summary" >

  <apt:section apt:name="Upgrade" apt:label="Upgrade summary" >
      <apt:property apt:name="UPGRADE_TEXT"
         apt:dataPath=""
         apt:type="xs:string">
         <apt:prop-value>$UPGRADE_SOFTWARE</apt:prop-value>
         <apt:visual>
            <apt:htmlPanel/>
         </apt:visual>
        </apt:property>
         <apt:property apt:name="UPGRADE_CONTENT"
         apt:dataPath=""
         apt:type="xs:string">
         <apt:prop-value><![CDATA[<HTML><BODY>
         </BODY></HTML>]]></apt:prop-value>
         <apt:visual>
            <apt:textArea apt:rows="9" apt:columns="33" apt:readOnly="true"/>
         </apt:visual>
         </apt:property>
       <apt:property apt:name="ALLOW_UPGRADE"
         apt:dataPath="upgrade.ALLOW_UPGRADE"
         apt:type="xs:string">
       <apt:prop-value>1</apt:prop-value>
       <apt:visual>
          <apt:radioButtons />
       </apt:visual>
       <apt:constraints>
         <apt:enumeration apt:value="0" apt:label="$UPGRADE_ALLOW_TEXT" apt:toolTip="$UPGRADE_ALLOW_TOOLTIP"/>
         <apt:enumeration apt:value="1" apt:label="$UPGRADE_DECLINE_TEXT" apt:toolTip="$UPGRADE_DECLINE_TOOLTIP"/>
       </apt:constraints>
       <apt:scriptHandler apt:scriptLanguage="beanshell">
          <apt:scriptCode ><![CDATA[
            theAcceptAL = new ActionListener() {
              actionPerformed(e) {
                decline = wizard.getComponentByName(content, "1");
                if(decline.isSelected()) {
                  wizard.enableNext(false);
                } else {
                  wizard.enableNext(true);
                }
              }
            };
            return theAcceptAL;]]>
        </apt:scriptCode>
      </apt:scriptHandler>
     </apt:property>

 </apt:section>
  <apt:scriptHandler apt:scriptLanguage="beanshell">
<apt:scriptCode><![CDATA[
import org.openinstaller.provider.ui.sequencer.GlobalPageSequence;
import org.openinstaller.util.Msg;
import org.openinstaller.provider.operation.Operation;
import org.openinstaller.provider.operation.OperationImpossibleException;
import org.openinstaller.provider.operation.Operation.OPTYPE;
import java.util.List;
import java.util.ArrayList;

toProperCase(aString) {
  if (aString == null || aString.equals("")) {
    return "";
  } else if (aString.length() == 1) {
    return aString.toUpperCase();
  }
  return aString.substring(0, 1).toUpperCase() + aString.substring(1).toLowerCase();
}

run () {
 if (! GlobalPageSequence.getCurrentPageName().equals("Upgrade")) {
  return;
 }

 /*Get the container to display the msg */
 upgradeContent = wizard.getComponentByName((Container)content, "UPGRADE_CONTENT");

 /* Get the operation type and NoUpgrade flag */
 Operation.OPTYPE theOpType = (Operation.OPTYPE)Scripting.getInterpreter().get("gOpType");
 boolean theNoUpgradeFlag = (boolean)Scripting.getInterpreter().get("gNoUpgrade");

 /* Get the list of products to upgrade */
 java.util.ArrayList theProductsToUpgrade = (java.util.List)Scripting.getInterpreter().get("gProductsToUpgrade");
 java.util.ArrayList theProductsToNotUpgrade = (java.util.List)Scripting.getInterpreter().get("gProductsToNotUpgrade");

 if (theProductsToUpgrade == null) theProductsToUpgrade = new ArrayList();
 if (theProductsToNotUpgrade == null) theProductsToNotUpgrade = new ArrayList();


 /* Upgrade msg to construct */
 StringBuilder theUpgradeMessage = new StringBuilder();

 if (!theProductsToUpgrade.isEmpty()) {
   /* Give appropriate message based on the NoUgradeFlag */
    if (theNoUpgradeFlag) {
      theUpgradeMessage.append(Msg.get("INSTALLED_PRODUCT_INFO", null));
    } else {
      theUpgradeMessage.append(Msg.get("UPGRADE_MSG", null));
      theUpgradeMessage.append("\n");
      theUpgradeMessage.append(Msg.get("UPGRADE_ALERT", null));
      theUpgradeMessage.append("\n");
    }
    theUpgradeMessage.append("\n");

    /* now add the list of products to ugprade */
    for (String theProdToUpgrade : theProductsToUpgrade) {
      theUpgradeMessage.append("\n");
      theUpgradeMessage.append(theProdToUpgrade);
      theUpgradeMessage.append("\n");
    }
    theUpgradeMessage.append("\n");
  } // isEmpty

  if (theNoUpgradeFlag) {
    if (!theProductsToUpgrade.isEmpty()) {
      theUpgradeMessage.append(Msg.get("INSTALL_CLEANUP_MSG", null));
    }
  } else {
    if (!theProductsToNotUpgrade.isEmpty()) {
      theUpgradeMessage.append(Msg.get("NO_UPGRADE_MSG", null));
      theUpgradeMessage.append("\n");
      for (String theProdToNotUpgrade : theProductsToNotUpgrade) {
        theUpgradeMessage.append("\n");
        theUpgradeMessage.append(theProdToNotUpgrade);
        theUpgradeMessage.append("\n");
      }
      theUpgradeMessage.append("\n");
    }
  }
  theUpgradeMessage.append("\n");
  upgradeContent.setText(theUpgradeMessage.toString());
  upgradeContent.repaint();

  /*
   * Show the content based on what is available for upgrade
   * 1. If there are products to upgrade and products at the same version, then
   *    change the button title to upgrade and show everything.
   * 2. If there are no products to upgrade, do not show the upgrade/do not ugprade checkboxes
   */
  if (theNoUpgradeFlag) {
    wizard.getComponentByName((Container)content, "0").setVisible(false);
    wizard.getComponentByName((Container)content, "1").setVisible(false);
    wizard.enableNext(false);
  } else {
    if ((!theProductsToUpgrade.isEmpty() && !theProductsToNotUpgrade.isEmpty()) ||
         (!theProductsToUpgrade.isEmpty() && theProductsToNotUpgrade.isEmpty()) ) {
      wizard.enableNext(wizard.getComponentByName((Container)content, "0").isSelected());
    } else if (theProductsToUpgrade.isEmpty() && !theProductsToNotUpgrade.isEmpty()) {
      wizard.getComponentByName((Container)content, "0").setVisible(false);
      wizard.getComponentByName((Container)content, "1").setVisible(false);
      wizard.enableNext(true);
    }
  }
  wizard.enableCancel(true);
  wizard.enableHelp(true);
  wizard.enableBack(true);
}
return (Runnable)this;]]></apt:scriptCode></apt:scriptHandler>
 </apt:page>
 </apt:category>
</apt:template>
