package com.vci.client.portal.NewNewUI.actionmng; import java.awt.Frame; 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.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import com.vci.client.portal.utility.UITools; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLActionParam; /** * 按钮参数创建修改窗口 * @author VCI-STGK006 * */ public class PLActionParamEditDialog extends JDialog { /** * serialVersionUID */ private static final long serialVersionUID = -2444304007551924327L; /** * 父窗口 */ private Frame owner; /** * 名称标签 */ private JLabel nameLabel; /** * 名称文本框 */ private JTextField nameField; /** * 默认值标签 */ private JLabel defaultValueLabel; /** * 默认值文本框 */ private JTextField defaultValueField; /** * 提示信息标签 */ private JLabel descLabel; /** * 提示信息文本域 */ private JTextArea descArea; /** * 确定按钮 */ private JButton okBtn; /** * 取消按钮 */ private JButton cancelBtn; /** * 继续添加按钮 */ private JButton nextBtn; /** * 0创建,1修改 */ private int flag; /** * Action对象 */ private PLAction action; /** * 修改时选择的参数对象 */ private PLActionParam param; /** * 是否保存 */ private boolean ok = false; /** * 构造器 * @param owner 父窗口 * @param title 标题 * @param flag 标记 0创建,1修改 * @param action Action对象 * @param param 参数对象 */ public PLActionParamEditDialog(Frame owner, String title, int flag, PLAction action, PLActionParam param) { super(owner, title, true); this.owner = owner; this.flag = flag; this.action = action; this.param = param; init(); } /** * 绘制窗口 */ private void init() { this.setSize(460, 300); this.setLayout(null); this.setResizable(false); nameLabel = new JLabel("参数名称"); nameLabel.setBounds(15, 15, 60, 25); nameField = new JTextField(); nameField.setBounds(70, 15, 150, 25); defaultValueLabel = new JLabel("默认值"); defaultValueLabel.setBounds(235, 15, 50, 25); defaultValueField = new JTextField(); defaultValueField.setBounds(280, 15, 150, 25); descLabel = new JLabel("提示信息"); descLabel.setBounds(15, 50, 60, 25); descArea = new JTextArea(); descArea.setLineWrap(true); JScrollPane descScrollPane = new JScrollPane(descArea); descScrollPane.setBounds(70, 50, 360, 150); nextBtn = new JButton("保存后继续添加"); nextBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { nextBtnActionListener(); } }); if(this.flag == 0) { nextBtn.setVisible(true); } else { nextBtn.setVisible(false); } nextBtn.setBounds(180, 215, 100, 25); okBtn = new JButton("保存"); okBtn.setBounds(290, 215, 50, 25); okBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okBtnActionListener(); } }); cancelBtn = new JButton("取消"); cancelBtn.setBounds(350, 215, 50, 25); cancelBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelBtnActionListener(); } }); if(this.flag != 0) { this.nameField.setText(this.param.name); this.defaultValueField.setText(this.param.defaultValue); this.descArea.setText(this.param.description); } this.add(nameLabel); this.add(nameField); this.add(defaultValueLabel); this.add(defaultValueField); this.add(descLabel); this.add(descScrollPane); this.add(nextBtn); this.add(okBtn); this.add(cancelBtn); this.validate(); this.setLocationRelativeTo(owner); this.setVisible(true); } /** * 继续添加按钮 */ private void nextBtnActionListener() { String message = save(); if(message.startsWith("0")) { if(message.equals("01")) { JOptionPane.showMessageDialog(this, "参数名已经存在!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } else if(message.equals("09")){ JOptionPane.showMessageDialog(this, "参数名称不能为空!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } else { JOptionPane.showMessageDialog(this, "添加按钮参数时发生异常:" + message.substring(1), "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } } this.ok = true; this.nameField.setText(""); this.defaultValueField.setText(""); this.descArea.setText(""); } /** * 保存按钮 */ private void okBtnActionListener() { String message = save(); if(message.startsWith("0")) { if(message.equals("01")) { JOptionPane.showMessageDialog(this, "参数名已经存在!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } else if(message.equals("09")){ JOptionPane.showMessageDialog(this, "参数名称不能为空!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } else { JOptionPane.showMessageDialog(this, "添加按钮参数时发生异常:" + message.substring(1), "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } } this.ok = true; JOptionPane.showMessageDialog(this, "保存成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE); this.dispose(); } /** * 保存对象 * @return */ private String save() { String name = getNotNullString(this.nameField.getText()); String defaultValue = getNotNullString(this.defaultValueField.getText()); String desc = getNotNullString(this.descArea.getText()); if(name == null || name.equals("")) { return "09"; } String message = ""; if(this.flag == 0) { this.param = new PLActionParam(); this.param.oid = ""; this.param.name = name; this.param.defaultValue = defaultValue; this.param.description = desc; this.param.action = this.action.plOId; message = UITools.getService().createPLActionParam(this.param); } else { this.param.name = name; this.param.defaultValue = defaultValue; this.param.description = desc; message = UITools.getService().editPLActionParam(this.param); } return message; } /** * 删除按钮 */ private void cancelBtnActionListener() { this.dispose(); } private String getNotNullString(String str) { if(str == null) { return ""; } return str.trim(); } public boolean isOk() { return ok; } }