package com.sun.solarisinstall.panels;

//
// Copyright (c) 1997 Sun Microsystems, Inc., all rights reserved.
//
//
// a very simple Error class

import java.util.Vector;
import java.awt.*;


public class SolarisWebStartError {

  public static final int SUCCESS		    = 0;
  public static final int PROD_NEEDS_MORE_OS	    = 1;
  public static final int CORE_OS_NOT_VALID	    = 2;
  public static final int OS_NOT_VALID		    = 3;
  public static final int NOT_ENOUGH_FS_SPACE	    = 4;
  public static final int MISSING_PROD_DEPEND	    = 5;
  public static final int BAD_FS_SIZE		    = 6;
  public static final int CANT_DELETE_FS	    = 7;
  public static final int CANT_CHANGE_FS_SIZE	    = 8;
  public static final int PRODS_CANT_HAVE_CORE	    = 9;
  public static final int HIT_PROD_LOCALE_DEPEND    = 10;
  public static final int HIT_OS_LOCALE_DEPEND      = 11;
  public static final int NEED_MORE_AC_SPACE        = 12;

  private Vector v;
  private int errorCode;


  public SolarisWebStartError() {
      reset();
  }

  public Vector getInfoVector() {
    return (v);
  }

  public int getErrorCode() {
    return (errorCode);
  }

  public void setErrorCode(int newValue) {
    errorCode = newValue;
  }

  public void reset() {
      errorCode = SUCCESS;
      v = new Vector();
  }

  public void appendInfo (Object o) {
      v.addElement(o);
  }

  public void setInfoAt (Object o, int index) {
      v.setElementAt(o, index);
  }

  public int getInfoSize() {
      return v.size();
  }

  public boolean hasError() {
      boolean result = false;

      if (errorCode != SUCCESS) {
	  result = true;
      }

      return (result);
  }


  public void setDisplayMsg(TextArea tp) {
    //
    // commented out until we figure out how to integrate Merlin's
    // internationalization scheme with this code
    //
/*

      switch (errorCode) {
	  case CORE_OS_NOT_VALID:
	      tp.addText (msgCatalog.getMessage ("If you select the Core Solaris Software Group, Solaris Web Start will be unable to install any co-packaged software products. This is because Solaris Web Start requires Java, which is not present in the Core Solaris Software Group."));
	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("If you want to install the Core Solaris Software Group and not install any co-packaged products, click OK."));
	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("If you want to install the selected products with a different Solaris software group, click Cancel."));
       	      break;

	  case OS_NOT_VALID:
	      String requiredOS = (String) v.elementAt(0);
	      String selectedOS = (String) v.elementAt(1);
	      tp.setListItemPrefix("      ");

	      tp.addText (msgCatalog.getMessage ("The following co-packaged software product(s) require a different Solaris software group from the one you have selected."));
	      for (int i = 2; i < v.size(); i++) {
		  tp.addListItem((String) v.elementAt(i));
              }

	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("If you want to install the ''{0}'' and not install the products above, click OK.",
		  selectedOS));
	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("If you want to retain the above products, click Cancel."));
	      break;

	  case NOT_ENOUGH_FS_SPACE:
	      String reqSize = (String) v.elementAt(0);
	      String totalSize = (String) v.elementAt(1);

	      tp.addText (msgCatalog.getMessage ("Sorry, the selected software cannot be installed because there is not enough disk space."));
	      break;
		
	  case PROD_NEEDS_MORE_OS:
	      String minOS        = (String) v.elementAt(0);
	      String curOS        = (String) v.elementAt(1);
	      String selectedProd = (String) v.elementAt(2);

	      tp.addText (msgCatalog.getFormattedMessage ("This product, {0}, requires the ''{1}''.  You currently have the ''{2}'' selected.",
		  selectedProd, minOS, curOS));
	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("If you would like to install this product with the required Solaris software group, click OK."));
	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("If you would like to retain the ''{0}'' and not install {1}, click Cancel.",
		  curOS, selectedProd));
	      break;

	  case MISSING_PROD_DEPEND:
	      String prodName = (String) v.elementAt(0);
	      String prodDependency = (String) v.elementAt(1);
	      tp.addText (msgCatalog.getFormattedMessage ("Selecting ''{0}'' requires that you select ''{1}''.",
		  prodName, prodDependency));
	      break;

	  case BAD_FS_SIZE:
	      tp.setListItemPrefix("      ");
	      tp.addText (msgCatalog.getMessage ("This software requires that you increase the size of one or more file systems:"));

	      for (int i = 0; i < v.size(); i++) {
	          String fsName = (String) v.elementAt(i);
		  i++;
	          reqSize = (String) v.elementAt(i);
		  i++;
	          String allocedSize = (String) v.elementAt(i);

		  tp.addListItem(msgCatalog.getFormattedMessage("''{0}'' must be {1} MB (currently {2})",
		      fsName, reqSize, allocedSize));
              }

	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("Return to the Lay Out File Systems Step to set these file systems to the correct sizes."));
	      break;

	  case CANT_DELETE_FS:
	      String fsName = (String) v.elementAt(0);
	      tp.addText (msgCatalog.getFormattedMessage ("Cannot delete file system ''{0}''.",
		  fsName));
	      break;


	  case CANT_CHANGE_FS_SIZE:
	      String newSize = (String) v.elementAt(0);
	      tp.addText (msgCatalog.getFormattedMessage ("Cannot change file system size to ''{0}''; use ''delete'' instead.",
		  newSize));
	      break;


	  case PRODS_CANT_HAVE_CORE:
	      minOS        = (String) v.elementAt(0);
	      curOS        = (String) v.elementAt(1);

	      tp.addText (msgCatalog.getMessage ("Since you selected the Core Solaris Software Group, Solaris Web Start will be unable to install any co-packaged software products. This is because Solaris Web Start requires Java, which is not present in the Core Solaris Software Group."));
	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("If you would like to install this product with the {0}, click OK.", minOS));
	      tp.addBreak();
	      tp.addText (msgCatalog.getMessage ("If you would like to retain the Core Solaris Software Group, click Cancel."));
	      break;

	  case HIT_PROD_LOCALE_DEPEND:
	      String locale = (String) v.elementAt(0);
	      tp.setListItemPrefix("      ");

	      tp.addText (msgCatalog.getFormattedMessage ("The following products also have ''{0}'' versions which cannot be installed unless you also install the ''{1}'' version of Solaris.", 
		  locale, locale));

	      for (int i = 1; i < v.size(); i++) {
		  Product depProd = (Product) v.elementAt(i);
		  tp.addListItem(depProd.getName());
              }

	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("If you want to install the above products without their ''{0}'' versions, click OK.",
		  locale));
	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("If you want to retain ''{0}'' versions of Solaris and the above products, click Cancel.", 
		  locale));
	      break;


	  case HIT_OS_LOCALE_DEPEND:
	      locale       = (String) v.elementAt(0);
	      curOS        = (String) v.elementAt(1);
	      prodName     = (String) v.elementAt(2);
	      tp.setListItemPrefix("      ");

	      tp.addText (msgCatalog.getFormattedMessage ("To install the ''{0}'' version of this product (or any other co-packaged software product), you must also install the ''{1}'' version of Solaris.", 
		  locale, locale));

	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("To install the ''{0}'' versions of this product and Solaris, click OK.",
		  locale));
	      tp.addBreak();
	      tp.addText (msgCatalog.getFormattedMessage ("To forget about installing the ''{0}'' version of this software, click Cancel.",
		  locale));
	      break;

	  case NEED_MORE_AC_SPACE:
	      tp.setListItemPrefix("      ");
	      tp.addText (msgCatalog.getMessage ("The following problem(s) exist with the client configuration you've selected:"));

	      for (int i = 0; i < v.size(); i++) {
	          String typeOfSpace = (String) v.elementAt(i);
		  i++;
	          fsName = (String) v.elementAt(i);
		  i++;
	          reqSize = (String) v.elementAt(i);
		  i++;
		  String actionType = (String) v.elementAt(i);

		  String args[] = new String[4];
		  args[0] = typeOfSpace;
		  args[1] = fsName;
		  args[2] = fsName;
		  args[3] = reqSize;

		  if (actionType.equalsIgnoreCase("create")) {
		      tp.addListItem(msgCatalog.getFormattedMessage("Client {0} space in {1} does not exist.  We recommend that you create an {2} file system of at least {3} MB.",
		          args));
		  } else {
		      tp.addListItem(msgCatalog.getFormattedMessage("Client {0} space in {1} is too small.  We recommend that you increase the {2} file system size to at least {3} MB.",
		          args));
		  }

	          tp.addBreak();
              }

	      tp.addText (msgCatalog.getMessage ("Return to the Lay Out File Systems Step to make any needed changes."));
	      break;

      }
*/
  }

}

