PotsComplexView.java :  » App » learnandroid » com » lgnortel » r4 » r4equipment » management » ont » pots » pots » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » r4 » r4equipment » management » ont » pots » pots » PotsComplexView.java
/**
 * 
 */
package com.lgnortel.r4.r4equipment.management.ont.pots.pots;

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.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;

import javax.swing.JButton;
import javax.swing.JPanel;

import com.lgnortel.lib.help.HelpTargetConst;
import com.lgnortel.netconf.wdmpon.JinterfacePots;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Ont;
import com.lgnortel.netconf.wdmpon.OntJinterface;
import com.lgnortel.netconf.wdmpon.OntPots;
import com.lgnortel.netconf.wdmpon.PonAccess;
import com.lgnortel.network.networkview.ErrorInspect;
import com.lgnortel.network.networkview.MessagePanel;
import com.lgnortel.network.networkview.User;
import com.lgnortel.r4.r4equipment.common.ComplexChildView;
import com.lgnortel.r4.r4equipment.common.ComplexViewKeyMap;
import com.lgnortel.r4.r4equipment.common.ComplexViewParentIF;
import com.lgnortel.r4.r4equipment.common.DefaultManagementView;
import com.lgnortel.r4.r4equipment.common.DuplicateKeyException;
import com.lgnortel.r4.r4equipment.common.ManagementComplexControllerIF;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ManagementTableIF;
import com.lgnortel.r4.r4equipment.common.R4CommonUtil;
import com.lgnortel.r4.r4equipment.common.R4HelpButton;
import com.lgnortel.r4.r4equipment.common.R4RefreshButton;
import com.lgnortel.r4.r4equipment.common.R4SetButton;
import com.lgnortel.r4.r4equipment.common.R4TableModel;
import com.lgnortel.r4.r4equipment.common.SimpleChildView;
import com.lgnortel.r4.r4equipment.common.WrongParameterException;
import com.lgnortel.r4.r4equipment.management.ont.PonAccessOntModel;
import com.lgnortel.r4.r4equipment.management.ont.PonAccessOntView;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.lgnortel.rmi.common.ClientManager;
import com.lgnortel.rmi.common.EmsCode;
import com.tailf.inm.ElementChildrenIterator;
import com.tailf.inm.INMException;

/**
 * Copyright (c) 2008 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: PotsComplexView.java<br>
 * Description: Menu >> OLT >> POTS >> POTS menu and node item.<br>
 * Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 * 
 * @author Jonghwa, Lee
 * @version 0.1
 * @created 2009. 5. 20.
 * @modified 2009. 5. 20.
 * @product EFA R4.0 EMS
 * @sw_block Client Block
 */
public class PotsComplexView extends DefaultManagementView implements ManagementComplexControllerIF, ComplexViewParentIF {
  /**
   * 
   */
  private static final long serialVersionUID = -7365762999315022740L;
  private ManagementComplexModelIF modelPots;
  private ManagementComplexModelIF modelCalling;
  private ManagementComplexModelIF modelVoice;
  private ManagementComplexModelIF modelTest;
//  private ManagementComplexModelIF modelStats;
  private ManagementTableIF modelOperPots;

  private PonAccessOntView pnlPon;
  private PotsView pnlPots;
  private ComplexChildView pnlCalling;
  private ComplexChildView pnlVoice;
  private ComplexChildView pnlTest;
//  private ComplexChildView pnlStats;
  private SimpleChildView pnlOperPots;

  private boolean isSetClicked;
  Object[] resultData;
  private int viewId;
  private int neId;

  private ClientManager clientManager = ClientManager.getInstance();
  private User user = User.getInstance();

  protected MessagePanel pnlSetResult;

  public PotsComplexView(int neId, String title) {
    super();
    this.neId = neId;
    this.sTitle = title;
    initialize();
  }

  @Override
  protected JPanel createMainPanel() {
    controller = new PonAccessOntModel();
    modelPots = new PotsModel();
    modelCalling = new PotsCallingFeauresModel();
    modelVoice = new PotsVoiceProcessingModel();
    modelTest = new PotsTestModel();
//    modelStats = new PotsStatsModel();
    modelOperPots = new OperOntPotsModel();

    pnlPon = new PonAccessOntView("PON Access ONT", controller, this, neId);
    pnlPots = new PotsView("POTS", modelPots, this);
    pnlCalling = new ComplexChildView("POTS Calling Features", modelCalling);
    pnlVoice = new ComplexChildView("POTS Voice Processing", modelVoice);
    pnlTest = new ComplexChildView("POTS Test", modelTest);
//    pnlStats = new ComplexChildView("POTS Stats", modelStats);
    pnlOperPots = new SimpleChildView("Show POTS", modelOperPots);
    pnlOperPots.setStatusPanel();

    btnRefresh = new R4RefreshButton();
    btnRefresh.addActionListener(handler);

    pnlSetResult = new MessagePanel(this);
    pnlSetResult.setBorder(null);

    btnSet = new R4SetButton();
    btnSet.addActionListener(handler);

    if (User.getInstance().getUserGrp() == User.MONITOR) {
      btnSet.setEnabled(false);
    }

    JPanel pnlSet = new JPanel();
    pnlSet.setLayout(new GridBagLayout());
    pnlSet.add(pnlSetResult, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 10), 0, 0));
    pnlSet.add(btnSet, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0));
    pnlSet.add(btnRefresh, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0));

    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.add(pnlPon, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlPots, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.15, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlCalling, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.12, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlVoice, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.05, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlTest, new GridBagConstraints(2, 3, 1, 1, 1.0, 0.05, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
//    panel.add(pnlStats, new GridBagConstraints(1, 4, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlSet, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(pnlOperPots, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.15, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));

    return panel;
  }

  @Override
  protected JPanel createResultPanel() {
    btnHelp = new R4HelpButton();
    btnHelp.addActionListener(handler);

    pnlResult = new MessagePanel(this);
    pnlResult.setBorder(null);

    JButton btnRefresh = new R4RefreshButton();
    btnRefresh.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        refreshOntPotsStatus();
      }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.add(pnlResult, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 10), 0, 0));
    panel.add(btnHelp, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
    panel.add(btnRefresh, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
    return panel;
  }

  public void requestInitializeCmd() {
    pnlPon.get();
  }

  @Override
  public void get() {
    Map<String, Object> ponKey = pnlPon.getSelectedRowKey();
    if (!R4CommonUtil.isEmptyMap(ponKey)) {
      removeKey(ponKey);

      saveAndRefreshPotsTable(ponKey);
    } 
  }

  private void refreshOntPotsStatus() {
    Msp filter = new Msp();
    Map<String, Object> key = pnlPon.getSelectedRowKey();
    if (R4CommonUtil.isEmptyMap(key)) {
      return;
    }

    String name = key.get(R4Constants.PON_ACCESS_ONT_KEY_NAME).toString();
    try {
      OntPots ontPots = new OntPots();
      if (R4Util.isExistingField(name)) {
        ontPots.setOntNameValue(name);
      }
      filter.addOper().addOntPots(ontPots);
      Object[] data = new Object[1];
      data[0] = filter;
      clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_GETFILTER, data, "");
    } catch (INMException e) {
      logger.info("Exception = " + e.getMessage());
    }
  }

  @Override
  public boolean cmdResponse(int viewId, int userId, int nodeId, int cmdCode, Object[] data, int result, String errMessage) {
    if (isSetClicked) {
      if (ErrorInspect.SUCCESS == result) {
        pnlPon.get();
      }
      pnlSetResult.updateMessage(errMessage);
      isSetClicked = false;
    } else {
      if (pnlPon.cmdResponse(viewId, userId, nodeId, cmdCode, data, result, errMessage)) {
        resultData = data;
        removeAllChildInfo();
        get();
      } else {
        pnlOperPots.cmdResponse(viewId, userId, nodeId, cmdCode, data, result, errMessage);
        R4TableModel model = pnlOperPots.getModel();
        if (model.getRowCount() == 0) {
          pnlResult.updateMessage("No Data ...");
        } else {
          pnlResult.updateMessage(errMessage);          
        }
      }
    }

    return true;
  }

  @Override
  protected void set() {
    try {
      pnlPon.checkTableValues();
      pnlPots.checkTableValues();
      pnlCalling.checkTableValues();
      pnlVoice.checkTableValues();
      pnlTest.checkTableValues();
//      pnlStats.checkTableValues();

      Msp msp = null;
      if (resultData.length == 2) {
        msp = (Msp) ((Msp) resultData[1]).clone();
      } else {
        msp = new Msp();
      }

      Msp newData = new Msp();
      PonAccess ponaccess = new PonAccess();
      newData.addPonAccess(ponaccess);

      ComplexViewKeyMap potsMap = pnlPots.getChildrenInfo();
      ComplexViewKeyMap callingMap = pnlCalling.getChildrenInfo();
      ComplexViewKeyMap voiceMap = pnlVoice.getChildrenInfo();
      ComplexViewKeyMap testMap = pnlTest.getChildrenInfo();
//      ComplexViewKeyMap statsMap = pnlStats.getChildrenInfo();

      Map<Integer, Map<String, Object>> ontKeyList = potsMap.getKeyMap();
      if (R4CommonUtil.isEmptyMap(ontKeyList)) {
        R4CommonUtil.displayConfirmDialog(this, sTitle, "Executable data does not exist !!");
        return;
      }

      for (Map<String, Object> ontKey : ontKeyList.values()) {
        if (R4CommonUtil.isEmptyMap(ontKey)) {
          continue;
        }
        String ontName = ontKey.get(R4Constants.PON_ACCESS_ONT_KEY_NAME).toString();

        deleteOntChild(msp, ontName);

        List<Map<String, Object>> potsTable = potsMap.getTable(ontKey);
        msp = modelPots.addTableInfoToMsp(msp, potsTable, ontKey);

        List<Map<String, Object>> potsKeyList = pnlPots.getTableKeyRows(potsTable);

        for (Map<String, Object> vlanKey : potsKeyList) {
          Map<String, Object> copyVlanKey = new TreeMap<String, Object>(vlanKey);
          copyVlanKey.putAll(ontKey);
          msp = modelCalling.addTableInfoToMsp(msp, callingMap.getTable(copyVlanKey), copyVlanKey);
          msp = modelVoice.addTableInfoToMsp(msp, voiceMap.getTable(copyVlanKey), copyVlanKey);
          msp = modelTest.addTableInfoToMsp(msp, testMap.getTable(copyVlanKey), copyVlanKey);
//          msp = modelStats.addTableInfoToMsp(msp, statsMap.getTable(copyVlanKey), copyVlanKey);
        }
        try {
          Ont newOnt = msp.ponAccess.getOnt(ontName);
          ponaccess.addOnt((Ont) newOnt.clone());
        } catch (Exception e) {
          continue;
        }
      }

      logger.info("msp ==> \n" + newData.toXMLString());

      if (R4CommonUtil.displayQuestionDialog(this, sTitle, "Do you want to execute?")) {
        this.set(newData);
        isSetClicked = true;
      }
    } catch (WrongParameterException we) {
      R4CommonUtil.displayConfirmDialog(this, sTitle, we.getDisplayMessage());
      logger.info("Parameter value is wrong !! " + we.getMessage());
    } catch (DuplicateKeyException dc) {
      R4CommonUtil.displayConfirmDialog(this, sTitle, dc.getDisplayMessage());
      logger.info("Duplicated key exists !! : " + dc.getMessage());
    } catch (Exception e) {
      R4CommonUtil.displayConfirmDialog(this, sTitle, "Internal Error!");
      logger.log(Level.SEVERE, "Execute failed!", e);
    }
  }

  private void deleteOntChild(Msp msp, String ontName) {
    if (msp.ponAccess == null) {
      return;
    }

    Ont ont = null;
    try {
      ont = msp.ponAccess.getOnt(ontName);
    } catch (INMException e1) {
      return;
    }

    if (ont == null) {
      return;
    }

    List<String> potsIdList = new ArrayList<String>();
    OntJinterface jinterface = ont.jinterface;
    for (ElementChildrenIterator potsChildren = jinterface.potsIterator(); potsChildren.hasNext();) {
      JinterfacePots pots = (JinterfacePots) potsChildren.next();
      try {
        potsIdList.add(pots.getIdValue().toString());
      } catch (INMException e) {
        continue;
      }
    }

    for (String potsId : potsIdList) {
      try {
        jinterface.deletePots(potsId);
      } catch (INMException e) {
        continue;
      }
    }
  }

  @Override
  public void set(Msp msp) {
    Msp filter = getFilter();
    Object[] data = new Object[2];
    data[0] = filter;
    data[1] = msp;
    clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_AUDIT, data, "");

  }

  @Override
  public String getHelpFilePath() {
    return HelpTargetConst.R4_ONT_POTS;
  }

  @Override
  public Msp getFilter() {
    Msp filter = new Msp();
    try {
      PonAccess ponAccess = new PonAccess();
      filter.addPonAccess(ponAccess);
      ComplexViewKeyMap potsMap = pnlPots.getChildrenInfo();
      Map<Integer, Map<String, Object>> ontNameList = potsMap.getKeyMap();
      for (Map<String, Object> ontName : ontNameList.values()) {
        if (R4CommonUtil.isEmptyMap(ontName)) {
          continue;
        }
        try {
          ponAccess.addOnt(ontName.get(R4Constants.PON_ACCESS_ONT_KEY_NAME).toString());
        } catch (Exception e) {
          continue;
        }
      }
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Exception", e);
    }

    return filter;
  }

  @Override
  public void setViewId(int viewId) {
    this.viewId = viewId;
    pnlPon.setViewId(viewId);
  }

  @Override
  public void removeAllChildInfo() {
    pnlPots.removeAllTableInformation();
    pnlCalling.removeAllTableInformation();
    pnlVoice.removeAllTableInformation();
    pnlTest.removeAllTableInformation();
//    pnlStats.removeAllTableInformation();

    pnlPots.clearTable();
    pnlCalling.clearTable();
    pnlVoice.clearTable();
    pnlTest.clearTable();
//    pnlStats.clearTable();
  }

  @Override
  public void arrangeTableInfo() {
    // TODO : delete this method.
  }

  @Override
  public void removeKey(Map<String, Object> key) {
    pnlPots.removeChildTableOfKey(key);
    pnlCalling.removeChildTableOfKey(key);
    pnlVoice.removeChildTableOfKey(key);
    pnlTest.removeChildTableOfKey(key);
//    pnlStats.removeChildTableOfKey(key);

    pnlPots.saveAndRefreshTable(null, key);
    pnlCalling.saveAndRefreshTable(null, key);
    pnlVoice.saveAndRefreshTable(null, key);
    pnlTest.saveAndRefreshTable(null, key);
//    pnlStats.saveAndRefreshTable(null, key);
  }

  @Override
  public void refreshComplexChildView(Map<String, Object> key) {
    if (R4CommonUtil.isEmptyMap(key)) {
      pnlPots.clearTable();
    } else {
      pnlPots.saveAndRefreshTable(resultData, key);
      List<Map<String, Object>> potsKeyList = pnlPots.getTableKeyRows();
      for (Map<String, Object> vlanKey : potsKeyList) {
        Map<String, Object> copyKey = new TreeMap<String, Object>(vlanKey);
        copyKey.putAll(key);
        pnlCalling.saveResponseDataIntoTable(resultData, copyKey);
//        pnlStats.saveAndRefreshTable(resultData, copyKey);
        pnlTest.saveAndRefreshTable(resultData, copyKey);
        pnlVoice.saveAndRefreshTable(resultData, copyKey);
      }
      refreshOntPotsStatus();

    }
    pnlCalling.clearTable();
    pnlVoice.clearTable();
    pnlTest.clearTable();
//    pnlStats.clearTable();
  }

  /**
   * @param selectedRowKey
   */
  public void refreshPotsChildrenTable(Map<String, Object> key) {
    if (R4CommonUtil.isEmptyMap(key)) {
      pnlCalling.clearTable();
      pnlVoice.clearTable();
      pnlTest.clearTable();
//      pnlStats.clearTable();
    } else {
      Map<String, Object> copyKey = new TreeMap<String, Object>(key);
      copyKey.putAll(pnlPon.getSelectedRowKey());
      pnlCalling.saveAndRefreshTable(resultData, copyKey);
      pnlVoice.saveAndRefreshTable(resultData, copyKey);
      pnlTest.saveAndRefreshTable(resultData, copyKey);
//      pnlStats.saveAndRefreshTable(resultData, copyKey);
    }
  }

  /**
   * @param selectedRowKey
   */
  public void removePotsKey(Map<String, Object> key) {
    Map<String, Object> copyKey = new TreeMap<String, Object>(key);
    copyKey.putAll(pnlPon.getSelectedRowKey());

    pnlCalling.removeChildTableOfKey(copyKey);
    pnlVoice.removeChildTableOfKey(copyKey);
    pnlTest.removeChildTableOfKey(copyKey);
//    pnlStats.removeChildTableOfKey(copyKey);

    pnlCalling.saveAndRefreshTable(null, copyKey);
    pnlVoice.saveAndRefreshTable(null, copyKey);
    pnlTest.saveAndRefreshTable(null, copyKey);
//    pnlStats.saveAndRefreshTable(null, copyKey);
  }

  private void saveAndRefreshPotsTable(Map<String, Object> key) {
    if (R4CommonUtil.isEmptyMap(key)) {
      pnlPots.clearTable();
    } else {
      pnlPots.saveAndRefreshTable(resultData, key);
      List<Map<String, Object>> potsKeyList = pnlPots.getTableKeyRows();
      for (Map<String, Object> vlanKey : potsKeyList) {
        Map<String, Object> copyKey = new TreeMap<String, Object>(vlanKey);
        copyKey.putAll(key);
        pnlCalling.saveResponseDataIntoTable(resultData, copyKey);
//        pnlStats.saveAndRefreshTable(resultData, copyKey);
        pnlTest.saveAndRefreshTable(resultData, copyKey);
        pnlVoice.saveAndRefreshTable(resultData, copyKey);
      }
    }
    pnlCalling.clearTable();
    pnlVoice.clearTable();
    pnlTest.clearTable();
//    pnlStats.clearTable();
  }
}
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.