/*
 * NetworkView.java
 * 
 * Copyright (c) 2003-2004 Digi International
 * This program and the information contained in it is confidential and
 * proprietary to Digi International and may not be used, copied, or re-
 * produced without the prior written permission of Digi International.
 * 
 */

package com.digi.config.ui;

import com.digi.config.core.*;
import com.digi.config.util.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;




/** 
 * This class is a view panel that shows a Network KvpNode 
 * informational panel for the ConnectMe device
 * 
 * This view can be embedded in other panels as desired.
 */

public class NetworkView extends AggregateConfigView {

    /**
     * View Enumerations
     */
    private final int NETWORK_BASIC_VIEW = 0;
    private final int NETWORK_WIRELESS_VIEW = 1;
    private final int NETWORK_WIRELESS_SECURITY_VIEW = 2;
    private final int NETWORK_SERVICES_VIEW = 3;
    private final int NETWORK_ADVANCED_VIEW = 4;

    /**
     * Basic constructor. Sets up the tree view and the edit panel.
     */
    public NetworkView() throws Exception {
        super(true);

        // Add network views
        addView(new NetworkBasicView());
        addView(new NetworkWirelessView());
        addView(new NetworkWirelessSecurityView());
        addView(new NetworkServicesView());
        addView(new NetworkAdvancedView());
    }

    /**
     * Informs view what device to work with. Subclass Views should flush any
     * cached device data and mark current view content as invalid
     * so that it is refreshed appropriatly.
     */
    public void setDevice(Device newDevice) {
        Device oldDevice = device;
        this.device = newDevice;
        if (oldDevice != newDevice) updateViews();
    }

    /**
     * Returns a one word name identifying this view. 
     */
    public String getName() {
        return "NetworkView";
    }

    /**
     * Called when the views need to change primarily due to device changing
     */
    private void updateViews() {
        try {
            // Hide All Views
            hideAllViews();

            // Add Views
            showView((ConfigView) viewList.get(NETWORK_BASIC_VIEW));
    
            // Only Allow Wireless Settings on Wireless Devices
            if (device != null && device.getDeviceModelInfo().getWirelessInterface()) {
                showView((ConfigView) viewList.get(NETWORK_WIRELESS_VIEW));
                showView((ConfigView) viewList.get(NETWORK_WIRELESS_SECURITY_VIEW));
            }

            showView((ConfigView) viewList.get(NETWORK_SERVICES_VIEW));

            // Advanced Tab contains Ethernet-specific Settings
            if (device != null && device.getDeviceModelInfo().getEthernetInterface()) {
                showView((ConfigView) viewList.get(NETWORK_ADVANCED_VIEW));
            }

            // Iterate Views and Set Device
            for (Iterator i=viewList.iterator(); i.hasNext();) {
                ConfigView view = (ConfigView) i.next();
                view.setDevice(device);
            }
        } catch (Exception e) {}
    }
}

