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
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
package com.vci.client.portal.Formdesign;
 
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.swing.ButtonGroup;
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.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.omd.btm.wrapper.BtmItemWrapper;
import com.vci.client.omd.linktype.LinkTypeWrapper;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.oq.QTClient;
import com.vci.client.oq.QTDClient;
import com.vci.client.portal.Formdesign.object.CompnentGroup;
import com.vci.client.portal.Formdesign.util.CompnentUtil;
import com.vci.client.portal.platformPortal.CreateQueryModelDialog;
import com.vci.client.portal.platformPortal.PlatformPortalTablePanel;
import com.vci.client.portal.utility.PRM;
import com.vci.client.portal.utility.PRMItem;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.common.portal.enums.ControlType;
import com.vci.common.portal.enums.PortalVIType;
import com.vci.common.portal.enums.PortalVITypeFlag;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.PortalVI;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.qtm.QTInfo;
 
/**
 * 自定义ui界面
 * 
 * @author liudi
 * 
 */
public class FormDesignDialog extends JDialog implements DropTargetListener, DragGestureListener, DragSourceListener {
    /**
     * 
     */
    // add by guo
    private boolean _isBtm = false;
    private static final long serialVersionUID = 1L;
    private JPanel attrPane = new JPanel();
    private JPanel contentPanel = new JPanel();
    private JButton addModelButton;
    private int type1 = 0;
    private String name;
    private boolean editFlag = false;
    private int KeyFlag = 0;
    private JPanel mainPanel = new JPanel();
    private int countX = 0;
    private int countY = 0;
    private List<JLabel> JLabelList = new ArrayList<JLabel>();
    DragSource dragSource;
 
    private String titleName = null;
    // 默认线的宽度
    static final int LINEWIDTH = 3;
 
    static final BasicStroke linestyle = new BasicStroke(LINEWIDTH);
    // 记录删除组件后的组件在布局中的坐标
    int[] coordinate;
 
    // 功能按钮
    private JButton saveBtn;
    private JButton clearCompnent;
    private JButton deleteCompnent;
 
    // 欲删除的组件
    private Component selectedComponent;
    /**
     * 页面元素
     */
//    private JLabel labelCom = null;
//    private JTextField textField = null;
//    private JTextArea textArea = null;
//    private JScrollPane jsp = null;
//    private VCIJCalendarPanel calendarPanel = null;
//    private VCIJComboBox comboBox;
//    private TextButtonJPanel textBtn = null;
//    private CanzhaoJPanel cz = null;
//    private JCheckBox checkBox = null;
//    private FileChooserJPanel fileChooserJPanel = null;
 
    private GridBagLayout gridBagLayout;
    // 组件坐标
    int x = 0, y = 0, width = 100, height = 20;
 
    // 组件唯一标识
    //private int comHashCode = 0;
    private JScrollPane jScrollPane;
 
    // 面板高度
    //private int panelheight;
 
    private int gridBaglayoutRowCount = 0;
    AttribItem attribItem;
    //String filenamePath;
 
    // 对象类型,可能是业务类型,也可能是链接类型
    private static String otName = "";
 
    //private Map<Component, String> textAreaMap = new HashMap<Component, String>();
 
    /**
     * 存储组件
     */
    private ArrayList<CompnentGroup> _lstCompnent = new ArrayList<CompnentGroup>();
 
    private WidgetPanel widgetPanel;
    private Object selectTreeNodeobject;
    private PortalVI pvi;
    private PRM prm;
    private PRMItem prmItem;
    private JPanel configPanel;
 
    /**
     * 存储属性名称和属性对象
     */
    //private Map<String, AttribItem> attribItemMap = new HashMap<String, AttribItem>();
    /**
     * 保存组件和属性的关系
     */
    //private Map<String, PRMItem> comPRMItemMap = (Map<String, PRMItem>) new ListOrderedMap();
    private PortalVIType portalVIType;
    // public static DragTreemain getInstance(){
    // if(dragTreemain == null){
    // dragTreemain = new DragTreemain(selectTreeNodeobject,type);
    // }
    // return dragTreemain;
    // }
 
    /**
     * 显示列数,默认是3列
     */
    private int colCount = 3;
    private PortalVITypeFlag typeFlag;
    private PlatformPortalTablePanel platformPortalTablePanel;
 
    public FormDesignDialog(Object object, PortalVIType portalVIType, PortalVI pvi, Boolean editFlag,
            PlatformPortalTablePanel platformPortalTablePanel, PortalVITypeFlag typeFlag) {
        this(object, portalVIType, pvi, editFlag, platformPortalTablePanel, typeFlag, false);
    }
 
    // add by guo
    public FormDesignDialog(Object object, PortalVIType portalVIType, PortalVI pvi, Boolean editFlag,
            PlatformPortalTablePanel platformPortalTablePanel, PortalVITypeFlag typeFlag, boolean isTrue) {
        super(LogonApplication.frame, true);
 
        this.titleName = "表单定义";
 
        this.selectTreeNodeobject = object;
        this.portalVIType = portalVIType;
        this._isBtm = isTrue;
        this.pvi = pvi;
        this.typeFlag = typeFlag;
        this.editFlag = editFlag;
        this.platformPortalTablePanel = platformPortalTablePanel;
        if (pvi != null) {
            titleName = pvi.viName;
        }
        init();
        actionListener();
        fillQtNameCom();
        initData();
        display();
    }
 
    private void init() {
        if (selectTreeNodeobject instanceof BtmItemWrapper) {
            otName = ((BtmItemWrapper) selectTreeNodeobject).btmItem.name;
        } else if (selectTreeNodeobject instanceof LinkTypeWrapper) {
            otName = ((LinkTypeWrapper) selectTreeNodeobject).linkType.name;
        }
        getContentPane().setLayout(new BorderLayout());
        dragSource = DragSource.getDefaultDragSource();
        dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
        attrPane.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                // TODO Auto-generated method stub
            }
 
            @Override
            public void keyReleased(KeyEvent e) {
                KeyFlag = 0;
                // TODO Auto-generated method stub
            }
 
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 17) {
                    KeyFlag = 1;
                }
                // TODO Auto-generated method stub
            }
        });
        new DropTarget(attrPane, DnDConstants.ACTION_COPY_OR_MOVE, this);
        attrPane.setBorder(new TitledBorder("页面定义"));
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, createTreePanel(), createTextPanel());
        splitPane.setDividerLocation(250);
        splitPane.setOneTouchExpandable(true);
 
        getContentPane().add(splitPane, BorderLayout.CENTER);
 
        gridBagLayout = new GridBagLayout();
        Dimension panelDimension = jScrollPane.getPreferredSize();
        //panelheight = panelDimension.height;
        gridBaglayoutRowCount = 100;// panelheight / 40;
        int[] gridBaglayoutRow = new int[gridBaglayoutRowCount];
        double[] gridBaglayoutRowWeidth = new double[gridBaglayoutRowCount];
        for (int i = 0; i < gridBaglayoutRowCount; i++) {
            gridBaglayoutRow[i] = 30;// 20;
            gridBaglayoutRowWeidth[i] = 0.1;
        }
        gridBagLayout.rowWeights = gridBaglayoutRowWeidth;
        gridBagLayout.rowHeights = gridBaglayoutRow;
        gridBagLayout.columnWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
        gridBagLayout.columnWidths = new int[] { 1, 1, 1, 1, 1 };
        attrPane.setLayout(gridBagLayout);
 
        panel = new JPanel(new GridBagLayout());
        panelMain = new JPanel();
        panelMain.add(panel, BorderLayout.WEST);
        mainPanel.add(panelMain, BorderLayout.NORTH);
 
        lblNewLabel = new JLabel("名称");
        GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
        gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
        gbc_lblNewLabel.fill = GridBagConstraints.WEST;
        gbc_lblNewLabel.gridx = 0;
        gbc_lblNewLabel.gridy = 0;
        panel.add(lblNewLabel, gbc_lblNewLabel);
 
        viName = new JTextField();
        GridBagConstraints gbc_viName = new GridBagConstraints();
        gbc_viName.gridwidth = 4;
        gbc_viName.insets = new Insets(0, 0, 0, 5);
        gbc_viName.gridx = 1;
        gbc_viName.gridy = 0;
        gbc_viName.weightx = 0.5;
        gbc_viName.fill = GridBagConstraints.HORIZONTAL;
        viName.setColumns(40);
        panel.add(viName, gbc_viName);
 
        qtNameLab = new JLabel("查询模板名称");
        GridBagConstraints gbc_qtNameLab = new GridBagConstraints();
        gbc_qtNameLab.anchor = GridBagConstraints.EAST;
        gbc_qtNameLab.gridwidth = 2;
        gbc_qtNameLab.insets = new Insets(0, 0, 0, 5);
        gbc_qtNameLab.gridx = 5;
        gbc_qtNameLab.gridy = 0;
        gbc_qtNameLab.anchor = GridBagConstraints.NORTHEAST;
        panel.add(qtNameLab, gbc_qtNameLab);
 
        qtName = new JComboBox();
        GridBagConstraints gbc_qtName = new GridBagConstraints();
        gbc_qtName.gridwidth = 3;
        gbc_qtName.insets = new Insets(0, 0, 0, 5);
        gbc_qtName.gridx = 7;
        gbc_qtName.gridy = 0;
        qtName.setPreferredSize(new Dimension(240, 23));
        panel.add(qtName, gbc_qtName);
 
        addModelButton = new JButton("添加");
        GridBagConstraints gbc_addModelButton = new GridBagConstraints();
        gbc_addModelButton.anchor = GridBagConstraints.WEST;
        gbc_addModelButton.insets = new Insets(0, 0, 0, 5);
        gbc_addModelButton.gridx = 10;
        gbc_addModelButton.gridy = 0;
        panel.add(addModelButton, gbc_addModelButton);
        if (editFlag == false) {
            addModelButton.setVisible(false);
        }
 
        label = new JLabel("显示列数");
        GridBagConstraints gbc_label = new GridBagConstraints();
        gbc_label.gridwidth = 2;
        gbc_label.insets = new Insets(0, 0, 0, 5);
        gbc_label.gridx = 11;
        gbc_label.gridy = 0;
        panel.add(label, gbc_label);
 
        componentDisCol = new JTextField();
        GridBagConstraints gbc_componentDisCol = new GridBagConstraints();
        gbc_componentDisCol.gridwidth = 2;
        gbc_componentDisCol.insets = new Insets(0, 0, 0, 5);
        gbc_componentDisCol.gridx = 13;
        gbc_componentDisCol.gridy = 0;
        componentDisCol.setText(colCount + "");
        componentDisCol.setColumns(10);
        panel.add(componentDisCol, gbc_componentDisCol);
 
        setColBtn = new JButton("设置");
        GridBagConstraints gbc_setColBtn = new GridBagConstraints();
        gbc_setColBtn.insets = new Insets(0, 0, 0, 5);
        gbc_setColBtn.gridx = 15;
        gbc_setColBtn.gridy = 0;
        panel.add(setColBtn, gbc_setColBtn);
 
        label_1 = new JLabel("位置");
        GridBagConstraints gbc_label_1 = new GridBagConstraints();
        gbc_label_1.insets = new Insets(0, 0, 0, 5);
        gbc_label_1.gridx = 16;
        gbc_label_1.gridy = 0;
        panel.add(label_1, gbc_label_1);
 
        compIndex = new JTextField();
        GridBagConstraints gbc_compIndex = new GridBagConstraints();
        gbc_compIndex.gridwidth = 2;
        gbc_compIndex.insets = new Insets(0, 0, 0, 5);
        gbc_compIndex.gridx = 17;
        gbc_compIndex.gridy = 0;
        compIndex.setColumns(10);
        panel.add(compIndex, gbc_compIndex);
 
        compIndexBtn = new JButton("调整位置");
        GridBagConstraints gbc_compIndexBtn = new GridBagConstraints();
        gbc_compIndexBtn.gridwidth = 2;
        gbc_compIndexBtn.insets = new Insets(0, 0, 0, 5);
        gbc_compIndexBtn.gridx = 19;
        gbc_compIndexBtn.gridy = 0;
        panel.add(compIndexBtn, gbc_compIndexBtn);
 
//        deleteRadio = new JRadioButton("删除前缀(值为字符个数)");
//        GridBagConstraints gbc_deleteRadio = new GridBagConstraints();
//        gbc_deleteRadio.gridwidth = 2;
//        gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
//        gbc_deleteRadio.insets = new Insets(0, 0, 0, 5);
//        gbc_deleteRadio.gridx = 1;
//        gbc_deleteRadio.gridy = 1;
//        panel.add(deleteRadio, gbc_deleteRadio);
//        bg.add(deleteRadio);
//        deleteRadio.setSelected(true);
//
//        addRadio = new JRadioButton("增加前缀(值为要增加的字符)");
//        GridBagConstraints gbc_addRadio = new GridBagConstraints();
//        gbc_addRadio.gridwidth = 2;
//        gbc_addRadio.insets = new Insets(0, 0, 0, 5);
//        gbc_addRadio.gridx = 3;
//        gbc_addRadio.gridy = 1;
//        panel.add(addRadio, gbc_addRadio);
//        bg.add(addRadio);
//
//        label_2 = new JLabel("值");
//        GridBagConstraints gbc_label_2 = new GridBagConstraints();
//        gbc_label_2.insets = new Insets(0, 0, 0, 5);
//        gbc_label_2.gridwidth = 2;
//        gbc_label_2.gridx = 5;
//        gbc_label_2.gridy = 1;
//        gbc_label_2.anchor = GridBagConstraints.NORTHEAST;
//        panel.add(label_2, gbc_label_2);
 
//        valueIndex = new JTextField();
//        GridBagConstraints gbc_valueIndex = new GridBagConstraints();
//        gbc_valueIndex.gridwidth = 2;
//        gbc_valueIndex.anchor = GridBagConstraints.WEST;
//        gbc_valueIndex.insets = new Insets(0, 0, 0, 5);
//        gbc_valueIndex.gridx = 7;
//        gbc_valueIndex.gridy = 1;
//        gbc_valueIndex.weightx = 0.5;
//        gbc_valueIndex.fill = GridBagConstraints.HORIZONTAL;
//        valueIndex.setColumns(10);
//        panel.add(valueIndex, gbc_valueIndex);
//
//        editIndexBtn = new JButton("修改");
//        GridBagConstraints gbc_editIndexBtn = new GridBagConstraints();
//        gbc_editIndexBtn.insets = new Insets(0, 0, 0, 5);
//        gbc_editIndexBtn.anchor = GridBagConstraints.WEST;
//        gbc_editIndexBtn.gridx = 10;
//        gbc_editIndexBtn.gridy = 1;
//        panel.add(editIndexBtn, gbc_editIndexBtn);
 
//        viewI18nButton = new JButton("查看国际化字典");
//        GridBagConstraints gbc_viewI18nButton = new GridBagConstraints();
//        gbc_viewI18nButton.insets = new Insets(0, 0, 0, 5);
//        gbc_viewI18nButton.anchor = GridBagConstraints.WEST;
//        gbc_viewI18nButton.gridx = 12;
//        gbc_viewI18nButton.gridy = 1;
//        panel.add(viewI18nButton, gbc_viewI18nButton);
    }
 
    private void display() {
        Insets screenInsets = Toolkit.getDefaultToolkit()
                .getScreenInsets(LogonApplication.frame.getGraphicsConfiguration());
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(0, 0);
        // dialog.setResizable(false);
        this.setSize((int) screenSize.getWidth(), (int) (screenSize.getHeight() - screenInsets.bottom));
    }
 
    private JPanel createTreePanel() {
        JPanel treePanel = new JPanel();
        JScrollPane js = new JScrollPane();
        DragTree tree = new DragTree(selectTreeNodeobject, otName);
        treePanel.setLayout(new BorderLayout());
        js.setViewportView(tree);
        treePanel.add(js, BorderLayout.CENTER);
        return treePanel;
    }
 
    private JPanel createTextPanel() {
        JPanel btnPanel = new JPanel();
        saveBtn = new JButton("保存");
        clearCompnent = new JButton("清空");
        deleteCompnent = new JButton("删除组件");
        btnPanel.add(saveBtn);
        btnPanel.add(clearCompnent);
        btnPanel.add(deleteCompnent);
 
        addCustBtn = new JButton("添加自定义组件");
        btnPanel.add(addCustBtn);
 
        previewBtn = new JButton("预览");
        btnPanel.add(previewBtn);
 
//        attrListBtn = new JButton("属性列表");
//        btnPanel.add(attrListBtn);
 
        configPanel = new JPanel();
        configPanel.setBorder(new TitledBorder("设置"));
        configPanel.setLayout(new BorderLayout());
        widgetPanel = new WidgetPanel(prmItem, attribItem, _lstCompnent, this);
        configPanel.add(widgetPanel, BorderLayout.CENTER);
 
        mainPanel.setLayout(new BorderLayout());
        contentPanel.setLayout(new BorderLayout());
        jScrollPane = new JScrollPane(attrPane);
        jScrollPane.setPreferredSize(new Dimension(800, 800));
        contentPanel.add(jScrollPane, BorderLayout.CENTER);
        // contentPanel.add(buttonPanel(),BorderLayout.SOUTH);
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        mainPanel.add(btnPanel, BorderLayout.SOUTH);
        // mainPanel.setBorder(BorderFactory
        // .createTitledBorder("Drop target for filenames"));
        mainPanel.add(configPanel, BorderLayout.EAST);
        return mainPanel;
    }
 
    private void actionListener() {
        // 修改前缀
//        editIndexBtn.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent paramActionEvent) {
//                if (JLabelList.size() < 1) {
//                    VCIOptionPane.showMessage(LogonApplication.frame, "请选择要修改的组件!");
//                    return;
//                }
//                String setLabIndex = valueIndex.getText();
//                if (setLabIndex != null && setLabIndex.length() > 0 && deleteRadio.isSelected()) {
//                    int labIndex = 0;
//                    try {
//                        labIndex = Integer.parseInt(setLabIndex);
//                    } catch (Exception e) {
//                        VCIOptionPane.showMessage(LogonApplication.frame, "输入值必须为整数!");
//                        return;
//                    }
//                    if (labIndex < 1) {
//                        VCIOptionPane.showMessage(LogonApplication.frame, "输入值无效!");
//                        return;
//                    }
//                    for (int i = 0; i < JLabelList.size(); i++) {
//                        String labText = JLabelList.get(i).getText();
//                        if (labText.length() <= labIndex) {
//                            VCIOptionPane.showMessage(LogonApplication.frame, "输入值必须小于字段长度!");
//                            return;
//                        }
//                        labText = labText.substring(labIndex);
////                        if (comPRMItemMap.containsKey(labText)) {
////                            VCIOptionPane.showMessage(LogonApplication.frame, "修改后字段名不能与当前已有字段同名!");
////                            return;
////                        }
//                        //prmItem = comPRMItemMap.get(JLabelList.get(i).getText());
//                        prmItem.setItemField(labText);
//                        JLabelList.get(i).setText(labText);
//                        //comPRMItemMap.remove(prmItem.getItemField());
//                        //comPRMItemMap.put(labText, prmItem);
//                    }
//                } else if (setLabIndex != null && setLabIndex.length() > 0 && addRadio.isSelected()) {
//                    for (int i = 0; i < JLabelList.size(); i++) {
//                        String labText = JLabelList.get(i).getText();
//                        labText = setLabIndex + labText;
////                        if (comPRMItemMap.containsKey(labText)) {
////                            VCIOptionPane.showMessage(LogonApplication.frame, "修改后字段名不能与当前已有字段同名!");
////                            return;
////                        }
//                        JLabelList.get(i).setText(labText);
//                        prmItem.setItemField(labText);
//                        //comPRMItemMap.remove(JLabelList.get(i).getText());
//                        //comPRMItemMap.put(labText, prmItem);
//                    }
//                } else {
//                    VCIOptionPane.showMessage(LogonApplication.frame, "值不能为空!");
//                    return;
//                }
//                layoutComponent();
//                configPanel.remove(widgetPanel);
//                addWidgetPanel();
//                configPanel.updateUI();
//            }
//        });
        // 保存页面元素
        saveBtn.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // filenamePath = JOptionPane.showInputDialog("输入文件名称");
                // if(filenamePath==null||"".equals(filenamePath)){
                // return;
                // }
                boolean flag = false;
                if (_isBtm == false) {
                    if (viName.getText() == null || "".equals(viName.getText())) {
                        VCIOptionPane.showMessage(LogonApplication.frame, "名称不能为空!");
                        return;
                    }
                    Component[] cs = attrPane.getComponents();
                    if (cs == null || cs.length == 0) {
                        VCIOptionPane.showMessage(LogonApplication.frame, "页面不能为空!");
                        return;
                    }
                    LinkedList<VCIJTableNode<PortalVI>> list = platformPortalTablePanel.getTablePanel().getTableModel()
                            .getList();
                    for (int i = 0; i < list.size(); i++) {
                        VCIJTableNode<PortalVI> vcijTableNode = list.get(i);
                        PortalVI object = vcijTableNode.getObject();
                        if (pvi != null) {
                            try {
                                flag = UITools.getService().judgeUpdateButton(typeFlag.getIntVal(), pvi.viName, pvi.typeName);
                            } catch (VCIError e) {
                                showMessage(LogonApplication.frame, new VCIException(e.code, e.messages));
                                return;
                            }
                            if (flag && (!viName.getText().equals(titleName)) && (titleName != null)) {
                                VCIOptionPane.showMessage(LogonApplication.frame, "该表单已经被引用,不能修改名称!");
                                viName.setText(pvi.viName);
                                return;
                            }
                            if (!object.id.equals(pvi.id)) {
                                if (object.viName.equals(viName.getText())) {
                                    VCIOptionPane.showMessage(LogonApplication.frame, "名称已经存在!");
                                    return;
                                }
                            }
                        } else {
                            if (object.viName.equals(viName.getText())) {
                                VCIOptionPane.showMessage(LogonApplication.frame, "名称已经存在!");
                                return;
                            }
                        }
 
                    }
                    if (saveForm()) {
                        dispose();
                    }
                } else {
                    try {
                        flag = UITools.getService().judgeUpdateButton(typeFlag.getIntVal(), pvi.viName, pvi.typeName);
                        if (saveForm()) {
                            dispose();
                        }
                    } catch (VCIError e) {
                        showMessage(LogonApplication.frame, new VCIException(e.code, e.messages));
                        return;
                    }
                }
            }
        });
 
        // 清空页面元素
        clearCompnent.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
                Object[] options = { "Yes", "No" };
                int option = JOptionPane.showOptionDialog(LogonApplication.frame, "确认是否清除所有组件", "表单页面定义",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
                // int option = JOptionPane.showConfirmDialog(getInstance(), "是否确认删除", "删除确认",
                // JOptionPane.YES_NO_CANCEL_OPTION);
                if (option != JOptionPane.YES_OPTION) {
                    return;
                }
                countX = 0;
                countY = 0;
                attrPane.removeAll();
                attrPane.updateUI();
                _lstCompnent.clear();
                configMap.clear();
                //comPRMItemMap.clear();
            }
        });
 
        // 删除指定组件
        deleteCompnent.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (selectedComponent instanceof JLabel) {
                    attrPane.remove(configMap.get(selectedComponent));
                    attrPane.remove(selectedComponent);
                    configMap.remove(selectedComponent);
 
                    for (int i = 0; i < _lstCompnent.size(); i++) {
                        if (_lstCompnent.get(i).getjLabel() != null && ((JLabel) selectedComponent).getText()
                                .equals(_lstCompnent.get(i).getjLabel().getText())) {
                            //comPRMItemMap.remove(((JLabel) selectedComponent).getText());
                            _lstCompnent.remove(i);
                            break;
                        }
                    }
                    attrPane.updateUI();
                    attrPane.validate();
 
                    layoutComponent();
                } else {
                    VCIOptionPane.showMessage(LogonApplication.frame, "请选择了组件名称进行删除!");
                }
            }
 
        });
 
        addCustBtn.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
                CustomWidgetDialog dialog = new CustomWidgetDialog(null, null, selectTreeNodeobject, null);//, comPRMItemMap);
                dialog.setVisible(true);
                String arrtName = dialog.getArrtName();
                if ("".equals(arrtName)) {
                    return;
                }
                CompnentGroup gg = new CompnentGroup(arrtName);
                String attrDisType = dialog.getAttrDisType();
                if (attribItem == null) {
                    attribItem = new AttribItem();
                }
                attribItem.name = dialog.getArrtName();
                gg.setPrmItem(dialog.getPrmItem());
                
                addCustomComponent(gg, arrtName, attrDisType);
                _lstCompnent.add(gg);
                layoutComponent();
            }
        });
        previewBtn.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
//                Component[] cs = attrPane.getComponents();// 遍历内容控制面版
                List<PRMItem> prmItemList = new ArrayList<PRMItem>();
//                for (int i = 0; i < cs.length; i++) {
//                    String name = "";
//                    if (cs[i] instanceof JLabel) {
//                        name = ((JLabel) cs[i]).getText();
//                    }
//                    if (name != null && !"".equals(name)) {
//                        PRMItem newPrmItem = comPRMItemMap.get(name);
//                        if (newPrmItem != null) {
//                            prmItemList.add(newPrmItem);
//                        }
//                    }
//                }
                for (int i = 0; i < _lstCompnent.size(); i++) {
                    prmItemList.add(_lstCompnent.get(i).getPrmItem());
                }
                
                PortalVI p = new PortalVI();
                p.viType = portalVIType.getIntVal();
                p.typeFlag = typeFlag.getIntVal();
                PRM newPrm = new PRM();
                newPrm.setShowCols(componentDisCol.getText());
                newPrm.setFormQtName((String) qtName.getSelectedItem());
                newPrm.setPrmItemList(prmItemList);
                String prmText;
                try {
                    prmText = UITools.getPRMText(newPrm);
                    p.viName = viName.getText();
                    p.typeName = otName;
                    p.prm = prmText;
                } catch (Throwable e) {
                    e.printStackTrace();
                }
 
                PreviewDialog pd = new PreviewDialog(p, typeFlag);
                pd.setVisible(true);
            }
        });
        setColBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent paramActionEvent) {
                colCount = Integer.parseInt(componentDisCol.getText());
                if (colCount > 3) {
                    VCIOptionPane.showMessage(LogonApplication.frame, "显示列不能超过3列!");
                    return;
                }
                layoutComponent();
            }
        });
 
        compIndexBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent paramActionEvent) {
                int setIndex = Integer.parseInt(compIndex.getText());
                if (setIndex < 1)
                    return;
                
                //ArrayList<CompnentGroup> newGroupList = new ArrayList<CompnentGroup>();
                String labText = ((JLabel) selectedComponent).getText();
                CompnentGroup group = getCompnentGroup(labText);
                _lstCompnent.remove(group);
                _lstCompnent.add(setIndex - 1, group);
                
//                List<CompnentGroup> hidComlist = new ArrayList<CompnentGroup>();
//                for (int i = 0; i < _lstCompnent.size(); i++) {
//                    if (_lstCompnent.get(i).getjLabel() == null) {
//                        hidComlist.add(_lstCompnent.get(i));
//                    }
//                }
//                for (int i = 0; i < hidComlist.size(); i++) {
//                    _lstCompnent.remove(hidComlist.get(i));
//                }
//                for (int i = 0; i < _lstCompnent.size(); i++) {
//                    if (labText.equals(_lstCompnent.get(i).getjLabel().getText())) {
//                        if (setLabIndex - 1 > i) {
//                            _lstCompnent.add(setLabIndex, _lstCompnent.get(i));
//                            _lstCompnent.remove(i);
//                        } else {
//                            _lstCompnent.add(setLabIndex - 1, _lstCompnent.get(i));
//                            _lstCompnent.remove(i + 1);
//                        }
//                        break;
//                    }
//                }
//                for(int i=0;i<_lstCompnent.size();i++){
//                    newGroupList.add(_lstCompnent.get(i));
//                }
//                _lstCompnent = newGroupList;
                layoutComponent();
            }
        });
 
        // ===add by guo===
        addModelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent paramActionEvent) {
                String btmName;
                if (selectTreeNodeobject instanceof BtmItemWrapper) {
                    btmName = ((BtmItemWrapper) selectTreeNodeobject).btmItem.name;
                    CreateQueryModelDialog queryModelDialog = new CreateQueryModelDialog(FormDesignDialog.this,
                            selectTreeNodeobject, PortalVITypeFlag.BtmType);
                    name = queryModelDialog.getSelectedObject1();
                    dialog(btmName, queryModelDialog);
 
                } else if (selectTreeNodeobject instanceof LinkTypeWrapper) {
                    btmName = ((LinkTypeWrapper) selectTreeNodeobject).linkType.name;
                    CreateQueryModelDialog queryModelDialog = new CreateQueryModelDialog(FormDesignDialog.this,
                            selectTreeNodeobject, PortalVITypeFlag.LinkType);
                    name = queryModelDialog.getSelectedObject2();
                    dialog(btmName, queryModelDialog);
                }
 
            }
        });
//       viewI18nButton.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent paramActionEvent) {
//                i18nTable();
//            }
//        });
    }
 
    /**
     * 
     * <p>
     * 国际化字典Dialog:
     * </p>
     * 
     * @author yangyang
     * @time 2017-10-31
     */
//    private void i18nTable(){
//        VciI18nTableDialog vi18n = new VciI18nTableDialog();
//        vi18n.setModal(true);
//        vi18n.init();
//        vi18n.setSize(900,600);
//        vi18n.setLocationRelativeTo(ClientContextVariable.getFrame());
//        vi18n.setVisible(true);
//    }
    private void dialog(String btmName, CreateQueryModelDialog queryModelDialog) {
        if (!"".equals(name) && name != null) {
            qtName.removeAllItems();
            if (type1 == 1) {
                btmName = ((BtmItemWrapper) selectTreeNodeobject).btmItem.name;
            } else if (type1 == 2) {
                btmName = ((LinkTypeWrapper) selectTreeNodeobject).linkType.name;
            }
            try {
                QTInfo[] qts = ServiceProvider.getOMDService().getQTDService().getObjTypeQTs(btmName);
                for (QTInfo qt : qts) {
                    qtName.addItem(qt.qtName.trim());
                }
            } catch (VCIError e) {
                e.printStackTrace();
            }
            qtName.setSelectedItem(name);
            queryModelDialog.dispose();
        }
    }
 
    public void showMessage(Component parent, VCIException exp) {
        String message = LocaleDisplay.getI18nString(exp, "PLMUIService", this.getLocale());
        VCIJOptionPane.showMessage(parent, message);
    }
 
    /**
     * 添加自定义组件
     * 
     * @param gg
     * @param arrtName
     */
    private void addCustomComponent(CompnentGroup gg, String arrtName, String type) {
//        labelCom = new JLabel(arrtName);
//        textField = new JTextField();
//        textField.setEditable(false);
//        textField.setPreferredSize(new Dimension(90, 25));
//        
//        textBtn = new TextButtonJPanel();
//        
//        textArea = new JTextArea();
//        textArea.setEnabled(false);
//        textArea.setEditable(false);
//        
//        calendarPanel = new VCIJCalendarPanel();
//        
//        comboBox = new VCIJComboBox();
//        comboBox.setEditable(false);
//        
//        cz = new CanzhaoJPanel();
//        
//        checkBox = new JCheckBox();
//        
//        fileChooserJPanel = new FileChooserJPanel();
        // System.out.println("X==" + countX + ";Y==" + countY);
//        int nextCountX = 0;
 
        ControlType ctrlType = ControlType.Parse(type);
        if (ctrlType == null)
            return;
 
        CompnentUtil.CreateCompent(gg, ctrlType);
 
        JLabel label = gg.getjLabel();
 
        configMap.put(gg.getjLabel(), gg.getjCompnent());
 
//        Map<String, List<String>> typeMap = TypeConstant.getTypeMap();
//        String vtDataType = "";
//        
//        for (Map.Entry<String, List<String>> entry : typeMap.entrySet()) {
//            List<String> value = entry.getValue();
//            for (int i = 0; i < value.size(); i++) {
//                if (type.equals(value.get(i))) {
//                    vtDataType = entry.getKey();
//                }
//            }
//        }
//        if (vtDataType.equals("VTInteger") || vtDataType.equals("VTString")
//                || vtDataType.equals("VTDouble")) {
//        }
//        // textarea类型
//        else if (vtDataType.equals("VTNote")) {
//        }
//        // 日期类型
//        else if (vtDataType.equals("VTDate") || vtDataType.equals("VTTime")
//                || vtDataType.equals("VTDateTime")) {
//        }
//        // 参照类型
//        else if (vtDataType.equals("canzhao")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(cz, new GridBagConstraints(nextCountX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, cz);
//            gg.setjCompnent(cz);
//            gg.setjLabel(labelCom);
//        }
//        // boolean类型
//        else if (vtDataType.equals("VTBoolean")) {
//        }
//        // 文件选择组件
//        else if (vtDataType.equals("VTFilePath")) {
//        }else if(vtDataType.equals("partition")){
//            
//        }else{
//        }
        if (btmAttrMap.size() == 0) {
            initBtmAttrMap();
        }
        attribItem = btmAttrMap.get(arrtName);
        //attribItemMap.put(arrtName, attribItem);
        gg.setAItem(attribItem);
        
        // attrNameAndCompMap.put(arrtName, configMap);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                attrPane.requestFocus();
                super.mouseClicked(e);
                labelActionListener(e);
            }
        });
    }
 
    /**
     * 添加自定义组件
     * 
     * @param gg
     * @param arrtName
     */
//    private void addCustomComponent_old(Group gg, String arrtName, String type) {
//        labelCom = new JLabel(arrtName);
//        textField = new JTextField();
//        textField.setEditable(false);
//        textField.setPreferredSize(new Dimension(90, 25));
//        textArea = new JTextArea();
//        textArea.setEnabled(false);
//        textArea.setEditable(false);
//        calendarPanel = new VCIJCalendarPanel();
//        comboBox = new VCIJComboBox();
//        comboBox.setEditable(false);
//        cz = new CanzhaoJPanel();
//        checkBox = new JCheckBox();
//        fileChooserJPanel = new FileChooserJPanel();
//        //System.out.println("X==" + countX + ";Y==" + countY);
//        int nextCountX = 0;
//        
//        
//        Map<String, List<String>> typeMap = TypeConstant.getTypeMap();
//        String vtDataType = "";
//        
//        for (Map.Entry<String, List<String>> entry : typeMap.entrySet()) {
//            List<String> value = entry.getValue();
//            for (int i = 0; i < value.size(); i++) {
//                if (type.equals(value.get(i))) {
//                    vtDataType = entry.getKey();
//                }
//            }
//        }
//        if (vtDataType.equals("VTInteger") || vtDataType.equals("VTString")
//                || vtDataType.equals("VTDouble")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(textField, new GridBagConstraints(nextCountX, countY,
//                    0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, textField);
//            gg.setjCompnent(textField);
//            gg.setjLabel(labelCom);
//        }
//        // textarea类型
//        else if (vtDataType.equals("VTNote")) {
//            countY++;
//            countX = 0;
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//
//            textArea = new JTextArea();
//            jsp = new JScrollPane();
//            jsp.getViewport().add(textArea);
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            // 文本域
//            attrPane.add(jsp, new GridBagConstraints(nextCountX, countY,
//                    7, 2, 0.0, 0.0, GridBagConstraints.NORTH,
//                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
//            countX = 0;
//            nextCountX = 0;
//            countY = countY + 2;
//            textAreaMap.put(labelCom, "VTNote");
//            textAreaMap.put(textArea, "VTNote");
//            configMap.put(labelCom, textArea);
//            gg.setjCompnent(textArea);
//            gg.setjLabel(labelCom);
//        }
//        // 日期类型
//        else if (vtDataType.equals("VTDate") || vtDataType.equals("VTTime")
//                || vtDataType.equals("VTDateTime")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(calendarPanel, new GridBagConstraints(nextCountX,
//                    countY, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, calendarPanel);
//            gg.setjCompnent(calendarPanel);
//            gg.setjLabel(labelCom);
//        }
//        // 参照类型
//        else if (vtDataType.equals("canzhao")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(cz, new GridBagConstraints(nextCountX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, cz);
//            gg.setjCompnent(cz);
//            gg.setjLabel(labelCom);
//        }
//        // boolean类型
//        else if (vtDataType.equals("VTBoolean")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            comboBox.setPreferredSize(new Dimension(120, 25));
//            comboBox.setEditable(false);
//            attrPane.add(comboBox, new GridBagConstraints(nextCountX, countY,
//                    0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, comboBox);
//            gg.setjCompnent(comboBox);
//            gg.setjLabel(labelCom);
//        }
//        // 文件选择组件
//        else if (vtDataType.equals("VTFilePath")) {
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(fileChooserJPanel, new GridBagConstraints(nextCountX,
//                    countY, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, fileChooserJPanel);
//            gg.setjCompnent(fileChooserJPanel);
//            gg.setjLabel(labelCom);
//        }else if(vtDataType.equals("partition")){
//            
//        }else{
//            attrPane.add(labelCom, new GridBagConstraints(countX, countY, 0, 0,
//                    0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            nextCountX = countX + 1;
//            //System.out.println("X1==" + nextCountX + ";Y1==" + countY);
//            attrPane.add(textField, new GridBagConstraints(nextCountX, countY,
//                    0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
//                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//            configMap.put(labelCom, textField);
//            gg.setjCompnent(textField);
//            gg.setjLabel(labelCom);
//        }
//        if(btmAttrMap.size() == 0){
//            initBtmAttrMap();
//        }
//        attribItem = btmAttrMap.get(arrtName);
//        attribItemMap.put(arrtName, attribItem);
//        attrNameAndCompMap.put(arrtName, configMap);
//        labelCom.addMouseListener(new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                attrPane.requestFocus();
//                super.mouseClicked(e);
//                labelActionListener(e);
//            }
//        });
//    }
 
    private void labelActionListener(MouseEvent e) {
//        Component[] components = attrPane.getComponents();
//        for (Component c : components) {
//            if (c instanceof JLabel) {
//                ((JLabel) c).setBorder(null);
//            }
//        }
        if (selectedComponent != null) {
            ((JLabel) selectedComponent).setBorder(null);
            selectedComponent = null;
        }
        Component source = (Component) e.getSource();
        selectedComponent = source;
        JLabel lb = (JLabel) selectedComponent;
        
        if (lb == null)
            return;
        
        lb.setBorder(javax.swing.BorderFactory.createLineBorder(Color.RED));
//        if (KeyFlag == 0 && JLabelList.size() == 0 || KeyFlag == 1 && JLabelList.size() > 0) {
//            int flag = -1;
//            for (int i = 0; i < JLabelList.size(); i++) {
//                if (JLabelList.get(i).getText().equals(lb.getText())) {
//                    flag = i;
//                    break;
//                }
//            }
//            if (flag == -1) {
//                JLabelList.add(lb);
//            } else {
//                JLabelList.remove(flag);
//            }
//        }
//        if (KeyFlag == 1) {
//            for (int i = 0; i < JLabelList.size(); i++) {
//                JLabelList.get(i).setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
//            }
//        } else {
//            lb.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
//            JLabelList.clear();
//            JLabelList.add(lb);
//        }
        //comHashCode = source.hashCode();
        // System.out.println("labelCom.comHashCode=" + comHashCode);
        //attribItem = attribItemMap.get(lb.getText());
        //prmItem = comPRMItemMap.get(lb.getText());
        CompnentGroup group = getCompnentGroup(lb.getName());
        if (group != null)
            prmItem = group.getPrmItem();
        else
            prmItem = null;
        
        attribItem = group.getAItem();
        
        configPanel.remove(widgetPanel);
        addWidgetPanel();
        configPanel.updateUI();
        
        int index = _lstCompnent.indexOf(group) + 1;
        compIndex.setText(index + "");
//        for (int i = 0; i < _lstCompnent.size(); i++) {
//            CompnentGroup group = _lstCompnent.get(i);
//            if (((JLabel) group.getjLabel()) != null && ((JLabel) group.getjLabel()).getText().equals(lb.getText())) {
//                i = i + 1;
//                compIndex.setText(i + "");
//            }
//        }
    }
    
    private CompnentGroup getCompnentGroup(String field) {
        for (int i = 0; i < _lstCompnent.size(); i++) {
            CompnentGroup group = _lstCompnent.get(i);
            if (group.getField().equals(field)) {
                return group;
            }
        }
        
        return null;
    }
 
    private Map<String, AttribItem> btmAttrMap = new HashMap<String, AttribItem>();
 
    private void initBtmAttrMap() {
        AttribItem[] btAbItems = BtmProvider.getInstance().getBtAbItems(otName);
        for (AttribItem attribItem : btAbItems) {
            btmAttrMap.put(attribItem.name, attribItem);
        }
    }
 
    private void labelKeyListener(KeyEvent e) {
        // System.out.println(e);
    }
 
    private void attrPane_key(KeyEvent e) {
 
    }
 
    private void addWidgetPanel() {
        widgetPanel = new WidgetPanel(prmItem, attribItem, _lstCompnent, this);
        configPanel.add(widgetPanel, BorderLayout.CENTER);
    }
 
    /**
     * 组件重新绘制
     */
    public void layoutComponent() {
        attrPane.removeAll();
        int x = 0;
        int y = 0;
        for (int i = 0; i < _lstCompnent.size(); i++) {
            if (x > 2 * colCount - 1) {
                x = 0;
                y++;
            }
 
            CompnentGroup comp = _lstCompnent.get(i);
            if (comp.getjCompnent() instanceof JTextArea) {
                if (x != 0)
                    y++;
                
                attrPane.add(comp.getjLabel(), new GridBagConstraints(0, y, 0, 0, 0.0, 0.0,
                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                JScrollPane jsp = new JScrollPane();
                jsp.getViewport().add(comp.getjCompnent());
                attrPane.add(jsp, new GridBagConstraints(1, y, 7, 2, 0.0, 0.0, GridBagConstraints.NORTH,
                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                y = y + 2;
                x = 0;
            } else {
                if (comp.getjLabel() != null) {
                    attrPane.add(comp.getjLabel(), new GridBagConstraints(x++, y, 0, 0, 0.0, 0.0,
                            GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    attrPane.add(comp.getjCompnent(), new GridBagConstraints(x++, y, 0, 0, 0.0, 0.0,
                            GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                }
            }
        }
        
        countX = x;
        countY = y;
        
        attrPane.updateUI();
    }
 
    /**
     * 存储lab与其后面关联的组件关系
     */
    private Map<Component, Component> configMap = new HashMap<Component, Component>();
    /**
     * 存储属性对应的控件
     */
    // private Map<String, Map<Component, Component>> attrNameAndCompMap = new
    // HashMap<String, Map<Component, Component>>();
    private JPanel panel;
    private JPanel panelMain;
    private JLabel lblNewLabel;
    private JTextField viName;
    private JButton addCustBtn;
    private JButton previewBtn;
//    private JButton attrListBtn;
    private JRadioButton deleteRadio;
    private JRadioButton addRadio;
    private ButtonGroup bg = new ButtonGroup();
 
    private JLabel label;
    private JLabel qtNameLab;
    private JTextField componentDisCol;
    private JButton setColBtn;
    private JLabel label_1;
    private JLabel label_2;
    private JTextField compIndex;
    private JTextField valueIndex;
    private JComboBox qtName;
    private JButton compIndexBtn;
    private JButton editIndexBtn;
    // private JButton viewI18nButton;
 
    public void drop(DropTargetDropEvent e) {
        try {
            DataFlavor stringFlavor = DataFlavor.stringFlavor;
            Transferable tr = e.getTransferable();
 
            if (e.isDataFlavorSupported(stringFlavor)) {
                Object transferData = tr.getTransferData(stringFlavor);
                String arrtName = "";
                if (transferData instanceof AttributeNode) {
                    AttributeNode anode = (AttributeNode)transferData;
                    attribItem = anode.getAttrItem();
                    arrtName = anode.getName();
                }
                else if (transferData instanceof AttribItem) {
                    attribItem = (AttribItem) transferData;
                    arrtName = attribItem.name;
                }
                else if (transferData instanceof String) {
                    arrtName = (String) transferData;
                    attribItem = new AttribItem();
                    attribItem.name = arrtName;
                }
                e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
 
                if (checkComponentIsExist(arrtName))
                    return;
 
                CompnentGroup gg = new CompnentGroup(arrtName);
                gg.setAItem(attribItem);
                addComponent(gg, arrtName);
 
                attrPane.updateUI();
                _lstCompnent.add(gg);
                layoutComponent();
                e.dropComplete(true);
            } else {
                e.rejectDrop();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (UnsupportedFlavorException ufe) {
            ufe.printStackTrace();
        }
    }
 
    /**
     * 添加页面元素
     * 
     * @param gg
     * @param arrtName
     */
    private void addComponent(CompnentGroup gg, String arrtName) {
 
        int nextCountX = 0;
        String vtDataType = "";
        vtDataType = attribItem.vtDataType;
        
        ControlType ctrlType = ControlType.Text;
        
        if (vtDataType.equals("VTString")) {
            ctrlType = ControlType.Text;
        }
        else if (vtDataType.equals("VTInteger") || vtDataType.equals("VTDouble")) {
            ctrlType = ControlType.Number;
        }
        // textarea类型
        else if (vtDataType.equals("VTNote")) {
            ctrlType = ControlType.TextArea;
        }
        // 日起类型
        else if (vtDataType.equals("VTDate") || vtDataType.equals("VTTime") || vtDataType.equals("VTDateTime")) {
            ctrlType = ControlType.Date;
        }
        // 参照类型
        else if (vtDataType.equals("canzhao")) {
            ctrlType = ControlType.TextBtn;
        }
        // boolean类型
        else if (vtDataType.equals("VTBoolean")) {
            ctrlType = ControlType.Checkbox;
        }
        // 文件选择组件
        else if (vtDataType.equals("VTFilePath")) {
            ctrlType = ControlType.File;
        } else {
            ctrlType = ControlType.Text;
        }
        
        if (gg.getPrmItem() == null) {
            PRMItem prmi = new PRMItem();
            prmi.setItemField(arrtName);
            prmi.setItemName(attribItem.label);
            prmi.setItemType(ctrlType.name().toLowerCase());
            prmi.setItemValueList(new ArrayList<String>());
            
            gg.setPrmItem(prmi);
        }
        
        CompnentUtil.CreateCompent(gg, ctrlType);
        
        if (ctrlType == ControlType.TextArea) {
            if (countX != 0)
                countY++;
            countX = 0;
            attrPane.add(gg.getjLabel(), new GridBagConstraints(countX, countY, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
 
            nextCountX = countX + 1;
            JScrollPane jsp = new JScrollPane();
            jsp.getViewport().add(gg.getjCompnent());
            attrPane.add(jsp, new GridBagConstraints(nextCountX, countY, 7, 2, 0.0, 0.0, GridBagConstraints.NORTH,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            countX = 0;
            countY = countY + 2;
        } else {
            attrPane.add(gg.getjLabel(), new GridBagConstraints(countX, countY, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
 
            nextCountX = countX + 1;
            attrPane.add(gg.getjCompnent(), new GridBagConstraints(nextCountX, countY, 0, 0, 0.0, 0.0,
                    GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        }
        //attribItemMap.put(arrtName, attribItem);
        
        // attrNameAndCompMap.put(arrtName, configMap);
        gg.getjLabel().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                labelActionListener(e);
            }
        });
        gg.getjLabel().addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                labelKeyListener(e);
            }
 
            @Override
            public void keyReleased(KeyEvent e) {
                labelKeyListener(e);
            }
 
            @Override
            public void keyPressed(KeyEvent e) {
                labelKeyListener(e);
            }
        });
    }
 
    /**
     * 判断页面元素重复
     * 
     * @param arrtName
     */
    private boolean checkComponentIsExist(String arrtName) {
        // 判断页面元素重复
        Component[] components = attrPane.getComponents();
        for (Component c : components) {
            if (c instanceof JLabel) {
                String labelName = ((JLabel) c).getText().toString().trim();
                if (labelName.equals(arrtName)) {
                    VCIOptionPane.showMessage(LogonApplication.frame, "该元素已经存在,不能重复添加!");
                    return true;
                }
            }
        }
        return false;
    }
 
    public boolean saveForm() {
        Component[] cs = this.attrPane.getComponents();// 遍历内容控制面版
        List<PRMItem> prmItemList = new ArrayList<PRMItem>();
//        for (int i = 0; i < cs.length; i++) {
//            String name = "";
//            if (cs[i] instanceof JLabel) {
//                name = ((JLabel) cs[i]).getText();
//            }
//            if (name != null && !"".equals(name)) {
//                PRMItem newPrmItem = comPRMItemMap.get(name);
//                if (newPrmItem == null) {
//                    VCIOptionPane.showMessage(LogonApplication.frame, "请先保存\"" + name + "\"的属性设置");
//                    return false;
//                }
////                comPRMItemMap.remove(name);
//                prmItemList.add(newPrmItem);
//            }
//        }
//        for (Map.Entry<String, PRMItem> entry : comPRMItemMap.entrySet()) {
//            PRMItem newPrmItem = entry.getValue();
//            if (newPrmItem == null) {
//                VCIOptionPane.showMessage(LogonApplication.frame, "请先保存\"" + entry.getValue() + "\"的属性设置");
//                return false;
//            }
////            prmItemList.add(newPrmItem);
//        }
        
        for (int i = 0; i < _lstCompnent.size(); i++) {
            PRMItem prmItem = _lstCompnent.get(i).getPrmItem();
            if (prmItem == null) {
                VCIOptionPane.showMessage(LogonApplication.frame, "请先保存\"" + _lstCompnent.get(i).getField() + "\"的属性设置");
                return false;
            }
            prmItemList.add(prmItem);
        }
        
        if (pvi == null) {
            pvi = new PortalVI();
            pvi.id = ObjectUtility.getNewObjectID36();
            pvi.viType = portalVIType.getIntVal();
        } else {
            pvi.viType = pvi.viType;
        }
        pvi.typeFlag = typeFlag.getIntVal();
        PRM newPrm = new PRM();
        newPrm.setShowCols(componentDisCol.getText());
        newPrm.setFormQtName((String) qtName.getSelectedItem());
        newPrm.setPrmItemList(prmItemList);
        try {
            String prmText = UITools.getPRMText(newPrm);
            pvi.viName = viName.getText();
            pvi.typeName = otName;
            pvi.prm = prmText;
            if (pvi == null) {
                UITools.getService().savePortalVI(pvi);
            } else {
                UITools.getService().updatePortalVI(pvi);
            }
            return true;
        } catch (Throwable e) {
            e.printStackTrace();
            return false;
        }
    }
 
    private void initData() {
        if (pvi != null) {
            viName.setText(pvi.viName);
            if (_isBtm == true) {
                viName.setEditable(false);
            }
            String prmText = pvi.prm;
            prm = UITools.getPRM(prmText);
            colCount = Integer.parseInt(prm.getShowCols() == null ? "3" : prm.getShowCols());
            componentDisCol.setText(colCount + "");
            qtName.setSelectedItem(prm.getFormQtName());
            PRMItem[] dataObjs = prm.getPrmItemList().toArray(new PRMItem[] {});
            // System.out.println();
            String arrtName = "";
            String arrtDisType = "";
            for (PRMItem obj : dataObjs) {
                CompnentGroup gg = new CompnentGroup(obj.getItemField());
                arrtName = obj.getItemField();
                arrtDisType = obj.getItemType();
                //comPRMItemMap.put(arrtName, obj);
                gg.setPrmItem(obj);
                
                addCustomComponent(gg, arrtName, arrtDisType);
                _lstCompnent.add(gg);
            }
            layoutComponent();
            // attrPane.updateUI();
        }
    }
 
    private void fillQtNameCom() {
        qtName.addItem("");
        try {
            QTInfo[] qts = ServiceProvider.getOMDService().getQTDService().getObjTypeQTs(otName);
            for (QTInfo qt : qts) {
                qtName.addItem(qt.qtName);
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
 
    }
 
    public void dragEnter(DropTargetDragEvent e) {
    }
 
    public void dragExit(DropTargetEvent e) {
    }
 
    public void dragOver(DropTargetDragEvent e) {
    }
 
    public void dropActionChanged(DropTargetDragEvent e) {
    }
 
    @Override
    public void dragGestureRecognized(DragGestureEvent e) {
 
    }
 
    @Override
    public void dragDropEnd(DragSourceDropEvent dsde) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void dragEnter(DragSourceDragEvent dsde) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void dragExit(DragSourceEvent dse) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void dragOver(DragSourceDragEvent dsde) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void dropActionChanged(DragSourceDragEvent dsde) {
        // TODO Auto-generated method stub
 
    }
 
}