package com.vci.client.omd.enumManager.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import javax.swing.JButton;
|
import javax.swing.JDialog;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
|
import com.vci.corba.omd.etm.EnumChild;
|
|
public class EmItemDialog extends JDialog{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -1924696083112318808L;
|
private EnumChild emChild;
|
private JPanel centerPanel, southPanel;
|
private JTextField tfName, tfValue;
|
private JTextArea taDescrip;
|
private JButton btnOK, btnCancel;
|
private String type;
|
private int length;
|
|
public EmItemDialog(EnumChild emChild, String type, int length){
|
this.emChild = emChild;
|
this.type = type;
|
this.length = length;
|
initUI();
|
initData();
|
addListener();
|
}
|
|
private void initUI(){
|
this.setTitle("枚举项");
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
this.setSize(screenSize.width/4, screenSize.height/4);
|
this.setSize(600, 400);//add by caill 2016.1.14调整弹出页面大小
|
this.setModal(true);
|
this.setLocationRelativeTo(null);
|
this.setResizable(false);
|
|
//centerPanel:枚举项名, 枚举项值, 描述
|
centerPanel = new JPanel();
|
//southPanel:确定, 取消
|
southPanel = new JPanel();
|
|
setLayout(new BorderLayout());
|
add(centerPanel, BorderLayout.CENTER);
|
add(southPanel, BorderLayout.SOUTH);
|
|
centerPanel.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.gridx = 0;
|
g.gridy = 0;
|
g.anchor = GridBagConstraints.WEST;//add by caill 2015.11.26将第一列控件设置为左对齐
|
g.insets = new Insets(20, 15, 10, 15);//add by caill 2016.1.14调整控件间距
|
centerPanel.add(new JLabel("枚举项名:"), g);
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.gridx = 1;
|
g1.gridy = 0;
|
g1.gridwidth = GridBagConstraints.REMAINDER;
|
g1.anchor = GridBagConstraints.WEST;//add by caill 2015.11.26将第二列控件设置为左对齐
|
g1.insets = new Insets(20, 15, 10, 15);
|
tfName = new JTextField(30);
|
centerPanel.add(tfName, g1);
|
g.gridy = 1;
|
centerPanel.add(new JLabel("枚举项值:"), g);
|
g1.gridy = 1;
|
tfValue = new JTextField(30);
|
centerPanel.add(tfValue, g1);
|
g.gridy = 2;
|
centerPanel.add(new JLabel("描述:"), g);
|
g1.gridy = 2;
|
taDescrip = new JTextArea(3,30);
|
taDescrip.setPreferredSize(new Dimension(110, 40));
|
taDescrip.setLineWrap(true);
|
centerPanel.add(new JScrollPane(taDescrip), g1);
|
|
btnOK = new JButton("确定");
|
btnCancel = new JButton("取消");
|
southPanel.add(btnOK);
|
southPanel.add(btnCancel);
|
}
|
|
private void initData(){
|
if(emChild == null){
|
return;
|
}
|
|
tfName.setText(emChild.name);
|
tfValue.setText(emChild.value);
|
taDescrip.setText(emChild.description);
|
}
|
private void addListener(){
|
btnOK.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
|
if(!checkName()){
|
return;
|
}
|
if(!checkValue()){
|
return;
|
}
|
if(emChild == null){
|
emChild = new EnumChild();
|
emChild.name = tfName.getText();
|
emChild.value = tfValue.getText();
|
emChild.description = taDescrip.getText();
|
EnumItemPanel.getInstance().emChildList.add(emChild);
|
}else{
|
for(int i = 0; i < EnumItemPanel.getInstance().emChildList.size(); i++){
|
if(EnumItemPanel.getInstance().emChildList.get(i).name.equals(emChild.name)){
|
EnumItemPanel.getInstance().emChildList.get(i).name = tfName.getText();
|
EnumItemPanel.getInstance().emChildList.get(i).value = tfValue.getText();
|
EnumItemPanel.getInstance().emChildList.get(i).description = taDescrip.getText();
|
}
|
}
|
}
|
|
EnumItemPanel.getInstance().initTableData();
|
dispose();
|
}
|
});
|
|
btnCancel.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
dispose();
|
}
|
});
|
}
|
|
private boolean checkName(){
|
if(tfName.getText().equals("")){
|
JOptionPane.showMessageDialog(this, "请输入枚举项名", "请输入枚举项名", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
|
String name = tfName.getText().trim();
|
|
for(int i = 0; i < EnumItemPanel.getInstance().emChildList.size(); i++){
|
EnumChild emChild = EnumItemPanel.getInstance().emChildList.get(i);
|
|
if(this.emChild == null){
|
if(emChild.name.equals(name)){
|
JOptionPane.showMessageDialog(this, "该枚举项已经存在", "该枚举项已经存在", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
}else{
|
if(!emChild.name.equals(this.emChild.name) && emChild.name.equals(name)){
|
JOptionPane.showMessageDialog(this, "该枚举项已经存在", "该枚举项已经存在", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
}
|
|
}
|
return true;
|
}
|
|
private boolean checkValue(){
|
if(tfValue.getText().equals("")){
|
JOptionPane.showMessageDialog(this, "请输入枚举项值", "请输入枚举项值", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
String text = tfValue.getText();
|
if(text.length() > length){
|
JOptionPane.showMessageDialog(this, "超过最大长度", "超过最大长度", JOptionPane.ERROR_MESSAGE);
|
return false;
|
}
|
if(type.equals("Integer")){
|
if(!text.matches("-?[1-9][0-9]*")){
|
JOptionPane.showMessageDialog(this, "枚举项值只能为Integer", "枚举项值类型错误", JOptionPane.WARNING_MESSAGE);
|
return false;
|
}
|
}else if(type.equals("String")){
|
// if(!text.matches("([a-z A-Z]*[0-9]*)*") && !text.matches("-?[1-9][0-9]*")){
|
// JOptionPane.showMessageDialog(this, "枚举项值只能为String", "枚举项值类型错误", JOptionPane.WARNING_MESSAGE);
|
// return false;
|
// }
|
}
|
return true;
|
}
|
}
|