<?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"

 APOC file for Progress Page
-->
<apt:template apt:name="Progress" 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="Progress" apt:label="Progress" >

 <apt:page apt:name="ProgressPage" apt:label="ProgressPage" >

  <apt:section apt:name="progress" apt:label="WELCOME" >
    <apt:property apt:name="TOP_MESSAGE"
                  apt:dataPath=""
                  apt:type="xs:string">
      <apt:prop-value><![CDATA[<HTML><BODY>0%</BODY></HTML>]]></apt:prop-value>
      <apt:visual>
        <apt:htmlPanel/>
      </apt:visual>
    </apt:property>
    <apt:property apt:name="PROGRESS"
        apt:dataPath=""
        apt:type="xs:string">
      <apt:prop-value >0</apt:prop-value>
      <apt:visual>
        <apt:progressBar apt:determinate="true" apt:toolTip="Progress" apt:progressMax="100"/>
      </apt:visual>
    </apt:property>
    <apt:property apt:name="BOTTOM_MESSAGE"
                  apt:dataPath=""
                  apt:type="xs:string">
      <apt:prop-value>$PROGRESS_WAIT</apt:prop-value>
      <apt:visual>
        <apt:htmlPanel/>
      </apt:visual>
    </apt:property>
  </apt:section>
   <apt:scriptHandler apt:scriptLanguage="beanshell">
    <apt:scriptCode><![CDATA[
import org.openinstaller.bus.*;
import org.openinstaller.core.*;
import org.openinstaller.provider.dependency.*;
import org.openinstaller.provider.operation.*;
import org.openinstaller.provider.sims.*;
import org.openinstaller.provider.task.TaskControl.TaskCommand;
import org.openinstaller.util.*;
import java.text.MessageFormat;
import java.util.logging.Logger;

run() {
  // Burn the bridge
  wizard.enableCancel(true);
  wizard.enableHelp(true);
  wizard.setNextButtonText(Msg.get("next", null));
  BusResponse theTaskResp =  Scripting.getInterpreter().get("gSharedResponse");
  while (theTaskResp == null) {
    /* wait for task resp to be set */
    Thread.sleep(500);
  }
  // Get the Progress Bar instance
  theProgressBar = wizard.getComponentByName(content, "PROGRESS");
  theTopMsg = wizard.getComponentByName(content, "TOP_MESSAGE");
  theBottomMsg = wizard.getComponentByName(content, "BOTTOM_MESSAGE");

  ProgressReporter theReporter = null;
  String theOldProgressStr = "";
  String theOldTopMsgStr = "";
  String theOldBottomMsgStr = "";
  String theHtmlStart = "<html><body><font face='Sans-Serif' size='3'>";
  String theHtmlEnd = "</font></body></html>";
  while (theTaskResp.isMore()) {
    theObject = theTaskResp.getResult();
    if (theObject != null) {
      ProgressReporter theProgReporter = (ProgressReporter) theObject;
      if (theProgReporter == theReporter) {
         Thread.sleep(250);
         continue;
      }
      theReporter = theProgReporter;
      theProgressBar.setValue(theProgReporter.totalPercent);
      progressStr = MessageFormat.format("{0,number,percent}", new Object[] {new Double(theProgReporter.totalPercent / 100.0)});

      if (theProgReporter.getEstimatedCompletionTime() >= 0) {
        int hours = theProgReporter.getEstimatedCompletionTime() / 3600;
        int mins = (theProgReporter.getEstimatedCompletionTime() % 3600) / 60;
        int secs = (theProgReporter.getEstimatedCompletionTime() % 3600) % 60;

        progressStr = Msg.get("PROGRESS_COMPLETE",
          new Object[] {
          new Double(theProgReporter.totalPercent / 100.0),
          new Integer(hours),
          new Integer(mins),
          new Integer(secs)});
      }
      if (!theOldProgressStr.equals(progressStr)) {
        theOldProgressStr = progressStr;
        theProgressBar.setString(theOldProgressStr);
        theProgressBar.setStringPainted(true);
      }
      if (!theOldTopMsgStr.equals(theProgReporter.totalString)) {
        theOldTopMsgStr = theHtmlStart + theProgReporter.totalString + theHtmlEnd;
        if (theOldTopMsgStr == null || theOldTopMsgStr.equals("")) {
          theTopMsg.setText("...");
        } else {
          theTopMsg.setText(theOldTopMsgStr);
        }
      }
      if (!theOldBottomMsgStr.equals(theProgReporter.subtotalString)) {
        theOldBottomMsgStr = theHtmlStart + theProgReporter.subtotalString + theHtmlEnd;
        if (theOldBottomMsgStr == null || theOldBottomMsgStr.equals("")) {
          theBottomMsg.setText("...");
        } else {
          theBottomMsg.setText(theOldBottomMsgStr);
        }
      }
    } else {
      LOGGER.fine("Progress information not available yet");
    }
    Thread.sleep(250);
  }
  if (theTaskResp.getException() != null) {
    String theMsg = Msg.get("INTERNAL_FATAL_ERROR",
      new String[]{EnhancedException.getLastCause(theTaskResp.getException()).getLocalizedMessage()});
    JOptionPane.showMessageDialog(frame, theMsg, Msg.get("ERROR", new String[] {}), JOptionPane.ERROR_MESSAGE);
    bus.publishEvent(new BusEvent("shutdown"));
  } else {
    wizard.enableNext(true);
    Thread.sleep(250);
    wizard.clickNext();
  }
}

return (Runnable)this;]]>

    </apt:scriptCode>
  </apt:scriptHandler>
  </apt:page>

  </apt:category>
</apt:template>
