/**
*
*/
package com.lgnortel.network.networkview;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
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.Enumeration;
import java.util.logging.Level;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.EtchedBorder;
import com.lgnortel.lib.help.HelpTargetConst;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.network.alarmBanner.ToolBarPanel;
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.common.DefaultManagementView;
import com.lgnortel.r4.r4equipment.common.ManagementGetIF;
import com.lgnortel.r4.r4equipment.common.ManagementHelpIF;
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.R4TableModel;
import com.lgnortel.r4.r4equipment.common.SimpleChildView;
import com.lgnortel.r4.r4equipment.management.olt.facility.FacilityBootEnvModel;
import com.lgnortel.r4.r4equipment.management.olt.facility.FacilityBootEnvView;
import com.lgnortel.rmi.common.ClientManager;
import com.lgnortel.rmi.common.EmsCode;
/**
* Copyright (c) 2010 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: R4OltBootEnvironmentView.java<br>
* Description: <br>
* Copyright: Copyright(c) 2010 LG-NORTEL ALL Rights Reserved<br>
* Company: LG-Nortel<br>
*
* @author Jonghwa, Lee
* @version 1.0
* @created 2010. 2. 3.
* @modified 2010. 2. 3.
* @product EFA R4.0 EMS
* @sw_block Client Block
*/
public class R4OltBootEnvironmentView extends DefaultManagementView implements ManagementGetIF, ManagementHelpIF, CommandResponseInterface {
/**
*
*/
private static final long serialVersionUID = 6018536925662873761L;
private ManagementTableIF modelBootEnv;
private SimpleChildView pnlBootEnv;
private int viewId;
private int neId;
private JLabel lblTid;
private JLabel lblAddr;
private JComboBox cbNode;
private JComboBox cbSubnet;
private ClientManager clientManager = ClientManager.getInstance();
private User user = User.getInstance();
private DBManager dbMgr = DBManager.getInstance();
private NetworkMgr networkMgr = NetworkMgr.getInstance();
public R4OltBootEnvironmentView(String title) {
super();
this.sTitle = title;
initialize();
}
@Override
protected JPanel createMainPanel() {
lblTid = new JLabel();
lblAddr = new JLabel();
btnRefresh = new R4RefreshButton();
btnRefresh.addActionListener(handler);
cbSubnet = new JComboBox();
cbSubnet.setPreferredSize(new Dimension(100, 25));
cbSubnet.setBackground(new Color(255, 250, 182));
cbSubnet.setBackground(new Color(151, 245, 118));
cbSubnet.setFont(new java.awt.Font("Dialog", 1, 12));
cbSubnet.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
getNeList(getSubnetId());
}
});
cbNode = new JComboBox();
cbNode.setPreferredSize(new Dimension(100, 25));
cbNode.setBackground(new Color(255, 250, 182));
cbNode.setBackground(new Color(151, 245, 118));
cbNode.setFont(new java.awt.Font("Dialog", 1, 12));
cbNode.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setNodeId(getNodeId());
refreshTid();
}
});
setDefaultData();
refreshTid();
JPanel pnlQuery = new JPanel();
pnlQuery.setLayout(new GridBagLayout());
pnlQuery.setBorder(new EtchedBorder());
pnlQuery.add(lblTid, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
pnlQuery.add(lblAddr, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
pnlQuery.add(new JLabel("Subnet"), new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
pnlQuery.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));
pnlQuery.add(new JLabel("Node"), new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
pnlQuery.add(cbNode, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
pnlQuery.add(btnRefresh, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
modelBootEnv = new FacilityBootEnvModel();
pnlBootEnv = new FacilityBootEnvView("Show OLT Boot Environment", modelBootEnv);
pnlBootEnv.removeTableKeyListener();
pnlBootEnv.removeTableMouseListener();
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(pnlQuery, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0));
panel.add(pnlBootEnv, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
return panel;
}
protected JPanel createResultPanel() {
btnHelp = new R4HelpButton();
btnHelp.addActionListener(handler);
pnlResult = new MessagePanel(this);
pnlResult.setBorder(null);
btnSet = new JButton("Boot Env Set");
btnSet.setForeground(Color.RED);
btnSet.setFont(new Font("Dialog", Font.BOLD, 12));
btnSet.setPreferredSize(new Dimension(120, 26));
btnSet.setMinimumSize(new Dimension(120, 26));
btnSet.setMaximumSize(new Dimension(120, 26));
btnSet.addActionListener(handler);
if (User.getInstance().getUserGrp() == User.MONITOR) {
btnSet.setEnabled(false);
}
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(pnlResult, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 10), 0, 0));
panel.add(btnHelp, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
panel.add(btnSet, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0));
return panel;
}
@Override
public void get() {
Msp filter = getFilter();
Object[] data = new Object[1];
data[0] = filter;
clientManager.cmdRequest(viewId, user.getUserId(), getNodeId(), 0, EmsCode.NETCONF_GETFILTER, data, "");
}
protected void set() {
JTable table = pnlBootEnv.getTable();
R4TableModel model = pnlBootEnv.getModel();
for (int row = 0, n = model.getRowCount(); row < n; row++) {
String value = model.getValueAt(table.convertRowIndexToModel(row), table.convertColumnIndexToModel(FacilityBootEnvView.COLUMN_SET)).toString();
if (Boolean.valueOf(value).booleanValue()) {
Object slot = model.getValueAt(table.convertRowIndexToModel(row), table.convertColumnIndexToModel(FacilityBootEnvView.COLUMN_SLOT));
Object mode = model.getValueAt(table.convertRowIndexToModel(row), table.convertColumnIndexToModel(FacilityBootEnvView.COLUMN_STARTUP));
Object bank = model.getValueAt(table.convertRowIndexToModel(row), table.convertColumnIndexToModel(FacilityBootEnvView.COLUMN_DEFAULT_BANK));
if (R4CommonUtil.displayQuestionDialog(this, sTitle, "Are you sure to set " + slot + "?")) {
((FacilityBootEnvModel) modelBootEnv).requestBootenv(viewId, neId, slot.toString(), mode.toString(), bank.toString());
}
break;
}
}
}
@Override
public String getHelpFilePath() {
return HelpTargetConst.R4_OLT_BOOT_ENV;
}
@Override
public Msp getFilter() {
Msp filter = new Msp();
try {
filter.addOper().addBootenv();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
return filter;
}
@Override
public void setViewId(int viewId) {
this.viewId = viewId;
}
@Override
public boolean cmdResponse(int viewId, int userId, int nodeId, int cmdCode, Object[] data, int result, String errMessage) {
if (EmsCode.NETCONF_GET_CONFIG == cmdCode || EmsCode.NETCONF_GETFILTER_CONFIG == cmdCode || EmsCode.NETCONF_GETFILTER == cmdCode) {
pnlBootEnv.cmdResponse(viewId, userId, nodeId, cmdCode, data, result, errMessage);
} else if (EmsCode.NETCONF_ACTION == cmdCode) {
get();
}
pnlResult.updateMessage(errMessage);
return true;
}
private void refreshTid() {
Object nodeName = cbNode.getSelectedItem();
if (nodeName == null)
return;
int nodeID = dbMgr.getNodeId(nodeName.toString());
String ipAddress = dbMgr.getIpAddress(nodeID);
if (cbNode.getSelectedItem() != null) {
lblTid.setText("TID : " + cbNode.getSelectedItem().toString());
lblAddr.setText("IP Address : " + ipAddress);
}
}
private void setDefaultData() {
getSubnetList();
ToolBarPanel toolBarPanel = ToolBarPanel.getInstance();
String nodeName = toolBarPanel.getFindNodeField();
int nodeId = dbMgr.getNodeId(nodeName);
neId = nodeId;
int parentNodeId = NetworkElement.ROOT_NODEID;
String parentNodeStr = "ROOT";
if (nodeId != -1) {
NetworkElement curNE = dbMgr.getNetworkElement(nodeId);
parentNodeId = curNE.getParentNodeId();
parentNodeStr = dbMgr.getNodeName(parentNodeId);
} else {
nodeName = "";
}
getNeList(parentNodeId);
cbSubnet.setSelectedItem(parentNodeStr);
cbNode.setSelectedItem(nodeName);
}
/**
* get subnet list
*/
private void getSubnetList() {
cbSubnet.removeAllItems();
Enumeration<NetworkElement> e = networkMgr.getSubnet().elements();
while (e.hasMoreElements()) {
NetworkElement subnet = (NetworkElement) e.nextElement();
cbSubnet.addItem(subnet.getNodeName());
}
}
/**
* get NE List
*
* @param subnet
*/
public void getNeList(int subnet) {
Object selectNode = cbNode.getSelectedItem();
cbNode.removeAllItems();
NetworkElement[] netElement = dbMgr.getNetworkElement();
if (netElement != null) {
for (int i = 0; i < netElement.length; i++) {
if ((netElement[i].getNodeType() == NetworkElement.NE_TYPE) && (netElement[i].parentNodeId == subnet) && DBDataDesc.R40_SYSTEM_TYPE == netElement[i].getSystemType()) {
cbNode.addItem(new String(netElement[i].nodeName));
}
}
}
try {
cbNode.setSelectedItem(selectNode);
} catch (NullPointerException ne) {
cbNode.setSelectedIndex(0);
}
}
private int getNodeId() {
if (cbNode.getSelectedIndex() < 0)
return 0;
String nodeName = (String) cbNode.getSelectedItem();
int nodeId = networkMgr.getNodeId(nodeName);
if (nodeId == -1) {
return neId;
} else {
return nodeId;
}
}
/**
* get subnet Id
*
* @return
*/
private int getSubnetId() {
if (cbSubnet.getSelectedIndex() < 0)
return 0;
String nodeName = (String) cbSubnet.getSelectedItem();
int nodeId = networkMgr.getNodeId(nodeName);
return nodeId;
}
private void setNodeId(int nodeId) {
this.neId = nodeId;
}
}
|