wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
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
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
package com.vci.client.uif.engine.client.objopt;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.text.JTextComponent;
 
import org.dom4j.DocumentException;
 
import com.vci.client.bof.AttributeChecker;
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.common.FreeMarkerCommon;
import com.vci.client.common.FreemarkerParamObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.common.oq.OQTool;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.omd.provider.ApProvider;
import com.vci.client.omd.provider.EnumProvider;
import com.vci.client.oq.QTClient;
import com.vci.client.portal.constants.QueryConditionConstants;
import com.vci.client.portal.form.defaultvalue.DefaultValueController;
import com.vci.client.portal.utility.DataModelFactory;
import com.vci.client.portal.utility.DataModelProcessor;
import com.vci.client.portal.utility.PLDefination;
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.swing.components.VCIJCalendarPanel;
import com.vci.client.ui.swing.components.VCIJComboBox;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.VCIJScrollPane;
import com.vci.client.ui.swing.components.VCIJTextField;
import com.vci.client.uif.actions.client.AbstractBatchBusionessOperationAction;
import com.vci.client.uif.actions.client.BusinessObjectAttributeChecker;
import com.vci.client.uif.actions.client.EditLinkAction;
import com.vci.client.uif.actions.client.UIFUtils;
import com.vci.client.uif.engine.client.IRegionPanel;
import com.vci.client.uif.engine.client.UIHelper;
import com.vci.client.uif.engine.client.controls.BaseCustomControl;
import com.vci.client.uif.engine.client.controls.ControlFactory;
import com.vci.client.uif.engine.client.controls.DateTimeControl;
import com.vci.client.uif.engine.client.controls.ICustomControl;
import com.vci.client.uif.engine.client.controls.RefObjChooseControl;
import com.vci.client.uif.engine.client.controls.VCIJComboBoxModelValueObject;
import com.vci.client.uif.engine.client.custom.ICustomAttributeInteceptor;
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog.OperateType;
import com.vci.client.uif.engine.common.CBOHelper;
import com.vci.client.uif.engine.common.ClientLOAndBOData;
import com.vci.client.uif.engine.common.DefaultTableNode;
import com.vci.client.uif.engine.common.GlobalContextParam;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.common.portal.enums.ControlType;
import com.vci.common.qt.object.Condition;
import com.vci.common.qt.object.ConditionItem;
import com.vci.common.qt.object.LeafInfo;
import com.vci.common.qt.object.QueryTemplate;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.portal.data.PortalVI;
import com.vci.corba.query.data.RefPath;
import com.vci.mw.ClientContextVariable;
import com.vci.omd.objects.OtherInfo;
import com.vci.omd.utils.ObjectTool;
 
public class ObjectAddEditPanel extends VCIJPanel {
 
    private static final long serialVersionUID = 6400165410571370254L;
 
    private String type = "";
    private String context = "";
    private PLDefination defination = null;
    private DataModelFactory factory = null;
    private Map<String, String> paramsMap = new LinkedHashMap<String, String>();
    private OperateType operateType = OperateType.ADD;
    private AttributeChecker curAttrChecher = null;
    private IRegionPanel regionPanel = null;
 
    private Map<String, String> valueMapNew = new LinkedHashMap<String, String>();
    private Map<String, String> valueMapOriginal = new LinkedHashMap<String, String>();
    /**
     * 全部的Label
     */
    private final HashMap<String, VCIJLabel> ctrlLabelMap = new LinkedHashMap<String, VCIJLabel>();
    /**
     * 全部的Component 控件
     */
    private HashMap<String, Component> ctrlComptMap = new LinkedHashMap<String, Component>();
    /**
     * 将界面元素属性集合设置成全局变量 在保存时用于判断属性是否为空
     */
    private final HashMap<String, PRMItem> itemMap = new LinkedHashMap<String, PRMItem>();
 
    private final HashMap<String, VCIJComboBox> ctrlComboBoxMap = new LinkedHashMap<String, VCIJComboBox>();
 
    /**
     * 控件的数据之间有级联数据控制的控件 KEY:主控属性字段 VALUE:受控(数据级联影响)属性字段
     * 受控控件的数据受主控属性控件的数据影响,一般是主控数据作为受控数据的查询条件
     */
    private final HashMap<String, List<String>> cascadeControlsMap = new LinkedHashMap<String, List<String>>();
 
    /**
     * 控件之间有显示控制 KEY:被控属性字段 VALUE:主控属性字段 受控件控件的显示与否,受主控属性的部分取值的影响
     */
    private final HashMap<String, List<String>> hiddenControlsMap = new LinkedHashMap<String, List<String>>();
 
    /**
     * 被控属性与主控属性之间在关联关联 key:被控属性 value:主控属性
     */
    private final HashMap<String, String> fieldToMasterFieldMap = new LinkedHashMap<String, String>();
 
    private final HashMap<String, String> SELECT_ATTRIBUTE = new LinkedHashMap<String, String>();
    private final HashMap<String, String> SELECT_ATTRIBUTE_VALUE = new LinkedHashMap<String, String>();
 
    /**
     * 当前窗口的表单类型 0:业务类型,1:链接类型 对于不同类型的表单,窗口中属性的命名规则不同
     */
    private int typeFlag = 0;
    /**
     * 如果是选择时记录用户选择的数据
     */
    private Object[] selectedDatas = null;
    private ClientBusinessObject cbo = null;
    private ClientLinkObject clo = null;
    private IDataNode dataNodeObject = new DefaultTableNode();
 
    /**
     * 判断是正向还是反响向
     */
    private boolean direction = true;
 
    private final UIFUtils operation = new UIFUtils();
 
    public ObjectAddEditPanel(String type, String context, PLDefination defination, DataModelFactory factory,
            Map<String, String> paramsMap, OperateType operateType, IRegionPanel regionPanel) {
        this.regionPanel = regionPanel;
        this.type = type;
        this.context = context;
        this.defination = defination;
        this.factory = factory;
        this.paramsMap = paramsMap;
        this.operateType = operateType;
        curAttrChecher = new AttributeChecker();
        curAttrChecher.getAllAttribute();
    }
 
    /**
     * 是否是创建窗口
     * 
     * @return
     */
    private boolean isAdd() {
        return (operateType == OperateType.ADD);
    }
 
    /**
     * 是否是添加窗口
     * 
     * @return
     */
    private boolean isEdit() {
        return (operateType == OperateType.EDIT);
    }
 
    /**
     * 是否是选择窗口
     * 
     * @return
     */
    private boolean isSelect() {
        return (operateType == OperateType.SELECT);
    }
 
    private boolean isOperateBusinessObject() {
        return getTypeFlag() == 0;
    }
 
    /**
     * 根据表单类型获得窗口的主对象 当为业务对象创建编辑时表单类型一定是 0; 当为link对象创建编辑时表单类型可能是0,也肯能是1
     */
    private void initEmptyObject() {
        if (isOperateBusinessObject()) {
            cbo = operation.createEmptyClientBusinessObject(ClientContextVariable.getFrame(),
                    getDefination().getShowType());
            dataNodeObject.setMasterObject(cbo);
        } else {
            clo = operation.createEmptyClientLinkObject(ClientContextVariable.getFrame(),
                    getDefination().getLinkType());
            dataNodeObject.setMasterObject(clo);
        }
    }
 
    public void init() {
        initEmptyObject();
        setLayout(new BorderLayout());
        VCIJScrollPane scroll = new VCIJScrollPane(getCenterPanel());
        add(scroll, BorderLayout.CENTER);
    }
 
    private PortalVI sheet = null;
 
    private PortalVI getPortalVIByFormOrTypeAndDef() throws VCIError {
        // 根据type、context获取对应�?'editForm'
        String formName = null;
        try {
            formName = defination.getTemplateId();// factory.getFormNameByByTypeAndContext(type,
                                                    // context);
        } catch (Throwable e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (formName != null && !"".equals(formName)) {
            sheet = UITools.getService().getPortalVIBySymbol(formName);
        }
        return sheet;
    }
 
    private VCIJPanel getCenterPanel() {
        VCIJPanel pal = new VCIJPanel(new GridBagLayout());
        try {
            PortalVI sheet = getPortalVIByFormOrTypeAndDef();
            if (sheet == null)
                return pal;
 
            pal = createControlsPanel(sheet);
            // pal.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return pal;
    }
 
    private void addItemToMap(List<PRMItem> items) {
        for (PRMItem item : items) {
            this.itemMap.put(item.getItemField(), item);
        }
    }
 
    private VCIJPanel createControlsPanel(PortalVI sheet) {
        VCIJPanel pal = new VCIJPanel(new GridBagLayout());
        PRM sheetPrm = UITools.getPRM(sheet.prm);
        List<PRMItem> itemList = sheetPrm.getPrmItemList();
 
        // 缓存PRMItem
        addItemToMap(itemList);
 
        int showColumns = 2;
        if (!"".equals(sheetPrm.getShowCols())) {
            showColumns = Integer.valueOf(sheetPrm.getShowCols());
        }
 
        int gridx = 0;
        int gridy = 0;
        int gridwidth = 1;
        int gridheight = 1;
        double weightx = 1.0;
        double weighty = 0.0;
        int padxy = 2;
        int latestGridx = 0;
        boolean latestIsTextArea = false;
 
        VCIJLabel lbl = null;
        Component compt = null;
        Component comptToAdd = null;
 
        for (int i = 0; i < itemList.size(); i++) {
 
            PRMItem item = itemList.get(i);
            String field = item.getItemField();
            String itemCols = item.getItemCols();
 
            lbl = new VCIJLabel(item.getItemName() + ":");
            compt = ControlFactory.createControl(item);
            if (compt == null)
                continue;
 
            ctrlComptMap.put(field, compt);
 
            if (itemCols == null || itemCols.trim().equals("") || itemCols.equals("0")) {
                continue;
            }
 
            if (ControlFactory.isLCStatusAttr(field) && compt instanceof VCIJComboBox) {
                String btmType = defination.getShowType();
                ((VCIJComboBox) compt).setModel(ControlFactory.getLCStatusComboboxModel(item, btmType));
            }
            comptToAdd = compt;
            if (comptToAdd instanceof ICustomControl) {
                ((ICustomControl) comptToAdd).setParentComponent(this);
            }
            if (compt instanceof JTextArea) {
                comptToAdd = new VCIJScrollPane(compt);
                comptToAdd.setPreferredSize(new Dimension(1, 1));
            }
 
            // 缓存控件
            ctrlLabelMap.put(field, lbl);
            ctrlComptMap.put(field, compt);
 
            // TextArea 占整行显示
            if (item.getItemType().toLowerCase().equals(ControlType.TextArea.name().toLowerCase())) {
                gridx = 0;
                gridy += 1;
                gridwidth = showColumns * 2 - 1;
                gridheight = 30;
                weightx = 1.0;
                weighty = 5.0;
 
                pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST,
                        GridBagConstraints.NONE, padxy));
 
                gridx += 1;
                pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty,
                        GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy));
 
                latestIsTextArea = true;
 
                // 重置一行位置信息
                gridx = 0;
                gridy += gridheight;
                gridwidth = 1;
                gridheight = 1;
                weightx = 1.0;
                weighty = 0.0;
                latestGridx = 0;
 
            } else {
                if (latestIsTextArea) {
                    // 如果最近的一个控件是TextArea,则位置信息已经是设置好了的,此时直接使用
                    pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST,
                            GridBagConstraints.NONE, padxy));
 
                    gridx += 1;
                    pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty,
                            GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy));
                    latestIsTextArea = false;
                } else {
                    if (latestGridx == showColumns) { // 本行已经到达最大,此时也需要换行,设置下一
                        // 重置一行位置信息
                        gridx = 0;
                        gridy += 1;
                        gridwidth = 1;
                        gridheight = 1;
                        weightx = 1.0;
                        weighty = 0.0;
                        latestGridx = 0;
                    } else {
                        // 重置一行位置信息
                        if (gridx != 0) {
                            gridx += 1;
                        }
                    }
                    // 普通单行内追加
                    pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST,
                            GridBagConstraints.NONE, padxy));
 
                    gridx += 1;
                    pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty,
                            GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy));
 
                }
 
                latestGridx++;
                latestIsTextArea = false;
                String itemAndFilter = item.getItemAddFilter();
                String itemCustomClass = item.getItemCustomClass();
                if (itemAndFilter != null && !"".equals(itemAndFilter)
                        && (itemCustomClass == null || "".equals(itemCustomClass))) {
                    SELECT_ATTRIBUTE.put(field, itemAndFilter);
                }
 
                // 处理属性与属性之间的关联控制数据
                // add by caill
                cascadeControlsMapConfig(item);
 
                // 处理属性与属性之间的 显示 控制数据
                parseFieldRefHideAndShowData(item);
 
                if (compt instanceof VCIJComboBox) {
                    VCIJComboBox cbx = (VCIJComboBox) compt;
                    // 主控属性,需要加入数据选择后的事件处理
//                    if (cascadeControlsMap.containsKey(field)) {
//                        cbx.addActionListener(new CascadeComboBoxActionListener(item));
//                    }
                    if (hiddenControlsMap.containsKey(field)) {
                        cbx.addActionListener(new HiddenOrShowComboBoxActionListener(item));
                    }
                    ctrlComboBoxMap.put(field, cbx);
                } else if (compt instanceof RefObjChooseControl) {
                    // 参照类型的控件,需要注册数据选择后的处理逻辑
                    // add by songyf 2014.08.15 使空间在不可编辑的时候也注册事件
                    // 这样,不可编辑但是在窗口打开的时候具有初始值的控件在初始化的时候也能设置关联空间的值
                    RefObjChooseControl rocc = (RefObjChooseControl) compt;
                    if (!"".equals(item.getItemListTable()) && !"".equals(item.getItemListVal())
                    // && !"1".equals(item.getItemIsEditable())
                    ) {
 
                        registeRefObjChooseListener(rocc);
                    }
                    // end by songyf 2014.08.15
                }
 
                // 如果是下拉列表、又是必填,尝试将其下拉列表的第一个值自动选择上
                /*
                 * if (compt instanceof VCIJComboBox && ControlFactory.isRequired(item)) {
                 * loadComboBoxData(field); }
                 */
                if (compt instanceof VCIJComboBox) { // add by caill 将是“必填”的条件去掉,否则在设置级联下拉列表不是必填的时候,不会显示名称,只会显示id
                    loadComboBoxData(field);
                }
            }
 
            // 当为浏览时设置空间不可编辑
            if (operateType.equals(OperateType.BROWSER)) {
                // add by xchao 2014.04.21 begin
                // 浏览模式下的txt控件为只读
                if (JTextComponent.class.isAssignableFrom(compt.getClass())) {
                    compt.setEnabled(true);
                    ((JTextComponent) compt).setEditable(false);
                } else {
                    compt.setEnabled(false);
                }
                // add by xchao 2014.04.21 end
            } else if (operateType.equals(OperateType.SELECT)) {
                // 如果为选择窗口时,需要判断form的类型来禁用相关的控件
                // 如果是业务类型,禁用所有控件,如果是link类型,禁用t_oid控件
                if (typeFlag == 0) {
                    compt.setEnabled(false);
                } else {
                    String head = "";
                    if (direction) {
                        head = "t_oid";
                    } else {
                        head = "f_oid";
                    }
                    if (field.toLowerCase().startsWith(head)) {
                        compt.setEnabled(false);
                    }
                }
            }
            VCIJLabel lblFill = new VCIJLabel("");
            pal.add(lblFill, getGBC(0, gridy + 10, showColumns * 2, 1, 1.0, 0.0, GridBagConstraints.EAST,
                    GridBagConstraints.BOTH, padxy));
 
            if (compt instanceof VCIJComboBox && !item.getItemAddFilter().equals("")) {
                VCIJComboBox cbx = (VCIJComboBox) compt;
                cbx.addPopupMenuListener(new ComboBoxDataLoaderListener(field));
            }
        }
 
        // 根据显示控制,隐藏控件显示
        for (Iterator<String> it = hiddenControlsMap.keySet().iterator(); it.hasNext();) {
            String masterField = it.next();
            List<String> list = hiddenControlsMap.get(masterField);
            for (String filedToControl : list) {
                if (ctrlLabelMap.containsKey(filedToControl))
                    ctrlLabelMap.get(filedToControl).setEnabled(false);
                if (ctrlComptMap.containsKey(filedToControl))
                    ctrlComptMap.get(filedToControl).setEnabled(false);
            }
        }
        return pal;
    }
 
    class ComboBoxDataLoaderListener implements PopupMenuListener {
        private String lastChangedName = "";
        private boolean manual = false;
        private String field = "";
 
        public ComboBoxDataLoaderListener(String field) {
            this.field = field;
        }
 
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            if (manual) {
                manual = false;
                return;
            }
            if (e.getSource() instanceof VCIJComboBox) {
                VCIJComboBox cbx = (VCIJComboBox) e.getSource();
                loadComboBoxData(field);
                manual = true;
                cbx.showPopup();
            }
        }
 
        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            if ("".equals(lastChangedName) && dataNodeObject != null) {
                lastChangedName = dataNodeObject.getValueMap().get(field);
            }
            VCIJComboBox cbx = (VCIJComboBox) e.getSource();
            String changeName = cbx.getSelectedItem().toString();
            if (!changeName.equals(lastChangedName)) {
                // 清空被关联控制的列表数据
                if (cascadeControlsMap.containsKey(field)) {
                    List<String> list = cascadeControlsMap.get(field);
                    for (String field : list) {
                        clearCascadeComboBoxData(field);
                    }
                }
            }
            lastChangedName = changeName;
        }
 
        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
 
    }
 
    /**
     * 级联清空被关联控制控件的列表
     * 
     * @param cascadeField
     */
    private void clearCascadeComboBoxData(String cascadeField) {
        Object compt = ctrlComboBoxMap.get(cascadeField);
        if (compt != null && compt instanceof VCIJComboBox) {
            VCIJComboBox cbx = (VCIJComboBox) compt;
            cbx.setModel(getDefaultEmptyModel());
        }
        if (cascadeControlsMap.containsKey(cascadeField)) {
            List<String> list = cascadeControlsMap.get(cascadeField);
            for (String field : list) {
                // 递归级联清空被关联的列表数据
                clearCascadeComboBoxData(field);
            }
        }
    }
 
    private DefaultComboBoxModel getDefaultEmptyModel() {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        VCIJComboBoxModelValueObject vo = new VCIJComboBoxModelValueObject("", "");
        model.addElement(vo);
        return model;
    }
 
    /**
     * 为参照属性注册数据选择&更换后的事件处理程序
     * 
     * @param rocc
     */
    private void registeRefObjChooseListener(RefObjChooseControl rocc) {
        rocc.addPropertyChangeListener(RefObjChooseControl.REF_OBJECT_CHANGED, new PropertyChangeListener() {
            @SuppressWarnings("unchecked")
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                Map<String, String> newValMap = (Map<String, String>) evt.getNewValue();
                RefObjChooseControl source = (RefObjChooseControl) evt.getSource();
                refreshOtherRefObjChooseControlData(source, newValMap);
            }
        });
    }
 
    /**
     * 刷新参照对象引用数据
     * 
     * @param rocc
     * @param newVal
     */
    private void refreshOtherRefObjChooseControlData(RefObjChooseControl rocc, Map<String, String> newVal) {
        PRMItem item = rocc.getPRMItem();
        String itemField = item.getItemField();
        String oid = newVal.get(UIHelper.OID);
        if (oid == null || "".equals(oid))
            return;
 
        // 查询关联列,数据处理
        if (item.getItemQueryRefFields() != null && !"".equals(item.getItemQueryRefFields())) {
            // 被关联的属性列表
            String[] toFields = item.getItemQueryRefFields().split(",");
            for (String toField : toFields) {
                PRMItem toItem = itemMap.get(toField);
                if (toItem == null)
                    continue;
                String toFilter = toItem.getItemAddFilter();
                if (toFilter == null || "".equals(toFilter))
                    continue;
                if (!ctrlComboBoxMap.containsKey(toField))
                    continue;
                SELECT_ATTRIBUTE.put(toField, toFilter);
                SELECT_ATTRIBUTE_VALUE.put(itemField, oid);
                loadComboBoxData(toField);
            }
        }
 
        // 相同参照对象的数据处理
        for (Iterator<String> it = ctrlComptMap.keySet().iterator(); it.hasNext();) {
            String key = it.next();
            Component compt = ctrlComptMap.get(key);
 
            // 规约:参照对象的其它参照只能是文本框。
            if (compt instanceof VCIJTextField) {
                VCIJTextField txt = (VCIJTextField) compt;
                PRMItem itemOther = (PRMItem) txt.getObj();
                String fieldOther = itemOther.getItemField();
                if (fieldOther.startsWith(itemField + ".")) {
                    // modify by songyf 2014.08.21 修改当创建表单时,控件值显示错误的问题
                    // 在表单上有多个参照属性,且参照属性如下
                    // smaterialratio(参照)
                    // smaterialratio.usemat(参照)
                    // 控件smaterialratio.usemat。xxx 还设置了默认值,此时由于参照属性设置顺序不同有时会出现
                    // 控件的值设置不上的情况。(smaterialratio控件如果后执行的话会出现错误)
                    fieldOther = fieldOther.substring(itemField.length() + 1);
                    if (newVal.containsKey(fieldOther)) {
                        String valueOther = newVal.get(fieldOther);
                        txt.setText(valueOther);
                    }
                    // end by songyf 2014.08.21
                }
            }
        }
    }
 
    private void loadComboBoxData(String field) {
        VCIJComboBox cbx = ctrlComboBoxMap.get(field);
        String sql = SELECT_ATTRIBUTE.get(field);
        if (sql == null)
            return;
        DefaultComboBoxModel model = new DefaultComboBoxModel();
 
        // 手工设置的默认选择值
        String manualSelectedValue = "";
        if (isFreemarkTemplateContent(sql)) {
            sql = getReplacedSql(sql);
            if (isSingleCol(sql)) {
                model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[0]));
            } else {
                model = convertSQLDataToDataModel(getMulColSQLData(sql, new AttributeValue[0]));
            }
            // 当查询出的数据值只有一个时,将其作为默认值
            if (model.getSize() == 1) {
                manualSelectedValue = ((VCIJComboBoxModelValueObject) model.getElementAt(0)).getValue();
            }
            model.insertElementAt(new VCIJComboBoxModelValueObject("", ""), 0);
        } else if (sql.indexOf(":") < 0) { // 纯SQL,直接执行查询
            // 兼容带:时也支持SQL
            if (isFreemarkTemplateContent(sql)) {
                sql = getReplacedSql(sql);
            }
 
            if (isSingleCol(sql)) {
                model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[0]));
            } else {
                model = convertSQLDataToDataModel(getMulColSQLData(sql, new AttributeValue[0]));
            }
            // 当查询出的数据值只有一个时,将其作为默认值
            if (model.getSize() == 1) {
                manualSelectedValue = ((VCIJComboBoxModelValueObject) model.getElementAt(0)).getValue();
            }
            model.insertElementAt(new VCIJComboBoxModelValueObject("", ""), 0);
        } else {
            for (Iterator<String> it = SELECT_ATTRIBUTE_VALUE.keySet().iterator(); it.hasNext();) {
                String akey = it.next();
                String[] ckeys = akey.split("-");
                String ckey = ckeys[ckeys.length - 1];
                if (ckey.indexOf("\\.") >= 0) {
                    ckey = ckey.split("\\.")[0];
                }
                if (sql.indexOf(":" + ckey) >= 0) {
                    AttributeValue attrVal = new AttributeValue();
                    attrVal.attrName = ckey;
                    attrVal.attrVal = SELECT_ATTRIBUTE_VALUE.get(ckey);
 
                    model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[] { attrVal }));
                    break;
                }
            }
        }
        String currentSelectedItemValue = "";
        if (manualSelectedValue != null && !"".equals(manualSelectedValue)) {
            currentSelectedItemValue = manualSelectedValue;
        } else if (cbx.getSelectedItem() != null) {
            currentSelectedItemValue = ((VCIJComboBoxModelValueObject) cbx.getSelectedItem()).getValue();
        }
        cbx.setModel(model);
        if (operateType == OperateType.BROWSER) {
            cbx.setEnabled(false);
        } else if (operateType == OperateType.ADD) {
            setComboBoxAddModeSelectItem(cbx, field, currentSelectedItemValue);
        } else if (operateType == OperateType.EDIT) {
            setComboBoxEditSelectItem(cbx, field, currentSelectedItemValue);
        }
    }
 
    /**
     * 查询语句查询是一列还是多列
     * 
     * @param sql
     * @return
     */
    private boolean isSingleCol(String sql) {
        while (sql.indexOf("(") >= 0) {
            sql = transferSqlToSimple(sql);
        }
        sql = sql.substring("select".length() + 1);
        sql = sql.substring(0, sql.indexOf(" from "));
        if (sql.split(",").length == 1) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 将sql中带括号的语句替换掉,方便截取
     * 
     * @param str
     * @return
     */
    private String transferSqlToSimple(String str) {
        Matcher lmatcher = Pattern.compile("\\(").matcher(str);
        Matcher rmatcher = Pattern.compile("\\)").matcher(str);
        List<Integer> lList = new ArrayList<Integer>();
        List<Integer> rList = new ArrayList<Integer>();
        while (lmatcher.find()) {
            lList.add(lmatcher.start());
        }
        while (rmatcher.find()) {
            rList.add(rmatcher.start());
        }
 
        int c = 0;
        for (int i = 0; i < lList.size(); i++) {
            if ((i + 1 < lList.size()) && (lList.get(i + 1) > rList.get(i))) {
                c = i;
                break;
            }
        }
        if (c == 0) {
            c = lList.size() - 1;
        }
        int pos = rList.get(c);
 
        String rstr = str.substring(pos + 1);
        String lstr = str.substring(0, lList.get(0));
 
        return (lstr + rstr);
    }
 
    private void setComboBoxAddModeSelectItem(VCIJComboBox cbx, String field, String currentSelectedItemValue) {
        ComboBoxModel model = cbx.getModel();
        int i = -1;
        Object selectedItem = null;
        while (i++ <= model.getSize()) {
            Object obj = model.getElementAt(i);
            if (!(obj instanceof VCIJComboBoxModelValueObject)) {
                continue;
            }
            VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) obj;
            if (vo.getName().equals(currentSelectedItemValue) || vo.getValue().equals(currentSelectedItemValue)) {
                selectedItem = vo;
                break;
            }
        }
        model.setSelectedItem(selectedItem);
    }
 
    private void setComboBoxEditSelectItem(VCIJComboBox cbx, String field, String currentSelectedItemValue) {
        ComboBoxModel model = cbx.getModel();
        if (this.dataNodeObject == null)
            return;
        Map<String, String> objValMap = this.dataNodeObject.getValueMap();
        if (objValMap.size() == 0)
            return;
        int i = -1;
        Object selectedItem = null;
        while (i++ <= model.getSize()) {
            Object obj = model.getElementAt(i);
            if (!(obj instanceof VCIJComboBoxModelValueObject)) {
                continue;
            }
            VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) obj;
            String valueInMap = objValMap.get(field);
            if (currentSelectedItemValue.equals(vo.getValue()) || currentSelectedItemValue.equals(vo.getName())) {
                selectedItem = obj;
                break;
            } else if (valueInMap == null) {
                continue;
            } else if ("".equalsIgnoreCase(valueInMap) || valueInMap.equals(vo.getValue())
                    || valueInMap.equals(vo.getName())) {
                selectedItem = obj;
                break;
            }
        }
        model.setSelectedItem(selectedItem);
    }
 
    private String getReplacedSql(String sql) {
        String res = sql;
        Map<String, String> valueMap = new HashMap<String, String>();
        appendToValueMap(sql, valueMap);
        Iterator<String> its = valueMap.keySet().iterator();
        while (its.hasNext()) {
            String key = its.next();
            sql = sql.replaceAll(key, key.replace(".", "_"));
        }
        Map<String, FreemarkerParamObject> rootMap = convertValueMapToFPOMap(valueMap);
        res = FreeMarkerCommon.getValueByTempRule(rootMap, sql);
        return res;
    }
 
    private String[] getSQLData(String sql, AttributeValue[] attrVals) {
        String[] clsfVals = new String[0];
        ClientBusinessObjectOperation bofactory = new ClientBusinessObjectOperation();
        try {
            clsfVals = bofactory.getClassficationValue(sql, attrVals);
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return clsfVals;
    }
 
    private String[][] getMulColSQLData(String sql, AttributeValue[] attrVals) {
        String[][] vals = new String[0][0];
        ClientBusinessObjectOperation bofactory = new ClientBusinessObjectOperation();
        try {
            vals = bofactory.getSqlQueryResult(sql, attrVals);
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return vals;
    }
 
    private DefaultComboBoxModel convertSQLDataToDataModel(String[] results) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (String res : results) {
            VCIJComboBoxModelValueObject obj = new VCIJComboBoxModelValueObject(res, res);
            model.addElement(obj);
        }
        return model;
    }
 
    private DefaultComboBoxModel convertSQLDataToDataModel(String[][] results) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (String[] res : results) {
            VCIJComboBoxModelValueObject obj = new VCIJComboBoxModelValueObject(res[0], res[1]);
            model.addElement(obj);
        }
        return model;
    }
 
    private class HiddenOrShowComboBoxActionListener implements ActionListener {
        private PRMItem fromItem = null;
 
        public HiddenOrShowComboBoxActionListener(PRMItem fromItem) {
            this.fromItem = fromItem;
        }
 
        @Override
        public void actionPerformed(ActionEvent e) {
            VCIJComboBox cbx = (VCIJComboBox) e.getSource();
            VCIJComboBoxModelValueObject valObj = (VCIJComboBoxModelValueObject) cbx.getSelectedItem();
 
            String[] displayConditions = fromItem.getItemCtrlDisplyCondition().split(";");
            List<String> controlToFiels = hiddenControlsMap.get(fromItem.getItemField());
            for (int i = 0; i < controlToFiels.size(); i++) {
                // 被控制属性字段
                String toField = controlToFiels.get(i);
 
                String condition = displayConditions[i];
                // 允许显示出该属性的取值
                String[] diplayShows = condition.split(",");
                boolean enable = false;
                for (String display : diplayShows) {
                    enable |= valObj.getName().equals(display);
                }
                Component compt = ctrlLabelMap.get(toField);
                if (compt != null)
                    compt.setEnabled(enable && operateType != OperateType.BROWSER);
 
                compt = ctrlComptMap.get(toField);
                if (compt != null)
                    compt.setEnabled(enable && operateType != OperateType.BROWSER);
            }
        }
    }
 
    /**
     * 处理属性之间的关联查询控制
     * 
     * @param item
     */
    private void cascadeControlsMapConfig(PRMItem item) {
        String field = item.getItemField();
        String itemQueryRefFields = item.getItemQueryRefFields();
        if (itemQueryRefFields != null && !"".equals(itemQueryRefFields)) {
            // 一个属性能够关联 多个属性,被关联的属性名称之间用逗号,分隔
            String[] itemQueryRefFieldsArray = itemQueryRefFields.split(",");
            List<String> list = new ArrayList<String>();
            if (cascadeControlsMap.containsKey(field)) {
                list = cascadeControlsMap.get(field);
            }
            for (String refField : itemQueryRefFieldsArray) {
                // 建立 主控属性与被属性之间关联关系,以控制被控属性的取值
                list.add(refField);
 
                // 建立被控属性 与 主控属性 之间的映射关联
                fieldToMasterFieldMap.put(refField, field);
            }
            cascadeControlsMap.remove(field);
            cascadeControlsMap.put(field, list);
        }
    }
 
    private void parseFieldRefHideAndShowData(PRMItem item) {
        String field = item.getItemField();
        String itemCtrlDisplayCol = item.getItemCtrlDisplyCol();
        if (itemCtrlDisplayCol != null && !"".equals(itemCtrlDisplayCol)) {
            String[] itemCtrlDisplayCols = itemCtrlDisplayCol.split(",");
            List<String> list = new ArrayList<String>();
            if (hiddenControlsMap.containsKey(field)) {
                list = hiddenControlsMap.get(field);
            }
            for (String refField : itemCtrlDisplayCols) {
                list.add(refField);
            }
            hiddenControlsMap.remove(field);
            hiddenControlsMap.put(field, list);
        }
    }
 
    private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx,
            double weighty, int anchor, int fill, int padxy) {
        return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill,
                new Insets(padxy, padxy, padxy, padxy), padxy, padxy);
    }
 
    /**
     * 设置已经修改了属性值的对象数据到UI
     * 
     * @param clientObject
     */
    public void setValueToUIControlByAttrValChange(Object clientObject) {
        if (clientObject instanceof ClientBusinessObject) {
            ClientBusinessObject cbo = (ClientBusinessObject) clientObject;
            setValueToUIControl(cbo, false);
        } else if (clientObject instanceof ClientLinkObject) {
            ClientLinkObject clo = (ClientLinkObject) clientObject;
            setValueToUIControl(clo, false);
        }
    }
 
    /**
     * 编辑Form对应的查询模板查询出的数据Map
     */
    public void setValueToUIControl(Object clientObject) {
        if (clientObject instanceof ClientBusinessObject) {
            ClientBusinessObject cbo = (ClientBusinessObject) clientObject;
            setValueToUIControl(cbo, true);
        } else if (clientObject instanceof ClientLinkObject) {
            ClientLinkObject clo = (ClientLinkObject) clientObject;
            setValueToUIControl(clo, true);
        }
    }
 
    /**
     * 根据idn重新设置表单的内容 如果是链接类型,根据空间的名称判断表单是正向还是反向
     * 
     * @param idn
     * @param typeFlag 表单类型 0业务类型,1连接类型
     */
    public void setValueToUIControl(IDataNode idn, int typeFlag) {
        // 判断选择的对象是BO还是LO
        String idnType = "9";
        if (idn.getMaterObject() instanceof ClientBusinessObject) {
            idnType = "0";
        } else if (idn.getMaterObject() instanceof ClientLinkObject) {
            idnType = "1";
        }
        if (idnType.equals("9")) {
            return;
        }
        // 根据表单的类型设置数据
        if (typeFlag == 0) {
            // BO类型
            if (idnType.equals("0")) {
                // BO对象对应业务类型的表单
                setValueToUIControl(idn.getMaterObject());
            } else {
                // TODO 暂时没有实现link设置到业务类型表单的情况
 
            }
        } else {
            // 链接类型
            if (idnType.equals("1")) {
                setValueToUIControl(idn.getMaterObject());
            } else {
                // BO对象,link表单
                setLinkFormData(idn, idn.getValueMap());
            }
        }
    }
 
    /**
     * 设置LinkForm的内容
     * 
     * @param dataNode  控件关联的数据对象
     * @param objValMap bo的valueMap
     */
    private void setLinkFormData(IDataNode dataNode, Map<String, String> objValMap) {
        HashMap<String, Component> comptMap = getCtrlComptMap();
        for (Iterator<String> i = comptMap.keySet().iterator(); i.hasNext();) {
            String field = i.next();
            String newKey = "";
            if (field.toUpperCase().startsWith("T_OID.")) {
                newKey = field.substring(field.indexOf(".") + 1, field.length());
            } else if (field.toUpperCase().startsWith("F_OID.")) {
                newKey = field.substring(field.indexOf(".") + 1, field.length());
            }
            if (!objValMap.containsKey(newKey))
                continue;
            String value = objValMap.get(newKey);
            if (field.toUpperCase().endsWith(".LCSTATUS")) {
                value = operation.transferLifecycle(value);
            }
            if (value == null) {
                value = "";
            }
            Component compt = comptMap.get(field);
            PRMItem item = itemMap.get(field);
 
            if (compt instanceof JTextComponent) {
                ((JTextComponent) compt).setText(value);
            } else if (compt instanceof VCIJComboBox) {
                VCIJComboBox cbx = (VCIJComboBox) compt;
                ComboBoxModel model = cbx.getModel();
                // 遍历所有下拉框选项
                for (int j = 0; j < model.getSize(); j++) {
                    Object Obj = model.getElementAt(j);
                    if (Obj instanceof VCIJComboBoxModelValueObject) {
                        VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj;
                        // 比较是否与业务对象属性值相同
                        if (value.equals(vo.getValue())) {
                            model.setSelectedItem(vo);
                            break;
                        }
                    }
                }
            } else if (compt instanceof ICustomControl) {
                ICustomControl ctrl = (ICustomControl) compt;
                // 将控件与数据主对象
                ctrl.setDataNode(dataNode);
                if (ctrl instanceof RefObjChooseControl) {
                    String refObjField = item.getItemListVal();
                    String refObjKey = newKey + "." + refObjField;
                    String refObjVal = value;
                    if (objValMap.containsKey(refObjKey)) {
                        refObjVal = objValMap.get(refObjKey);
                    }
                    value = value + "," + refObjVal;
                }
                ctrl.setValue(value);
            }
        }
    }
 
    /**
     * 从控件中取值
     * 
     * @param field
     * @param dataMap
     */
    private String getValueFromUIControl(String field) {
        String res = "";
        String key = field;
        Component compt = this.ctrlComptMap.get(key);
        if (compt instanceof VCIJComboBox) {
            VCIJComboBox cbx = (VCIJComboBox) compt;
            Object obj = cbx.getModel().getSelectedItem();
            if (obj != null && obj instanceof VCIJComboBoxModelValueObject) {
                VCIJComboBoxModelValueObject val = (VCIJComboBoxModelValueObject) obj;
                if (val != null && !val.getValue().trim().equalsIgnoreCase("")) {
                    res = val.getValue();
                }
            }
        } else if (compt instanceof JTextComponent) {
            res = ((JTextComponent) compt).getText();
        } else if (compt instanceof VCIJCalendarPanel) {
            res = ((VCIJCalendarPanel) compt).getDateString();
        }
        return res;
    }
 
    /**
     * 设置页面空间的属性值 cbo一定不为空 当clo为空的时候,页面说是用的Form一定是BO的Form
     * 当clo不为空的时候分为使用BO的Form或是使用LOForm
     * 
     * @param clo
     * @param cbo
     */
    public void setValueToUIControl(ClientLinkObject clo, ClientBusinessObject cbo) {
        if (cbo == null || cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")) {
            return;
        }
        if (clo == null || clo.getLinkObject().oid == null || clo.getLinkObject().oid.equals("")) {
            setValueToUIControl(cbo);
        } else {
            // 此时为修改或浏览lo对象,需要判断所使用的form类型
            if (getTypeFlag() == 0) {
                // 使用的是BO的Form,页面上所有的属性都是BO的属性
                setValueToUIControl(cbo);
            } else {
                // 使用的LO的Form,以t_oid开头的属性是BO的属性
                setValueToUIControl(clo);
            }
        }
    }
 
    /**
     * modify by songyf 2014.09.02 修改form中使用link表单时查询模板参数设置问题
     * 
     * @param objOid
     * @return
     */
    @SuppressWarnings("deprecation")
    private IDataNode getDataNodeFromBoLoId(String objOid) {
        DataModelProcessor processor = new DataModelProcessor();
        String showType = defination.getShowType();
        String linkType = defination.getLinkType();
        IDataNode dataNode = null;
        try {
            PortalVI formDef = UITools.getService().getPortalVIBySymbol(this.getDefination().getTemplateId());
            boolean isShowLinkType = (formDef.typeFlag == 1);
            PRM prm = UITools.getPRM(formDef.prm);
            Map<String, String> columnsMap = processor.getFormColumnMap(formDef);
            // 获得查询模板,并根据查询模板设置查询条件
            Map<String, String> conditionMap = getQueryTemplateReplaceMap(prm, objOid, this.regionPanel.getSourceData(),
                    isShowLinkType);
            conditionMap.put(UIHelper.TYPE, showType);
            // conditionMap.put(UIHelper.OID, objOid);
            if (objOid != null && !"".equals(objOid)) {
                ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation();
                conditionMap.put(QueryConditionConstants.TRAINSITIONOID, objOid);
                ClientBusinessObject ccbo = operation.readBusinessObjectById(objOid, showType);
                conditionMap.put(QueryConditionConstants.NAME_OID, ccbo.getNameoid());
            }
            String queryTemplate = prm.getFormQtName();
            // 提示查询模板未配置
            if (queryTemplate == null || queryTemplate.equals("")) {
                UIFUtils.showMessage(this, "uifmodel.plm.uif.engine.querytemplate.notexits");
                return null;
            }
            if (isShowLinkType) {
                dataNode = getLinkObjectDataNode(objOid, conditionMap, processor, queryTemplate, columnsMap, linkType);
            } else {
                dataNode = getBusinessObjectDataNode(objOid, conditionMap, processor, queryTemplate, columnsMap,
                        showType);
            }
        } catch (Throwable e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return dataNode;
    }
 
    /**
     * 获得查询模板,并根据查询模板设置查询条件
     * 
     * @param prm
     * @param objOid
     * @param sourceData
     * @param isShowLinkType
     * @return
     */
    private Map<String, String> getQueryTemplateReplaceMap(PRM prm, String objOid, IDataNode sourceData,
            boolean isShowLinkType) {
        Map<String, String> replaceMap = new HashMap<String, String>();
 
        String queryTemplateName = prm.getFormQtName();
        QueryTemplate qt = UIFUtils.getQueryTemplateByName(queryTemplateName);
        if (qt != null) {
            Condition cond = qt.getCondition();
            if (cond != null) {
                Map<String, FreemarkerParamObject> rootMap = new HashMap<String, FreemarkerParamObject>();
                Map<String, String> globalConditionMap = GlobalContextParam.getInstance().getDefaultConditionMap();
                Map<String, ConditionItem> ciMap = cond.getCIMap();
                Iterator<String> it = ciMap.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    ConditionItem ci = ciMap.get(key);
                    if (ci == null)
                        continue;
                    LeafInfo li = ci.getLeafInfo();
                    if (li == null)
                        continue;
                    // 替换值
                    String replaceField = li.getValue().getOrdinaryValue();
                    String replacedValue = "";
                    if (replaceField.equals(QueryConditionConstants.FROM_OID)) {
                        replacedValue = objOid;
                    } else if (replaceField.equals(UIHelper.OID)) {
                        // 为了不影响原来的配置,如果是BO的表单,oid的值还设置为原来的objOid(objOid在MainDataFrompanel中已经转成了BO的OID)
                        // 对于LO的表单,sourceData应该是一个LO对象,如果是一个BO的话应该在查询模板中配置${ui.inpu....}来获得相关的参数,此时再使用OID
                        // 获得的参数可能会出现错误
                        if (isShowLinkType) {
                            if (sourceData.getMaterObject() instanceof ClientBusinessObject) {
                                replacedValue = this.regionPanel.getBusinessObjectOid(sourceData);
                            } else if (sourceData.getMaterObject() instanceof ClientLinkObject) {
                                replacedValue = this.regionPanel.getLinkObjectOid(sourceData);
                            }
                        } else {
                            replacedValue = objOid;
                        }
                    }
                    // 基础固有查询条件
                    else if (globalConditionMap.containsKey(replaceField)) {
                        replacedValue = globalConditionMap.get(replaceField);
                    } else if (replaceField.startsWith("#") && replaceField.endsWith("#")) {
                        replaceField = replaceField.substring(1, replaceField.length() - 1);
                        if (globalConditionMap.containsKey(replaceField)) {
                            replacedValue = globalConditionMap.get(replaceField);
                        }
                    }
                    // 替换值是 ${x}-${y} 形式的 变量
                    else if (isFreemarkTemplateContent(replaceField)) {
                        Map<String, String> valueMap = null;
 
                        if (sourceData != null)
                            valueMap = appendToValueMap(replaceField, sourceData.getValueMap());
                        // add by xhcao 2014.11.25 begin
                        // 完善 如果被修改的对象来自选择的数据时
                        // 从被选择数据的valueMap取标记值
 
                        if (regionPanel != null) {
                            Object[] secObjs = regionPanel.getDataModel().getSelectObjects();
                            if (secObjs != null && secObjs.length > 0 && secObjs[0] instanceof IDataNode) {
                                valueMap = appendToValueMap(replaceField, ((IDataNode) secObjs[0]).getValueMap());
                            }
                        }
 
                        if (valueMap == null)
                            valueMap = new HashMap<String, String>();
 
                        // add by xhcao 2014.11.25 begin
                        if (rootMap.size() == 0) {
                            rootMap = this.convertValueMapToFPOMap(valueMap);
                        }
                        if (isExistInMap(replaceField, valueMap)) {
                            replacedValue = FreeMarkerCommon.getValueByTempRule(rootMap,
                                    replaceFreemarkerField(replaceField));
                        } else {
                            replacedValue = replaceField;
                        }
                    }
                    // 固定值
                    else {
                        replacedValue = replaceField;
                    }
                    replaceMap.put(replaceField, replacedValue);
                }
            }
        }
        return replaceMap;
    }
 
    private String replaceFreemarkerField(String replaceValue) {
        String src = replaceValue;
        String field = replaceValue;
        int begin = field.indexOf("${");
        int end = field.indexOf("}");
        int len = field.length();
        String key = "";
        while (!"".equals(field) && begin >= 0 && end < len) {
            key = field.substring(begin + 2, end);
            src = src.replace(key, key.replace(".", "_"));
            field = field.substring(end + 1);
            begin = field.indexOf("${");
            end = field.indexOf("}");
            len = field.length();
        }
        return src;
    }
 
    private Map<String, String> appendToValueMap(String replaceField, Map<String, String> valueMap) {
        String field = replaceField;
        int begin = field.indexOf("${");
        int end = field.indexOf("}");
        int len = field.length();
        String key = "";
        while (!"".equals(field) && begin >= 0 && end < len) {
            key = field.substring(begin + 2, end);
            if (!valueMap.containsKey(key)) {
                valueMap.put(key, key);
            }
            field = field.substring(end + 1);
            begin = field.indexOf("${");
            end = field.indexOf("}");
            len = field.length();
        }
        return valueMap;
    }
 
    /**
     * 检查要替换的字段KEY是否全部存在于valueMap中
     * 
     * @param replaceField 查询模板中替换值的查询属性值
     * @param valueMap     dataSource.getValueMap()
     * @return
     */
    private boolean isExistInMap(String replaceField, Map<String, String> valueMap) {
        boolean res = true;
        String field = replaceField;
        int begin = field.indexOf("${");
        int end = field.indexOf("}");
        int len = field.length();
        String key = "";
        while (!"".equals(field) && begin >= 0 && end < len) {
            key = field.substring(begin + 2, end);
            if (!valueMap.containsKey(key)) {
                System.out.println("变量:" + key + " 在 sourceData.getValueMap() 中不存在。");
                return false;
            }
            field = field.substring(end + 1);
            begin = field.indexOf("${");
            end = field.indexOf("}");
            len = field.length();
            res = true;
        }
        return res;
    }
 
    private IDataNode getLinkObjectDataNode(String objOid, Map<String, String> conditionMap,
            DataModelProcessor processor, String queryTemplate, Map<String, String> columnsMap, String linkType)
            throws VCIError, DocumentException {
 
        LinkedList<IDataNode> dataNodeList = new LinkedList<IDataNode>();
        @SuppressWarnings("unchecked")
        Map<String, String>[] valueMaps = new LinkedHashMap[0];
 
        // conditionMap.put(QueryConditionConstants.FROM_OID, objOid);
        LinkObject[] los = processor.getLinkObjectByQueryTemplate(queryTemplate, conditionMap);
        Map<String, List<LinkObject>> multiTypeLink = new LinkedHashMap<String, List<LinkObject>>();
        for (LinkObject lo : los) {
            if (multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, "t_btwname")) == null) {
                List<LinkObject> cLink = new LinkedList<LinkObject>();
                cLink.add(lo);
                multiTypeLink.put(ObjectTool.getLOAttributeValue(lo, "t_btwname"), cLink);
            } else {
                multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, "t_btwname")).add(lo);
            }
            // 在LinkObject 加入 linkTypeName 属性
            AttributeValue[] avs = Arrays.copyOfRange(lo.hisAttrValList, 0, lo.hisAttrValList.length + 1);
            AttributeValue av = new AttributeValue("linkTypeName".toLowerCase(), linkType);
            avs[avs.length - 1] = av;
            lo.hisAttrValList = avs;
 
            // 将数据对象加入到列表
            IDataNode dataNode = new DefaultTableNode();
            ClientLinkObject clo = new ClientLinkObject();
            clo.setLinkObject(lo);
            dataNode.setMasterObject(clo);
            dataNodeList.add(dataNode);
        }
        Map<String, List<String>> referenceKeyMap = processor.getReferenceCol(columnsMap);
        Iterator<String> referenceKey = referenceKeyMap.keySet().iterator();
        List<String> referenceList = new LinkedList<String>();
        while (referenceKey.hasNext()) {
            referenceList.add(referenceKey.next());
        }
        List<Map<String, String>> listRes = new LinkedList<Map<String, String>>();
        Iterator<String> itor = multiTypeLink.keySet().iterator();
        while (itor.hasNext()) {
            String cType = itor.next();
            List<LinkObject> cLinkList = multiTypeLink.get(cType);
            valueMaps = CBOHelper.getLOValueMap(cLinkList.toArray(new LinkObject[] {}));
            Map<String, String> rowRefMap = new LinkedHashMap<String, String>();
            Map<String, String> rowKeyMap = new LinkedHashMap<String, String>();
            for (LinkObject lo : cLinkList.toArray(new LinkObject[] {})) {
                String oid = lo.oid;
                String refKey = "";
                // XXX 在referenceList大于一的时候会落掉其他的参照查询
                // 如果通过循环把其它的参照加进来的话查出的值是null
                // 测试使用MBOM下级零部件的修改按钮
                if (referenceList.size() > 0) {
                    refKey = referenceList.get(0);
                    oid = ObjectTool.getLOAttributeValue(lo, refKey);
                }
                rowRefMap.put(oid, refKey);
                rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid);
                // if(referenceList.isEmpty()) {
                // rowRefMap.put(oid, refKey);
                // rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid);
                // } else {
                // for(String key : referenceList) {
                // refKey = key;
                // oid = ObjectTool.getLOAttributeValue(lo, refKey);
                // rowRefMap.put(oid, refKey);
                // rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid);
                // }
                // }
            }
            Map<String, String> secQueryMap = processor.getQueryLinkObjectCondition(linkType, rowKeyMap, rowRefMap,
                    referenceKeyMap);
            RefPath[] refPaths = processor.queryReference(secQueryMap, cType);
            connectSecondQueryResult(valueMaps, refPaths, secQueryMap, referenceKeyMap);
            for (Map<String, String> resMap : valueMaps) {
                listRes.add(resMap);
            }
        }
        for (int i = 0; i < listRes.size(); i++) {
            IDataNode dataNode = dataNodeList.get(i);
            dataNode.setValueMap(listRes.get(i));
        }
        IDataNode dataNode = null;
        if (dataNodeList.size() != 0) {
            dataNode = dataNodeList.get(0);
        }
        return dataNode;
    }
 
    private IDataNode getBusinessObjectDataNode(String objOid, Map<String, String> conditionMap,
            DataModelProcessor processor, String queryTemplate, Map<String, String> columnsMap, String showType)
            throws VCIError, DocumentException {
 
        LinkedList<IDataNode> dataNodeList = new LinkedList<IDataNode>();
        @SuppressWarnings("unchecked")
        Map<String, String>[] valueMaps = new LinkedHashMap[0];
 
        // 传入分页参数
        BusinessObject[] objs = processor.getBusinessObjectByQueryTemplate(queryTemplate, conditionMap);
        Map<String, List<String>> referenceKeyMap = processor.getReferenceCol(columnsMap);
        Iterator<String> referenceKey = referenceKeyMap.keySet().iterator();
        List<String> referenceList = new LinkedList<String>();
        while (referenceKey.hasNext()) {
            referenceList.add(referenceKey.next());
        }
        Map<String, Map<String, String>> rowRefMap = new LinkedHashMap<String, Map<String, String>>();
        for (BusinessObject obj : objs) {
            String oid = obj.oid;
            Map<String, String> refMap = new LinkedHashMap<String, String>();
            for (int j = 0; j < referenceList.size(); j++) {
                String refKey = referenceList.get(j);
                String refVal = ObjectTool.getBOAttributeValue(obj, refKey);
                refMap.put(refKey, refVal);
            }
            rowRefMap.put(oid, refMap);
            // 将数据对象加入到列表
            IDataNode dataNode = new DefaultTableNode();
            ClientBusinessObject cbo = new ClientBusinessObject();
            cbo.setBusinessObject(obj);
            dataNode.setMasterObject(cbo);
            dataNodeList.add(dataNode);
        }
        Map<String, String> emptypMap = new HashMap<String, String>();
        if (rowRefMap.size() == 1) {
            Iterator<String> itor = rowRefMap.keySet().iterator();
            while (itor.hasNext()) {
                Map<String, String> crowMap = rowRefMap.get(itor.next());
                Iterator<String> rowMap = crowMap.keySet().iterator();
                List<String> removeList = new ArrayList<String>();
                while (rowMap.hasNext()) {
                    String ckey = rowMap.next();
                    String value = crowMap.get(ckey);
                    if (value == null || value.trim().equals("")) {
                        removeList.add(ckey);
                    }
                }
                int len = removeList.size();
                for (int i = 0; i < len; i++) {
                    List<String> list = referenceKeyMap.get(removeList.get(i));
                    emptypMap.put(removeList.get(i), "");
                    for (int j = 0; j < list.size(); j++) {
                        emptypMap.put(list.get(j), "");
                    }
                    crowMap.remove(removeList.get(i));
                    referenceKeyMap.remove(removeList.get(i));
                }
            }
 
        }
        Map<String, String> secQueryMap = processor.getQueryBusinessObjectCondition(showType, rowRefMap,
                referenceKeyMap);
        RefPath[] refPaths = processor.queryReference(secQueryMap, showType);
        valueMaps = CBOHelper.getBOValueMap(objs);
        connectSecondQueryResult(valueMaps, refPaths, secQueryMap, referenceKeyMap);
        for (int i = 0; i < valueMaps.length; i++) {
            IDataNode dataNode = dataNodeList.get(i);
            valueMaps[i].putAll(emptypMap);
            dataNode.setValueMap(valueMaps[i]);
        }
        IDataNode dataNode = null;
        if (dataNodeList.size() != 0) {
            dataNode = dataNodeList.get(0);
        }
        return dataNode;
    }
 
    private void connectSecondQueryResult(Map<String, String>[] res, RefPath[] refPaths,
            Map<String, String> secQueryMap, Map<String, List<String>> referenceKeyMap) {
        if (refPaths != null) {
            int colNum = secQueryMap.size();
            for (int i = 0; i < res.length; i++) {
                Map<String, String> rowVal = res[i];
                for (int j = 0; j < colNum; j++) {
                    String key = secQueryMap.keySet().toArray(new String[colNum])[j];
                    if (referenceKeyMap.containsKey(key)) {
                        continue;
                    }
                    // TODO 获取value的显示值,如果为enum类型,应该显示名称
                    if (refPaths[j].values.length <= i) {
                        continue;
                    }
                    String cVal = refPaths[j].values[i].value;
                    rowVal.put(secQueryMap.keySet().toArray(new String[colNum])[j], cVal);
                }
            }
        }
    }
 
    /**
     * 将业务对象的数据值设置到UI控件上
     * 
     * @param cboObj       BO、LO、或是文件夹对象
     * @param reloadFromDB
     */
    private void setValueToUIControl(Object cboObj, boolean reloadFromDB) {
        String oid = "";
        if (cboObj instanceof ClientBusinessObject) {
            // 如果是BO对象
            oid = ((ClientBusinessObject) cboObj).getBusinessObject().oid;
        } else if (cboObj instanceof ClientLinkObject) {
            // 如果是LO对象
            oid = ((ClientLinkObject) cboObj).getLinkObject().oid;
        } else {
 
        }
        if (reloadFromDB) {
            dataNodeObject = getDataNodeFromBoLoId(oid);
            if (dataNodeObject == null) {
                dataNodeObject = new DefaultTableNode();
            }
        } else {
            dataNodeObject.setMasterObject(cboObj);
        }
        if (dataNodeObject.getMaterObject() instanceof ClientBusinessObject) {
            this.cbo = (ClientBusinessObject) dataNodeObject.getMaterObject();
        } else if (dataNodeObject.getMaterObject() instanceof ClientLinkObject) {
            this.clo = (ClientLinkObject) dataNodeObject.getMaterObject();
        }
        Map<String, String> objValMap = dataNodeObject.getValueMap();
        HashMap<String, Component> comptMap = getCtrlComptMap();
        for (Iterator<String> i = comptMap.keySet().iterator(); i.hasNext();) {
            String field = i.next();
            loadComboBoxData(field); // add by caill 解决点击修改时责任人不能根据选中的责任部门自动带入的问题
            // String value = cbo.getAttributeValue(field);
            // if(value == null || "".equals(value)){
            // value = dataNodeObject.getValueMap().get(field);
            // }
            String value = objValMap.get(field);
            if (field.equalsIgnoreCase("lcstatus")) {
                value = operation.transferLifecycle(value);
            }
            if (value == null) {
                value = "";
            }
            // 如果 新查询的valueMap中不存在field的值,且field又设置过默认值,
            // 此时显示此设置的默认值
            if (value.equals("") && getComptDefValMap().containsKey(field)) {
                value = getComptDefValMap().get(field);
            }
            if (!comptMap.containsKey(field))
                continue;
 
            Component compt = comptMap.get(field);
            PRMItem item = itemMap.get(field);
 
            if (compt instanceof JTextComponent) {
                ((JTextComponent) compt).setText(value);
            } else if (compt instanceof VCIJComboBox) {
                VCIJComboBox cbx = (VCIJComboBox) compt;
                AttribItem fieldDef = AttributeChecker.attrItemMap.get(field);
                ComboBoxModel model = cbx.getModel();
                if ((fieldDef != null && fieldDef.vtDataType.equals("VTBoolean")) || isEnumAttr(field)) {
                    // 遍历所有下拉框选项
                    for (int j = 0; j < model.getSize(); j++) {
                        Object Obj = model.getElementAt(j);
                        if (Obj instanceof VCIJComboBoxModelValueObject) {
                            VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj;
                            // 比较是否与业务对象属性值相同
                            if (value.equals(vo.getValue())) {
                                model.setSelectedItem(vo);
                                break;
                            }
                        }
                        if (item.getItemCustomClass() != null && !item.getItemCustomClass().equals("")) {
 
                        }
                    }
                } else if (model != null && model.getSize() > 0) { // add by caill 使配置的下拉列表项显示名字而不是id
                    for (int j = 0; j < model.getSize(); j++) {
                        Object Obj = model.getElementAt(j);
                        if (Obj instanceof VCIJComboBoxModelValueObject) {
                            VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj;
                            // 比较是否与业务对象属性值相同
                            if (value.equals(vo.getValue())) {
                                model.setSelectedItem(vo);
                                break;
                            }
                        }
                        if (item.getItemCustomClass() != null && !item.getItemCustomClass().equals("")) {
 
                        }
                    }
                } else {
                    DefaultComboBoxModel cmodel = new DefaultComboBoxModel();
                    VCIJComboBoxModelValueObject voe = new VCIJComboBoxModelValueObject("", "");
                    VCIJComboBoxModelValueObject vo = new VCIJComboBoxModelValueObject(value, value);
                    cmodel.addElement(voe);
                    cmodel.addElement(vo);
                    cmodel.setSelectedItem(vo);
                    cbx.setModel(model);
                }
            } else if (compt instanceof ICustomControl) {
                ICustomControl ctrl = (ICustomControl) compt;
                // 将控件与数据主对象
                ctrl.setDataNode(dataNodeObject);
                if (ctrl instanceof RefObjChooseControl) {
                    String refObjField = item.getItemListVal();
                    String refObjKey = item.getItemField() + "." + refObjField;
                    String refObjVal = value;
                    if (objValMap.containsKey(refObjKey)) {
                        refObjVal = objValMap.get(refObjKey);
                    } else {
                        // 重新加载对象
                        try {
                            // 根据“item.getItemField()”参照属性获取btmName
                            String itemField = item.getItemField();
                            if (itemField.indexOf(".") > 0) {
                                String[] strs = itemField.split("\\.");
                                itemField = strs[strs.length - 1];
                            }
                            AttribItem attribItem = ApProvider.getAbItemByName(itemField);
                            OtherInfo otherInfo = OtherInfo.getOtherInfoByText(attribItem.other);
                            String btmName = otherInfo.getRefTypeName();
                            ClientBusinessObject tempbo = new ClientBusinessObjectOperation()
                                    .readBusinessObjectById(value, btmName);
                            if (tempbo != null) {
                                refObjVal = ObjectTool.getBOAttributeValue(tempbo.getBusinessObject(), refObjField);
                            }
                            if (refObjVal == null || refObjVal.equals("")) {
                                // add xchao 2014.08.21 begin
                                // 如果bo的refObjField属性值为空,则显示" "
                                refObjVal = " ";
                                // add xchao 2014.08.21 end
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    value = value + "," + refObjVal;
                }
                ctrl.setValue(value);
            }
        }
    }
 
    private boolean isEnumAttr(String field) {
        boolean res = false;
        String[] fields = field.split("\\.");
        AttribItem attr = ApProvider.getAbItemByName(fields[fields.length - 1]);
        if (attr == null)
            return false;
        String enumName = ApProvider.getOtherValueByType(attr.other, "enumName");
        if (enumName == null || "".equals(enumName))
            return false;
        EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName);
        if (enumItem == null)
            return false;
        res = true;
        return res;
    }
 
    //
    // /**
    // * 设置页面空间的值
    // * 在编辑,浏览link对象的时候
    // * 有可能使用的是BO的Form,也有可能是有的是LO的Form
    // * @param clo
    // */
    // private void setValueToUIControl(ClientLinkObject clo, boolean
    // reloadFromDB){
    // this.clo = clo;
    // }
 
    /**
     * 从控件中获取最新值
     * 
     * @return
     */
    public Map<String, String> getNewValueMapFromUI() {
        HashMap<String, String> valueMap = new HashMap<String, String>();
        HashMap<String, Component> comptMap = getCtrlComptMap();
        for (Iterator<String> i = comptMap.keySet().iterator(); i.hasNext();) {
            String field = i.next();
            Component compt = comptMap.get(field);
            String value = "";
 
            if (compt instanceof JTextComponent) {
                value = ((JTextComponent) compt).getText();
            } else if (compt instanceof VCIJComboBox) {
                VCIJComboBox cbx = (VCIJComboBox) compt;
                ComboBoxModel model = cbx.getModel();
                Object selectObj = model.getSelectedItem();
                if (selectObj instanceof VCIJComboBoxModelValueObject) {
                    VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) selectObj;
                    value = vo.getValue();
                }
            } else if (compt instanceof ICustomControl) {
                ICustomControl ctrl = (ICustomControl) compt;
                value = ctrl.getValue();
            }
            if (value instanceof String) {
                value = value.trim();
            }
            valueMap.put(field, value);
        }
        return valueMap;
    }
 
    /**
     * 从控件中获取最新值
     * 
     * @return
     */
    @Deprecated
    public Map<String, String> getNewValueMap() {
        return this.getNewValueMapFromUI();
    }
 
    public String getType() {
        return type;
    }
 
    public void setType(String type) {
        this.type = type;
    }
 
    public String getContext() {
        return context;
    }
 
    public void setContext(String context) {
        this.context = context;
    }
 
    public PLDefination getDefination() {
        return defination;
    }
 
    public void setDefination(PLDefination defination) {
        this.defination = defination;
    }
 
    public DataModelFactory getFactory() {
        return factory;
    }
 
    public void setFactory(DataModelFactory factory) {
        this.factory = factory;
    }
 
    public Map<String, String> getParamsMap() {
        return paramsMap;
    }
 
    public void setParamsMap(Map<String, String> paramsMap) {
        this.paramsMap = paramsMap;
    }
 
    public HashMap<String, Component> getCtrlComptMap() {
        return ctrlComptMap;
    }
 
    public void setCtrlComptMap(HashMap<String, Component> ctrlComptMap) {
        this.ctrlComptMap = ctrlComptMap;
    }
 
    public Map<String, String> getValueMapNew() {
        return valueMapNew;
    }
 
    public void setValueMapNew(Map<String, String> valueMapNew) {
        this.valueMapNew = valueMapNew;
    }
 
    public Map<String, String> getValueMapOriginal() {
        return valueMapOriginal;
    }
 
    public void setValueMapOriginal(Map<String, String> valueMapOriginal) {
        this.valueMapOriginal = valueMapOriginal;
    }
 
    public OperateType getOperateType() {
        return operateType;
    }
 
    public void setOperateType(OperateType operateType) {
        this.operateType = operateType;
    }
 
    public int getTypeFlag() {
        return typeFlag;
    }
 
    public void setTypeFlag(int typeFlag) {
        this.typeFlag = typeFlag;
    }
 
    /**
     * 获得IDataNode
     * 
     * @param isCheck 判断是否需要进行数据控件校验
     * @return
     */
    public IDataNode getDataNodeObject(boolean isCheck) {
        if (!setUIValueToMasterObject(dataNodeObject, isCheck)) {
            return null;
        }
        return dataNodeObject;
    }
 
    /**
     * 封装窗口数据
     * 
     * 在此进行数据校验
     * 
     * 此处不判断是创建BO对象还是创建LO对象 根据表单类型,如果表单类型是业务类型,直接创建BO对象 如果表单类型是link类型则创建LO和BO对象
     * 
     * 如果是选择窗口在封装数据时不需要校验to端对象的属性
     * 
     * @param dataNodeObject
     * @param isCheck        是否需要进行控件校验
     */
    @SuppressWarnings("deprecation")
    private boolean setUIValueToMasterObject(IDataNode dataNodeObject, boolean isCheck) {
        try {
            if (isAdd() || isEdit() || isSelect()) {
                // 业务对象属性校验
                BusinessObjectAttributeChecker boacer = new BusinessObjectAttributeChecker(
                        ClientContextVariable.getFrame() == null ? new JLabel() : ClientContextVariable.getFrame());
                // 进行控件校验
                Map<String, String> valueMapNew = this.getNewValueMapFromUI();
                // List<PRMItem> itemList = itemMap;
                // 业务对象界面属性(此处的非空校验是在设置创建界面时设置的)
                if (itemMap.size() != 0 && isCheck) {
                    Iterator<String> it = itemMap.keySet().iterator();
                    while (it.hasNext()) {
                        // 如果设置原色在界面上显示并且设置为必填项
                        PRMItem item = itemMap.get(it.next());
                        if (item.getItemCols() != null && !item.getItemCols().trim().equals("")
                                && !item.getItemCols().equals("0") && item.getItemIsRequired() != null
                                && item.getItemIsRequired().equals("1")) {
                            String tempStr = valueMapNew.get(item.getItemField());
                            if (tempStr == null || tempStr.equals("")) {
                                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                                        "uifmodel.plm.uif.actions.validate.999", item.getItemName());
                                return false;
                            }
                        }
                    }
                }
                // 进行属性校验,检验属性时只校验LO或BO对象固有的属性
                if (typeFlag == 0) {
                    // 表单上只有BO对象的属性
                    // 业务对象属性
                    Map<String, String> boAttrMap = new HashMap<String, String>();
                    // 此处的BO对象应该是在窗口初始化的时候set的一个空的业务对象
                    ClientBusinessObject cbo = null;
                    // 构建一个空的BO对象,主要是用来或的BO对象所具有的属性
                    ClientBusinessObject emptyBO = null;
                    if (isAdd()) {
                        cbo = (ClientBusinessObject) dataNodeObject.getMaterObject();
                        emptyBO = cbo;
                    } else if (isEdit()) {
                        cbo = this.cbo;
                        emptyBO = operation.createEmptyClientBusinessObject(this, cbo.getBusinessObject().btName);
                    } else if (isSelect()) {
                        cbo = (ClientBusinessObject) ((IDataNode) selectedDatas[0]).getMaterObject();
                        emptyBO = operation.createEmptyClientBusinessObject(this, cbo.getBusinessObject().btName);
                    }
 
                    // 得到业务对象属性集合
                    AttributeValue[] avs = emptyBO.getBusinessObject().newAttrValList;
                    // 这三个属性是固定的
                    boAttrMap.put("id", valueMapNew.get("id") == null ? "" : valueMapNew.get("id"));
                    boAttrMap.put("name", valueMapNew.get("name") == null ? "" : valueMapNew.get("name"));
                    boAttrMap.put("description",
                            valueMapNew.get("description") == null ? "" : valueMapNew.get("description"));
                    if (avs != null && avs.length > 0) {
                        for (AttributeValue av : avs) {
                            String attrName = av.attrName.toLowerCase();
                            // 当时编辑时只需要设置页面上能够修改的属性,对于隐藏的属性不需要重新设置newAttrValList
                            if (valueMapNew.containsKey(attrName)) { // add by zgy 2015-02,保证非UI界面的数据保留
                                if (isEdit()) {
                                    if (valueMapNew.containsKey(attrName)) {
                                        boAttrMap.put(attrName,
                                                valueMapNew.get(attrName) == null ? "" : valueMapNew.get(attrName));
                                    }
                                } else {
                                    boAttrMap.put(attrName,
                                            valueMapNew.get(attrName) == null ? "" : valueMapNew.get(attrName));
                                }
                            }
                        }
                    }
                    // 选择窗口不进行TO对象的属性校验
                    // 也不需要设置对象属性
                    if (!isSelect()) {
                        boolean result = boacer.validateAttr(boAttrMap);
                        if (!result) {
                            return false;
                        }
                        serUIValueObject(boAttrMap, cbo, valueMapNew, "");
                    }
                    Map<String, String> valueMap = dataNodeObject.getValueMap();
                    if (valueMap != null && valueMap.size() > 0) {
                        valueMap.putAll(valueMapNew);
                    }
                    dataNodeObject.setValueMap(valueMap);
                } else if (typeFlag == 1) {
                    // 保单上BO的属性是以t_oid开头的和LO的属性
                    // link对象属性
                    Map<String, String> loAttrMap = new HashMap<String, String>();
                    // 业务对象属性
                    Map<String, String> boAttrMap = new HashMap<String, String>();
                    // 此处的LO对象应该是在窗口初始化的时候set的一个空的链接对象
                    ClientLinkObject clo = this.clo;
                    clo.getLinkObject().ltName = defination.getLinkType();
                    // 构建一个空的LO对象,主要是用来获得LO对象所具有的属性
                    ClientLinkObject emptyLO = operation.createEmptyClientLinkObject(this, defination.getLinkType());
                    if (emptyLO == null) {
                        return false;
                    }
                    // link对象属性
                    AttributeValue[] loav = emptyLO.getLinkObject().newAttrValList;
                    if (loav != null && loav.length > 0) {
                        for (AttributeValue av : loav) {
                            String attrVal = "";
                            String attrName = av.attrName.toLowerCase();
                            if (valueMapNew.containsKey(attrName) && valueMapNew.get(attrName) != null) {
                                attrVal = valueMapNew.get(attrName);
                                loAttrMap.put(attrName, attrVal);
                            }
                        }
                    }
                    // 校验link对象属性
                    boolean result = boacer.validateAttr(loAttrMap);
                    if (!result) {
                        return false;
                    }
                    // 根据link的信息得到一个空的to端对象
                    ClientBusinessObject to = null;
                    // 构建一个空的BO对象,主要是用来或的BO对象所具有的属性
                    ClientBusinessObject emptyBO = null;
                    if (isAdd()) {
                        to = operation.createEmptyClientBusinessObject(this, defination.getShowType());
                        emptyBO = to;
                    } else if (isEdit()) {
                        emptyBO = operation.createEmptyClientBusinessObject(this, clo.getLinkObject().toBTName);
                        to = operation.reloadClientBusinessObject(this, clo.getLinkObject().toOid,
                                clo.getLinkObject().toBTName);
                    } else if (isSelect()) {
                        IDataNode selectNode = (IDataNode) this.selectedDatas[0];
                        to = (ClientBusinessObject) selectNode.getMaterObject();
                        // XXX 表单类型中有目标对象的类型 该如何获得
                        if (clo.getLinkObject().toBTName == null || clo.getLinkObject().toBTName.equals("")) {
                            emptyBO = to;
                        } else {
                            emptyBO = operation.createEmptyClientBusinessObject(this, clo.getLinkObject().toBTName);
                        }
 
                    }
 
                    if (to == null || emptyBO == null) {
                        return false;
                    }
                    // 如果对应form类型是link类型,则业务对象是以t_oid.或是t_oid开头的,其它的是link对象的属性
                    // 业务对象属性
                    AttributeValue[] avs = emptyBO.getBusinessObject().newAttrValList;
                    // 这三个属性是固定的
                    String idVal = "";
                    String heard = "t_oid";
                    if (direction) {
                        heard = "t_oid";
                    } else {
                        heard = "f_oid";
                    }
                    if (valueMapNew.containsKey(heard + ".id")) {
                        idVal = valueMapNew.get(heard + ".id");
                    } else if (valueMapNew.containsKey(heard + "id")) {
                        idVal = valueMapNew.get(heard + "id");
                    }
                    boAttrMap.put("id", idVal);
                    String nameVal = "";
                    if (valueMapNew.containsKey(heard + ".name")) {
                        nameVal = valueMapNew.get(heard + ".name");
                    } else if (valueMapNew.containsKey(heard + "name")) {
                        nameVal = valueMapNew.get(heard + "name");
                    }
                    boAttrMap.put("name", nameVal);
                    String descriptionVal = "";
                    if (valueMapNew.containsKey(heard + ".description")) {
                        descriptionVal = valueMapNew.get(heard + ".description");
                    } else if (valueMapNew.containsKey(heard + "description")) {
                        descriptionVal = valueMapNew.get(heard + "description");
                    }
                    boAttrMap.put("description", descriptionVal);
                    if (avs != null && avs.length > 0) {
                        for (AttributeValue av : avs) {
                            String attrVal = "";
                            String attrName = av.attrName.toLowerCase();
                            if (valueMapNew.containsKey(heard + "." + attrName)) {
                                attrVal = valueMapNew.get(heard + "." + attrName);
                                boAttrMap.put(attrName, attrVal == null ? "" : attrVal);
                            } else if (valueMapNew.containsKey(heard + "" + attrName)) {
                                attrVal = valueMapNew.get(heard + "" + attrName);
                                boAttrMap.put(attrName, attrVal == null ? "" : attrVal);
                            }
                        }
                    }
                    // 如果是选择添加时,不需要校验选择的BO对象的属性,也不用设置BO对象的属性
                    if (!isSelect()) {
                        result = boacer.validateAttr(boAttrMap);
                        if (!result) {
                            return false;
                        }
                        serUIValueObject(boAttrMap, to, valueMapNew, heard + ".");
                    }
                    // 设置LO,BO属性
                    serUIValueObject(loAttrMap, clo);
                    ClientLOAndBOData clbo = new ClientLOAndBOData();
                    clbo.setData(clo, to);
                    dataNodeObject.setMasterObject(clbo);
                    dataNodeObject.setValueMap(valueMapNew);
                }
            }
        } catch (Exception e) {
            UIFUtils.showErrorMessage(this, e);
            return false;
        }
        return true;
    }
 
    /**
     * 设置BO对象属性 如果是创建时需要判断是否是主属性 如果是修改则将修改的信息全部保存到BO属性中
     * 
     * @param valueMap
     * @param cbo
     * @throws VCIError
     */
    private void serUIValueObject(Map<String, String> valueMap, ClientBusinessObject cbo,
            Map<String, String> valueMapNew, String header) throws VCIError {
        Iterator<String> it = valueMap.keySet().iterator();
        while (it.hasNext()) {
            String field = it.next();
            String value = valueMap.get(field);
            if (isAdd() || isSelect()) {
                cbo.setAttributeValue(field, value, true);
            } else if (isEdit()) {
                if ((field.equalsIgnoreCase("id") || field.equalsIgnoreCase("name")
                        || field.equalsIgnoreCase("description")) && !valueMapNew.containsKey(header + field)) {
                    continue;
                }
                cbo.setAttributeValue(field, value);
            }
        }
    }
 
    /**
     * 设置LO对象属性
     * 
     * @param valueMap
     * @param clo
     * @throws VCIError
     */
    private void serUIValueObject(Map<String, String> valueMap, ClientLinkObject clo) throws VCIError {
        Iterator<String> it = valueMap.keySet().iterator();
        while (it.hasNext()) {
            String field = it.next();
            String value = valueMap.get(field);
            clo.setAttributeValue(field, value);
        }
    }
 
    public void setDataNodeObject(IDataNode dataNodeObject) {
        this.dataNodeObject = dataNodeObject;
    }
 
    private boolean isFreemarkTemplateContent(String itemValue) {
        return UIFUtils.isFreemarkTemplateContent(itemValue);
    }
 
    @Deprecated // by zhonggy 2015-06
    public void setUIControlDefaultValue(IDataNode dataNode) {
        Iterator<String> it = this.itemMap.keySet().iterator();
        Map<String, FreemarkerParamObject> rootMap = this.convertValueMapToFPOMap(dataNode.getValueMap());
        while (it.hasNext()) {
            String field = it.next();
            PRMItem item = this.itemMap.get(field);
            Component compt = this.ctrlComptMap.get(field);
            if (item == null || compt == null)
                continue;
            String itemValue = item.getItemValue();
            if (itemValue == null || "".equals(itemValue))
                continue;
 
            String defaultValue = itemValue;
            // 如果是Freemark的模板格式
            if (isFreemarkTemplateContent(itemValue)) {
                // update by xchao 2014.03.26 begin
                // 修复 如果模板规则中的属性(字段)在 dataNode.getValueMap() 中不存在时,则将计算后的值处理为空
                // ${t_oid.notfound}-${f_oid.notfound}
                String rule = itemValue;
                int start = rule.indexOf("${");
                int end = rule.indexOf("}");
                boolean allFieldExistInMap = true;
                while (start >= 0 && end >= 0 && start < end && end < rule.length()) {
                    String fieldRule = rule.substring(start + 2, end);
                    rule = rule.substring(end + 1);
                    if (!dataNode.getValueMap().containsKey(fieldRule)) {
                        String tempValue = this.regionPanel.getBaseLayoutPanel().getValue(fieldRule);
                        if (tempValue.equals(fieldRule)) {
                            defaultValue = "";
                        } else {
                            defaultValue = tempValue;
                        }
                        allFieldExistInMap = false;
                        break;
                    }
                    start = rule.indexOf("${");
                    end = rule.indexOf("}");
                }
                // update by xchao 2014.03.26 end
                if (allFieldExistInMap) {
                    defaultValue = FreeMarkerCommon.getValueByTempRule(rootMap, itemValue.replace(".", "_"));
                    defaultValue = this.regionPanel.getBaseLayoutPanel().getValue(defaultValue);
                }
            } else if (itemValue.indexOf("#") == 0) {
                defaultValue = getGloableVariableDefaultValue(itemValue);
            } else if (dataNode.getValueMap().containsKey(itemValue)) {
                defaultValue = dataNode.getValueMap().get(itemValue);
            }
 
            if (compt instanceof JTextComponent) {
                // 文本控件
                JTextComponent txt = (JTextComponent) compt;
                txt.setText(defaultValue);
            } else if (compt instanceof VCIJComboBox) {
                // 枚举、值列表的下拉列表控件
                VCIJComboBox cbx = (VCIJComboBox) compt;
                setComboxDefaultValue(item, cbx, defaultValue);
            } else if (compt instanceof RefObjChooseControl) {
                RefObjChooseControl roc = (RefObjChooseControl) compt;
                setRocDefaultValue(item, roc, defaultValue);
            } else if (compt instanceof DateTimeControl) {
                DateTimeControl dtc = (DateTimeControl) compt;
                dtc.setValue(defaultValue);
            } else if (compt instanceof BaseCustomControl) {
                BaseCustomControl bcc = (BaseCustomControl) compt;
                UserObject userObj = getUserObjectByName(defaultValue);
                if (userObj != null) {
                    // 用户账号##VCI##用户姓名 存储值##VCI##显示值
                    String value = userObj.getUserName() + ICustomAttributeInteceptor.SPLIT_CHAR + userObj.getTrueName()
                            + "(" + userObj.getUserName() + ")";
                    bcc.setValue(value);
                }
            }
        }
    }
 
    /**
     * 设置UI界面的全局默认值
     */
    @Deprecated // by zhonggy 2015-06
    public void setUIGloableDefaultValue() {
        Iterator<String> it = this.itemMap.keySet().iterator();
        while (it.hasNext()) {
            String field = it.next();
            PRMItem item = this.itemMap.get(field);
            Component compt = this.ctrlComptMap.get(field);
            if (item == null || compt == null)
                continue;
            String itemValue = item.getItemValue();
            if (itemValue == null || "".equals(itemValue))
                continue;
 
            String defaultValue = itemValue;
            // 如果是Freemark的模板格式
            if (isFreemarkTemplateContent(itemValue)) {
                defaultValue = "";
                String key = itemValue;
                String value = defaultValue;
                String valueFromUILayout = this.regionPanel.getBaseLayoutPanel().getValue(key);
                if (!valueFromUILayout.equals(key)) {
                    value = valueFromUILayout;
                }
                defaultValue = value;
            } else if (itemValue.indexOf("#") == 0) {
                defaultValue = getGloableVariableDefaultValue(itemValue);
            }
            if (defaultValue == null || defaultValue.trim().equals("")) {
                continue;
            }
            if (compt instanceof JTextComponent) {
                // 文本控件
                JTextComponent txt = (JTextComponent) compt;
                txt.setText(defaultValue);
            } else if (compt instanceof VCIJComboBox) {
                // 枚举、值列表的下拉列表控件
                VCIJComboBox cbx = (VCIJComboBox) compt;
                setComboxDefaultValue(item, cbx, defaultValue);
            } else if (compt instanceof RefObjChooseControl) {
                RefObjChooseControl roc = (RefObjChooseControl) compt;
                setRocDefaultValue(item, roc, defaultValue);
            } else if (compt instanceof DateTimeControl) {
                DateTimeControl dtc = (DateTimeControl) compt;
                dtc.setValue(defaultValue);
            } else if (compt instanceof BaseCustomControl) {
                BaseCustomControl bcc = (BaseCustomControl) compt;
                UserObject userObj = getUserObjectByName(defaultValue);
                if (userObj != null) {
                    // 用户账号##VCI##用户姓名 存储值##VCI##显示值
                    String value = userObj.getUserName() + ICustomAttributeInteceptor.SPLIT_CHAR + userObj.getTrueName()
                            + "(" + userObj.getUserName() + ")";
                    bcc.setValue(value);
                }
            }
        }
    }
 
    public UserObject getUserObjectByName(String userName) {
        // 根据存储的值,通过查询,得到显示的值
        UserObject userObj = null;
        try {
            userObj = new RightManagementClientDelegate().getUserObjectByUserName(userName);
        } catch (VCIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            VCIJOptionPane.showError(ClientContextVariable.getFrame(), "查询责任人显示值发生错误" + e.toString());
        }
        return userObj;
    }
 
    private String getGloableVariableDefaultValue(String key) {
        if (key.equalsIgnoreCase("#CURRENTUSER.ID#")) {
            return ClientContextVariable.getVariablebyKey("CURRENTUSER.ID");
        } else if (key.equalsIgnoreCase("#CURRENTTIME#")) {
            return getDataTime();
        } else if (key.equalsIgnoreCase("#CURRENTUSER.EMAIL#")) {
            return ClientContextVariable.getVariablebyKey("CURRENTUSER.EMAIL");
        } else if (key.equalsIgnoreCase("#CURRENTUSER.NAME#")) {
            return ClientContextVariable.getVariablebyKey("CURRENTUSER.NAME");
        } else if (key.equalsIgnoreCase("#CURRENTUSER.SECRETGRADE#")) {
            return ClientContextVariable.getVariablebyKey("CURRENTUSER.SECRETGRADE");
        } else if (key.equalsIgnoreCase("#CURRENTUSER.GROUPNUM#")) {
            return ClientContextVariable.getVariablebyKey("CURRENTUSER.GROUPNUM");
        }
 
        return "";
    }
 
    /**
     * 获取当前时间,暂时支持yyyy-MM-dd的格式显示
     * 
     * @return
     */
    private String getDataTime() {
        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String dateString = sdf.format(Calendar.getInstance().getTime());
        return dateString;
    }
 
    public void setComboxDefaultValue(PRMItem item, VCIJComboBox cbx, String defaultValue) {
        DefaultComboBoxModel cbxModel = (DefaultComboBoxModel) cbx.getModel();
        int existIndex = getComboBoxValueIndex(cbxModel, defaultValue);
        if (existIndex >= 0) {
            cbx.setSelectedItem(cbxModel.getElementAt(existIndex));
        } else {
            VCIJComboBoxModelValueObject cbxVo = new VCIJComboBoxModelValueObject(defaultValue, defaultValue);
            cbxModel.addElement(cbxVo);
            cbx.setModel(cbxModel);
            cbx.setSelectedItem(cbxVo);
        }
    }
 
    private int getComboBoxValueIndex(DefaultComboBoxModel cbxModel, String newValue) {
        int res = -1;
        for (int i = 0; i < cbxModel.getSize(); i++) {
            Object obj = cbxModel.getElementAt(i);
            if (obj instanceof VCIJComboBoxModelValueObject) {
                VCIJComboBoxModelValueObject cbxVO = (VCIJComboBoxModelValueObject) obj;
                if (cbxVO.getValue().equals(newValue)) {
                    res = i;
                    break;
                }
            }
        }
        return res;
    }
 
    public void setRocDefaultValue(PRMItem item, RefObjChooseControl roc, String defaultValue) {
        if ("".equals(defaultValue))
            return;
        String type = item.getItemListTable();
        String oid = defaultValue;
        String showColumn = item.getItemListVal();
        ClientBusinessObject refCbo = getClientBusinessObjectbyByRefTypeAndOid(type, oid);
        if (refCbo == null) {
            return;
        }
        String showValue = "";
        if (refCbo != null) {
            showValue = refCbo.getAttributeValue(showColumn);
        }
        String newValue = defaultValue + "," + showValue;
        roc.setValue(newValue);
        roc.firePropertyChangeManual(RefObjChooseControl.REF_OBJECT_CHANGED, "",
                CBOHelper.getBOValueMap(refCbo.getBusinessObject()));
    }
 
    private ClientBusinessObject getClientBusinessObjectbyByRefTypeAndOid(String type, String oid) {
        ClientBusinessObject cbo = null;
        try {
            QueryTemplate qt9 = new QueryTemplate();
            qt9.setId("btmQuery");
            qt9.setBtmType(type);
            qt9.setRightFlag(false);
            qt9.setType("btm");
            qt9.setQueryChildrenFlag(true);
            List<String> clauseList = new ArrayList<String>();
            clauseList.add("*");
            qt9.setClauseList(clauseList);
            Map<String, String> conditions = new HashMap<String, String>();
            conditions.put("oid", oid);
            Condition cond = OQTool.getCondition(conditions);
            qt9.setCondition(cond);
            BusinessObject[] bos = QTClient.getService().findBTMObjects(qt9.getId(), OQTool.qtTOXMl(qt9).asXML());
            if (bos != null && bos.length > 0) {
                cbo = new ClientBusinessObject();
                cbo.setBusinessObject(bos[0]);
            }
        } catch (VCIError e) {
            e.printStackTrace();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        if (cbo == null || cbo.getOid().equals("")) {
            return null;
        }
        return cbo;
    }
 
    public Map<String, FreemarkerParamObject> convertValueMapToFPOMap(Map<String, String> map) {
        Map<String, FreemarkerParamObject> rootMap = new LinkedHashMap<String, FreemarkerParamObject>();
        Iterator<String> it = map.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            String value = map.get(key);
            String valueFromUILayout = this.regionPanel.getBaseLayoutPanel().getValue(key);
            if (!valueFromUILayout.equals(key)) {
                value = valueFromUILayout;
            } else {
                // 尝试从表单控件上取值
                if (value.equals(key)) {
                    value = getValueFromUIControl(key);
                }
            }
            if (value == null) {
                value = "";
            }
            String newKey = key.replace(".", "_");
            FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value);
            rootMap.put(newKey, fpo);
        }
        return rootMap;
    }
 
    public Object[] getSelectedDatas() {
        return selectedDatas;
    }
 
    public void setSelectedDatas(Object[] selectedDatas) {
        this.selectedDatas = selectedDatas;
    }
 
    public boolean isDirection() {
        return direction;
    }
 
    public void setDirection(boolean direction) {
        this.direction = direction;
    }
 
    public HashMap<String, PRMItem> getItemMap() {
        return itemMap;
    }
 
    public IRegionPanel getRegionPanel() {
        return regionPanel;
    }
 
    public void setRegionPanel(IRegionPanel regionPanel) {
        this.regionPanel = regionPanel;
    }
 
    /**
     * 各组件对应的默认值Map
     */
    private Map<String, String> comptDefValMap = new HashMap<String, String>();
 
    /**
     * 返回 各组件对应的默认值Map
     * 
     * @return
     */
    public Map<String, String> getComptDefValMap() {
        return comptDefValMap;
    }
 
    /**
     * 设置 各组件对应的默认值Map
     * 
     * @param hasDefValComptMap 各组件对应的默认值Map
     */
    public void setComptDefValMap(Map<String, String> comptDefValMap) {
        this.comptDefValMap = comptDefValMap;
    }
 
    private DefaultValueController defaultValueController = null;
 
    public void setUIFormFieldDefaultValue(AbstractBatchBusionessOperationAction sourceBtm, IDataNode iDataNode) {
        if (defaultValueController == null) {
            defaultValueController = new DefaultValueController();
            defaultValueController.setFormPanel(this);
        }
        setComptDefValMap(defaultValueController.setUIFormFieldDefaultValue(sourceBtm, iDataNode));
    }
}