wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
package com.vci.client.portal.NewNewUI.actionmng;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
 
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
 
import com.vci.corba.portal.*;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLActionCls;
import com.vci.mw.ClientContextVariable;
import com.vci.client.LogonApplication;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
 
public class ActionEditDialog extends JDialog {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private final JPanel contentPanel = new JPanel();
    private JTextField plcode;
    private JTextField plname;
    private JTextField plBSUrl;
    private JComboBox plTypeType;
    private JTextField plDesc;
    private JButton okButton;
    private JButton cancelButton;
    private Map<String,String> plTypeTypeMap;
    private PLAction plAction;
    private PLActionCls cls;
    private JLabel label_1;
    private JTextField plCSClassTxt;
    private JLabel clsLable;
    private JTextField clsField;
    private JButton clsBtn;
 
    /**
     * Create the dialog.
     */
    public ActionEditDialog(PLActionCls cls, PLAction plAction) {
        super(ClientContextVariable.getFrame(), true);
        this.plAction = plAction;
        this.cls = cls;
        init();
        initplTypeTypeComb();
        ActionListener();
        initData();
        this.validate();
        this.setLocationRelativeTo(ClientContextVariable.getFrame());
        this.setVisible(true);
    }
 
    private void init() {
        this.setSize(450, 300);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        GridBagLayout gbl_contentPanel = new GridBagLayout();
        gbl_contentPanel.columnWidths = new int[]{0, 0, 0, 0, 0};
        gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
        gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
        gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
        contentPanel.setLayout(gbl_contentPanel);
        {
            JLabel label = new JLabel("编号");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 0;
            contentPanel.add(label, gbc_label);
        }
        {
            plcode = new JTextField();
            GridBagConstraints gbc_textField = new GridBagConstraints();
            gbc_textField.insets = new Insets(0, 0, 5, 5);
            gbc_textField.fill = GridBagConstraints.HORIZONTAL;
            gbc_textField.gridx = 2;
            gbc_textField.gridy = 0;
            contentPanel.add(plcode, gbc_textField);
            plcode.setColumns(10);
        }
        {
            JLabel label = new JLabel("名称");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 1;
            contentPanel.add(label, gbc_label);
        }
        {
            plname = new JTextField();
            GridBagConstraints gbc_textField_1 = new GridBagConstraints();
            gbc_textField_1.insets = new Insets(0, 0, 5, 5);
            gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
            gbc_textField_1.gridx = 2;
            gbc_textField_1.gridy = 1;
            contentPanel.add(plname, gbc_textField_1);
            plname.setColumns(10);
        }
        //增加分类
        {
            clsLable = new JLabel("分类");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 2;
            contentPanel.add(clsLable, gbc_label);
        }
        {
            clsField = new JTextField();
            clsField.setColumns(10);
            clsBtn = new JButton("选择");
            clsBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    selectCls();
                }
            });
            JPanel tPanel = new JPanel();
            tPanel.setLayout(new BorderLayout());
            tPanel.add(clsField, BorderLayout.CENTER);
            tPanel.add(clsBtn, BorderLayout.EAST);
            
            GridBagConstraints gbc_textField_1 = new GridBagConstraints();
            gbc_textField_1.insets = new Insets(0, 0, 5, 5);
            gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
            gbc_textField_1.gridx = 2;
            gbc_textField_1.gridy = 2;
            contentPanel.add(tPanel, gbc_textField_1);
        }
        {
            label_1 = new JLabel("类路径");
            GridBagConstraints gbc_label_1 = new GridBagConstraints();
            gbc_label_1.anchor = GridBagConstraints.EAST;
            gbc_label_1.insets = new Insets(0, 0, 5, 5);
            gbc_label_1.gridx = 1;
            gbc_label_1.gridy = 3;
            contentPanel.add(label_1, gbc_label_1);
        }
        {
            plCSClassTxt = new JTextField();
            GridBagConstraints gbc_plCSClassTxt = new GridBagConstraints();
            gbc_plCSClassTxt.insets = new Insets(0, 0, 5, 5);
            gbc_plCSClassTxt.fill = GridBagConstraints.HORIZONTAL;
            gbc_plCSClassTxt.gridx = 2;
            gbc_plCSClassTxt.gridy = 3;
            contentPanel.add(plCSClassTxt, gbc_plCSClassTxt);
            plCSClassTxt.setColumns(10);
        }
        {
            JLabel label = new JLabel("链接地址");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 4;
            contentPanel.add(label, gbc_label);
        }
        {
            plBSUrl = new JTextField();
            GridBagConstraints gbc_textField_2 = new GridBagConstraints();
            gbc_textField_2.insets = new Insets(0, 0, 5, 5);
            gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
            gbc_textField_2.gridx = 2;
            gbc_textField_2.gridy = 4;
            contentPanel.add(plBSUrl, gbc_textField_2);
            plBSUrl.setColumns(10);
        }
        {
            JLabel label = new JLabel("类型");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 5;
            contentPanel.add(label, gbc_label);
        }
        {
            plTypeType = new JComboBox();
            GridBagConstraints gbc_comboBox = new GridBagConstraints();
            gbc_comboBox.insets = new Insets(0, 0, 5, 5);
            gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
            gbc_comboBox.gridx = 2;
            gbc_comboBox.gridy = 5;
            contentPanel.add(plTypeType, gbc_comboBox);
        }
        {
            JLabel label = new JLabel("描述");
            GridBagConstraints gbc_label = new GridBagConstraints();
            gbc_label.insets = new Insets(0, 0, 5, 5);
            gbc_label.gridx = 1;
            gbc_label.gridy = 6;
            contentPanel.add(label, gbc_label);
        }
        {
            plDesc = new JTextField();
            GridBagConstraints gbc_textField_3 = new GridBagConstraints();
            gbc_textField_3.insets = new Insets(0, 0, 5, 5);
            gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
            gbc_textField_3.gridx = 2;
            gbc_textField_3.gridy = 6;
            contentPanel.add(plDesc, gbc_textField_3);
            plDesc.setColumns(10);
        }
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                okButton = new JButton("确定");
                buttonPane.add(okButton);
            }
            {
                cancelButton = new JButton("取消");
                buttonPane.add(cancelButton);
            }
        }
    }
 
    private void ActionListener() {
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if(plcode.getText().trim().equals("")){
                    JOptionPane.showMessageDialog(getThis(), "请输入编号", "请输入编号", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                System.out.println(plAction);
                try {
                    PLAction[] actionsInDB= UITools.getService().getAllPLAction();
                    for(int i =0;i<actionsInDB.length;i++){
                        if (plAction == null && plcode.getText().trim().equals(actionsInDB[i].plCode)) {
                            JOptionPane.showMessageDialog(getThis(),
                                    "新建Action编号重复,请重新输入编号", "Action定义",
                                    JOptionPane.ERROR_MESSAGE);
                            return;
                        }else if (plAction != null && !plAction.plCode.equals(plcode.getText().trim()) && plcode.getText().trim().equals(actionsInDB[i].plCode)) {
                            JOptionPane.showMessageDialog(getThis(),
                                    "修改Action编号重复,请重新输入编号", "Action定义",
                                    JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if(plname.getText().trim().equals("")){
                    JOptionPane.showMessageDialog(getThis(), "请输入名称", "请输入名称", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(plTypeType.getSelectedItem() == null || plTypeType.getSelectedItem().equals("")){
                    JOptionPane.showMessageDialog(getThis(), "请选择类型", "请选择类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(plAction==null){
                    save();
                }else{
                    edit();    
                }
            }
        });
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                dispose();
            }
        });
    }
    
    private void edit() {
        PLAction object = new PLAction();
        object.plOId = plAction.plOId;
        object.plCode = plcode.getText()==null?"":plcode.getText();
        object.plName = plname.getText()==null?"":plname.getText();
        object.plCSClass = plCSClassTxt.getText()==null?"":plCSClassTxt.getText();
        object.plBSUrl = plBSUrl.getText()==null?"":plBSUrl.getText();
        object.plDesc = plDesc.getText()==null?"":plDesc.getText();
        object.plCreateUser = plAction.plCreateUser;
        object.plModifyUser = LogonApplication.getUserEntityObject().getUserName();
        object.plActionCls = this.cls.id;
        object.plTypeType = (String) (plTypeType==null?"":getplTypeTypeValue());
        try {
            UITools.getService().updatePLAction(object);
            VCIOptionPane.showMessage(LogonApplication.frame, "保存成功!");
            dispose();
        } catch (VCIError e) {
            e.printStackTrace();
            VCIOptionPane.showMessage(LogonApplication.frame, "保存失败!");
        }
    }
 
    private void save() {
        PLAction plAction = new PLAction();
        plAction.plOId = ObjectUtility.getNewObjectID36();
        plAction.plCode = plcode.getText()==null?"":plcode.getText();
        plAction.plName = plname.getText()==null?"":plname.getText();
        plAction.plCSClass = plCSClassTxt.getText()==null?"":plCSClassTxt.getText();
        plAction.plBSUrl = plBSUrl.getText()==null?"":plBSUrl.getText();
        plAction.plDesc = plDesc.getText()==null?"":plDesc.getText();
        plAction.plCreateUser = LogonApplication.getUserEntityObject().getUserName();
        plAction.plModifyUser = LogonApplication.getUserEntityObject().getUserName();
        plAction.plActionCls = this.cls.id;
        plAction.plTypeType = (String) (plTypeType==null?"":getplTypeTypeValue());
        try {
            UITools.getService().savePLAction(plAction);
            VCIOptionPane.showMessage(LogonApplication.frame, "保存成功!");
            dispose();
        } catch (VCIError e) {
            e.printStackTrace();
            VCIOptionPane.showMessage(LogonApplication.frame, "保存失败!");
        }
    }
 
    /**
     * 选择分类
     */
    private void selectCls() {
        PLActionClsSelectDialog dialog = new PLActionClsSelectDialog(this);
        if(dialog.isOk()) {
            this.cls = dialog.getCurrentCls();
            clsField.setText(cls.name);
        }
    }
 
    private void initplTypeTypeComb(){
        plTypeType.addItem("");
        plTypeTypeMap = new HashMap<String,String>();
        plTypeTypeMap.put("business", "业务类型");
        plTypeTypeMap.put("link", "链接类型");
        
        Set<String> keySet = plTypeTypeMap.keySet();
        Iterator<String> iterator = keySet.iterator();
        for(;iterator.hasNext();){
            String next = iterator.next();
            plTypeType.addItem(plTypeTypeMap.get(next));
        }
    }
    
    private String getplTypeTypeValue() {
        String value = "";
        for(Map.Entry<String, String> entry : plTypeTypeMap.entrySet()){
            if(plTypeType.getSelectedItem().equals(entry.getValue())){
                value = entry.getKey();
                break;
            }
        }
        return value;
    }
    
    private void initData(){
        clsField.setEditable(false);
        if(plAction!=null){
            plcode.setText(plAction.plCode);
            plname.setText(plAction.plName);
            plCSClassTxt.setText(plAction.plCSClass);
            plBSUrl.setText(plAction.plBSUrl);
            plDesc.setText(plAction.plDesc);
            plTypeType.setSelectedItem(plTypeTypeMap.get(plAction.plTypeType));
            clsField.setText(this.cls.name);
        } else {
            clsField.setText(this.cls.name);
            clsBtn.setEnabled(false);
        }
    }
    
    private JDialog getThis(){
        return this;
    }
}