ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
package com.vci.client.oq.ui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException;
import java.awt.Toolkit;
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.Arrays;
import java.util.List;
 
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
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.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
 
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
 
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.qtm.QTD;
import com.vci.client.common.oq.OQTool;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.omd.btm.ui.BtmTree;
import com.vci.client.omd.btm.wrapper.BtmItemWrapper;
import com.vci.client.omd.linktype.LinkTypeTree;
import com.vci.client.omd.linktype.LinkTypeWrapper;
import com.vci.client.omd.linktype.itf.LinkTypeInterfaceImpl;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.oq.QTDClient;
import com.vci.client.oq.wrapper.QTDWrapper;
import com.vci.client.ui.table.CheckBoxEditor;
import com.vci.client.ui.table.CheckBoxRenderer;
import com.vci.client.ui.util.PostorderEnumeration;
import com.vci.corba.common.VCIError;
 
public class QTDPanel extends JPanel{
 
    /**
     * 
     */
    private static final long serialVersionUID = -6885848663019109473L;
    private static QTDPanel qtdPanel = null;
    /**
     * add by caill
     * 添加定位框和定位按钮,并添加left 和leftTopPanel容器
     * */
    private JTextField textField=new JTextField(20);
    private JButton sel=new JButton("定位");
    private JPanel left=new JPanel();
    private JPanel leftTopPanel=new JPanel();
    /**
     * northPanel: 创建, 修改, 删除查询模板按钮
     */
    private JPanel northPanel;
    /**
     * centerPanel: cp_treePanel, cp_mainPanel
     */
    private JSplitPane centerPanel;
    /**
     * cp_treePanel:业务类型树/连接类型树
     */
    private JPanel cp_treePanel;
    /**
     * cp_mainPanel:选择查询属性, 定制查询模板; 确定, 取消按钮
     * 执行查询
     */
    private JPanel cp_mainPanel;
    private JButton btnCreate, btnModify, btnDelete;
    private static BtmTree btmTree = new BtmTree();
    private static LinkTypeTree linkTypeTree = new LinkTypeTree();
    /**
     * cpm_northPanel : 查询模板定义列表, 查询模板定义名
     */
    private JPanel cpm_northPanel;
    private JComboBox combQTD;
    private JTextField tfName;
    /**
     * cmp_centerPanel : 选择查询属性, 定制查询模板
     */
    private JPanel cpm_centerPanel;
    private JScrollPane scrollPane;
    private JXTable abTable;
    private BtmAttrTableModel tableModel;
    private final int TABLE_HEADER_HEIGHT = 25;
    private final int ROW_HEIGHT = 30;
    /**
     * cmp_southPanel : 确定, 取消按钮
     */
    private JPanel cpm_southPanel;
    private JButton btnOK, btnCancel, btnSelectAll;
    private BtmItem selectedBtm = null;
    /**
     * 0: 查看, 1: 创建, 2: 修改
     */
    private int flag = 0;
    private JLabel qtdLab;
    private JRadioButton rdBtm;
    private JRadioButton rdLinkType;
    private ButtonGroup btnGroup;
    private LinkType selectedLinkType;
    private int isAllSelected = -1;//等于0,已经全部选中;等于1,一个都没有选中。
    private boolean selectAll = false ;
    
    private QTDPanel(){
        initUI();
        initCombQTD();
        addListener();
    }
    
    static void initVars(){
        qtdPanel = null;
        btmTree = new BtmTree();
        linkTypeTree = new LinkTypeTree();
    }
    
    public static void cleanInstance(){
        initVars();
        qtdPanel = null;
    }
    
    public static QTDPanel getInstance(){
        if(qtdPanel == null){
            qtdPanel = new QTDPanel();
        }
        if(btmTree != null){
            btmTree.initOrUpdate();
        }
        if(linkTypeTree != null){
            linkTypeTree.initOrUpdate();
        }
        
        qtdPanel.updateUI();
        return qtdPanel;
    }
    
    private void initUI(){
        this.setBackground(Color.WHITE);
        this.setLayout(new BorderLayout(0, 0));
        northPanel = new JPanel();
        this.add(northPanel, BorderLayout.NORTH);
        cp_treePanel = new JPanel();
        cp_mainPanel = new JPanel();
        //add by caill
        //为业务类型树和链接类型树添加公用定位框和定位按钮,并添加left和leftTopPanel容器
        //搜索框的设置
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0.7;
        gbc.weighty = 0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        leftTopPanel.setLayout(new GridBagLayout());
        leftTopPanel.add(textField,gbc);
        leftTopPanel.add(sel);
        left.setLayout(new BorderLayout());
        left.add(leftTopPanel,BorderLayout.NORTH);
        left.add(new JScrollPane(cp_treePanel),BorderLayout.CENTER);
        centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, cp_mainPanel);
        //add by caill end
        //centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(cp_treePanel), cp_mainPanel);
        centerPanel.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().width/5);
        centerPanel.setOneTouchExpandable(true);
        this.add(centerPanel, BorderLayout.CENTER);
        
        btnCreate = new JButton("创建");
        btnModify = new JButton("修改");
        btnDelete = new JButton("删除");
        rdBtm = new JRadioButton("业务类型");
        rdLinkType = new JRadioButton("链接类型");
        rdBtm.setSelected(true);
        btnGroup = new ButtonGroup();
        btnGroup.add(rdBtm);
        btnGroup.add(rdLinkType);
        northPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        northPanel.add(btnCreate);
        northPanel.add(btnModify);
        northPanel.add(btnDelete);
        northPanel.add(rdBtm);
        northPanel.add(rdLinkType);
        //add by caill start 
        //为定位按钮增添点击事件
        sel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //e.getSource();
                String test = textField.getText().trim();
                //当业务类型树被选中时
                if(rdBtm.isSelected()){
                    DefaultTreeModel model = (DefaultTreeModel)btmTree.getModel();
                    //model.reload();    
                    TreeNode root = (TreeNode) model.getRoot();
                    PostorderEnumeration enumeration = new PostorderEnumeration(
                            root);
                    while (enumeration.hasMoreElements()) {
                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                                .nextElement();
                        if (element.getUserObject() instanceof BtmItemWrapper) {
                            BtmItemWrapper wrapper = (BtmItemWrapper) element
                                    .getUserObject();
                                
                            if (wrapper != null && wrapper.btmItem!=null
                                    && wrapper.btmItem.name.equals(test)) {
                                TreeNode[] path = element.getPath();
                                TreePath treePath = new TreePath(path);
                                btmTree.setSelectionPath(treePath);
                                return;
                            }
                            ;
                        }
                    }
                    if (test.equals("")) {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "{ " + test + " }业务类型不存在", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
                }
                //当链接类型树被选中时
                else{
                    DefaultTreeModel model = (DefaultTreeModel)linkTypeTree.getModel();
                    //model.reload();    
                    TreeNode root = (TreeNode) model.getRoot();
                    PostorderEnumeration enumeration = new PostorderEnumeration(
                            root);
                    while (enumeration.hasMoreElements()) {
                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                                .nextElement();
                        if (element.getUserObject() instanceof LinkTypeWrapper) {
                            LinkTypeWrapper wrapper = (LinkTypeWrapper) element
                                    .getUserObject();
                                
                            if (wrapper != null && wrapper.linkType!=null
                                    && wrapper.linkType.name.equals(test)) {
                                TreeNode[] path = element.getPath();
                                TreePath treePath = new TreePath(path);
                                linkTypeTree.setSelectionPath(treePath);
                                return;
                            }
                            ;
                        }
                    }
                    if (test.equals("")) {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "{ " + test + " }业务类型不存在", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
 
                }
 
            }
 
        });    
        //为定位框增加键盘事件
        textField.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                
                JTextField text = (JTextField) e.getSource();
                String test = text.getText().trim();
                //当业务类型树被选中时
                if(rdBtm.isSelected()){
                    DefaultTreeModel model = (DefaultTreeModel)btmTree.getModel();
                    //model.reload();    
                    TreeNode root = (TreeNode) model.getRoot();
                    PostorderEnumeration enumeration = new PostorderEnumeration(
                            root);
                    while (enumeration.hasMoreElements()) {
                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                                .nextElement();
                        if (element.getUserObject() instanceof BtmItemWrapper) {
                            BtmItemWrapper wrapper = (BtmItemWrapper) element
                                    .getUserObject();    
                            if (wrapper != null && wrapper.btmItem!=null
                                    && wrapper.btmItem.name.equals(test)) {
                                TreeNode[] path = element.getPath();
                                TreePath treePath = new TreePath(path);
                                btmTree.setSelectionPath(treePath);
                                return;
                            }
                            ;
                        }
                    }
                    if (test.equals("")) {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "{ " + test + " }业务类型不存在", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
 
 
                }
                //当链接类型树被选中时
                else{
                    DefaultTreeModel model = (DefaultTreeModel)linkTypeTree.getModel();
                    //model.reload();    
                    TreeNode root = (TreeNode) model.getRoot();
                    PostorderEnumeration enumeration = new PostorderEnumeration(
                            root);
                    while (enumeration.hasMoreElements()) {
                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                                .nextElement();
                        if (element.getUserObject() instanceof LinkTypeWrapper) {
                            LinkTypeWrapper wrapper = (LinkTypeWrapper) element
                                    .getUserObject();
                                
                            if (wrapper != null && wrapper.linkType!=null
                                    && wrapper.linkType.name.equals(test)) {
                                TreeNode[] path = element.getPath();
                                TreePath treePath = new TreePath(path);
                                linkTypeTree.setSelectionPath(treePath);
                                return;
                            }
                            ;
                        }
                    }
                    if (test.equals("")) {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(
                                com.vci.client.LogonApplication.frame,
                                "{ " + test + " }业务类型不存在", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
 
                }
            }
 
        });
        //add by caill end        
 
        //设置cp_treePanel
        cp_treePanel.setLayout(new GridBagLayout());
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 0;
        g.weightx = 1.0;
        g.weighty = 1.0;
        g.fill = GridBagConstraints.BOTH;
        if(rdBtm.isSelected()){
            cp_treePanel.add(btmTree, g);
        }else if(rdLinkType.isSelected()){
            cp_treePanel.add(linkTypeTree, g);
        }
        
        
        //设置cp_mainPanel
        cp_mainPanel.setLayout(new BorderLayout());
        cpm_northPanel = new JPanel();
        cpm_centerPanel = new JPanel();
        cpm_southPanel = new JPanel();
        cp_mainPanel.add(cpm_northPanel, BorderLayout.NORTH);
        cp_mainPanel.add(cpm_centerPanel, BorderLayout.CENTER);
        cp_mainPanel.add(cpm_southPanel, BorderLayout.SOUTH);
        
        cpm_northPanel.setMinimumSize(new Dimension(400, 40));
        
        cpm_northPanel.setLayout(new GridBagLayout());
        GridBagConstraints g1 = new GridBagConstraints();
        g1.gridheight = 30;
        
        g1.anchor = GridBagConstraints.WEST;
        g1.gridx = 0;
        g1.gridy = 0;
        g1.weighty = 0.0;
        g1.fill = GridBagConstraints.NONE;
        cpm_northPanel.add(new JLabel("模板列表  "), g1);
        g1.gridx = 1;
        combQTD = new JComboBox();
        combQTD.setPreferredSize(new Dimension(300, 23));
        cpm_northPanel.add(combQTD, g1);
        g1.gridx = 2;
        qtdLab = new JLabel("模板名: ");
        cpm_northPanel.add(qtdLab, g1);
        g1.gridx = 3;
        g1.gridwidth = GridBagConstraints.REMAINDER;
        tfName = new JTextField(20);
        cpm_northPanel.add(tfName, g1);
        qtdLab.setVisible(false);
        tfName.setVisible(false);
        
        
        
        //设置cpm_centerPanel选择查询属性, 定制查询模板
        cpm_centerPanel.setBorder(BorderFactory.createTitledBorder("选择查询属性"));
        //占用空间的透明边框(间距)
        cpm_centerPanel.setAutoscrolls(true);
        cpm_centerPanel.setLayout(new BorderLayout(5, 5));
        scrollPane = new JScrollPane();
        cpm_centerPanel.add(scrollPane, BorderLayout.CENTER);
        tableModel = new BtmAttrTableModel();
        abTable = new JXTable(tableModel);
        TableColumn colIndex = abTable.getColumn(0);
        colIndex.setMaxWidth(50);
        colIndex.setMinWidth(50);
 
        TableColumn column = abTable.getColumn(1);
        column.setCellEditor(new CheckBoxEditor(new JCheckBox()));
        column.setCellRenderer(new CheckBoxRenderer());
        column.setMaxWidth(60);
        column.setMinWidth(60);
        
        abTable.setRowHeight(ROW_HEIGHT);
        abTable.setHorizontalScrollEnabled(true);
        abTable.setHighlighters(HighlighterFactory.createAlternateStriping());
        //排序后,引起其他页面的数据不显示
        abTable.setSortable(false);
        //设置表头高度
        JTableHeader tableHeader = abTable.getTableHeader();
        Dimension size = tableHeader.getPreferredSize();
        size.height = TABLE_HEADER_HEIGHT;
        tableHeader.setPreferredSize(size);
        scrollPane.setViewportView(abTable);
        
        
        //设置cpm_southPanel确定, 取消按钮
        btnSelectAll = new JButton("全选");
        btnOK = new JButton("确定");
        btnCancel = new JButton("取消");
        FlowLayout layout2 = (FlowLayout) cpm_southPanel.getLayout();
        layout2.setAlignment(FlowLayout.RIGHT);
        cpm_southPanel.setLayout(layout2);
        cpm_southPanel.add(btnSelectAll);
        cpm_southPanel.add(btnOK);
        cpm_southPanel.add(btnCancel);
        
        setEnable();
    }
    
    /**
     * 加监听
     */
    private void addListener(){
        //创建查询模板
        btnCreate.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(rdBtm.isSelected() && selectedBtm == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中业务类型创建模板", "无业务类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(rdLinkType.isSelected() && selectedLinkType == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中链接类型创建模板", "无链接类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(flag == 1){
                    return;
                }else{
                    flag = 1;
                    setEnable();
                }
            }
        });
        
        //修改查询模板
        btnModify.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(rdBtm.isSelected() && selectedBtm == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中业务类型创建模板", "无业务类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(rdLinkType.isSelected() && selectedLinkType == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中链接类型创建模板", "无链接类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                QTDWrapper qtdWrapper = (QTDWrapper)combQTD.getSelectedItem();
                if(qtdWrapper == null){
                    JOptionPane.showMessageDialog(northPanel, "请选择要修改的模板", "没有选中模板", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if(flag == 2){
                    return;
                }else{
                    flag = 2;
                    setEnable();
                    initCombQTD();
                }
            }
        });
        
        //删除查询模板
        btnDelete.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(rdBtm.isSelected() && selectedBtm == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中业务类型创建模板", "无业务类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(rdLinkType.isSelected() && selectedLinkType == null){
                    JOptionPane.showMessageDialog(northPanel, "请选中链接类型创建模板", "无链接类型", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                QTDWrapper qtdWrapper = (QTDWrapper)combQTD.getSelectedItem();
                if(qtdWrapper == null){
                    JOptionPane.showMessageDialog(northPanel, "请选择要删除的模板", "没有选中模板", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                Object[] options = { "Yes", "No" };
                String qtdName = qtdWrapper.qtd.name;
                int option = JOptionPane
                        .showOptionDialog(getInstance(), "确认是否删除查询模版定义\""
                                + qtdName + "\"", "查询模版定义删除",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options,
                                options[1]);
                //    int option = JOptionPane.showConfirmDialog(getInstance(), "是否确认删除", "删除确认", JOptionPane.YES_NO_CANCEL_OPTION);                
                //            int option = JOptionPane.showConfirmDialog(northPanel, "是否确定要删除查询模板", "确认删除", JOptionPane.YES_NO_OPTION);
                if(option != JOptionPane.YES_OPTION){
                    return;
                }
                boolean flag = false;
                try {
                    flag = ServiceProvider.getOMDService().getQTDService().deleteQTD(qtdName);
                } catch (VCIError e1) {
                    e1.printStackTrace();
                } 
                if(flag){
                    JOptionPane.showMessageDialog(northPanel, "删除查询模板成功", "删除模板成功", JOptionPane.INFORMATION_MESSAGE);
                    initCombQTD();
                }else{
                    JOptionPane.showMessageDialog(northPanel, "删除查询模板失败", "删除模板失败", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        rdBtm.addItemListener(new ItemListener() {
            
            @Override
            public void itemStateChanged(ItemEvent e) {
                cp_treePanel.removeAll();
                GridBagConstraints g = new GridBagConstraints();
                g.gridx = 0;
                g.gridy = 0;
                g.weightx = 1.0;
                g.weighty = 1.0;
                g.fill = GridBagConstraints.BOTH;
                cp_treePanel.add(btmTree, g);
                cp_treePanel.updateUI();
                selectedLinkType = null;
                tfName.setText("");
            }
        });
        rdLinkType.addItemListener(new ItemListener() {
            
            @Override
            public void itemStateChanged(ItemEvent e) {
                cp_treePanel.removeAll();
                GridBagConstraints g = new GridBagConstraints();
                g.gridx = 0;
                g.gridy = 0;
                g.weightx = 1.0;
                g.weighty = 1.0;
                g.fill = GridBagConstraints.BOTH;
                cp_treePanel.add(linkTypeTree, g);
                cp_treePanel.updateUI();
                selectedBtm = null;
                tfName.setText("");
            }
        });
        //业务类型树选择的变化
        btmTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            
            @Override
            public void valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) btmTree.getLastSelectedPathComponent();
                if(selectedNode == null){
                    selectedBtm = null;
                }
                if(selectedNode.getUserObject() instanceof BtmItemWrapper){
                    selectedBtm = ((BtmItemWrapper)selectedNode.getUserObject()).btmItem;
                }else{
                    selectedBtm = null;
                }
                initBtmAttrTable();
                initCombQTD();
                setEnable();
                
            }
        });
        //链接类型树选择的变化
        linkTypeTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            
            @Override
            public void valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) linkTypeTree.getLastSelectedPathComponent();
                if(selectedNode == null){
                    selectedLinkType = null;
                }
                if(selectedNode.getUserObject() instanceof LinkTypeWrapper){
                    selectedLinkType = ((LinkTypeWrapper)selectedNode.getUserObject()).linkType;
                }else{
                    selectedLinkType = null;
                }
                initLinkTypeAttrTable();
                initCombQTD();
                setEnable();
                
            }
        });
        
        //确定(创建, 修改业务类型的查询模板)
        btnOK.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(flag == 1){
                    if(!checkName()){
                        return;
                    }
                    QTD qtd = new QTD();
                    qtd.name = tfName.getText();
                    qtd.creator = "sam";
                    qtd.createTime = System.currentTimeMillis();
                    qtd.btmName = selectedBtm == null ? "" : selectedBtm.name;
                    qtd.linkTypeName = selectedLinkType == null ? "" : selectedLinkType.name;
                    List<String> abList = new ArrayList<String>();
                    for(int i = 0; i < abTable.getRowCount(); i++){
                        if(((JCheckBox)abTable.getValueAt(i, 1)).isSelected()){
                            abList.add((String)abTable.getValueAt(i, 2));
                        }
                    }
                    qtd.abNames = abList.toArray(new String[0]);
                    boolean addFlag = false;
                    try {
                        addFlag = ServiceProvider.getOMDService().getQTDService().addQTD(qtd);
                    } catch (VCIError e1) {
                        e1.printStackTrace();
                    } 
                    if(addFlag){
                        JOptionPane.showMessageDialog(cp_mainPanel, "增加业务类型查询模板成功", "增加模板成功", JOptionPane.INFORMATION_MESSAGE);
                    }else{
                        JOptionPane.showMessageDialog(cp_mainPanel, "增加业务类型查询模板失败", "增加模板失败", JOptionPane.ERROR_MESSAGE);
                    }
                    flag = 0;
                    updateInfo();
                }else if(flag == 2){
                    QTDWrapper qtdWrapper = (QTDWrapper)combQTD.getSelectedItem();
                    if(qtdWrapper == null){
                        JOptionPane.showMessageDialog(cp_mainPanel, "请选择要修改的模板", "没有选中模板", JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    QTD qtd = qtdWrapper.qtd;
                    List<String> abNameList = new ArrayList<String>();
                    int count = abTable.getRowCount();
                    for(int i = 0; i < count; i++){
                        if(((JCheckBox)abTable.getValueAt(i, 1)).isSelected()){
                            abNameList.add(((String)abTable.getValueAt(i, 2)));
                        }
                    }
                    qtd.abNames = abNameList.toArray(new String[0]);
                    boolean modifyFlag = false;
                    try {
                        modifyFlag = ServiceProvider.getOMDService().getQTDService().modifyQTD(qtd);
                    } catch (VCIError e1) {
                        e1.printStackTrace();
                    } 
                    if(modifyFlag){
                        JOptionPane.showMessageDialog(cp_mainPanel, "修改模板成功", "修改成功", JOptionPane.INFORMATION_MESSAGE);
                    }else{
                        JOptionPane.showMessageDialog(cp_mainPanel, "修改模板失败", "修改失败", JOptionPane.ERROR_MESSAGE);
                    }
                    flag = 0;
                    updateInfo();
                }
            }
        });
        
        combQTD.addItemListener(new ItemListener() {
            
            @Override
            public void itemStateChanged(ItemEvent e) {
                isAllSelected = -1;//等于0,已经全部选中;等于1,一个都没有选中。
                selectAll = false ;
                if(rdBtm.isSelected()){
                    initBtmAttrTable();
                }else if(rdLinkType.isSelected()){
                    initLinkTypeAttrTable();
                }
            }
        });
    //add by guo ==全选,selectAll值为false,第一次点击"全选"按钮;isAllSelected=0,属性全选中,isAllSelected=1,属性全部没有选中
        btnSelectAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                List<String> attsList = null;
                String[] attsArr;
                if(rdBtm.isSelected()){//业务类型
                    attsList = BtmProvider.getInstance().getAllAbNames(selectedBtm.name);
                } else {//链接类型
                    attsArr = new LinkTypeInterfaceImpl().getDetailAttributesByLinkTypeName(selectedLinkType.name);
                    attsList = Arrays.asList(attsArr);
                }
                int countAtts = attsList.size();
                if(selectAll == false){//第一次点击"全选"
                    selectAll = true;
                    List<String> abNameList = new ArrayList<String>();
                    for(int i = 0; i < countAtts; i++){
                        if(((JCheckBox)abTable.getValueAt(i, 1)).isSelected()){
                            abNameList.add(((String)abTable.getValueAt(i, 2)));
                        }
                    }
                    if(abNameList.size() == countAtts){
                        for(int i = 0; i < countAtts; i++){
                            ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(false);
                        }
                        isAllSelected = 1;
                    } else {
                        for(int i = 0; i < countAtts; i++){
                            ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(true);
                        }
                        isAllSelected = 0;
                    }
                } else {//已经点击过"全选"按钮
                    if(isAllSelected == 0){//属性全选中
                        for(int i = 0; i < countAtts; i++){
                            ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(false);
                        }
                         isAllSelected = 1;
                    } else if(isAllSelected == 1){//属性没有被选中
                        for(int i = 0; i < countAtts; i++){
                            ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(true);
                        }
                        isAllSelected = 0;
                    } 
                }
                abTable.repaint();
            }
        });
    };
    
    
    /**
     * 设置当前业务类型下的模板定义列表
     */
    private void initCombQTD(){
        combQTD.removeAllItems();
        if(rdBtm.isSelected() && selectedBtm == null){
            return;
        }
        if(rdLinkType.isSelected() && selectedLinkType == null){
            return;
        }
        QTD[] qtdArray = null;
        if(rdBtm.isSelected()){
            String btmName = selectedBtm.name;
            if(btmName == null || btmName.equals("")){
                return;
            }
            try {
                qtdArray = ServiceProvider.getOMDService().getQTDService().getBizTypeQTDs(btmName);
            } catch (VCIError e) {
                e.printStackTrace();
            } 
            
            if(qtdArray == null){
                return;
            }
            for(int i = 0; i < qtdArray.length; i++){
                combQTD.addItem(new QTDWrapper(qtdArray[i]));
            }
        }else if(rdLinkType.isSelected()){
            String linkTypeName = selectedLinkType.name;
            if(linkTypeName == null || linkTypeName.equals("")){
                return;
            }
            try {
                qtdArray = ServiceProvider.getOMDService().getQTDService().getLinkTypeQTDs(linkTypeName);
            } catch (VCIError e) {
                e.printStackTrace();
            }
            
            if(qtdArray == null){
                return;
            }
            for(int i = 0; i < qtdArray.length; i++){
                combQTD.addItem(new QTDWrapper(qtdArray[i]));
            }
        }
        
        
    }
    
    /**
     * 设置业务类型的属性列表
     * @param abNameList
     */
    private void initBtmAttrTable(){
        if(selectedBtm == null){
            tableModel.setRowCount(0);
            return;
        }
        List<String> selectedABS = null;
        QTDWrapper qtdWrapper = (QTDWrapper)combQTD.getSelectedItem();
        if(qtdWrapper != null){
            selectedABS = Arrays.asList(qtdWrapper.qtd.abNames);
        }
        
        List<String> abNameList = BtmProvider.getInstance().getAllAbNames(selectedBtm.name);
        int count = abNameList.size();
        tableModel.setRowCount(count);
        //重新设置table的Cell的可编辑性
        tableModel.setInitFlag(false);
        for(int i = 0; i < count; i++){
            abTable.setValueAt(i, i, 0);
            abTable.setValueAt(new JCheckBox(), i, 1);
            if(selectedABS != null){
                if(selectedABS.contains(abNameList.get(i))){
                    ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(true);
                }
            }
            abTable.setValueAt(abNameList.get(i), i, 2);
        }
        //重新设置table的Cell的可编辑性
        tableModel.setInitFlag(true);
    }
    
    /**
     * 设置链接类型的属性列表
     * @param abNameList
     */
    private void initLinkTypeAttrTable(){
        if(selectedLinkType == null){
            tableModel.setRowCount(0);
            return;
        }
        List<String> selectedABS = null;
        QTDWrapper qtdWrapper = (QTDWrapper)combQTD.getSelectedItem();
        if(qtdWrapper != null){
            selectedABS = Arrays.asList(qtdWrapper.qtd.abNames);
        }
        String[] abNameList = new LinkTypeInterfaceImpl().getDetailAttributesByLinkTypeName(selectedLinkType.name);
        int count = abNameList.length;
        tableModel.setRowCount(count);
        //重新设置table的Cell的可编辑性
        tableModel.setInitFlag(false);
        for(int i = 0; i < count; i++){
            abTable.setValueAt(i, i, 0);
            abTable.setValueAt(new JCheckBox(), i, 1);
            if(selectedABS != null){
                if(selectedABS.contains(abNameList[i])){
                    ((JCheckBox)abTable.getValueAt(i, 1)).setSelected(true);
                }
            }
            abTable.setValueAt(abNameList[i], i, 2);
        }
        //重新设置table的Cell的可编辑性
        tableModel.setInitFlag(true);
    }
    
    /**
     * 当flag为0时, unenable
     * 当flag为1时, enable
     */
    private void setEnable(){
        if(flag == 0){
            combQTD.setEnabled(true);
            qtdLab.setVisible(false);
            tfName.setVisible(false);
            
            abTable.setEnabled(false);
            btnSelectAll.setEnabled(false);
            btnOK.setEnabled(false);
            btnCancel.setEnabled(false);
        }else if(flag == 1){
            combQTD.setSelectedItem(null);
            combQTD.setEnabled(false);
            qtdLab.setVisible(true);
            tfName.setVisible(true);
            
            abTable.setEnabled(true);
            btnSelectAll.setEnabled(true);
            btnOK.setEnabled(true);
            btnCancel.setEnabled(true);
        }else if(flag == 2){
            combQTD.setEnabled(true);
            qtdLab.setVisible(false);
            tfName.setVisible(false);
            
            abTable.setEnabled(true);
            btnSelectAll.setEnabled(true);
            btnOK.setEnabled(true);
            btnCancel.setEnabled(true);
        }
    }
    
    private boolean checkName(){
        if(tfName.getText().equals("")){
            JOptionPane.showMessageDialog(this, "请输入模板定义名", "注意", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        
        String name = tfName.getText();
        if(!name.matches("[a-z A-Z]*")){
            JOptionPane.showMessageDialog(this, "模板定义名只能为英文字母", "注意", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        String qtdName = name.toLowerCase();
        
        try {
            if(ServiceProvider.getOMDService().getQTDService().isExistsQTD(qtdName)){
                JOptionPane.showMessageDialog(this, "该模板定义名已经被使用, 请更换", "注意", JOptionPane.WARNING_MESSAGE);
                return false;
            }
        } catch (VCIError e) {
            e.printStackTrace();
        } catch (HeadlessException e) {
            e.printStackTrace();
        }
        return true;
    }
    
    private void updateInfo(){
        initCombQTD();
        if(rdBtm.isSelected()){
            initBtmAttrTable();
        }else if(rdLinkType.isSelected()){
            initLinkTypeAttrTable();
        }
        setEnable();
    }
}