wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
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("");
        }
    }
}