R4EditView.java :  » App » learnandroid » com » lgnortel » network » networkview » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » network » networkview » R4EditView.java
/**
 * 
 */
package com.lgnortel.network.networkview;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.tree.DefaultMutableTreeNode;

import com.lgnortel.lib.view.EmsSwingSet;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.platform.db.DBDataDesc;
import com.lgnortel.platform.db.DBManager;
import com.lgnortel.platform.model.NetworkElement;
import com.lgnortel.platform.model.NetworkMgr;
import com.lgnortel.r4.r4equipment.common.CommandResponseInterface;
import com.lgnortel.r4.r4equipment.navigator.R4NavigatorNode;
import com.lgnortel.r4.r4equipment.navigator.R4NavigatorTableController;
import com.lgnortel.r4.r4equipment.navigator.R4NavigatorTableView;
import com.lgnortel.r4.r4equipment.navigator.R4NavigatorTreeNodeSelectionIF;
import com.lgnortel.r4.r4equipment.navigator.R4NavigatorTreeView;

/**
 * Copyright (c) 2009 LG-Nortel, Inc. All Rights Reserved.
 * 
 * CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
 * third parties embodied herein, contains code, information, data and concepts <br>
 * which are confidential and/or proprietary to LG-Nortel and such third <br>
 * parties. This software is licensed for use solely in accordance with the <br>
 * terms and conditions of the applicable license agreement with LG-Nortel or <br>
 * its authorized distributor, and not for any other use or purpose. No <br>
 * redistribution of this software by any party is permitted. <br>
 * 
 * Title: R4EditView.java<br>
 * Description: <br>
 * Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 * 
 * @author Jonghwa, Lee
 * @version 1.0
 * @created 2009. 12. 7.
 * @modified 2009. 12. 7.
 * @product EFA R4.0 EMS
 * @sw_block Client Block
 */
public class R4EditView extends JPanel implements R4NavigatorTreeNodeSelectionIF, CommandResponseInterface {

  /**
   * 
   */
  private static final long serialVersionUID = 8062652978222833119L;

  private JComboBox cbNode;
  private JComboBox cbSubnet;

  private R4NavigatorTableView navigatorView;
  private R4NavigatorTreeView navigatorTree;

  NetworkMgr networkMgr = NetworkMgr.getInstance();

  private int neId;
  private int viewId;

  public R4EditView(int viewId) {
    this.viewId = viewId;
    initialize();
  }

  private void initialize() {
    JLabel lblSubnet = new JLabel("Subnet");
    JLabel lblNode = new JLabel("Node");

    cbSubnet = new JComboBox();
    cbSubnet.setPreferredSize(new Dimension(150, 25));
    cbSubnet.setMinimumSize(new Dimension(150, 25));
    cbSubnet.setBackground(Color.WHITE);

    cbNode = new JComboBox();
    cbNode.setPreferredSize(new Dimension(150, 25));
    cbNode.setMinimumSize(new Dimension(150, 25));
    cbNode.setBackground(Color.WHITE);

    initializeComboBox();
    cbSubnet.addActionListener(eventHandler);
    cbNode.addActionListener(eventHandler);

    neId = networkMgr.getNeId((String) cbNode.getSelectedItem());

    R4NavigatorTableController controller = new R4NavigatorTableController(neId);
    controller.setViewId(viewId);
    navigatorView = new R4NavigatorTableView(controller);
    navigatorTree = R4NavigatorTreeView.createR4NavigatorTreeView(this);

    JPanel pnlSelection = new JPanel();
    pnlSelection.setLayout(new GridBagLayout());
    pnlSelection.setBorder(EmsSwingSet.createMatteBorder("Select Node"));
    pnlSelection.add(lblSubnet, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
    pnlSelection.add(cbSubnet, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
    pnlSelection.add(lblNode, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
    pnlSelection.add(cbNode, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));

    JPanel pnlRight = new JPanel();
    pnlRight.setLayout(new GridBagLayout());
    pnlRight.add(pnlSelection, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0));
    pnlRight.add(navigatorView, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 1, 1, 1), 0, 0));

    JSplitPane pane = new JSplitPane();
    pane.setLeftComponent(navigatorTree);
    pane.setRightComponent(pnlRight);
    pane.setDividerLocation(300);
    
    this.setLayout(new GridBagLayout());
    this.add(pane, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
  }

  @Override
  public void changeTreeNode(DefaultMutableTreeNode selectedNode) {
    Object obj = selectedNode.getUserObject();
    if (obj instanceof R4NavigatorNode) {
      navigatorView.changeNode(selectedNode);
    }
  }

  private void initializeComboBox() {
    setSubnetList();
    setNodeList(getSubnetId());
    NetworkElement node = networkMgr.getNeNetworkElement(neId);
    if (node == null) {
      cbSubnet.setSelectedItem("ROOT");
      setNodeList(getSubnetId());
    } else {
      NetworkElement subnet = networkMgr.getSubnetNetworkElement(node.parentNodeId);

      String subnetName = "";

      if (subnet == null) {
        subnetName = "ROOT";
      } else {
        subnetName = subnet.getNodeName();
      }

      cbSubnet.setSelectedItem(subnetName);
      cbNode.setSelectedItem(node.getNodeName());
    }
  }

  private int getSubnetId() {
    if (cbSubnet.getSelectedIndex() < 0)
      return 0;

    String nodeName = (String) cbSubnet.getSelectedItem();

    int nodeId = networkMgr.getNodeId(nodeName);

    return nodeId;
  }

  private void setSubnetList() {
    Enumeration<?> e = networkMgr.getSubnet().elements();
    
    List<String> subnets = new ArrayList<String>();
    while (e.hasMoreElements()) {
      NetworkElement subnet = (NetworkElement) e.nextElement();
      subnets.add(subnet.getNodeName());
    }
    cbSubnet.setModel(new DefaultComboBoxModel(subnets.toArray()));
  }

  private void setNodeList(int subnet) {
    cbNode.removeAllItems();

    DBManager dbMgr = DBManager.getInstance();
    Object[] netElement = dbMgr.getNetworkElement();
    
    cbNode.removeActionListener(eventHandler);
    if (netElement != null) {
      Vector<Object> nodeList = new Vector<Object>();
      for (int i = 0; i < netElement.length; i++) {
        NetworkElement temp = (NetworkElement) netElement[i];
        if ((temp.getNodeType() == NetworkElement.NE_TYPE) && (temp.parentNodeId == subnet) && DBDataDesc.R40_SYSTEM_TYPE == temp.getSystemType()) {
          nodeList.add(temp.nodeName);
        }
      }
      cbNode.setModel(new DefaultComboBoxModel(nodeList));
    }
    cbNode.addActionListener(eventHandler);
  }

  private void changeNE() {
    int selectedNeId = networkMgr.getNeId((String) cbNode.getSelectedItem());
    if (selectedNeId != this.neId) {
      try {
        navigatorTree.reload();
        navigatorView.clearTable();
        navigatorView.exchangeNodeId(selectedNeId);
        this.neId = selectedNeId;        
      } catch (Exception e) {
        // to do nothing.
      }
    }
  }

  IvjEventHandler eventHandler = new IvjEventHandler();

  class IvjEventHandler implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      Object src = e.getSource();
      if (cbSubnet == src) {
        setNodeList(getSubnetId());
        changeNE();
      } else if (cbNode == src) {
        changeNE();
      }
    }
  }

  @Override
  public void initializingNavigator() {
    navigatorView.clearTable();
  }

  @Override
  public boolean cmdResponse(int currentCmdCnt, int userId, int nodeId, int cmdCode, Object[] data, int result, String errMessage) {
    navigatorTree.cmdResponse(currentCmdCnt, userId, nodeId, cmdCode, data, result, errMessage);
    navigatorView.cmdResponse(currentCmdCnt, userId, nodeId, cmdCode, data, result, errMessage);
    return true;
  }

  /**
   * @return
   */
  public int getSelectedNeId() {
    return networkMgr.getNeId((String) cbNode.getSelectedItem());
  }

  public Msp getNavigatorTreeData() {
    return navigatorTree.getTreeData();
  }

  /**
   * 
   */
  public void reqeustInitailizeCmd() {
    navigatorView.get();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.