wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.framework.rightdistribution.roleRight;
 
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
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.Map.Entry;
import java.util.Set;
 
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.TreePath;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.corba.omd.btm.BtmItem;
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.client.common.VCIBasePanel;
import com.vci.client.common.objects.RoleObject;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.framework.common.RightType;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.delegate.RoleRightClientDelegate;
import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.framework.rightConfig.operate.ObjectListCellRenderer;
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow;
import com.vci.client.framework.systemConfig.stafforgmanage.ListLabelCellRender;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.portal.utility.UIDataFetcher;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.image.BundleImage;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.process.QANProcessBar;
import com.vci.client.ui.process.QANProcessBarFrame;
import com.vci.client.ui.swing.KJButton;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJList;
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.tree.CheckBoxTreeManager;
import com.vci.client.ui.tree.VCIBaseTree;
import com.vci.client.ui.tree.VCIBaseTreeModel;
import com.vci.client.ui.tree.VCIBaseTreeNode;
import com.vci.client.LogonApplication;
import com.vci.client.common.ClientLog4j;
import com.vci.corba.common.VCIError;
 
/**
 * 在bs架构下,基于建模类型的UI模块授权
 * @author VCI_STGK_Lincq
 *
 */
public class BSTypeRoleRightPanelV3 extends VCIBasePanel implements IModuleShow{
    
    private JLabel roleListLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.RoleList","RMIPFramework", getLocale()));// 角色列表Lab
    private JLabel titleLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.name","RMIPFramework", getLocale()));// title
    JList roleList = new JList(); // 角色列表
    
    private JButton addButton = new JButton();
    private JButton reAddButton = new JButton();
    private JButton delButton = new JButton();
    private JButton searchButton = new JButton();
    //private JButton clearButton = new JButton();
    //private JButton removeButton = new JButton();
    
    private String moduleName = "";
    private boolean isSearch=false;
    
    JScrollPane scrollTree = null;
    JSplitPane jspConfigPanel; // 把Panel分成左右两部分
    private JScrollPane leftPanel = new JScrollPane();
    VCIBaseTree tree;
    VCIBaseTreeModel treeModel;
    VCIBaseTreeNode rootNode;
    CheckBoxTreeManager treeManager;
    private RoleObject curRole = null;
 
    private JTextField top = new JTextField();// 上横线
    private JTextField bottom = new JTextField();// 下横线
    private static Map<String, String> funMap = new LinkedHashMap<String, String>();
    private Map<String,RoleRightObject> rightMap = new HashMap<String,RoleRightObject>();
    
    /**
     * 刷新按钮
     */
    private JMenuItem refMenuItem = new JMenuItem("刷新", VCISwingUtil.createImageIcon("arrow_refresh.png"));//刷新
    
    /**查询功能**/
    private JLabel searchLbl = new JLabel("查询:");
    private JTextField searchTxt = new JTextField(20);
    private KJButton searchRoleBtn = new KJButton("", "search.gif");
    private String currentUserName = LogonApplication.getUserEntityObject().getUserName();
    
    /**权限树的查询 */
    private JLabel typeLbl = new JLabel("业务类型:");
    private JTextField typeText = new JTextField(20);
    private JLabel contextLbl = new JLabel("上下文:");
    private JTextField contextText = new JTextField(20);
    //private KJButton sBtn = new KJButton("", "search.gif");
    private UIDataFetcher uiDataFechter = new UIDataFetcher();
 
    public BSTypeRoleRightPanelV3(FunctionObject funcObj) {
        super(funcObj);
        init();
        //LogonApplication.getUserEntityObject().setModules(this.getClass().getName());
        LogonApplication.getUserEntityObject().setModules(this.getModuleName());
    }
 
    public void init() {
        JPanel palMain = new JPanel();
        JPanel contentPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        JPanel midPanel = new JPanel();
        palMain.setLayout(new BorderLayout());
        roleList("");
        contentItem(contentPanel);
        jButtonPanl(buttonPanel);
        initTreeNode();
        
        refMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                refreshRole();
            }
        });
        
        searchRoleBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                searchRoleList();
            }
        });
        searchButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.lookButton.file","RMIPFramework", getLocale()));
        searchButton.setIcon(new BundleImage().createImageIcon("search.gif"));
        searchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
//                searchMyRigth();
            }
        });
        
        midPanel.setLayout(new BorderLayout());
        midPanel.add(top, BorderLayout.NORTH);
        midPanel.add(bottom, BorderLayout.SOUTH);
        midPanel.add(contentPanel, BorderLayout.CENTER);
        palMain.add(titleLab, BorderLayout.NORTH);
        palMain.add(midPanel, BorderLayout.CENTER);
        palMain.add(buttonPanel, BorderLayout.SOUTH);
        
        JPanel leftMainPanel = new JPanel(new BorderLayout());
        leftMainPanel.add(leftPanel,BorderLayout.CENTER);
        leftMainPanel.add(getSearchPanel(),BorderLayout.NORTH);
 
        jspConfigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftMainPanel, palMain);
        jspConfigPanel.setDividerSize(7);
        jspConfigPanel.setContinuousLayout(true);
        jspConfigPanel.setOneTouchExpandable(true);
        jspConfigPanel.setDividerLocation(220);
        this.setLayout(new BorderLayout());
        this.add(jspConfigPanel, BorderLayout.CENTER);
    }
    
    public void roleList(String searchText) {
        setRoleList(searchText);
        roleList.setCellRenderer(new ListLabelCellRender());
        roleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        roleList.getSelectedValue();
        roleList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                RoleObject roleObj = (RoleObject)roleList.getSelectedValue();
                curRole = roleObj;
                tree.clearSelection();
                treeManager.getSelectionModel().clearSelection();
                initRoleRight(roleObj.getId());
            }
        });
        leftPanel.getViewport().add(roleList);
    }
    
    Map<String,RoleRightObject> allRightRoleMap = new HashMap<String,RoleRightObject>();
    
    
    public void initRoleRight(String roleId){
        try {
            allRightRoleMap = new HashMap<String,RoleRightObject>();
            RoleRightObject[] roleRightObjs = new RoleRightClientDelegate().getRoleRightList(roleId, LogonApplication.getUserEntityObject().getUserName());
            visitAllTreeNode(rootNode, roleRightObjs);
        } catch (VCIException e) {
            e.printStackTrace();
            VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
        }
    }
    
    /*public void initRoleRight(String roleId){
        try{
            //先清除所有展开的节点
            for(int i=rootNode.getChildCount(); i>0; i--){
                VCIBaseTreeNode childNode = (VCIBaseTreeNode)rootNode.getChildAt(i-1);
                for(int j=childNode.getChildCount();j>0;j--){
                    VCIBaseTreeNode cchildNode = (VCIBaseTreeNode)childNode.getChildAt(j-1);
                    treeModel.removeNodeFromParent(cchildNode);
                }
            }
            //initTreeNode();
            //allRightRoleMap = new HashMap<String,RoleRightObject>();
            funMap.clear();
            //开始展示我的权限内容
            long s = System.currentTimeMillis();
            RoleRightObject[] roleRightObjs = new RoleRightClientDelegate().getRoleRightList(roleId, LogonApplication.getUserEntityObject().getUserName());
            
            long t = System.currentTimeMillis();
            System.out.println("1: " + (t - s));
            s = System.currentTimeMillis();
            BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
            t = System.currentTimeMillis();
            System.out.println("2: " + (t - s));
            
            s = System.currentTimeMillis();
            Map<String,Long> rightMap = new HashMap<String,Long>();
            for(RoleRightObject obj:roleRightObjs){
                allRightRoleMap.put(obj.getFuncId(), obj);
                rightMap.put(obj.getFuncId(), obj.getRightValue());
            }
            t = System.currentTimeMillis();
            System.out.println("3: " + (t - s));
            
            //添加type节点
            UIDataFetcher uiDataFechter = new UIDataFetcher();
            s = System.currentTimeMillis();
            int ii=0;
            for(BtmItem btmItem: btmItems){
                
                if(rightMap.containsKey(btmItem.name))
                {
                    //VCIBaseTreeNode node = new VCIBaseTreeNode(btmItem.label+"("+ btmItem.name+")", btmItem);
                    VCIBaseTreeNode node = (VCIBaseTreeNode)rootNode.getChildAt(ii);
                    //node.setExpand(true);
                    funMap.put(btmItem.name, btmItem.name);
                //    treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
                //    setChildNode(node, btmItem, rightMap);
                    setChildNode(node, btmItem, uiDataFechter);
                }
                ii++;
            }
            t = System.currentTimeMillis();
            System.out.println("4: " + (t - s));
            
            s = System.currentTimeMillis();
            visitAllTreeNode(rootNode, roleRightObjs);
            //treeManager.getSelectionModel().addSelectionPath(new TreePath(rootNode.getPath()));
            t = System.currentTimeMillis();
            System.out.println("5: " + (t - s));
        } catch (VCIException e) {
            e.printStackTrace();
            VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
        }
    }*/
    private void setChildNode(VCIBaseTreeNode node ,Object funcObj, UIDataFetcher uiDataFechter) {
        if (funcObj instanceof BtmItem) {
            BtmItem btmItem = (BtmItem) funcObj;
            List<PLUILayout> contexts = uiDataFechter.getContext(btmItem.name);
            if (contexts == null) {
                return;
            }
            for(PLUILayout context : contexts){
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(context.plName+"("+context.plCode+")", context);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(context.plOId, context.plCode);
                setChildNode(curNode, context, uiDataFechter);
            }
        } else if (funcObj instanceof PLUILayout) {
            PLUILayout context = (PLUILayout) funcObj;
            List<PLTabPage> tabs = uiDataFechter.getTabs(context.plOId);
            if (tabs == null) {
                return;
            }
            for(PLTabPage tab : tabs){
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(tab.plName, tab);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(tab.plOId, tab.plName);
                setChildNode(curNode, tab, uiDataFechter);
            }
        } else if (funcObj instanceof PLTabPage) {
            PLTabPage tab = (PLTabPage) funcObj;
            List<PLPageDefination> pageDefinations = uiDataFechter.getComopnent(tab.plOId);
            if (pageDefinations == null) {
                return;
            }
            for (PLPageDefination pageDefination : pageDefinations) {
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(pageDefination.name, pageDefination);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(pageDefination.plOId, pageDefination.name);
                setChildNode(curNode, pageDefination, uiDataFechter);
            }
        } else if (funcObj instanceof PLPageDefination) {
            PLPageDefination pageDef = (PLPageDefination) funcObj;
            List<PLTabButton> buttons = uiDataFechter.getButtons(pageDef.plOId);
            if (buttons == null) {
                return;
            }
            for(PLTabButton button : buttons){
                if(!button.show.equals("0")){
                    continue;
                }
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(button.plLabel, button);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(button.plTableOId, button.plLabel);
                setChildNode(curNode, button, uiDataFechter);
                curNode.setLeaf(true);
            }
        }
        else if (funcObj instanceof PLTabButton) {
            node.setLeaf(true);
        }
    }
    private void setChildNode(VCIBaseTreeNode node ,Object funcObj, Map<String, Long> rightMap) {
        if (funcObj instanceof BtmItem) {
            BtmItem btmItem = (BtmItem) funcObj;
            List<PLUILayout> contexts = uiDataFechter.getContext(btmItem.name);
            if (contexts == null) {
                return;
            }
            for(PLUILayout context : contexts){
                if(rightMap.containsKey(context.plOId)){
                    VCIBaseTreeNode curNode  = new VCIBaseTreeNode(context.plName+"("+context.plCode+")", context);
                    curNode.setExpand(true);
                    treeModel.insertNodeInto(curNode, node,node.getChildCount());
                    funMap.put(context.plOId, context.plCode);
                    setChildNode(curNode, context, rightMap);
                }
            }
        } else if (funcObj instanceof PLUILayout) {
            PLUILayout context = (PLUILayout) funcObj;
            List<PLTabPage> tabs = uiDataFechter.getTabs(context.plOId);
            if (tabs == null) {
                return;
            }
            for(PLTabPage tab : tabs){
                if(rightMap.containsKey(tab.plOId)){
                    VCIBaseTreeNode curNode  = new VCIBaseTreeNode(tab.plName, tab);
                    curNode.setExpand(true);
                    treeModel.insertNodeInto(curNode, node,node.getChildCount());
                    funMap.put(tab.plOId, tab.plName);
                    setChildNode(curNode, tab, rightMap);
                }
            }
        } else if (funcObj instanceof PLTabPage) {
            PLTabPage tab = (PLTabPage) funcObj;
            List<PLPageDefination> pageDefinations = uiDataFechter.getComopnent(tab.plOId);
            if (pageDefinations == null) {
                return;
            }
            for (PLPageDefination pageDefination : pageDefinations) {
                if(rightMap.containsKey(pageDefination.plOId)){
                    VCIBaseTreeNode curNode  = new VCIBaseTreeNode(pageDefination.name, pageDefination);
                    curNode.setExpand(true);
                    treeModel.insertNodeInto(curNode, node,node.getChildCount());
                    funMap.put(pageDefination.plOId, pageDefination.name);
                    setChildNode(curNode, pageDefination, rightMap);
                }
            }
        } else if (funcObj instanceof PLPageDefination) {
            PLPageDefination pageDef = (PLPageDefination) funcObj;
            List<PLTabButton> buttons = uiDataFechter.getButtons(pageDef.plOId);
            if (buttons == null) {
                return;
            }
            for(PLTabButton button : buttons){
                if(rightMap.containsKey(button.plTableOId)){
                    Long rightValue = rightMap.get(button.plTableOId);
                    int nodeValue = button.plSeq;
                    if (nodeValue >= 0 && nodeValue <= 63) {
                        //long preValue = (long)Math.pow(2, nodeValue);
                        //进行位与操作,如果相等则表示具有当前操作的权限
                        //if(preValue == (preValue & rightValue)){
                        long preValue = (rightValue >> nodeValue) & 1;
                        if (preValue == 1) {
                            VCIBaseTreeNode curNode  = new VCIBaseTreeNode(button.plLabel, button);
                            curNode.setExpand(true);
                            treeModel.insertNodeInto(curNode, node,node.getChildCount());
                            funMap.put(button.plTableOId, button.plLabel);
                            setChildNode(curNode, button, rightMap);
                            curNode.setLeaf(true);
                        }
                    }
                }
            }
        }
        else if (funcObj instanceof PLTabButton) {
            node.setLeaf(true);
        }
    }
    
    private void visitAllTreeNode(VCIBaseTreeNode node, RoleRightObject[] roleRightObjs){
        Map<String,Long> rightMap = new HashMap<String,Long>();
        for(RoleRightObject obj:roleRightObjs){
            allRightRoleMap.put(obj.getFuncId(), obj);
            rightMap.put(obj.getFuncId(), obj.getRightValue());
        }
        visitAllTreeNode(node,rightMap);
    }
    private void visitAllTreeNode(VCIBaseTreeNode node,Map<String,Long> rightMap){
        for(int i = 0;i < node.getChildCount();i++){
            VCIBaseTreeNode childNode = (VCIBaseTreeNode)node.getChildAt(i);
            Object obj = childNode.getObj();
            //如果是模块,则先判断是否有此模块权限,如果有,则判断下级模块及操作
            if(obj instanceof BtmItem){
                String id = ((BtmItem) obj).name;
                if(rightMap.containsKey(id)){
                    visitAllTreeNode(childNode,rightMap);
                }
            } else if(obj instanceof PLUILayout){
                visitAllTreeNode(childNode,rightMap);
            } else if (obj instanceof PLTabPage) {
                visitAllTreeNode(childNode,rightMap);
            } else if (obj instanceof PLPageDefination) {
                visitAllTreeNode(childNode,rightMap);
            } else if (obj instanceof PLTabButton) {
                String id = ((PLTabButton) obj).plTableOId;
                if(rightMap.containsKey(id)){
                    Long rightValue = rightMap.get(id);
                    int nodeValue = ((PLTabButton) obj).plSeq;
                    if (nodeValue >= 0 && nodeValue <= 63) {
                        //long preValue = (long)Math.pow(2, nodeValue);
                        //进行位与操作,如果相等则表示具有当前操作的权限
                        //if(preValue == (preValue & rightValue)){
                        long preValue = (rightValue >> nodeValue) & 1;
                        if (preValue == 1) {
                            treeManager.getSelectionModel().addSelectionPath(new TreePath(childNode.getPath()));
                        }
                    }
                }
            }
        }
    }
    
    /**
     * 给角色列表赋值
     */
    private void setRoleList(String searchText) {
        try {
            RightManagementClientDelegate rightManagementClient = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
            RoleObject[] roleObjs = rightManagementClient.fetchRoleInfoByUserType(LogonApplication.getUserEntityObject().getUserName());// 取得角色信息
            if(!"".equals(searchText)) {
                List<RoleObject> list = new LinkedList<RoleObject>();
                for(RoleObject roleObj : roleObjs) {
                    if(roleObj.getName().indexOf(searchText) != -1) {
                        list.add(roleObj);
                    }
                }
                roleList = new JList(list.toArray(new RoleObject[0]));
                roleList.setCellRenderer(new ObjectListCellRenderer());
                return ;
            }
            roleList = new JList(roleObjs);
            roleList.setCellRenderer(new ObjectListCellRenderer());
        } catch (VCIException e) {
            e.printStackTrace();
            VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
        }
    }
    
    public void contentItem(JPanel contentPanel) {
        top.setPreferredSize(new Dimension(60,2));
        scrollTree = new JScrollPane();
        bottom.setPreferredSize(new Dimension(60,2));
        contentPanel.setLayout(new BorderLayout());
        contentPanel.add(roleListLab);
        contentPanel.add(scrollTree);
    }
    
    public void jButtonPanl(JPanel p) {
        addButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.addButton.file","RMIPFramework", getLocale()));
        addButton.setIcon(new BundleImage().createImageIcon("create.gif"));
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                add_actionPerform();
            }
        });
        
        reAddButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.reAddButton.file","RMIPFramework", getLocale()));
        reAddButton.setIcon(new BundleImage().createImageIcon("create.gif"));
        reAddButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                reAdd_actionPerform();
            }
        });
        
 
        delButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.delButton.file","RMIPFramework", getLocale()));
        delButton.setIcon(new BundleImage().createImageIcon("delete.gif"));
        delButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rightMap.clear();
                treeManager.getSelectionModel().clearSelection();
            }
        });
        
/*        removeButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.removeButton.file","RMIPFramework", getLocale()));
        removeButton.setIcon(new BundleImage().createImageIcon("remove.gif"));
        removeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                remove_actionPerform();
            }
        });
        
        clearButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.clearButton.file","RMIPFramework", getLocale()));
        clearButton.setIcon(new BundleImage().createImageIcon("clear.gif"));
        clearButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clear_actionPerform();
            }
        });*/
        
        searchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String typeStr = typeText.getText();
                String contextStr = contextText.getText();
                if(StringUtils.isNotBlank(typeStr)||StringUtils.isNotBlank(contextStr)){
                    isSearch=true;
                    addButton.setEnabled(false);
                }else{
                    isSearch=false;
                    addButton.setEnabled(true);
                }
                //先清除所有展开的节点
                rootNode.removeAllChildren();
                /*for(int i=rootNode.getChildCount(); i>0; i--){
                    VCIBaseTreeNode childNode = (VCIBaseTreeNode)rootNode.getChildAt(i-1);
                    treeModel.removeNodeFromParent(childNode);
                }*/
                funMap.clear();
                //为保证每次的查询还原到初始所有一级节点执行以下操作
                /*BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
                for (int i = 0; i < btmItems.length; i++) {
                    VCIBaseTreeNode node = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
                    treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
                }*/
                /*for(int i=0; i< rootNode.getChildCount(); i++){
                    VCIBaseTreeNode childNode = (VCIBaseTreeNode)rootNode.getChildAt(i);
                    for(int j=childNode.getChildCount(); j>0; j--){
                        VCIBaseTreeNode node = (VCIBaseTreeNode) childNode.getChildAt(j-1);
                        treeModel.removeNodeFromParent(node);
                    }
                }*/
                BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
                
                if(contextStr.trim().length() > 0){
                    try {
                        //获取所有匹配的上下文对象???sss
                        PLUILayout[] contexts = UITools.getService().getPLUILayoutEntity(contextStr);
                        Map<String, VCIBaseTreeNode> showNodes = new HashMap<String, VCIBaseTreeNode>();
                        for(PLUILayout context: contexts){
                            for (int i = 0; i < btmItems.length; i++) {
                                if((context.plRelatedType).equals(btmItems[i].name)){
                                    if(btmItems[i].label.contains(typeStr) || btmItems[i].name.contains(typeStr)){
                                        VCIBaseTreeNode typeNode = showNodes.get(btmItems[i].name);
                                        if(typeNode == null){
                                            //添加类型节点
                                            typeNode = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
                                            funMap.put(btmItems[i].name, btmItems[i].name);
                                            showNodes.put(btmItems[i].name, typeNode);
                                            treeModel.insertNodeInto(typeNode, rootNode,rootNode.getChildCount());
                                        }
                                        //添加上下文节点及子节点
                                        VCIBaseTreeNode curNode  = new VCIBaseTreeNode(context.plName+"("+context.plCode+")", context);
                                        treeModel.insertNodeInto(curNode, typeNode,typeNode.getChildCount());
                                        funMap.put(context.plOId, context.plCode);
                                        setChildNode(curNode, context);
                                    }
                                }
                            }
                        }
                    } catch (VCIError e1) {
                        e1.printStackTrace();
                    }
                }else if(typeStr.trim().length() > 0 ){
                    for (int i = 0; i < btmItems.length; i++) {
                        if(btmItems[i].label.contains(typeStr) || btmItems[i].name.contains(typeStr)){
                            VCIBaseTreeNode typeNode = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
                            funMap.put(btmItems[i].name, btmItems[i].name);
                            treeModel.insertNodeInto(typeNode, rootNode,rootNode.getChildCount());
                            List<PLUILayout> contexts = uiDataFechter.getContext(btmItems[i].name);
                            if (contexts == null) {
                                return;
                            }
                            for(PLUILayout context : contexts){
                                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(context.plName+"("+context.plCode+")", context);
                                treeModel.insertNodeInto(curNode, typeNode,typeNode.getChildCount());
                                funMap.put(context.plOId, context.plCode);
                                setChildNode(curNode, context, uiDataFechter);
                            }
                        }
                    }
                }else{
                    /*for (int i = 0; i < btmItems.length; i++) {
                        VCIBaseTreeNode typeNode = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
                        funMap.put(btmItems[i].name, btmItems[i].name);
                        treeModel.insertNodeInto(typeNode, rootNode,rootNode.getChildCount());
                    }*/
                    initTreeNode();
                    //initRightNode();
                }
                //treeManager.getSelectionModel().removeSelectionPath(new TreePath(rootNode.getPath()));
            }
        });
        p.add(typeLbl);
        p.add(typeText);
        p.add(contextLbl);
        p.add(contextText);
        //p.add(sBtn);
        p.add(searchButton);
        p.add(addButton);
        p.add(reAddButton);
        p.add(delButton);
        //p.add(removeButton);
        //p.add(clearButton);
    }
    
    /*public void initTreeNode(){
        rootNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.moduleTree","RMIPFramework", getLocale()), "root");
        treeModel = new VCIBaseTreeModel(rootNode);
        tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer());
        BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
        funMap.clear();
        for(int k = 0;k < btmItems.length;k++) {
            funMap.put(btmItems[k].name, btmItems[k].name);
        }
        
        for (int i = 0; i < btmItems.length; i++) {
            VCIBaseTreeNode node = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
            treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
        }
        treeManager = new CheckBoxTreeManager(tree);
        scrollTree.getViewport().removeAll();
        scrollTree.getViewport().add(tree);
        scrollTree.repaint();
        tree.addTreeExpansionListener(new TreeExpansionListener() {
            
            @Override
            public void treeExpanded(TreeExpansionEvent event) {
                TreePath path = event.getPath();
                VCIBaseTreeNode selNode = (VCIBaseTreeNode)path.getLastPathComponent();
                if(!selNode.isLeaf() && selNode.getChildCount() == 0 && !selNode.isExpand()){
                    setChildNode(selNode, selNode.getObj());
                }
            }
            
            @Override
            public void treeCollapsed(TreeExpansionEvent event) {
                
            }
        });
    }*/
    
    public void initTreeNode(){
        rootNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.moduleTree","RMIPFramework", getLocale()), "root");
        treeModel = new VCIBaseTreeModel(rootNode);
        tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer());
        BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
        funMap.clear();
        for(int k = 0;k < btmItems.length;k++) {
            funMap.put(btmItems[k].name, btmItems[k].name);
        }
        
        UIDataFetcher uiDataFechter = new UIDataFetcher();
        for (int i = 0; i < btmItems.length; i++) {
            VCIBaseTreeNode node = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
            treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
            long startTime = System.currentTimeMillis();
            setChildNode(node, btmItems[i], uiDataFechter);
            long endTime = System.currentTimeMillis();
            long d = endTime -startTime;
            //System.out.println(btmItems[i].name + " - " + d);
            ClientLog4j.logger.debug("加载时间:" + btmItems[i].name + " - " + d + " ms");
        }
        treeManager = new CheckBoxTreeManager(tree);
        scrollTree.getViewport().removeAll();
        scrollTree.getViewport().add(tree);
        scrollTree.repaint();
    }
    
    private void refreshRole() {
        roleList("");
        treeManager.getSelectionModel().clearSelection();
    }
    
    /**查询满足条件的角色信息**/
    private void searchRoleList() {
        String search = this.searchTxt.getText().trim();
        roleList(search);
        treeManager.getSelectionModel().clearSelection();
    }
    
    private JPanel getSearchPanel() {
        //JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JPanel searchPanel = new JPanel();
        searchPanel.add(searchLbl);
        searchPanel.add(searchTxt);
        searchPanel.add(searchRoleBtn);
        
        GridBagLayout layout = new GridBagLayout();
        searchPanel.setLayout(layout);
 
        GridBagConstraints s = new GridBagConstraints();
        s.fill = GridBagConstraints.HORIZONTAL;
        s.gridwidth = 1;
        s.weightx = 0;
        s.weighty = 0;
        layout.setConstraints(searchLbl, s);
        s.gridwidth = 1;
        s.weightx = 1;
        s.weighty = 0;
        layout.setConstraints(searchTxt, s);
        s.gridwidth = 1;
        s.weightx = 0;
        s.weighty = 0;
        layout.setConstraints(searchRoleBtn, s);
        
//        GridLayout layout = new GridLayout(1, 3);
//        searchPanel.setLayout(layout);
//        searchPanel.add(searchLbl);
//        searchPanel.add(searchTxt);
//        searchPanel.add(searchRoleBtn);
        
        return searchPanel;
        
    }
    
    private void add_actionPerform(){
        if (!checkItem()) {
            return;
        }
        final QANProcessBarFrame frame = new QANProcessBarFrame();
        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
        if (treePath == null || treePath.length == 0) {
            VCIOptionPane.showMessage(LogonApplication.frame, "您没有选择当前页面上的任何权限,如果需要去除当前页面下的所有权限请选择权限后点击【清除本界面中权限】");
            return ;
        } 
        QANProcessBar bar = null;
        Thread t = new Thread(){
            public void run() {
                frame.setContent("正在授权,请稍等......");
                try {
                    rightMap.clear();
                    boolean refresh = true;
                    TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
                    //当没有选中模块的时候
                    if (treePath == null && treePath.length == 0){
                        refresh = false;
                    }else{
                        RoleRightObject[] roleRightObjs = getSelectedRoleRightObjs(treePath);
                        boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).saveRoleRight(roleRightObjs,curRole.getId(),currentUserName);
                        frame.setProcessBarCancel(true);
                        if(res){
                            VCIOptionPane.showMessage(LogonApplication.frame, "UI授权成功!");
                        }
                    }
                    if(refresh&&isSearch){
                        //treeManager.getSelectionModel().clearSelection();
                        initTreeNode();
                        initRoleRight(curRole.getId());
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
                } finally {
                    frame.setProcessBarCancel(true);
                }
            }
        };
        bar = new QANProcessBar(t, frame, frame,"功能模块授权",false);
        bar.setVisible(true);
    }
    
    private void remove_actionPerform(){
        if (!checkItem()) {
            return;
        }
        final QANProcessBarFrame frame = new QANProcessBarFrame();
        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
        if (treePath == null || treePath.length == 0) {
            VCIOptionPane.showMessage(LogonApplication.frame, "请选择要删除的权限");
            return ;
        } 
        QANProcessBar bar = null;
        Thread t = new Thread(){
            public void run() {
                frame.setContent("正在授权,请稍等......");
                try {
                    rightMap.clear();
                    boolean refresh = true;
                    TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
                    //当没有选中模块的时候
                    if (treePath == null && treePath.length == 0){
                        refresh = false;
                    }else{
                        RoleRightObject[] roleRightObjs = getRemoveedSelectedRoleRightObjs(treePath);
                        boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).removeRoleRight(roleRightObjs,curRole.getId(),currentUserName);
                        frame.setProcessBarCancel(true);
                        if(res){
                            VCIOptionPane.showMessage(LogonApplication.frame, "移除UI操作权限成功!");
                        }
                    }
                    if(refresh&&isSearch){
                        treeManager.getSelectionModel().clearSelection();
                        initRoleRight(curRole.getId());
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
                } finally {
                    frame.setProcessBarCancel(true);
                }
            }
        };
        bar = new QANProcessBar(t, frame, frame,"UI操作授权",false);
        bar.setVisible(true);
    }
    
    private void clear_actionPerform(){
        if (!checkItem()) {
            return;
        }
        final QANProcessBarFrame frame = new QANProcessBarFrame();
        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
        if (treePath == null || treePath.length == 0) {
            int result = VCIOptionPane.showConfirmDialog(LogonApplication.frame, this, "您确定要清除所有的UI操作权限吗?", "注意,您确定要清除所有的UI权限吗?", VCIOptionPane.YES_NO_OPTION, VCIOptionPane.WARNING_MESSAGE);
            if(result != VCIOptionPane.YES_OPTION){
                return;
            }
        } 
        QANProcessBar bar = null;
        Thread t = new Thread(){
            public void run() {
                frame.setContent("正在清除授权,请稍等......");
                try {
                    rightMap.clear();
                    boolean refresh = true;
                    TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
                    //当没有选中模块的时候
                    RoleRightObject[] roleRightObjs = new RoleRightObject[0];
                    boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).clearRight(curRole.getId(),currentUserName,(short)1);
                    frame.setProcessBarCancel(true);
                    if(res){
                        VCIOptionPane.showMessage(LogonApplication.frame, "UI操作权限清空成功!");
                    }
                    
                    if(refresh&&isSearch){
                        treeManager.getSelectionModel().clearSelection();
                        initRoleRight(curRole.getId());
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
                } finally {
                    frame.setProcessBarCancel(true);
                }
            }
        };
        bar = new QANProcessBar(t, frame, frame,"UI操作授权",false);
        bar.setVisible(true);
    }
    /*
     * 该方法作为补充添加授权功能应用
     */
    private void reAdd_actionPerform(){
        if (!checkItem()) {
            return;
        }
        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
        if (treePath == null || treePath.length == 0) {
            VCIOptionPane.showMessage(LogonApplication.frame, "您没有在当前页面选择任何的权限,所以将不执行追加权限");
            return ;
        } 
        final QANProcessBarFrame frame = new QANProcessBarFrame();
        Thread t = new Thread(){
            public void run() {
                frame.setContent("正在授权,请稍等......");
                try {
                    rightMap.clear();
                    boolean refresh = true;
                    TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
                    //当没有选中模块的时候
                    if (treePath == null) {
                        refresh = false;
                    } 
                    RoleRightObject[] roleRightObjs = getSelectedRoleRightObjs(treePath);
                    boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).addRoleRight(roleRightObjs,curRole.getId(),currentUserName);
                    frame.setProcessBarCancel(true);
                    if(res){
                        VCIOptionPane.showMessage(LogonApplication.frame, "功能模块授权成功!");
                    }
                    if(refresh&&isSearch){
                        treeManager.getSelectionModel().clearSelection();
                        initRoleRight(curRole.getId());
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
                } finally {
                    if (frame.isActive()) {
                        frame.setProcessBarCancel(true);
                    }
                }
            }
        };
        QANProcessBar bar = new QANProcessBar(t, frame, frame,"功能模块授权",false);
        bar.setVisible(true);
    }
    
    private RoleRightObject[] getSelectedRoleRightObjs(TreePath[] treePath){
        rightMap.clear();
        RoleRightObject[] roleRightObjs = new RoleRightObject[0];
        if(treePath == null){
            //1。先从所有权限对象中删除模块权限对象
            Set<Entry<String, String>> funSet = funMap.entrySet();
            Iterator<Entry<String, String>> funIt = funSet.iterator();
            while(funIt.hasNext()){
                Entry<String, String> next = funIt.next();
                String key = next.getKey();
                String value = next.getValue();
                allRightRoleMap.remove(key);
            }
            //2。再保存选中的模块对象到所有权限中
            Set<Entry<String, RoleRightObject>> entrySet = rightMap.entrySet();
            Iterator<Entry<String, RoleRightObject>> iterator = entrySet.iterator();
            while(iterator.hasNext()){
                Entry<String, RoleRightObject> next = iterator.next();
                String key = next.getKey();
                RoleRightObject value = next.getValue();
                allRightRoleMap.put(value.getFuncId(), value);
            }
            cloneMap(allRightRoleMap, rightMap);
            //rightMap = allRightRoleMap;
            /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
            roleRightObjs =    new RoleRightObject[rightMap.size()];
            Set<String> objSet = rightMap.keySet();
            Iterator<String> it = objSet.iterator();
            int i = 0;
            while(it.hasNext()){
                roleRightObjs[i++] = rightMap.get(it.next());
            }
        } else {
            for(int i = 0;i < treePath.length;i++){
                VCIBaseTreeNode node = (VCIBaseTreeNode)treePath[i].getLastPathComponent();
                Object obj = node.getObj();
                if(obj instanceof String){//如果是root节点,则保存所有模块的权限
                    getRightValue(node,false);//向下获取所有模块的权限值
                }else if(!(node.getObj() instanceof PLTabButton)){
                    getRightValue(node,true);//向上处理
                    getRightValue(node,false);//向下处理(包含当前节点)
                }else if(node.getObj() instanceof PLTabButton){
                    VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
                    String funcId = ((PLPageDefination)parentNode.getObj()).plOId;
                    getRightValue(parentNode,true);//向上处理该操作父级的上级模块权限(不包含父节点)
                    if(!rightMap.containsKey(funcId)){
                        RoleRightObject roleRightObj = new RoleRightObject();
                        roleRightObj.setFuncId(funcId);
                        roleRightObj.setRightType(RightType.UI);
                        roleRightObj.setRightValue(countRightValue(parentNode,false));//没有操作的模块权限值存储为0
                        roleRightObj.setRoleId(curRole.getId());
                        roleRightObj.setCreateUser(currentUserName);
                        roleRightObj.setCreateTime(new Date());
                        roleRightObj.setModifyUser(currentUserName);
                        roleRightObj.setModifyTime(new Date());
                        roleRightObj.setLicensor("");
                        rightMap.put(funcId, roleRightObj);
                    }
                }
            }
            //1。先从所有权限对象中删除模块权限对象
            Set<Entry<String, String>> funSet = funMap.entrySet();
            Iterator<Entry<String, String>> funIt = funSet.iterator();
            while(funIt.hasNext()){
                Entry<String, String> next = funIt.next();
                String key = next.getKey();
                String value = next.getValue();
                allRightRoleMap.remove(key);
            }
            //2。再保存选中的模块对象到所有权限中
            Set<Entry<String, RoleRightObject>> entrySet = rightMap.entrySet();
            Iterator<Entry<String, RoleRightObject>> iterator = entrySet.iterator();
            while(iterator.hasNext()){
                Entry<String, RoleRightObject> next = iterator.next();
                String key = next.getKey();
                RoleRightObject value = next.getValue();
                if(!allRightRoleMap.containsKey(value.getFuncId().trim())){
                    allRightRoleMap.put(value.getFuncId(), value);
                }
            }
            cloneMap(allRightRoleMap, rightMap);
            //rightMap = allRightRoleMap;
            /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
            roleRightObjs =    new RoleRightObject[rightMap.size()];
            Set<String> objSet = rightMap.keySet();
            Iterator<String> it = objSet.iterator();
            int i = 0;
            while(it.hasNext()){
                roleRightObjs[i++] = rightMap.get(it.next());
            }
        }
        return roleRightObjs;
    }
    
    private RoleRightObject[] getRemoveedSelectedRoleRightObjs(TreePath[] treePath){
        rightMap.clear();
        RoleRightObject[] roleRightObjs = new RoleRightObject[0];
        if(treePath != null){
            for(int i = 0;i < treePath.length;i++){
                VCIBaseTreeNode node = (VCIBaseTreeNode)treePath[i].getLastPathComponent();
                Object obj = node.getObj();
                if(obj instanceof String){//如果是root节点,则保存所有模块的权限
                    getRightValue(node,false);//向下获取所有模块的权限值
                }else if(!(node.getObj() instanceof PLTabButton)){
                    getRightValue(node,true);//向上处理
                    getRightValue(node,false);//向下处理(包含当前节点)
                }else if(node.getObj() instanceof PLTabButton){
                    VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
                    String funcId = ((PLPageDefination)parentNode.getObj()).plOId;
                    getRightValue(parentNode,true);//向上处理该操作父级的上级模块权限(不包含父节点)
                    if(!rightMap.containsKey(funcId)){
                        RoleRightObject roleRightObj = new RoleRightObject();
                        roleRightObj.setFuncId(funcId);
                        roleRightObj.setRightType(RightType.UI);
                        roleRightObj.setRightValue(countRightValue(parentNode,false));//没有操作的模块权限值存储为0
                        roleRightObj.setRoleId(curRole.getId());
                        roleRightObj.setCreateUser(currentUserName);
                        roleRightObj.setCreateTime(new Date());
                        roleRightObj.setModifyUser(currentUserName);
                        roleRightObj.setModifyTime(new Date());
                        roleRightObj.setLicensor("");
                        rightMap.put(funcId, roleRightObj);
                    }
                }
            }
            //cloneMap(allRightRoleMap, rightMap);
            //rightMap = allRightRoleMap;
            /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
            roleRightObjs =    new RoleRightObject[rightMap.size()];
            Set<String> objSet = rightMap.keySet();
            Iterator<String> it = objSet.iterator();
            int i = 0;
            while(it.hasNext()){
                roleRightObjs[i++] = rightMap.get(it.next());
            }
        }
        return roleRightObjs;
    }
    
    
    private void cloneMap(Map source, Map target){
        target.clear();
        for( Object key: source.keySet()){
            target.put(key, source.get(key));
        }
    }
    
    /**
     * 获取权限
     * @param isUp 是否是向上获取,如果是向上获取,传进来的必然是模块节点,且上级模块必然是没有选中
     */
    private void getRightValue(VCIBaseTreeNode node,boolean isUp){
        if(isUp){//向上获取,存储每个上级模块的权限值
            VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
            while(parentNode!=null&&!"root".equals(parentNode.getObj())){
                String funcId = "";
                if (parentNode.getObj() instanceof BtmItem) {
                    BtmItem btmItem = (BtmItem) parentNode.getObj();
                    funcId = btmItem.name;
                } else if (parentNode.getObj() instanceof PLUILayout) {
                    PLUILayout context = (PLUILayout) parentNode.getObj();
                    funcId = context.plOId;
                } else if (parentNode.getObj() instanceof PLTabPage) {
                    PLTabPage tab = (PLTabPage) parentNode.getObj();
                    funcId = tab.plOId;
                } else if (parentNode.getObj() instanceof PLPageDefination){
                    PLPageDefination pageDef = (PLPageDefination) parentNode.getObj();
                    funcId = pageDef.plOId;
                } else if (parentNode.getObj() instanceof PLTabButton) {
                    PLTabButton but = (PLTabButton)parentNode.getObj();
                    funcId = but.plOId;
                }
                RoleRightObject obj = new RoleRightObject();
                obj.setFuncId(funcId);
                obj.setRightType(RightType.UI);
                obj.setRightValue(1);//没有操作的模块权限值存储为0
                obj.setRoleId(curRole.getId());
                
                obj.setCreateUser(currentUserName);
                obj.setCreateTime(new Date());
                obj.setModifyUser(currentUserName);
                obj.setModifyTime(new Date());
                obj.setLicensor("");
                if(!rightMap.containsKey(funcId)){
                    rightMap.put(funcId, obj);
                }
                parentNode = (VCIBaseTreeNode)parentNode.getParent();
            }
        }else{//向下获取,无需判断是否选中,但需要判断其子级是否是操作
            //先存储当前节点
            String funcId = "";
            if(node.getObj() instanceof String){
                funcId = (String)node.getObj();
            } else if (node.getObj() instanceof BtmItem) {
                BtmItem btmItem = (BtmItem) node.getObj();
                funcId = btmItem.name;
            } else if (node.getObj() instanceof PLUILayout) {
                PLUILayout context = (PLUILayout) node.getObj();
                funcId = context.plOId;
            } else if (node.getObj() instanceof PLTabPage) {
                PLTabPage tab = (PLTabPage) node.getObj();
                funcId = tab.plOId;
            } else if (node.getObj() instanceof PLPageDefination){
                PLPageDefination pageDef = (PLPageDefination) node.getObj();
                funcId = pageDef.plOId;
            } else if (node.getObj() instanceof PLTabButton) {
                PLTabButton but = (PLTabButton)node.getObj();
                funcId = but.plOId;
            }
            if(!node.isLeaf() && node.getChildCount() == 0){
                setChildNode(node, node.getObj());
            }
            if(!(node.getObj() instanceof PLPageDefination)){//子节点不是操作
                if(!rightMap.containsKey(funcId)&&!funcId.equals("root")){
                    RoleRightObject roleRightObj = new RoleRightObject();
                    roleRightObj.setFuncId(funcId);
                    roleRightObj.setRightType(RightType.UI);
                    roleRightObj.setRightValue(0);//没有操作的模块权限值存储为0
                    roleRightObj.setRoleId(curRole.getId());
                    
                    roleRightObj.setCreateUser(currentUserName);
                    roleRightObj.setCreateTime(new Date());
                    roleRightObj.setModifyUser(currentUserName);
                    roleRightObj.setModifyTime(new Date());
                    roleRightObj.setLicensor("");
                    rightMap.put(funcId, roleRightObj);
                }
                for(int i = 0;i < node.getChildCount();i++){
                    //对每个子向下递归遍历
                    getRightValue((VCIBaseTreeNode)node.getChildAt(i),false);
                }
            }else{//子节点是操作
                if(!rightMap.containsKey(funcId)){
                    RoleRightObject roleRightObj = new RoleRightObject();
                    roleRightObj.setFuncId(funcId);
                    roleRightObj.setRightType(RightType.UI);
                    roleRightObj.setRightValue(countRightValue(node,true));//没有操作的模块权限值存储为0
                    roleRightObj.setRoleId(curRole.getId());
                    
                    roleRightObj.setCreateUser(currentUserName);
                    roleRightObj.setCreateTime(new Date());
                    roleRightObj.setModifyUser(currentUserName);
                    roleRightObj.setModifyTime(new Date());
                    roleRightObj.setLicensor("");
                    rightMap.put(funcId, roleRightObj);
                }
            }
        }
    }
    
    /**
     * 传入直接挂接操作的模块的节点,计算该节点的权限值
     * @param node 模块节点
     * @param isAll 是否子级全部选中
     * @return
     */
    private long countRightValue(VCIBaseTreeNode node,boolean isAll){
        long value = 0;
        for(int i = 0;i < node.getChildCount();i++){
            VCIBaseTreeNode childNode = (VCIBaseTreeNode)node.getChildAt(i);
            if(isAll || treeManager.getSelectionModel().isPathSelected(new TreePath(childNode.getPath()))){
                PLTabButton obj = (PLTabButton)childNode.getObj();
                value += (long)Math.pow(2, obj.plSeq);//累计加上各个操作的权限值
            }
        }
        return value;
    }
    
    private void setChildNode(VCIBaseTreeNode node ,Object funcObj) {
        if (funcObj instanceof BtmItem) {
            BtmItem btmItem = (BtmItem) funcObj;
            List<PLUILayout> contexts = uiDataFechter.getContext(btmItem.name);
            if (contexts == null) {
                return;
            }
            for(PLUILayout context : contexts){
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(context.plName+"("+context.plCode+")", context);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(context.plOId, context.plCode);
                setChildNode(curNode, context);
            }
        } else if (funcObj instanceof PLUILayout) {
            PLUILayout context = (PLUILayout) funcObj;
            List<PLTabPage> tabs = uiDataFechter.getTabs(context.plOId);
            if (tabs == null) {
                return;
            }
            for(PLTabPage tab : tabs){
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(tab.plName, tab);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(tab.plOId, tab.plName);
                setChildNode(curNode, tab);
            }
        } else if (funcObj instanceof PLTabPage) {
            PLTabPage tab = (PLTabPage) funcObj;
            List<PLPageDefination> pageDefinations = uiDataFechter.getComopnent(tab.plOId);
            if (pageDefinations == null) {
                return;
            }
            for (PLPageDefination pageDefination : pageDefinations) {
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(pageDefination.name, pageDefination);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(pageDefination.plOId, pageDefination.name);
                setChildNode(curNode, pageDefination);
            }
        } else if (funcObj instanceof PLPageDefination) {
            PLPageDefination pageDef = (PLPageDefination) funcObj;
            List<PLTabButton> buttons = uiDataFechter.getButtons(pageDef.plOId);
            if (buttons == null) {
                return;
            }
            for(PLTabButton button : buttons){
                if(!button.show.equals("0")){
                    continue;
                }
                VCIBaseTreeNode curNode  = new VCIBaseTreeNode(button.plLabel, button);
                treeModel.insertNodeInto(curNode, node,node.getChildCount());
                funMap.put(button.plTableOId, button.plLabel);
                setChildNode(curNode, button);
                curNode.setLeaf(true);
            }
        }
        else if (funcObj instanceof PLTabButton) {
            node.setLeaf(true);
        }
    }
    
    /**
     * 校验
     * 
     * @return
     */
    public boolean checkItem() {
        //modify by weidy@2019-02-17
        //修改模块的名称
        LogonApplication.getUserEntityObject().setModules(this.getModuleName());
//        UserEntityObject ueo = LogonApplication.getUserEntityObject();
//        if(getFuncObj() != null && StringUtils.isNotBlank(getFuncObj().getName())) {    
//            ueo.setModules(getFuncObj().getName());
//        }else {
//            ueo.setModules("授权");
//        }
//        LogonApplication.userEntityObject = ueo;
        //end weidy
        if (roleList.getSelectedValue() == null|| "null".equals(roleList.getSelectedValue())) {
            message("rmip.framework.rightdistribution.moduleRight.roleListNotNull.message","RMIPFramework");
            return false;
        }
        return true;
    }
    
    private void message(String proValue, String fileName) {
        VCIOptionPane.showMessage(LogonApplication.frame,LocaleDisplay.getI18nString(proValue, fileName, getLocale()));
    }
    
    /**
     * 
     */
    private static final long serialVersionUID = 120493240584388454L;
 
    @Override
    public String getUserID() {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public String getRoleID() {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public JPanel getModuleComponent() {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public String getModuleName() {
        // TODO Auto-generated method stub
        if (this.getFuncObj() != null && this.getFuncObj().getName() != null)
            return  this.getFuncObj().getName();
        else if (moduleName != null && !moduleName.isEmpty())
            return moduleName;
        else
            return this.getClass().getName();
        
        //return null;
    }
 
    @Override
    public String getIconName() {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public String getModuleShowInfo() {
        // TODO Auto-generated method stub
        return null;
    }
 
    
    private LinkedHashMap<RoleObject, RoleRightObject[]> roleRightObjsMap = new LinkedHashMap<RoleObject, RoleRightObject[]>();
    private void saveToTemp(){
        if(!isSelectedRole()) return;
        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
        RoleRightObject[] lastRoleRightObjs = getSelectedRoleRightObjs(treePath);
        if(roleRightObjsMap.containsKey(curRole)){
            roleRightObjsMap.remove(curRole);
        }
        roleRightObjsMap.put(curRole, lastRoleRightObjs);
        VCIJOptionPane.showMessage(this, "存储成功!");
    }
    private void applyFromTemp(){
        if(!isSelectedRole()) return;
        if(roleRightObjsMap.size() == 0){
            VCIJOptionPane.showMessage(this, "请先存储模板!");
            return;
        }
        int index = 0;
        int size = roleRightObjsMap.size();
        RoleObject[] roles = new RoleObject[size];
        RoleRightObject[] lastRoleRightObjs = new RoleRightObject[0];
        Iterator<RoleObject> it = roleRightObjsMap.keySet().iterator();
        while(it.hasNext()){
            RoleObject roleObj = it.next();
            roles[index] = roleObj;
            lastRoleRightObjs = roleRightObjsMap.get(roleObj);
            index += 1;
        }
        
        if(size == 1){
            tree.clearSelection();
            treeManager.getSelectionModel().clearSelection();
            visitAllTreeNode(rootNode, lastRoleRightObjs);
        } else {
            Object[] messages = new Object[2];            
            messages[0] = new VCIJLabel("请选择:");
            VCIJPanel pal = new VCIJPanel(new BorderLayout());
            VCIJList list = new VCIJList(roles);
            list.setSelectedIndex(0);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            pal.add(new VCIJScrollPane(list), BorderLayout.CENTER);
            pal.setPreferredSize(new Dimension(200, 100));
            messages[1] = pal;
            Object[] options = {"确定","取消"};
            int res = VCIJOptionPane.showOptionDialog(
                    LogonApplication.frame, 
                    messages, 
                    "选择模板", 
                    VCIJOptionPane.DEFAULT_OPTION, 
                    VCIJOptionPane.INFORMATION_MESSAGE,
                    null, 
                    options,
                    options[0]);
            if(res == 0){
                RoleObject roleObj = (RoleObject)list.getSelectedValue();
                lastRoleRightObjs = roleRightObjsMap.get(roleObj);
                tree.clearSelection();
                treeManager.getSelectionModel().clearSelection();
                visitAllTreeNode(rootNode, lastRoleRightObjs);
                VCIJOptionPane.showMessage(this, "应用成功!");
            } 
        }
    }
    private boolean isSelectedRole(){
        if(curRole == null) {
            VCIJOptionPane.showMessage(this, "请先选择角色!");
            return false;
        }
        return true;
    }
    
}