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
package com.vci.client.uif.actions.client;
 
import java.awt.Component;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
 
import javax.swing.JOptionPane;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.common.ConfigUtils;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.logon.base.TabPanelManage;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.portal.utility.DataModelFactory;
import com.vci.client.portal.utility.PLDefination;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.JClosableTabbedPane;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
import com.vci.client.uif.engine.client.IDataModel;
import com.vci.client.uif.engine.client.IRegionPanel;
import com.vci.client.uif.engine.client.UILayoutPanel;
import com.vci.client.uif.engine.client.controls.FileChooseControlPanel;
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
import com.vci.client.uif.engine.client.tableArea.TablePanel;
import com.vci.client.uif.engine.common.GlobalContextParam;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.corba.common.VCIError;
import com.vci.corba.common.data.VCIInvocationInfo;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.framework.data.CheckValue;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLPageDefination;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.corba.portal.data.PLTabButton;
import com.vci.corba.portal.data.PLTabPage;
import com.vci.corba.portal.data.PortalVI;
import com.vci.mw.ClientContextVariable;
 
/**
 * 抽象的单数据操作接口封装
 * @author xchao
 *
 */
public abstract class AbstractBatchBusionessOperationAction implements BusinessOperationAction {
    private Map<String, String> buttonParams = new HashMap<String, String>();
    private Component parentComponent = null;
    private IDataModel dataModel = null;
    private PLDefination defination = null;
    private PLTabButton button = null;
    private VCIJDialog ownerDialog = null;
    private IRegionPanel regionPanel = null;
    /**
     * Action配置信息
     */
    private PLAction action = null;
 
    private Component buttonComponent = null;
    public AbstractBatchBusionessOperationAction(){
        
    }
    
    @Override
    public void setButtonParams(Map<String, String> buttonParams){
        this.buttonParams = buttonParams;
    }
    @Override
    public Map<String, String> getButtonParams(){
        return this.buttonParams;
    }
    
    @Override
    public Component getParentComponent(){
        return this.parentComponent;
    }
    @Override
    public void setParentComponent(Component parentComponent){
        this.parentComponent = parentComponent;
    }
 
    /**
     * 设置 Action 所在区域的DataModel
     * @param dataModel
     */
    @Override
    public void setDataModel(IDataModel dataModel){
        this.dataModel = dataModel;
    }
    
    /**
     * 返回 Action 所在区域的DataModel
     * @return
     */
    @Override
    public IDataModel getDataModel(){
        return this.dataModel;
    }
 
    /**
     * 设置Button 对应的 Action 所在的Defination
     * @param defination
     */
    public void setDefination(PLDefination defination){
        this.defination = defination;
    }
    /**
     * 返回 Button 对应的 Action 所在的Defination
     * @return
     */
    public PLDefination getDefination(){
        return this.defination;
    }
    /**
     * 设置 Button
     * @param button
     */
    public void setButton(PLTabButton button){
        this.button = button;
    }
    /**
     * 返回 与此Action关联对应的Button
     * @return
     */
    public PLTabButton getButton(){
        return this.button;
    }
    
    protected int getPreeventCount(){
        int def = 10;
        int res = def;
        String preeventCountValue = getParameterValue(ValueType.ButtonConfig, "preeventCount", 1);
        if(preeventCountValue == null || "".equals(preeventCountValue)){
            return def;
        } else {
            try{
                res = Integer.valueOf(preeventCountValue);
            }catch(Exception ex){
                return def;
            }
        }
        return res;
    }
    protected int getPostEventCount(){
        int def = 10;
        int res = def;
        String preeventCountValue = getParameterValue(ValueType.ButtonConfig, "posteventCount", 1);
        if(preeventCountValue == null || "".equals(preeventCountValue)){
            return def;
        } else {
            try{
                res = Integer.valueOf(preeventCountValue);
            }catch(Exception ex){
                return def;
            }
        }
        return res;
    }
    
    private String getClassNameDefPreFix(String classNameDef){
        String prefix = "";
        if(classNameDef == null) {
            return "";
        }
        classNameDef = classNameDef.trim();
        if("".equals(classNameDef)) {
            return "";
        }
        if (classNameDef.length() > 7 && classNameDef.toLowerCase().indexOf("net_") == 0) {
            prefix = classNameDef.substring(0, 6);
            if (prefix.toLowerCase().equals("net_cs")) {
                prefix = "net_cs";
                classNameDef = classNameDef.substring(7);
            }else if (prefix.toLowerCase().equals("net_bs")) {
                prefix = "net_bs";
                classNameDef = classNameDef.substring(7);
            }
        }else if (classNameDef.length() > 8 && classNameDef.toLowerCase().indexOf("java_") == 0) {
            prefix = classNameDef.substring(0, 7);
            if (prefix.toLowerCase().equals("java_cs")) {
                prefix = "java_cs";
                classNameDef = classNameDef.substring(8);
            }else if (prefix.toLowerCase().equals("java_bs")) {
                prefix = "java_bs";
                classNameDef = classNameDef.substring(8);
            }
        }else if (classNameDef.length() > 10 && classNameDef.toLowerCase().indexOf("mobile_") == 0) {
            prefix = classNameDef.substring(0, 9);
            if (prefix.toLowerCase().equals("mobile_cs")) {
                prefix = "mobile_cs";
                classNameDef = classNameDef.substring(10);
            }else if (prefix.toLowerCase().equals("mobile_bs")) {
                prefix = "mobile_bs";
                classNameDef = classNameDef.substring(10);
            }
        }
        return prefix;
    }
    
    protected boolean getPreeventResult(String className){
        if(className == null) {
            return true;
        }
        className = className.trim();
        if("".equals(className)) {
            return true;
        }
        //edit start by lmh20151223.在一个值中配置多个事件,用;号分隔,分别前后触发
        String[] classNames = className.split(";");
        boolean res = true;
        for(String name : classNames) {
            String prefix = this.getClassNameDefPreFix(name);
            if (!(prefix.equals("") || prefix.equals("java_cs"))) {
                return true;
            }else {
                if (prefix.equals("java_cs")) {
                    name = name.substring(prefix.length() + 1);
                }
            }
            //前置事件对象实例化
            PostActionListener pal = createPostActionListenerInstance(name);
            if(pal == null) {
                return true;
            }
            //前置事件参数对象
            PostActionEvent pae = new PostActionEvent();
            //pae.setSource(this);//当前Action对象        --目前如果都是this对象传入,那么先不赋值(以便插件获取参数的清晰)
            pae.setBusinessOperationAction(this);//当前业务对象
            try {
                PostActionResult par = pal.actionPerformed(pae);        //触发事件
                res = par.isSuccess();
                String message = par.getLastErrorMessage();
                if(!par.isSuccess() && !"".equals(message)){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(), message);
                    break;//lizf add 20160621如果当前的前置事件饭后的是false,则跳出循环。
                }
            } catch (Exception e) {
                e.printStackTrace();
                res = false;                    //终止
                UIFUtils.showMessage(ClientContextVariable.getFrame(), e.getMessage());
            }
        }
        //edit end
        return res;
    }
    
    private PostActionListener createPostActionListenerInstance(String className){
        PostActionListener pal = null;
        try {
            if (className != null && !className.equals("")) {
                Object obj = Class.forName(className).getConstructor().newInstance();
                if(obj instanceof PostActionListener){
                    pal = (PostActionListener)obj;
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return pal;
    }
    
    protected boolean isSelectedObject(){
        IDataModel dataModel = getDataModel();
        if(getDataModel() == null) {
            VCIJOptionPane.showMessageDialog(
                    ClientContextVariable.getFrame(), " dataModel is null", "提示", JOptionPane.WARNING_MESSAGE);
            System.out.println(getClassName() + ".doAction() execute, getDataModel() result is null");
            return false;
        } 
 
        Object[] objs = dataModel.getSelectObjects();
        if(objs == null){
            VCIJOptionPane.showMessageDialog(
                    ClientContextVariable.getFrame(), "请选择数据再进行此操作!", "提示", JOptionPane.INFORMATION_MESSAGE);
            System.out.println(getClassName() + ".doAction() execute, getDataModel().getSelectObjects() result is null");
            return false;
        } else if(objs.length == 0){
            VCIJOptionPane.showMessageDialog(
                    ClientContextVariable.getFrame(), "请选择数据再进行此操作!", "提示", JOptionPane.INFORMATION_MESSAGE);
            System.out.println(getClassName() + ".doAction() execute, getDataModel().getSelectObjects().length = 0 ");
            return false;
        } else if(objs != null && objs.length == 0) { 
            return false;
        }
        return true;
    }
    
    /**
     * Action框架主入口,继承复写请慎重...
     * @Title        :doAction
     * @Description    :
     * @return
     */
    public boolean doAction(){
        boolean res = false;
        
        if(!isSelectedObject()) return false;
        //判断是否需要进行数据权限校验
        String rightSwitch = ConfigUtils.getConfigValue("right.switch");
        if(rightSwitch != null && rightSwitch.equals("on")){
            // 权限检查,有权限时才执行后续的操作
            if(!checkHasRight()){
                VCIJOptionPane.showMessageDialog(
                        ClientContextVariable.getFrame(), sbBatchCheckHasRightMessage.toString(), "提示", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }            
        }
        // 在选定了数据及有权限之后,执行
        res = doActionDetailBySelectedObject();
        return res;
    }
    
    @Override        //Modify by ZhongGY 2015-05-29    
    public boolean beforePost() {
        return true;
    }
    
    protected boolean getAllPreEventResult(){
        boolean res = true;
        String className = getParameterValue(ValueType.ButtonConfig, "preevent", 1);
        res &= getPreeventResult(className);
        if (res == false) {
            return false;        //前置事件主要存在错误就退出  ADD By ZhongGY
        }
        int preEventCount = getPreeventCount();    //同事也支持多事件
        for (int i = 0; (i <= preEventCount); i++) {            //&& res == true
            className = getParameterValue(ValueType.ButtonConfig, "preevent" + String.valueOf(i), 1);
            res &= getPreeventResult(className);
            if (res == false) {
                return false;        //前置事件主要存在错误就退出  ADD By ZhongGY
            }
        }
        return res;
    }
    
    /**
     * //ADD by ZhongGY 2015-05-29    --保证Action本身能的前置事件能触发
     * @Title        :rawBeforePost
     * @Description    :
     * @return
     */
    private boolean rawBeforePost() {
        boolean res = false;
        if ((res = beforePost())) {
            res = getAllPreEventResult();
        }
        return res;
    }
    
    /**
     * Action真实处理入口
     * @Title        :doActionDetailBySelectedObject
     * @Description    :
     * @return
     */
    protected boolean doActionDetailBySelectedObject(){
        boolean res = false;
        // 有权限时,先执行 beforePost()
        // 当且仅当 beforePost() == true 时,才执行 doPost()
        if(rawBeforePost()){
            res = doPost();
            // 当且仅当 doPost() == true 时,才执行 afterPost()
            if(res){
                res = rawAfterPost();
                // 当且仅当 afterPost() == true 时,才执行 getDataModel().refresh() ,即刷新
                if(res){
                    afterPostAfterRefresh();
                }
            }
        }
        return res;
    }
    
    /**
     * //ADD by ZhongGY 2015-05-29    --保证Action本身能的后置事件能触发
     * @Title        :rawAfterPost
     * @Description    :
     * @return
     */
    private boolean rawAfterPost() {
        //System.out.println(getClassName() + ".afterPost() execution");
        boolean res = true;
        //先处理Button自定义的后处理事件
        String className = getParameterValue(ValueType.ButtonConfig, "postevent", 1);
        res &= getPostEventResult(className);                                //后置事件之间默认是连续执行(哪怕是前一事件有错误)    By ZhongGY
        int preEventCount = getPostEventCount();                            //支持多事件(默认10个)
        for (int i = 0; (i <= preEventCount && res == true); i++) {
            className = getParameterValue(ValueType.ButtonConfig, "postevent" + String.valueOf(i), 1);
            res &= getPostEventResult(className);
        }
        //再处理Action本身的后处理事件
        return res && afterPost();            //保证Action本身的后置事件也能触发
    }
    
    /**
     * Button(定义的)后处理事件触发        --ADD By ZhongGY 2015-05-29
     * @Title        :getPostEventResult
     * @Description    :
     * @param className
     * @return
     */
    protected boolean getPostEventResult(String className){
        if (className == null || className.trim().equals("")) {
            return true;
        }
        String prefix = this.getClassNameDefPreFix(className);
        if (!(prefix.equals("") || prefix.equals("java_cs"))) {
            return true;
        }else {
            if (prefix.equals("java_cs")) {
                className = className.substring(prefix.length() + 1);
            }
        }
        //edit start by lmh20151223.在一个值中配置多个事件,用;号分隔,分别前后触发
        String[] classNames = className.split(";");
        boolean res = true;
        for(String name : classNames) {
            
            //前置事件对象实例化
            PostActionListener pal = createPostActionListenerInstance(className);
            if(pal == null) {
                return true;
            }
            //前置事件参数对象
            PostActionEvent pae = new PostActionEvent();
            //pae.setSource(this);//当前Action对象
            pae.setBusinessOperationAction(this);//当前业务对象
            try {
                //getDataModel().refresh(getDataModel());    //保证后处理的相关数据为Post()之后刷新的数据        ADD By ZhongGY
                PostActionResult par = pal.actionPerformed(pae);        //触发事件
                res = par.isSuccess();
                String message = par.getLastErrorMessage();
                if(!par.isSuccess() && !"".equals(message)){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(), message);
                }
            } catch (Exception e) {
                e.printStackTrace();
                res = true;
                UIFUtils.showMessage(ClientContextVariable.getFrame(), e.getMessage());
            }
        }
        //edit end
        return res;
    }
    
    /**        //Modify by ZhongGY 2015-05-29 
     * Action行为处理后事件
     * 返回True表示要触发界面刷新
     */
    @Override
    public boolean afterPost() {
        return true;
    }
    
    
    private Object afterPostDataExt = null;
    /**
     * AfterPost事件与事件之间可需要额外特殊处理的数据
     * @Title        :getAfterPostDataExt
     * @Description    :
     * @return
     */
    public Object getAfterPostDataExt() {
        return afterPostDataExt;
    }
    /**
     * AfterPost事件与事件之间可需要额外特殊处理的数据
     * @Title        :setAfterPostDataExt
     * @Description    :
     * @param afterPostDataExt
     */
    public void setAfterPostDataExt(Object afterPostDataExt){
        this.afterPostDataExt = afterPostDataExt;
    }
    
    protected void afterPostAfterRefresh(){
        getDataModel().refresh(getDataModel());
        // add by xchao 2014.10.27 begin
        // 根据按钮参数定义,在结束后,是否需要进行UI全刷新
        String refreshValue = getParameterValue(ValueType.ButtonConfig, "refresh", -1);
        if(refreshValue != null && Boolean.valueOf(refreshValue)){
            refreshUI();
        }
        // add by xchao 2014.10.27 end
    }
 
    private void refreshUI(){
        JClosableTabbedPane tab = TabPanelManage.getInstance().getTabPanel();
        for (int i = 0; i < tab.getTabCount(); i++) {
            Component compt = tab.getComponent(i);
            if(compt instanceof UILayoutPanel){
                UILayoutPanel uilayout = (UILayoutPanel)compt;
                refreshUILayoutModel(uilayout);
            }
        }
    }
    
    private void refreshUILayoutModel(UILayoutPanel uilayoutPanel){
        Map<String, IRegionPanel> map = uilayoutPanel.getRegionPanelMap();
        Iterator<String> its = map.keySet().iterator();
        while(its.hasNext()){
            String key = its.next();
            IRegionPanel regionPanel = map.get(key);
            if(regionPanel instanceof TablePanel){
                TablePanel tablePanel = (TablePanel)regionPanel;
                tablePanel.getDataTablePanel().refreshTableData();
            }
        }
    }
    
    
    private StringBuffer sbBatchCheckHasRightMessage = new StringBuffer();
    
    //增加一个全局的变量用来存储需要进行数据权限的数据
    private Object checkObj = null;
    private Object[] getCheckObjects() {
        if(this.checkObj != null) {
            return new Object[]{checkObj};
        } else {
            return getDataModel().getSelectObjects();
        }
    }
    private int[] getCheckRowIndexs() {
        if(this.checkObj != null) {
            return new int[]{1};
        } else {
            return getDataModel().getSelectObjectRowIndexs();
        }
    }
    public void setCheckObject(Object checkObj) {
        this.checkObj = checkObj;
    }
    //end
    
    @Override
    public boolean checkHasRight() {
        // add by xchao 2014.08.20 显示的根据按钮中定义的参数,确定是否需要进行数据权限校验
        boolean res = false;
        String ignoredr = this.getParameterValue(ValueType.ButtonConfig, "ignoredr", -1);
        if("true".equalsIgnoreCase(ignoredr)){
            return true;
        }
        // add by xchao 2014.08.20 end
        
        StringBuffer sbNotRightRowIndex = new StringBuffer();
        int[] rows = getCheckRowIndexs();
        Object[] objs = getCheckObjects();
        Boolean[] hasRights = new Boolean[objs.length];
        boolean allTrue = true;
        DataRightUtil dRU= new DataRightUtil(this.buttonParams);
        for (int i = 0; i < objs.length; i++) {
            boolean checkRes = false;//checkHasRight(objs[i], this.getButtonParams());
            // V2
            String dataRightCheckType = getDataRightCheckType();
            Object seledObj = objs[i];
                String key = getKey();
                try {
                    checkRes=dRU.getCheckRes(dataRightCheckType,seledObj,key);
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            // add by xchao 2015.01.14 begin
            // 将没有权限的数据索引添加单独的结构中维护,以便统一输出提示信息
            if(!checkRes){
                sbNotRightRowIndex.append(String.valueOf(rows[i] + 1)).append("、");
            }
            // add by xchao 2015.01.14 end
            
            hasRights[i] = checkRes;
            
            // 按位与,确定是否对全部数据有权限
            allTrue &= checkRes;
        }
        //权限校验完成后清空临时全局变量
        this.checkObj = null;
        res = allTrue;
        // add by xchao 2015.01.14 begin
        // 按统一的方式提示没有权限
        sbBatchCheckHasRightMessage = new StringBuffer("");
        if(!allTrue && sbNotRightRowIndex.length() > 0){
            String rowIndexStr = sbNotRightRowIndex.toString();
            if(rowIndexStr.endsWith("、")){
                rowIndexStr = rowIndexStr.substring(0, rowIndexStr.length() - 1);
            }
            sbBatchCheckHasRightMessage.append("您没有权限对第\n" + rowIndexStr + "\n条数据进行此操作!");    
        }
        // add by xchao 2015.01.14 end
        return res;
    }
    
    private String getButtonParamLinkType(){
        String res = "";
        res = getParameterValue(ValueType.ButtonConfig, "linktype", -1);
        if(res == null){
            res = getParameterValue(ValueType.ButtonConfig, "linkType", -1);
            if(res == null){
                res = getParameterValue(ValueType.ButtonConfig, "LinkType", -1);
                if(res == null){
                    res = "";
                }
            }
        }
        return res;
    }
    
    /**
     * 1、对于一个按钮可能是业务类型,也可能是链接类型,
     *    但是在操作时用户选择的数据可能是LO,也可能BO,
     *    所以在校验试需要根据按钮的类型来判断传递的oid
     *    和businesstype是什么值
     * 2、   
     * @param selectedObject 用户选择的数据
     * @return
     */
    protected boolean checkHasRight(Object selectedObject, Map<String, String> buttonParam){
        // add by xchao 2014.08.20 显示的根据按钮中定义的参数,确定是否需要进行数据权限校验
        boolean res = false;
        String ignoredr = this.getParameterValue(ValueType.ButtonConfig, "ignoredr", -1);
        if("true".equalsIgnoreCase(ignoredr)){
            return true;
        }
        // add by xchao 2014.08.20 end
        
        try {
            String rightCheckType = null;
            String rightCheckLogical = null;
            String boOpReflect = null; 
            Iterator<String> itor = buttonParam.keySet().iterator();
            //TODO
            //对单独的link进行鉴权处理
            //对to端link进行测试
            while (itor.hasNext()) {
                String key = itor.next();
                if (key == null) {
                    continue;
                }
                if (key.equals(RightCheckConstants.RIGHT_CHECK_TYPE)) {
                    rightCheckType = buttonParam.get(key);
                } else if (key.equals(RightCheckConstants.RIGHT_CHECK_LOGICAL)) {
                    rightCheckLogical = buttonParam.get(key);
                } else if (key.equals(RightCheckConstants.BO_OP_REFLECT)) {
                    boOpReflect = buttonParam.get(key);
                }
            }
            String[][] result = new String[2][];
            String[] boResult = null;
            String[] loResult = null;
            if (rightCheckType == null || rightCheckType.equals("")) {
                boResult = getCheckObject(selectedObject);
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_B)) {
                boResult = this.getBOcheckObject(selectedObject);
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_L)) {
                loResult = this.getLOcheckObject(selectedObject);
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_FB)){
                boResult = this.getFromBOCheckObject(selectedObject);
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_TB)){
                boResult = this.getToBOCheckObject(selectedObject);
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_LFB)){
                result = this.getLoFromBOCheckObject(selectedObject);
                boResult = result[0];
                loResult = result[1];
            } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_LTB)){
                result = this.getLoToBOCheckObject(selectedObject);
                boResult = result[0];
                loResult = result[1];
            }
            
            boolean[] checkRes = new boolean[2];
            checkRes[0] = false;
            checkRes[1] = false;
            String opname = getKey();
            
            if (boResult != null && boResult.length != 0) {
                if (boOpReflect != null) {
                    opname = boOpReflect; 
                }
                checkRes[0] = getCheckResult(boResult, opname);
            }
            
            if (loResult != null && loResult.length != 0) {
                opname = loResult[4] + "." + getKey();
                checkRes[1] = getCheckResult(loResult, opname);
            }
            
//            for (int i = 0; i < 2; i++) {
//                if (result[i] == null || result[i].length == 0) {
//                    continue;
//                }
//                if (i == 0 && boOpReflect != null) {
//                    opname = boOpReflect; 
//                } else if (i == 1){
//                    opname = result[i][4] + "." + getKey();
//                }
//                checkRes[i] = getCheckResult(result[i], opname);
//            }
            
            if (rightCheckLogical != null && rightCheckLogical.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_LOGICAL_B)) {
                res = checkRes[0] && checkRes[1];
            } else {
                res = checkRes[0] || checkRes[1];
            }
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return res;
    }
    
    private boolean getCheckResult(String[] result, String opname) throws VCIError {
        VCIInvocationInfo invocationInfo = ClientContextVariable.getInvocationInfo();
        String oid = result[0];
        String btmName = result[1];
        String revisionOid = result[2];
        String nameOid = result[3];
        CheckValue params = new CheckValue();
        params.users = invocationInfo.userName;
        params.roles = getArrayString(invocationInfo.roleNames);
        params.userGroups = getArrayString(invocationInfo.groupNames);
        params.paramValues= GlobalContextParam.getInstance().getDefaultConditionString();
        params.opname = opname;
        params.objectmoid = nameOid;
        params.objectroid = revisionOid;
        params.businesstype = btmName;
        params.objectoid = oid;
        String where = ServiceProvider.getFrameService().checkRight(params);
        String[] ops = where.split(":");
        String msg = "0";
        //TODO 需要处理 query 类型的操作,权限定义(返回数据格)不一样的问题
        for (String s : ops) {
            if (s != null && !s.equals("")) {
                String[] op = s.split(",");
                msg = op[1];
                break;
            }
        }
        boolean res = ("1".equals(msg));
        
        return res;
    }
    
    protected String getArrayString(String[] values){
        String res = "";
        if (values != null) {
            for (int i = 0; i < values.length; i++) {
                if (i != 0) {
                    res += ",";
                }
                res += values[i];
            }
        }
        return res;
    }
 
    protected String[] getSelectedObjectIds(){
        String[] res = new String[0];
        return res;
    }
 
    protected String getSelectedObjectId(int index){
        String res = "";
        IDataModel dataModel = getDataModel();
        if(dataModel == null) {
            System.out.println(getClassName() + ".getDataModel() result is null");
            return "";
        }
        
        Object[] objs = dataModel.getSelectObjects();
        if(objs.length == 0) return "";
        
        Object obj = objs[index];
        if(IDataNode.class.isAssignableFrom(obj.getClass())){
            IDataNode dataNode = (IDataNode)obj;
            obj = dataNode.getMaterObject();
        }
        if(ClientBusinessObject.class.isAssignableFrom(obj.getClass())){
            ClientBusinessObject bo = (ClientBusinessObject)obj;
            res = bo.getBusinessObject().oid;
        } else if(ClientLinkObject.class.isAssignableFrom(obj.getClass())){
            ClientLinkObject lo = (ClientLinkObject)obj;
            res = lo.getLinkObject().oid;
        }
        return res;
    }
    
    public boolean isAssignableFrom(Class<?> superClass, Class<?> instanceClass){
        return superClass.isAssignableFrom(instanceClass);
    }
    
    protected String getClassName(){
        return getClass().getName();
    }
 
    protected int getQuestionDialogResult(String message){
        return VCIJOptionPane.showConfirmDialog(ClientContextVariable.getFrame(), message, "询问", VCIJOptionPane.YES_NO_OPTION);
    }
    
    
    protected PortalVI getFormPortalVIByFormId(String formId){
        PortalVI res = null;
        DataModelFactory factory = new DataModelFactory();
        try {
             res = factory.getFormViewById(formId);
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return res;
    }
    
    /**
     * 获取参数
     * @param valueType 参数值的来源
     * @param key 参数的 key
     * @param dataIndex 参数数据索引(第xx条数据的 x)
     * @return
     */
    public String getParameterValue(ValueType valueType, String key, int dataIndex){
        String res = null;
        Map<String, String> map = null;
        if(valueType == ValueType.ButtonConfig){
            map = getButtonParams();
        } else if(valueType == ValueType.RuntimeData){
            IDataModel dataModel = getDataModel();
            Object rowData = dataModel.getSelectObjects()[dataIndex];
            if(rowData instanceof IDataNode){
                IDataNode dataNode = (IDataNode)rowData;
                map = dataNode.getValueMap();
            }
        }
        res = map.get(key);
        return res;
    }
    
    /**
     * 设置Action所在的Dialog
     * @param ownerDialog
     */
    @Override
    public void setOwnerDialog(VCIJDialog ownerDialog){
        this.ownerDialog = ownerDialog;
    }
    
    /**
     * 返回 Action 所在的Dialog
     * @return VCIJDialog
     */
    @Override
    public VCIJDialog getOwnerDialog(){
        return this.ownerDialog;
    }
    
    public void closeOwnerDailog(VCIJDialog ownerDialog, DialogResult dialogResult){
        if(ownerDialog != null){
            ownerDialog.setDialogResult(dialogResult);
            ownerDialog.dispose();
            ownerDialog.setVisible(false);
        }
    }
    
    /**
     * 设置 Button&Action所在的RegionPanel
     */
    @Override
    public void setRegionPanel(IRegionPanel regionPanel){
        this.regionPanel = regionPanel;
    }
    /**
     * 返回 Button&Action所在的RegionPanel
     * @return
     */
    @Override
    public IRegionPanel getRegionPanel(){
        return this.regionPanel;
    }
    
    /**
     * 获得控制区中一个tab页的PLDefination
     * @param type 类型
     * @param context 上下文
     * @return
     * @throws Throwable
     */
    public PLDefination getDefination(String type, String context) throws Throwable{
        PLDefination btnOwnDefinatio = null;
        PLUILayout plDef = getContext(type, context);
        Map<PLTabPage, PLDefination> tabPageMap = getTabPage(plDef.plOId, (short)2);
        Iterator<PLTabPage> it = tabPageMap.keySet().iterator();
        while(it.hasNext()){
            PLTabPage tabPage = it.next();
            btnOwnDefinatio = tabPageMap.get(tabPage);
        }
        return btnOwnDefinatio;
    }
    
    /**
     * 获取当前context的详细信息
     * @return
     * @throws Throwable 
     * @throws Exception 
     */
    private PLUILayout getContext(String type, String context) throws Exception, Throwable {
        DataModelFactory factory = new DataModelFactory();
        PLUILayout contextDef = factory.getContextDefination(
                type, context);
        if (contextDef == null || contextDef.plOId.equals("")) {
            BtmItem item = BtmProvider.getInstance().getBtmItemByName(type);
            if (item.fName == null || item.fName.equals("")) {
                return null;
            }
            return getContext(item.fName, item.fName);
        }
        return contextDef;
    }
    
    /**
     * 获得当前上下文的所有tab page
     * @return
     * @throws Throwable
     */
    private Map<PLTabPage, PLDefination> getTabPage(String contextOid, short areaType) throws Throwable {
        PLTabPage[] tabs = UITools.getService().getTabPagesByContextIdAndType(contextOid, areaType);
        Map<PLTabPage, PLDefination> defMap = new LinkedHashMap<PLTabPage, PLDefination>(); 
        for (int i = 0; i < tabs.length; i++) {
            PLPageDefination[] definations = UITools.getService().getPLPageDefinationsByPageContextOId(tabs[i].plOId);
            if (definations != null && definations.length < 1) {
                continue;
            }
            PLDefination defination = UITools
                    .getPLDefination(definations[0].plDefination);
            defMap.put(tabs[i], defination);
        }
        return defMap;
    }
    
    /**
     * 如果有文件控件则判断是否需要上传文件
     * @param oaed oaed
     * @param cbo 创建的CBO对象
     * @return
     */
    public boolean UploadFile(ObjectAddEditDialog oaed, ClientBusinessObject cbo){
        try {
            if(oaed == null){
                return true;
            }
            HashMap<String, Component> ctrlComptMap= oaed.getOaep().getCtrlComptMap();
            Iterator<String> it = ctrlComptMap.keySet().iterator();
            while(it.hasNext()){
                //如果设置原色在界面上显示并且设置为必填项
                Object obj = ctrlComptMap.get(it.next());
                if(obj != null && obj instanceof FileChooseControlPanel){
                    FileChooseControlPanel comp = (FileChooseControlPanel) obj;
                    //XXX 暂时没有判断是否保存成功
                    comp.executeUpload(cbo);
                }
            }
        } catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
    
    /**
     * 得到数据权限校验相关信息
     * @param selectedObject 用户选择对象
     * @return String[0] oid
     *               [1] btmName
     *               [2] revisionOid
     *               [3] nameOid
     */
    @SuppressWarnings("rawtypes")
    public String[] getCheckObject(Object selectedObject){
        String[] result = new String[4];
        String oid = "";
        String btmName = "";
        String revisionOid = "";
        String nameOid = "";
        try {
            PLAction action = getAction();
            PLDefination pldef = getDefination();
            //TODO 暂时没有处理反向的问题
            if(action.plTypeType.equals("business")){
                if(selectedObject instanceof String){
                    oid = (String) selectedObject;
                    btmName = pldef.getShowType();
                } else if (selectedObject instanceof Map){
                    if(pldef.getType() == 0){
                        oid = (String) ((Map)selectedObject).get("oid");
                        btmName = (String) ((Map)selectedObject).get("btmName");
                    } else if (pldef.getType() == 1){
                        oid = (String) ((Map)selectedObject).get("t_oid");
                        btmName = (String) ((Map)selectedObject).get("t_btmName");
                    }
                } else if (selectedObject instanceof IDataNode){
                    ClientBusinessObject cbo = new UIFUtils(
                            ).getBusinessObject(selectedObject, true);
                    if(cbo != null && cbo.getBusinessObject() != null){
                        oid = cbo.getBusinessObject().oid;
                        btmName = cbo.getBusinessObject().btName;
                        revisionOid = cbo.getBusinessObject().revisionid;
                        nameOid = cbo.getBusinessObject().nameoid;
                    }
                }
            } else {
                if(selectedObject instanceof String){
                    oid = (String) selectedObject;
                    btmName = pldef.getLinkType();
                } else if (selectedObject instanceof Map){
                    if(pldef.getType() == 0){
                        oid = (String) ((Map)selectedObject).get("oid");
                        btmName = (String) ((Map)selectedObject).get("btmName");
                    } else if (pldef.getType() == 1){
                        oid = (String) ((Map)selectedObject).get("oid");
                        btmName = pldef.getLinkType();
                    }
                } else if (selectedObject instanceof IDataNode){
                    if(((IDataNode) selectedObject).getMaterObject() instanceof ClientLinkObject){
                        oid = ((ClientLinkObject)((IDataNode
                                ) selectedObject).getMaterObject()).getLinkObject().oid;
                        btmName = pldef.getShowType();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        result[0] = oid;
        result[1] = btmName;
        result[2] = revisionOid;
        result[3] = nameOid;
        return result;
    }
    
    private String[] getBOcheckObject(Object selectedObject) {
          String[] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientBusinessObject) {
                ClientBusinessObject cbo = (ClientBusinessObject) masterObj;
                result = new String[4];
                result[0] = cbo.getBusinessObject().oid;
                result[1] = cbo.getBusinessObject().btName;
                result[2] = cbo.getBusinessObject().revisionid;
                result[3] = cbo.getBusinessObject().nameoid;
            }
        }
        
        return result;
    }
    
    private String[] getLOcheckObject(Object selectedObject) {
          String[] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientLinkObject) {
                ClientLinkObject clo = (ClientLinkObject) masterObj;
                result = new String[5];
                PLDefination pldef = getDefination();
                result[0] = clo.getFromOid() + ";" + clo.getOid();
                result[1] = clo.getFromBTMName();
                result[2] = "";
                result[3] = "";
                result[4] = pldef.getLinkType();
            }
        }
        
        return result;
    }
    
    private String[] getFromBOCheckObject(Object selectedObject) {
        String[] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientLinkObject) {
                ClientLinkObject clo = (ClientLinkObject) masterObj;
                result = new String[4];
                result[0] = clo.getFromOid();
                result[1] = clo.getFromBTMName();
                result[2] = clo.getFromRevisionOid();
                result[3] = clo.getFromNameOid();
            }
        }
        return result;
    }
    
    private String[] getToBOCheckObject(Object selectedObject) {
        String[] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientLinkObject) {
                ClientLinkObject clo = (ClientLinkObject) masterObj;
                result = new String[4];
                result[0] = clo.getToOid();
                result[1] = clo.getToBTMName();
                result[2] = clo.getToRevisionOid();
                result[3] = clo.getToNameOid();
            }
        }
        return result;
    }
    
    private String[][] getLoFromBOCheckObject(Object selectedObject) {
        String[][] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientLinkObject) {
                result = new String[2][];
                ClientLinkObject clo = (ClientLinkObject) masterObj;
                result[0] = new String[4];
                result[0][0] = clo.getFromOid();
                result[0][1] = clo.getFromBTMName();
                result[0][2] = clo.getFromRevisionOid();
                result[0][3] = clo.getFromNameOid();
                
                PLDefination pldef = getDefination();
                result[1] = new String[5];
                result[1][0] = clo.getFromOid() + ";" + clo.getOid();
                result[1][1] = clo.getFromBTMName();
                result[1][2] = "";
                result[1][3] = "";
                result[1][4] = pldef.getLinkType();
            }
        }
        return result;
    }
    
    private String[][] getLoToBOCheckObject(Object selectedObject) {
        String[][] result = null;
        if (selectedObject instanceof IDataNode){
            IDataNode dataNode = (IDataNode) selectedObject;
            Object masterObj = dataNode.getMaterObject();
            if (masterObj instanceof ClientLinkObject) {
                result = new String[2][];
                ClientLinkObject clo = (ClientLinkObject) masterObj;
                result[0] = new String[4];
                result[0][0] = clo.getToOid();
                result[0][1] = clo.getToBTMName();
                result[0][2] = clo.getToRevisionOid();
                result[0][3] = clo.getToNameOid();
                
                PLDefination pldef = getDefination();
                result[1] = new String[4];
                result[1][0] = clo.getFromOid() + ";" + clo.getOid();
                result[1][1] = clo.getFromBTMName();
                result[1][2] = "";
                result[1][3] = "";
                result[1][4] = pldef.getLinkType();
            }
        }
        return result;
    }
 
    public Component getButtonComponent() {
        return buttonComponent;
    }
 
    public void setButtonComponent(Component buttonComponent) {
        this.buttonComponent = buttonComponent;
    }
    
    /**
     * 设置Action配置信息
     * @param action
     */
    public void setAction(PLAction action){
        this.action = action;
    }
    
    /**
     * 获得Action配置信息
     * @return
     */
    public PLAction getAction(){
        return this.action;
    }
    
 
    /**
     * 检查按钮上定义的参数是否有效(不等于null且不等于"")
     * @param param 参数值
     * @param errorMessage 无效时的提示信息
     * @return
     */
    protected boolean checkButtonParamIsValid(String paramValue, String message){
        return checkButtonParamIsValid(paramValue, message, true);
    }
    /**
     * 检查按钮上定义的参数是否有效(不等于null且不等于"")
     * @param param 参数值
     * @param errorMessage 无效时的提示信息
     * @return
     */
    protected boolean checkButtonParamIsValid(String paramValue, String errorMessage, boolean showErrorMessage){
        boolean res = true;
        if(UIFUtils.isNullOrEmpty(paramValue)){
            res = false;
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), new VCIException(errorMessage));
        }
        return res;
    }
    
    private String dataRightCheckType = RightCheckConstants.RIGHT_CHECK_TYPE_NONE;
    /**
     * 设置 action 需要使用的数据权限检查类型
     * @param dataRightCheckType 数据权限检查类型
     */
    public void setDataRightCheckType(String dataRightCheckType){
        this.dataRightCheckType = dataRightCheckType;
    }
    /**
     * 返回 action 使用的数据权限检查类型
     * @return
     */
    public String getDataRightCheckType(){
        return this.dataRightCheckType;
    }
    
    /**
     * 调用按钮所在Dialog的注册的回调函数
     */
    public void invokeOwnedDialogCallback(){
        VCIJDialog dialog = this.getOwnerDialog();
        if(dialog != null){
            Runnable runnable = dialog.getDialogCallback();
            if(runnable != null){
                VCISwingUtil.invokeLater(runnable, 0);
            }
        }
    }
}