import java.io.*;
import java.util.*;

import com.sun.sysid.core.*;
import com.sun.sysid.panels.*;

import com.sun.wizards.builder.*;
import com.sun.wizards.core.*;
import com.sun.wizards.panels.*;
import com.sun.wizards.nodes.*;
import com.sun.wizards.tasks.*;

/**
 * SysIDBuilder is a builder that builds a Web Start
 * config wizard for the sysid tools.
 */
public class SysIDBuilder extends ArchiveWriter
{
  
  private static String appName = "SysIDConfig";
  
  public SysIDBuilder()
    {
      setArchiveName("sysid");
    }
  
  protected void createClientTree()
    {
      super.createClientTree();
      WizardState wizardState = getWizardState();
      WizardComposite root = getRoot();

      /*
       * Set up all the wizardState Data
       */
      wizardState.setData("hostName", "");
      wizardState.setData("timeZone", "");
      wizardState.setData("subNetMask", "255.255.255.0");
      wizardState.setData("ipAddress", "");
      wizardState.setData("ifName", "");
      wizardState.setData("nameService", "nisplus");
      wizardState.setData("domainName", "");
      wizardState.setData("nameServerName", "");
      wizardState.setData("nameServerAddr", "");
      wizardState.setData("termType", "sun-cmd");
      wizardState.setData("locale", "");
      wizardState.setData("ipv6", "no");
     
      String[] dnsNameServers = new String[3];
      for (int i = 0; i<3; ++i)
	dnsNameServers[i] = "";
      wizardState.setData("DNSnameServers",dnsNameServers);
      String[] dnsSearchList = new String[6];
      for (int i = 0; i< 6; ++i)
	dnsSearchList[i] = "";
      wizardState.setData("DNSsearchList", dnsSearchList);
      
      //wizardState.setData("use24bit", new Boolean(false));
      
      wizardState.setData("skipGet", new Boolean(false));
      wizardState.setData("isNetworked", new Boolean(true));
      wizardState.setData("isStandalone", new Boolean(false));
      wizardState.setData("skipNetworked", new Boolean(false));
      wizardState.setData("isDHCP", new Boolean(false));
      wizardState.setData("skipDHCP", new Boolean(false));
      wizardState.setData("skipIPv6", new Boolean(false));
      wizardState.setData("subNet", new Boolean(true));
      wizardState.setData("skipsubNet", new Boolean(false));
      wizardState.setData("skipNameSvc", new Boolean(false));
      wizardState.setData("skipNIS", new Boolean(true));
      wizardState.setData("skipDNS", new Boolean(true));
      
      wizardState.setData("skipFindSvr", new Boolean(false));
      wizardState.setData("findAServer", new Boolean(true));
      
      wizardState.setData("enableIpv6", new Boolean(false));
      wizardState.setData("skipGeoRegion", new Boolean(true));
      wizardState.setData("skipOffset", new Boolean(true));
      wizardState.setData("skipFile", new Boolean(true));

      wizardState.setData("skipHostname", new Boolean(true));
      
      // Wizard State info for EStar Power Management
      wizardState.setData("skipPM", new Boolean(true));
      wizardState.setData("usePM", new Boolean(false));
      wizardState.setData("eStarOn", new Boolean(true));
      wizardState.setData("askAtReboot", new Boolean(false));
      
      // Wizard state data for Proxy Config
      wizardState.setData("connectSuccess", new Boolean(false));
      wizardState.setData("needsProxy", new Boolean(false));
      wizardState.setData("proxyServer", new String("null"));
      wizardState.setData("proxyPort", new String("null"));
      
      /*
       * Create the tree hierarchy
       */
      WizardComposite node = null;
      WizardComposite getNode = null;
      WizardComposite networkNoDHCPNode = null;
      WizardComposite ipv6Node = null;
      WizardComposite dhcpNode = null;
      WizardComposite hostNameNode = null;
      //      WizardComposite subnetNode = null;
      WizardComposite namesvcNode = null;
      WizardComposite nisNode = null;
      WizardComposite specifyNode = null;
      WizardComposite dnsNode = null;
      WizardComposite findNode = null;
      WizardComposite standaloneNode = null;
      
      /* 
       * Initialize the Panels
       */
      
      // Panels always run from root
      //WizLocalePanel localePanel = new WizLocalePanel(wizardState); 		
      SysWelcomePanel welcomePanel = new SysWelcomePanel(wizardState);
      GetPanel getPanel = new GetPanel(wizardState);
      NetworkedPanel networkedPanel = new NetworkedPanel(wizardState);
      
      DHCPPanel dhcpPanel  = new DHCPPanel(wizardState);

      //Run only if not DHCP
      HostNamePanel hostNamePanel = new HostNamePanel(wizardState);
      
      
      // Run only if networked and not DHCP
      IPAddressPanel ipAddressPanel = new IPAddressPanel(wizardState);
      IPvPanel ipvPanel = new IPvPanel(wizardState);
      
      // For proxy configuration
      ProxyConfigPanel proxyConfig = new ProxyConfigPanel(wizardState);
      
      NameServicePanel nameServicePanel = new NameServicePanel(wizardState);
      DomainNamePanel domainNamePanel = new DomainNamePanel(wizardState);
      FindSpecifyPanel findSpecifyPanel = new FindSpecifyPanel(wizardState);
      NameSvrIDPanel nameSvrIDPanel = new NameSvrIDPanel(wizardState);
      
      SubNetMaskPanel subNetMaskPanel = new SubNetMaskPanel(wizardState);
     
      DnsNameServerPanel dnsNameServerPanel = new DnsNameServerPanel(wizardState);
      DnsSearchListPanel dnsSearchListPanel = new DnsSearchListPanel(wizardState);
      
      // Always Run
      TimeZonePanel timeZonePanel = new TimeZonePanel(wizardState);
      GeoRegionPanel geoRegionPanel = new GeoRegionPanel(wizardState);
      OffsetPanel offsetPanel = new OffsetPanel(wizardState);
      TZFilePanel tzFilePanel = new TZFilePanel(wizardState);
      DateTimePanel dateTimePanel = new DateTimePanel(wizardState);		
      
      // Always Run
      RootPasswdPanel rootPasswdPanel = 
      new RootPasswdPanel(wizardState);
      EStarPanel eStarPanel = new EStarPanel(wizardState);		
      ConfirmPanel confirmPanel = new ConfirmPanel(wizardState);
      
      /*
       * Set up nodes
       */
     
      root.addChild(welcomePanel);
      root.addChild(getNode = new SkipNode(wizardState, "Get",
							      "skipGet"));
      getNode.addChild(getPanel);
      root.addChild(networkedPanel);
      root.addChild(dhcpNode = new SkipNode(wizardState, "DHCP",
					    "skipDHCP"));
      dhcpNode.addChild(dhcpPanel);
      root.addChild(hostNameNode = new SkipNode(wizardState, "Host Name",
							      "skipHostName"));
      hostNameNode.addChild(hostNamePanel);
      
      /*
       * The next whole section will only take place
       * if the system is networked.
       */
      root.addChild(networkNoDHCPNode = new SkipNode(wizardState, 
					       "Host IP Address",
					       "skipNetworked"));
      networkNoDHCPNode.addChild(ipAddressPanel);
      networkNoDHCPNode.addChild(subNetMaskPanel);
      root.addChild(ipv6Node = new SkipNode(wizardState, "IPv6", "skipIPv6"));
      ipv6Node.addChild(ipvPanel);

      //root.addChild(networkSumPanel);
      root.addChild(namesvcNode = new SkipNode(wizardState,
					       "Name Service",
					       "skipNameService"));
      namesvcNode.addChild(nameServicePanel);
      namesvcNode.addChild(nisNode = new SkipNode(wizardState,
							"Domain Name",
							"skipNIS"));
      nisNode.addChild(domainNamePanel);
      nisNode.addChild(findSpecifyPanel);
      nisNode.addChild(specifyNode = new SkipNode(wizardState, "Find Specify",
						  "skipFindSvr"));
      specifyNode.addChild(nameSvrIDPanel);

      // DNS configuration panels
      namesvcNode.addChild(dnsNode = new SkipNode(wizardState,
							"Domain Name",
							"skipDNS"));
      dnsNode.addChild(domainNamePanel);
      dnsNode.addChild(dnsNameServerPanel);
      dnsNode.addChild(dnsSearchListPanel);

      /*
       * The timezone questions should only be asked if
       * a) the system is networked, but cannot find the
       * info on the net or b) the system is not networked.
       */
      
      root.addChild(timeZonePanel);
      root.addChild(node = new SkipNode(wizardState, "Geo Region",
					"skipGeoRegion"));
      node.addChild(geoRegionPanel);
      root.addChild(node = new SkipNode(wizardState, "Offset",
					"skipOffset"));
      node.addChild(offsetPanel);
      root.addChild(node = new SkipNode(wizardState, "File",
					"skipFile"));
      node.addChild(tzFilePanel);
      
      root.addChild(dateTimePanel);		
      root.addChild(rootPasswdPanel);	

      // eStartPanel should only be shown if the hardware is eStar
      // compliant.
      root.addChild(node = new SkipNode(wizardState, "Power Management",
					"skipPM"));
      node.addChild(eStarPanel);
      
      // OLD    root.addChild(eStarPanel);
      root.addChild(proxyConfig);	
      root.addChild(confirmPanel);
    }
  
  public static void main(String args[])
    {
      SysIDBuilder ib = new SysIDBuilder();
      ib.writeArchive();
      System.exit(0);
    }
}
