package com.vci.client.framework.systemConfig.stafforgmanage;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.Rectangle;
|
import java.awt.event.ActionEvent;
|
|
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.vci.client.ClientSession;
|
import com.vci.client.LogonApplication;
|
import com.vci.client.framework.delegate.UserEntityClientDelegate;
|
import com.vci.client.framework.systemConfig.object.TransmitMethod;
|
import com.vci.client.logon.base.BaseJDialog;
|
import com.vci.client.omd.enumManager.ui.EnumClient;
|
import com.vci.client.ui.swing.KJButton;
|
import com.vci.client.ui.swing.KTextField;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.common.locale.LocaleDisplay;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.framework.data.MachSecurityInfo;
|
import com.vci.corba.omd.etm.EnumChild;
|
import com.vci.corba.omd.etm.EnumItem;
|
import com.vci.corba.common.data.UserEntityInfo;
|
import com.vci.mw.ClientContextVariable;
|
|
|
public class MachSecurityDialog extends BaseJDialog {
|
private static final long serialVersionUID = 1L;
|
|
private static final String ENUM_USERSECURITYENUM = "usersecurityenum";
|
private static final String ENUM_SECURITYGRADE = "Enumsecretgrade";
|
private EnumChild[] securityEnum;
|
|
private UserEntityInfo userInfo = null;
|
|
private OptionType opType = OptionType.Unknow;
|
private MachSecurityPanel tablePanel;
|
private MachSecurityInfo msObj = null;
|
|
private JLabel nameLabel = new JLabel(
|
LocaleDisplay.getI18nString("rmip.stafforg.logal.name", "RMIPFramework", getLocale()));
|
private JLabel descLabel = new JLabel(
|
LocaleDisplay.getI18nString("rmip.stafforg.logal.desc", "RMIPFramework", getLocale()));
|
KTextField nameText = new KTextField();
|
KTextField ipText = new KTextField();
|
JTextArea descArea = new JTextArea();
|
|
private JLabel securityLabel = new JLabel(
|
LocaleDisplay.getI18nString("rmip.stafforg.logal.security", "RMIPFramework", getLocale()));
|
private JComboBox securityCombo = new JComboBox();
|
|
private KJButton conformButton = new KJButton(
|
LocaleDisplay.getI18nString("rmip.framework.button.confirm", "RMIPFramework", getLocale()),
|
"bullet_blue.png");
|
private KJButton cancelButton = new KJButton(
|
LocaleDisplay.getI18nString("rmip.framework.button.cancel", "RMIPFramework", getLocale()),
|
"bullet_delete.png");
|
|
public enum OptionType {
|
Unknow, Add, Edit
|
}
|
|
public MachSecurityDialog(MachSecurityPanel tablePanel, MachSecurityInfo obj, OptionType opType) {
|
super(LogonApplication.frame);
|
this.opType = opType;
|
this.msObj = obj;
|
this.tablePanel = tablePanel;
|
|
userInfo = UserEntityClientDelegate.changeUserEntityToInfo(LogonApplication.getUserEntityObject());
|
|
this.setModal(true);
|
|
initDialog();
|
}
|
|
/**
|
* 初始化界面
|
*/
|
public void initDialog() {
|
this.setTitle("机器密级");
|
|
JPanel bottomPanel = new JPanel();
|
conformButton.setPreferredSize(new Dimension(90, 30));
|
cancelButton.setPreferredSize(new Dimension(90, 30));
|
bottomPanel.add(conformButton);
|
bottomPanel.add(cancelButton);
|
|
conformButton.addActionListener(new java.awt.event.ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
add_actionPerformed(e);
|
}
|
});
|
|
cancelButton.addActionListener(new java.awt.event.ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
cancelButton_ActionPerformed(e);
|
}
|
});
|
|
JPanel contentPanel = initCenterContentPanel();
|
|
this.setLayout(new BorderLayout());
|
// this.add(titleLabel, BorderLayout.NORTH);
|
this.add(contentPanel, BorderLayout.CENTER);
|
this.add(bottomPanel, BorderLayout.SOUTH);
|
initDialogSize(420, 320);
|
this.setVisible(true);
|
}
|
|
private JPanel initCenterContentPanel() {
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(null);
|
|
JLabel ipLabel = new JLabel();
|
ipLabel.setText("IP地址");
|
ipLabel.setBounds(new Rectangle(30, 20, 60, 25));
|
ipText.setBounds(new Rectangle(90, 20, 300, 25));
|
if (opType != OptionType.Add)
|
ipText.setEditable(false);
|
|
contentPanel.add(ipLabel);
|
contentPanel.add(ipText);
|
|
nameLabel.setBounds(new Rectangle(30, 55, 60, 25));
|
nameLabel.setText("机器名");
|
nameText.setBounds(new Rectangle(90, 55, 300, 25));
|
contentPanel.add(nameLabel);
|
contentPanel.add(nameText);
|
|
securityLabel.setBounds(new Rectangle(30, 90, 60, 25));
|
securityLabel.setText("密级");
|
securityCombo.setBounds(new Rectangle(90, 90, 300, 25));
|
contentPanel.add(securityLabel);
|
contentPanel.add(securityCombo);
|
|
JScrollPane jsDescription = new JScrollPane();
|
descLabel.setBounds(new Rectangle(30, 125, 60, 25));
|
descLabel.setText("描述");
|
descArea.setLineWrap(true);
|
jsDescription.getViewport().add(descArea);
|
jsDescription.setBounds(new Rectangle(90, 125, 300, 100));
|
contentPanel.add(descLabel);
|
contentPanel.add(jsDescription);
|
|
initContent();
|
return contentPanel;
|
}
|
|
private void initContent() {
|
if (msObj != null) {
|
nameText.setText(msObj.name);
|
ipText.setText(msObj.ipAddress);
|
descArea.setText(msObj.desc);
|
}
|
|
initSecurityCombo();
|
}
|
|
@SuppressWarnings("unchecked")
|
private void initSecurityCombo() {
|
try {
|
securityCombo.setEditable(false);
|
EnumItem item = EnumClient.getService().getEmItemByName(ENUM_SECURITYGRADE);
|
securityEnum = item.children;
|
if (!ClientContextVariable.getIpSecretSwitch().equals("on")) {
|
securityCombo.addItem("");
|
}
|
|
String secretGrade = "";
|
if (msObj != null) {
|
secretGrade = String.valueOf(msObj.secretGrade);
|
}
|
for (EnumChild child : securityEnum) {
|
securityCombo.addItem(child.name);
|
if (msObj != null && child.value.equals(secretGrade)) {
|
securityCombo.setSelectedItem(child.name);
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
private void add_actionPerformed(ActionEvent e) {
|
|
if (!checkValue()) {
|
return;
|
}
|
|
try {
|
if(opType == OptionType.Add) {
|
ClientSession.getFrameworkService().saveMachSecurity(msObj, userInfo);
|
} else if (opType == OptionType.Edit) {
|
ClientSession.getFrameworkService().updateMachSecurity(msObj, userInfo);
|
}
|
} catch (VCIError er) {
|
VCIOptionPane.showError(LogonApplication.frame, er);
|
return;
|
}
|
this.dispose();
|
tablePanel.refreshTableData();
|
}
|
|
/**
|
* 取消按钮事件
|
*
|
* @param e
|
*/
|
private void cancelButton_ActionPerformed(ActionEvent e) {
|
this.dispose();
|
}
|
|
private boolean checkValue() {
|
|
String name = nameText.getText();
|
String ipAddress = ipText.getText();
|
short secretGrade = getSecurity();
|
String desc = descArea.getText();
|
|
if("".equals(name)){
|
VCIOptionPane.showMessageDialog(this, "机器名不能空");
|
return false;
|
}
|
|
if(opType == OptionType.Add) {
|
ipAddress = ipAddress.trim();
|
if ("".equals(ipAddress)){
|
VCIOptionPane.showMessageDialog(this, "机器IP地址不能空");
|
return false;
|
}
|
|
String regEx = "^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$";
|
if (!TransmitMethod.checkCharacter(ipAddress, regEx)) {
|
VCIOptionPane.showMessageDialog(this, "机器IP地址不符合IP地址格式要求");
|
return false;
|
}
|
|
MachSecurityInfo ms;
|
try {
|
ms = ClientSession.getFrameworkService().getMachSecurityInfo(ipAddress, (short)0, userInfo);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
return false;
|
}
|
if (!StringUtils.isEmpty(ms.id)) {
|
VCIOptionPane.showMessageDialog(this, "机器IP地址已经存在,请重新输入IP地址!");
|
return false;
|
}
|
}
|
|
msObj.name = name;
|
msObj.ipAddress = ipAddress;
|
msObj.secretGrade = secretGrade;
|
msObj.desc = desc;
|
|
return true;
|
}
|
|
public short getSecurity(){
|
String selItem = (String) securityCombo.getSelectedItem();
|
if(selItem != ""){
|
for(EnumChild child: securityEnum){
|
if(child.name.equals(selItem)){
|
return Short.valueOf(child.value);
|
}
|
}
|
}
|
return 0;
|
}
|
}
|