1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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;
    }
}