package com.vci.client.omd.attribpool.ui;
|
|
import java.awt.BorderLayout;
|
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.awt.event.ItemEvent;
|
import java.awt.event.ItemListener;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import javax.swing.BorderFactory;
|
import javax.swing.JButton;
|
import javax.swing.JCheckBox;
|
import javax.swing.JComboBox;
|
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.client.common.datatype.VTString;
|
import com.vci.client.omd.enumManager.toOutside.GetEnumForOut;
|
import com.vci.corba.omd.atm.AttribItem;
|
|
public class VTStringPanel extends VTDataTypePanel{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 568014877587595753L;
|
private JCheckBox cbNull;
|
private JTextField tfLen, tfDefValue;
|
private JComboBox combDefValue;
|
private JTextField tfRage;
|
private JButton btnEqu;
|
private JTextArea taRage;
|
private JButton btnRemove;
|
private HashMap<String, String> detailInfoMap = null;
|
//枚举选择
|
private JCheckBox chbEnum;
|
private JComboBox combEnum;
|
private ArrayList<String> valueList;
|
private JButton btnAddRef, btnRemoveRef;
|
private JTextField tfRefName;
|
private HashMap<String, ArrayList<String>> enumMap = null;
|
private JComboBox combRef;
|
private JComboBox combVer;
|
|
public VTStringPanel(){
|
initUI();
|
addListener();
|
}
|
|
private void initUI(){
|
|
this.setLayout(new GridBagLayout());
|
JPanel leftPanel = new JPanel();
|
JPanel rightPanel = new JPanel();
|
|
GridBagConstraints gb = new GridBagConstraints();
|
gb.gridx = 0;
|
gb.gridy = 0;
|
gb.weightx = 1.0;
|
gb.weighty = 1.0;
|
gb.fill = GridBagConstraints.BOTH;
|
|
this.add(leftPanel, gb);
|
gb.gridx = 1;
|
this.add(rightPanel, gb);
|
leftPanel.setPreferredSize(new Dimension(this.getSize().width/2,
|
this.getSize().height));
|
rightPanel.setPreferredSize(new Dimension(this.getSize().width/2,
|
this.getSize().height));
|
|
//设置左边panel的控件
|
leftPanel.setBorder(BorderFactory.createTitledBorder("VTString"));
|
leftPanel.setLayout(new BorderLayout());
|
JScrollPane lpTempSP = new JScrollPane();
|
leftPanel.add(lpTempSP);
|
JPanel lpTempPanel = new JPanel();
|
lpTempSP.setViewportView(lpTempPanel);
|
lpTempSP.setBorder(null);
|
lpTempPanel.setLayout(new BorderLayout());
|
JPanel leftPanel2 = new JPanel();
|
lpTempPanel.add(leftPanel2, BorderLayout.CENTER);
|
cbNull = new JCheckBox("允许为空");
|
cbNull.setSelected(true);
|
// cbFixLen = new JCheckBox("定长");
|
// leftPanel1.add(cbFixLen);
|
leftPanel2.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.insets = new Insets(15, 10, 5, 10);
|
g.gridx = 0;
|
g.gridy = 0;
|
g.anchor = GridBagConstraints.WEST;//add by caill 2016.1.15将“长度”和“默认值”左对齐
|
leftPanel2.add(cbNull,g); //add by caill 2016.1.15将“允许为空”放到“长度”的上面
|
g.gridy = 1;
|
leftPanel2.add(new JLabel("长度"), g);
|
tfLen = new JTextField(30); //add by caill 2016.1.15增加文本框长度
|
tfLen.setText(VTString.lenMax + "");
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.insets = new Insets(15, 10, 5, 10);
|
g1.gridx = 1;
|
g1.gridy = 1;
|
g1.gridwidth = GridBagConstraints.REMAINDER;
|
g1.anchor = GridBagConstraints.WEST; //add by caill 2016.1.15将文本框左对齐
|
leftPanel2.add(tfLen, g1);
|
|
g.gridy = 2;
|
leftPanel2.add(new JLabel("默认值"), g);
|
tfDefValue = new JTextField(30);
|
g1.gridy = 2;
|
leftPanel2.add(tfDefValue, g1);
|
combDefValue = new JComboBox();
|
combDefValue.setPreferredSize(new Dimension(187, 25));//add by caill 2016.1.15调整默认值下拉框的长度
|
leftPanel2.add(combDefValue, g1);
|
|
//设置右边panel的控件
|
rightPanel.setBorder(BorderFactory.createTitledBorder("值域"));
|
rightPanel.setLayout(new BorderLayout());
|
|
JScrollPane tempSP = new JScrollPane();
|
tempSP.setBorder(null);
|
rightPanel.add(tempSP);
|
JPanel tempPanel = new JPanel();
|
tempPanel.setLayout(new GridBagLayout());
|
tempSP.setViewportView(tempPanel);
|
|
JPanel rightPanel1 = new JPanel();
|
JPanel rightPanel2 = new JPanel();
|
JPanel rightPanel3 = new JPanel();
|
|
GridBagConstraints gRight = new GridBagConstraints();
|
gRight.gridx = 0;
|
gRight.gridy = 0;
|
gRight.weightx = 1.0;
|
gRight.weighty = 1.0;
|
gRight.fill = GridBagConstraints.BOTH;
|
|
tempPanel.add(rightPanel1, gRight);
|
gRight.gridy = 1;
|
tempPanel.add(rightPanel2, gRight);
|
gRight.gridy = 2;
|
tempPanel.add(rightPanel3, gRight);
|
|
rightPanel1.setLayout(new GridBagLayout());
|
GridBagConstraints grigth1 = new GridBagConstraints();
|
grigth1.anchor = GridBagConstraints.WEST;
|
grigth1.insets = new Insets(5, 5, 5, 5);
|
grigth1.gridx = 0;
|
grigth1.gridy = 0;
|
//------------START----
|
combRef = new JComboBox();
|
combRef.addItem("业务类型");
|
combRef.addItem("链接类型");
|
rightPanel1.add(combRef, grigth1);
|
grigth1.gridx = 1;
|
btnAddRef = new JButton("+");
|
rightPanel1.add(btnAddRef, grigth1);
|
grigth1.gridx = 2;
|
tfRefName = new JTextField(10);
|
tfRefName.setEditable(false);
|
rightPanel1.add(tfRefName, grigth1);
|
combVer = new JComboBox();
|
combVer.addItem("当前版本版次");
|
combVer.addItem("最新版本版次");
|
combVer.setVisible(false);
|
grigth1.gridx = 3;
|
rightPanel1.add(combVer, grigth1);
|
btnRemoveRef = new JButton("x");
|
grigth1.gridwidth = GridBagConstraints.REMAINDER;
|
grigth1.gridx = 4;
|
rightPanel1.add(btnRemoveRef, grigth1);
|
//------------END----
|
chbEnum = new JCheckBox("使用枚举");
|
combEnum = new JComboBox();
|
combEnum.setVisible(false);
|
combEnum.setPreferredSize(new Dimension(187, 25));//add by caill 2016.1.15调整“使用枚举”下面的下拉框大小
|
grigth1.gridx = 0;
|
grigth1.gridy = 1;
|
rightPanel1.add(chbEnum, grigth1);
|
grigth1.gridy = 2;
|
rightPanel1.add(combEnum, grigth1);
|
tfRage = new JTextField(30);//add by caill 2016.1.15调整“使用枚举”下面的文本框大小
|
//tfRage.setPreferredSize(new Dimension(200, 30));
|
rightPanel1.add(tfRage, grigth1);
|
|
btnEqu = new JButton("=");
|
rightPanel2.add(btnEqu);
|
|
rightPanel3.setLayout(new GridBagLayout());
|
taRage = new JTextArea(4, 20);
|
taRage.setLineWrap(true);
|
GridBagConstraints gr3 = new GridBagConstraints();
|
gr3.insets = new Insets(5, 5, 5, 5); //add by caill 2016.1.16调整文本域和“-”之间的距离
|
gr3.gridx =0;
|
gr3.gridy = 0;
|
gr3.weightx = 0;
|
rightPanel3.add(new JScrollPane(taRage), gr3);
|
gr3.anchor = GridBagConstraints.NORTHWEST;
|
gr3.gridx = 1;
|
gr3.gridwidth = GridBagConstraints.REMAINDER;
|
gr3.insets = new Insets(5, 5, 5, 48);//add by caill 2016.1.16调整文本域和“-”的位置
|
btnRemove = new JButton("-");
|
rightPanel3.add(btnRemove, gr3);
|
combDefValue.setVisible(false);
|
initCombEnum();
|
}
|
|
public void addListener(){
|
|
btnAddRef.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String selectedItem = (String) combRef.getSelectedItem();
|
if(selectedItem == null){
|
return;
|
}else if(selectedItem.equals("业务类型")){
|
BtmSelectDialog dialog = new BtmSelectDialog();
|
dialog.setVisible(true);
|
if(!dialog.getSelectedBtwName().equals("")){
|
tfRefName.setText(dialog.getSelectedBtwName());
|
updateRageUIAccordRef(1);
|
}
|
}else if(selectedItem.equals("链接类型")){
|
LinkTypeSelectDialog dialog = new LinkTypeSelectDialog();
|
dialog.setVisible(true);
|
if(!dialog.getSelectedltName().equals("")){
|
tfRefName.setText(dialog.getSelectedltName());
|
updateRageUIAccordRef(1);
|
}
|
}
|
|
}
|
});
|
|
btnRemoveRef.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
tfRefName.setText("");
|
updateRageUIAccordRef(0);
|
}
|
});
|
chbEnum.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
if(chbEnum.isSelected()){
|
combEnum.setVisible(true);
|
tfRage.setVisible(false);
|
btnEqu.setVisible(false);
|
btnRemove.setVisible(false);
|
tfDefValue.setVisible(false);
|
combDefValue.setVisible(true);
|
|
}else{
|
taRage.setText("");
|
combEnum.setVisible(false);
|
tfRage.setVisible(true);
|
btnEqu.setVisible(true);
|
btnRemove.setVisible(true);
|
|
tfDefValue.setVisible(true);
|
combDefValue.setVisible(false);
|
}
|
setTaRageForEnum();
|
}
|
});
|
|
combEnum.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
setTaRageForEnum();
|
}
|
});
|
|
btnEqu.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String rageStr = tfRage.getText();
|
if(rageStr.equals("")){
|
return;
|
}
|
if(taRage.getText().equals("")){
|
taRage.setText(rageStr);
|
}else if(taRage.getText().contains(rageStr)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + rageStr);
|
}
|
}
|
});
|
|
btnRemove.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
int lastN = taRage.getText().lastIndexOf("\n");
|
if(lastN > 0){
|
taRage.setText(taRage.getText().substring(0, lastN));
|
}else{
|
taRage.setText("");
|
}
|
|
}
|
});
|
|
combRef.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
String selectedItem = (String) combRef.getSelectedItem();
|
if(selectedItem == null){
|
return;
|
}else if(selectedItem.equals("业务类型")){
|
combVer.setVisible(false);
|
}else if(selectedItem.equals("链接类型")){
|
combVer.setVisible(true);
|
}
|
}
|
});
|
}
|
|
/**
|
* 枚举选择框
|
*/
|
private void initCombEnum(){
|
enumMap = new GetEnumForOut().getEnumMap("String");
|
combEnum.removeAllItems();
|
|
if(enumMap == null){
|
return;
|
}
|
for(Iterator<String> i = enumMap.keySet().iterator(); i.hasNext();){
|
String emName = i.next();
|
combEnum.addItem(emName);
|
}
|
|
setTaRageForEnum();
|
}
|
|
/**
|
* 默认值选择框
|
*/
|
private void initCombDefValue(){
|
combDefValue.removeAllItems();
|
if(valueList == null || valueList.size() == 0){
|
return;
|
}
|
for(int i = 0; i < valueList.size(); i++){
|
combDefValue.addItem(valueList.get(i));
|
}
|
}
|
|
private void setTaRageForEnum(){
|
if(!chbEnum.isSelected()){
|
return;
|
}
|
valueList = new ArrayList<String>();
|
String emName = (String) combEnum.getSelectedItem();
|
if(emName == null || emName.equals("")){
|
return;
|
}
|
valueList = enumMap.get(emName);
|
String taRageText = "";
|
for(int i = 0; i < valueList.size(); i++){
|
taRageText = taRageText + valueList.get(i);
|
if(i < valueList.size() - 1){
|
taRageText = taRageText + "\n";
|
}
|
}
|
|
taRage.setText(taRageText);
|
|
initCombDefValue();
|
}
|
/**
|
* 获取VTDataType的详细信息
|
* @return
|
*/
|
public HashMap<String, String> getDetailInfo(){
|
detailInfoMap = new HashMap<String, String>();
|
String otherValue = "";
|
|
if(tfDefValue.isVisible()){
|
detailInfoMap.put(VTDataTypePanel.DEFVALUE, tfDefValue.getText());
|
}else{
|
detailInfoMap.put(VTDataTypePanel.DEFVALUE, (String)combDefValue.getSelectedItem());
|
}
|
detailInfoMap.put(VTDataTypePanel.RAGE, taRage.getText().replace("\n", ";"));
|
|
if(combRef.getSelectedItem().equals("业务类型")){
|
otherValue += VTDataTypePanel.BTM + " = " + tfRefName.getText() + ";";
|
}else if(combRef.getSelectedItem().equals("链接类型")){
|
otherValue += VTDataTypePanel.LINKTYPENAME + " = " + tfRefName.getText() + ";";
|
if(combVer.getSelectedItem().equals("当前版本版次")){
|
otherValue += VTDataTypePanel.VERSION + " = " + 1 + ";";
|
}else if(combVer.getSelectedItem().equals("最新版本版次")){
|
otherValue += VTDataTypePanel.VERSION + " = " + 3 + ";";
|
}
|
}
|
if(cbNull.isSelected()){
|
otherValue += VTDataTypePanel.ALLOWNULL + " = yes;";
|
}else{
|
otherValue += VTDataTypePanel.ALLOWNULL + " = no;";
|
}
|
|
// if(cbFixLen.isSelected()){
|
// otherValue += VTDataTypePanel.ISFIXLEN + " = yes;";
|
// }else{
|
// otherValue += VTDataTypePanel.ISFIXLEN + " = no;";
|
// }
|
otherValue += VTDataTypePanel.LENGTH + " = " +
|
tfLen.getText() + ";";
|
|
if(chbEnum.isSelected()){
|
otherValue += VTDataTypePanel.ENUMNAME + " = " +
|
combEnum.getSelectedItem() + ";";
|
}
|
otherValue = otherValue.substring(0, otherValue.lastIndexOf(";"));
|
detailInfoMap.put(VTDataTypePanel.OTHER, otherValue);
|
|
return detailInfoMap;
|
}
|
|
/**
|
* 根据当前状态(查看,创建,修改), 设置相关组件的显示情况
|
* @param flag
|
*/
|
public void updataUIStatus(AttribItem abItem, int flag){
|
String enumName = null;
|
if(abItem != null){
|
tfDefValue.setText(abItem.defValue);
|
taRage.setText(abItem.rage.replace(";", "\n"));
|
enumName = getOtherValueByType(abItem.other, VTDataTypePanel.ENUMNAME);
|
String other = abItem.other;
|
String length = getOtherValueByType(other, "length");
|
tfLen.setText(length);
|
}
|
|
if(flag == 0){
|
cbNull.setEnabled(false);
|
// cbFixLen.setEnabled(false);
|
tfLen.setEditable(false);
|
tfDefValue.setEditable(false);
|
|
|
//值域输入组件群
|
{
|
chbEnum.setVisible(false);
|
tfRage.setVisible(false);
|
btnEqu.setVisible(false);
|
|
//业务类型
|
btnAddRef.setEnabled(false);
|
btnRemoveRef.setEnabled(false);
|
|
if(enumName != null && !enumName.equals("")){
|
chbEnum.setVisible(true);
|
chbEnum.setEnabled(true);
|
chbEnum.setSelected(true);
|
|
combEnum.setEnabled(true);
|
combEnum.setSelectedItem(enumName);
|
combEnum.setEnabled(false);
|
combDefValue.setSelectedItem(abItem.defValue);
|
}
|
chbEnum.setEnabled(false);
|
}
|
|
//值域显示组件群
|
{
|
taRage.setEditable(false);
|
btnRemove.setVisible(false);
|
}
|
}
|
|
if(flag == 1 || flag == 2){
|
cbNull.setEnabled(true);
|
// cbFixLen.setEnabled(true);
|
tfLen.setEditable(true);
|
tfDefValue.setEditable(true);
|
|
|
//值域输入组件群
|
{
|
chbEnum.setVisible(true);
|
tfRage.setVisible(true);
|
btnEqu.setVisible(true);
|
|
//业务类型
|
btnAddRef.setEnabled(true);
|
btnRemoveRef.setEnabled(true);
|
}
|
|
//值域显示组件群
|
{
|
taRage.setEditable(true);
|
btnRemove.setVisible(true);
|
}
|
|
if(flag == 2){
|
if(enumName != null && !enumName.equals("")){
|
chbEnum.setSelected(true);
|
combEnum.setSelectedItem(enumName);
|
chbEnum.setEnabled(true);
|
combEnum.setEnabled(true);
|
tfRage.setVisible(false);
|
combDefValue.setSelectedItem(abItem.defValue);
|
}else{
|
chbEnum.setSelected(false);
|
chbEnum.setEnabled(true);
|
combEnum.setEnabled(true);
|
tfRage.setVisible(false);
|
}
|
}
|
}
|
|
if(abItem != null){
|
tfDefValue.setText(abItem.defValue);
|
taRage.setText(abItem.rage.replace(";", "\n"));
|
|
String btmName = getOtherValueByType(abItem.other, VTDataTypePanel.BTM);
|
String ltName = getOtherValueByType(abItem.other, VTDataTypePanel.LINKTYPENAME);
|
if(btmName != null && !btmName.equals("")){
|
tfRefName.setText(btmName);
|
updateRageUIAccordRef(1);
|
combRef.setSelectedItem("业务类型");
|
}else if(ltName != null && !ltName.equals("")){
|
tfRefName.setText(ltName);
|
updateRageUIAccordRef(1);
|
combRef.setSelectedItem("链接类型");
|
combVer.setVisible(true);
|
String version = getOtherValueByType(abItem.other, VTDataTypePanel.VERSION);
|
if(version != null && !version.equals("")){
|
if(version.equals("1")){
|
combVer.setSelectedItem("当前版本版次");
|
}else if(version.equals("3")){
|
combVer.setSelectedItem("最新版本版次");
|
}
|
}
|
}else{
|
tfRefName.setText("");
|
updateRageUIAccordRef(0);
|
}
|
|
}
|
}
|
|
/**
|
* 根据是否参照类型,设置值域是否显示
|
* flag = 0 :不参照业务类型
|
* flag = 1 :参照业务类型
|
*/
|
private void updateRageUIAccordRef(int flag){
|
if(flag == 0){
|
chbEnum.setVisible(true);
|
tfRage.setVisible(true);
|
btnEqu.setVisible(true);
|
taRage.setVisible(true);
|
btnRemove.setVisible(true);
|
}else if(flag == 1){
|
chbEnum.setVisible(false);
|
tfRage.setVisible(false);
|
btnEqu.setVisible(false);
|
taRage.setVisible(false);
|
btnRemove.setVisible(false);
|
|
chbEnum.setSelected(false);
|
tfRage.setText("");
|
taRage.setText("");
|
}
|
}
|
}
|