<?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 Ready To Uninstall page.
-->
<apt:template apt:name="ReadyToUninstall" 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="ReadyToUninstall" apt:label="Ready To Uninstall" >

 <apt:page apt:name="ReadyToUninstall" apt:label="Ready To Uninstall" >

  <apt:section apt:name="ReadyToUninstall" apt:label="Ready To Uninstall" >
         <apt:property apt:name="TO_OPERATE_ON"
         apt:dataPath=""
         apt:type="xs:string">
         <apt:prop-value><![CDATA[<HTML><BODY>
         </BODY></HTML>]]></apt:prop-value>
         <apt:visual>
            <apt:htmlPanel/>
         </apt:visual>
        </apt:property>
 </apt:section>
  <apt:scriptHandler apt:scriptLanguage="beanshell">
<apt:scriptCode><![CDATA[
import org.openinstaller.provider.ui.sequencer.GlobalPageSequence;
import org.openinstaller.provider.dependency.DependencyControl;
import org.openinstaller.contracts.product.ProductNodeInterface;
import org.openinstaller.provider.sims.SIMSControl;
import org.openinstaller.bus.BusRequest;
import org.openinstaller.sims.SystemProduct;
import org.openinstaller.bus.BusResponse;
import org.openinstaller.bus.ControlBus;
import org.openinstaller.provider.operation.Operation;
import org.openinstaller.provider.operation.ProductMap;
import org.openinstaller.provider.operation.Operation.OPTYPE;
import org.openinstaller.provider.operation.OpsControl;
import org.openinstaller.provider.operation.OpsProvider;
import org.openinstaller.provider.operation.OperationImpossibleException;
import org.openinstaller.provider.operation.Operation.OPTYPE;
import org.openinstaller.provider.sims.SIMSControl.SIMSCommand;
import org.openinstaller.provider.dependency.DependencyProvider;
import org.openinstaller.provider.dependency.MediaProduct;
import org.openinstaller.util.install.Common;
import org.openinstaller.core.*;
import java.util.HashSet;

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("ReadyToUninstall")) {
    return;
  }

  toOperateOn = wizard.getComponentByName((Container)content, "TO_OPERATE_ON");
  theOperations = (java.util.List )Scripting.getInterpreter().get("gOperations");
  String theProductList = "<HTML><body><font face='Sans-Serif' size='3'>";
  theProductList = theProductList +(String)TemplateProcessor.getInstance().getFromDataModel("PRODUCT_NAME")+"<ul>";
  //  FIXME: This is temporary solution to remove duplicate operation entries.
  theSeenSet = new HashSet();
  for (Operation op : theOperations) {
    if (op.getOperation() == Operation.OPTYPE.UNREGISTER @and op.getSystemProduct() != null) {
      theID = op.getSystemProduct().getID();
      theName = op.getSystemProduct().getShortDescription();
      theDesc = op.getSystemProduct().getDescription();
      if (!theSeenSet.contains(theID)) {
        theProductList = theProductList + "<li>" + Msg.get("uninstall", new Object[]{theName.equals("")?theID:theName});
        theSeenSet.add(theID);
      }
    } else if (op.getOperation() == Operation.OPTYPE.REGISTER @and op.getMediaPackage() == null @and op.getMediaProduct() != null) {
      theID = op.getMediaProduct().getID();
      theName = op.getMediaProduct().getShortDescription();
      theDesc = op.getMediaProduct().getDescription();
      if (!theSeenSet.contains(theID)) {
        theProductList = theProductList +"<li>" + Msg.get("install", new Object[]{theName.equals("")?theID:theName});
        theSeenSet.add(theID);
      }
    } else if (op.getOperation() == Operation.OPTYPE.CONFIGURE @and op.getMediaProduct() != null) {
      theID = op.getMediaProduct().getID();
      theName = op.getMediaProduct().getShortDescription();
      theDesc = op.getMediaProduct().getDescription();
      if (!theSeenSet.contains(theID)) {
        theProductList = theProductList +"<li>" + Msg.get("configure", new Object[]{theName.equals("")?theID:theName});
        theSeenSet.add(theID);
      }
    } else if (op.getOperation() == Operation.OPTYPE.UNCONFIGURE @and op.getSystemProduct() != null) {
      theID = op.getSystemProduct().getName();
      theName = op.getSystemProduct().getShortDescription();
      theDesc = op.getSystemProduct().getDescription();
      theProductList = theProductList +"<li>" + Msg.get("unconfigure", new Object[]{theName.equals("")?theID:theName});
    } else if (op.getOperation() == Operation.OPTYPE.REPAIR @and op.getMediaProduct() != null @and op.getSystemProduct() != null) {
      theID = op.getMediaProduct().getID();
      theName = op.getMediaProduct().getShortDescription();
      theDesc = op.getMediaProduct().getDescription();
      if (!theSeenSet.contains(theID)) {
        theProductList = theProductList +"<li>" + Msg.get("repair", new Object[]{theName.equals("")?theID:theName});
      }
    }
  }
  theProductList += "</ul></font></body></HTML>";
  toOperateOn.setText(theProductList);
  toOperateOn.repaint();

  /* get processing mode */
  String theMode = Common.getProcessingMode();
  String theOpName;
  if (theMode.equals("INSTALL") || theMode.equals("REMOVE")) {
    theOpName = Enum.valueOf(Operation.OPTYPE.class, theMode).name();
  } else {
    throw new EnhancedException("UNEXPECTED_PROCESSING_MODE", "mode=" + theMode);
  }

  wizard.setNextButtonText(Msg.get(theOpName, new String[] {}));
  wizard.enableCancel(true);
  wizard.enableHelp(true);
  wizard.enableNext(true);
}
return (Runnable)this;]]></apt:scriptCode></apt:scriptHandler>
 </apt:page>
 </apt:category>
</apt:template>
