田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.client.workflow.task;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.TransmitTreeObject;
import com.vci.client.common.objects.DeptObject;
import com.vci.client.common.objects.RoleObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.systemConfig.stafforgmanage.RightManagementTreeCellRenderer;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.VCIBaseTree;
import com.vci.client.ui.tree.VCIBaseTreeModel;
import com.vci.client.ui.tree.VCIBaseTreeNode;
import com.vci.client.workflow.delegate.EventConfClientDelegate;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.editor.ui.CustomClassTableModel;
import com.vci.client.workflow.editor.ui.PropertyObject;
import com.vci.corba.common.VCIError;
 
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * 任务指派
 * @author liudi
 *
 * 2013-7-5
 */
public class AppointTaskDialog extends JDialog {
    private JLabel curTaskNameLab;
    private JScrollPane tableScrollPane;
    private JButton cancelBtn;
    private JButton okBtn;
    private JTable eventTable;
    private JLabel eventLab;
    private JComboBox appointTaskCombo;
    private JLabel appointTaskLab;
    private JTextField curTaskNameText;
    private JButton deleteBtn;
    private JButton addBtn;
    private JTextField jtfAddPerson;
    private JLabel jlAddPerson;
    private JButton btnAddPerson;
    
    private String curtTaskName;
    private String executionId;
    
    private String eventType = "appoint";
    
    private UserObject userInfo;
    private String userName = LogonApplication.getUserEntityObject().getUserName();
    private VCIBaseTree rightManagementTree;
    private TransmitTreeObject transmitTreeObject = new TransmitTreeObject();
    private VCIBaseTreeModel treeModel;
 
    private JList list;
    private DefaultListModel listModel;
    private JList userList;
    private JList roleList;
    private JList deptList;
 
    private DefaultListModel userListModel;
    private DefaultListModel roleListModel;
    private DefaultListModel deptListModel;
    
    //存放用户信息
    private List<UserObject> userObjectlist = new ArrayList<UserObject>();
    //存放角色信息
    private List<RoleObject> roleObjectlist = new ArrayList<RoleObject>();
    //存放部门信息
    private List<DeptObject> deptObjectlist = new ArrayList<DeptObject>();
 
//    private KJButton okBtn = new KJButton(this.getI18nString("btnOk"), "ok.gif");
//    private KJButton cancelBtn = new KJButton(this.getI18nString("btnCancel"), "cancel.gif");
 
    private JRadioButton userButton = new JRadioButton("成员");
//    private JRadioButton roleButton = new JRadioButton("角色");
//    private JRadioButton departButton = new JRadioButton("部门");
    JScrollPane scrollPane_1 = new JScrollPane();
//    JScrollPane scrollPane_2 = new JScrollPane();
    //选中某一按钮,记录下所选按钮的对象名称
    private String radioChoseFlag = "user";
    
    /**
    * Auto-generated main method to display this 
    * JPanel inside a new JFrame.
    */
    public AppointTaskDialog(String taskName,String executionId) {
        super(LogonApplication.frame,true);
        this.curtTaskName = taskName;
        this.executionId = executionId;
        initGUI();
        displayCenter();
        setVisible(true);
    }
    /**
     *显示在屏幕中央 
     */
    private void displayCenter() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = this.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        this.setLocation((screenSize.width - frameSize.width) / 2,
                       (screenSize.height - frameSize.height) / 2);
        this.setModal(true);
    }
    private void initGUI() {
        try {
            this.setTitle("任务指派 ");
            this.setSize(new java.awt.Dimension(470, 750));
            setLayout(new BorderLayout());
            
            JScrollPane contentJsp = new JScrollPane();
            JPanel mainPanel = new JPanel();
            mainPanel.setLayout(new BorderLayout());
            JScrollPane viewImgePanel = new JScrollPane();
            ViewExecutionImagePanel viewPanel = new ViewExecutionImagePanel(executionId, curtTaskName);
            viewImgePanel.getViewport().add(viewPanel);
            
            mainPanel.add(viewImgePanel,BorderLayout.NORTH);
            
            JPanel contentPanel = new JPanel();
//            JScrollPane jsp = new JScrollPane();
            JPanel jsp = new JPanel();
            jsp.setLayout(new BorderLayout());
            contentPanel.setLayout(null);
            JPanel panelLeft = new JPanel();
            JPanel panelRight = new JPanel();
            panelRight = getUserSelectionPanel();
//            panelLeft.setLayout(new BorderLayout());
//            panelLeft.add(jsp,BorderLayout.CENTER);
//            panelLeft.add(panelRight,BorderLayout.EAST);
            jsp.add(contentPanel,BorderLayout.CENTER);
            jsp.add(panelRight,BorderLayout.EAST);
            mainPanel.add(jsp);
            add(mainPanel,BorderLayout.CENTER);
            {
                curTaskNameLab = new JLabel();
                contentPanel.add(curTaskNameLab);
                curTaskNameLab.setText("当前任务名称:");
                curTaskNameLab.setBounds(72, 53, 85, 17);
            }
            {
                curTaskNameText = new JTextField();
                curTaskNameText.setText(curtTaskName);
                curTaskNameText.setEditable(false);
                contentPanel.add(curTaskNameText);
                curTaskNameText.setBounds(183, 49, 152, 24);
            }
            {
                appointTaskLab = new JLabel();
                contentPanel.add(appointTaskLab);
                appointTaskLab.setText("指派任务名称:");
                appointTaskLab.setBounds(72, 105, 85, 17);
            }
            {
                ComboBoxModel appointTaskComboModel = 
                    new DefaultComboBoxModel();
                appointTaskCombo = new JComboBox();
                contentPanel.add(appointTaskCombo);
                appointTaskCombo.setModel(appointTaskComboModel);
                appointTaskCombo.setBounds(183, 101, 152, 24);
                String deployId = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getDeploymentIdByExecutionId(executionId);
                String[] taskNames = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getAllTaskNames(deployId);
                for(String taskName : taskNames){
                    if(!curtTaskName.equals(taskName)){
                        appointTaskCombo.addItem(taskName);
                    }
                }
            }
            {
                eventLab = new JLabel();
                contentPanel.add(eventLab);
                eventLab.setText("指派任务事件");
                eventLab.setBounds(72, 153, 132, 17);
            }
            {
                tableScrollPane = new JScrollPane();
                contentPanel.add(tableScrollPane);
                tableScrollPane.setBounds(72, 176, 268, 143);
                {
                    tableScrollPane.setViewportView(getCustomProperty());
                }
            }
            {
                okBtn = new JButton();
                contentPanel.add(okBtn);
                okBtn.setText("确定");
                okBtn.setBounds(128, 343, 62, 24);
                okBtn.addActionListener(new ActionListener() {
                    
                    public void actionPerformed(ActionEvent e) {
                        ProcessCustomClientDelegate clientDelagate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
                        String tagActivityName = (String) appointTaskCombo.getSelectedItem();
                        int rowCount = eventTable.getRowCount();
                        String[] classNames = new String[rowCount];
                        for(int i=0;i<rowCount;i++){
                            String valueAt = (String) eventTable.getModel().getValueAt(i, 0);
                            PropertyObject[] eventTypes = getEventTypes(eventType);
                            for(int p =0;p<eventTypes.length;p++){
                                String className = eventTypes[p].getValue();
                                String classValue = "";
                                String initEventClass = "";
                                classValue = eventTypes[p].getProperty();
                                /*initEventClass = EventProperties.getStringProperty("workflow.event.type." + classValue
                                        + ".class");*/
                                //add by caill start 2016.4.8 通过corba连接服务端
                                try {
                                    initEventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type." + classValue
                                            + ".class");
                                } catch (VCIError en) {
                                    // TODO Auto-generated catch block
                                    en.printStackTrace();
                                }
                                //add by caill end
                                if(valueAt.equals(className)){
                                    classNames[i] = initEventClass;
                                }
                            }
                        }
                        //选择的候选人数组
                        
                        if(userListModel.size() == 0){
                            VCIOptionPane.showMessage(LogonApplication.frame, "请选择候选人!");
                            return;
                        }
                        String[] userNames = new String[userListModel.size()];
                        userObjectlist.clear();
                        for (int i =0;i<userListModel.size();i++) {
                            Object object = userListModel.get(i);
                            UserObject obj = (UserObject)object;
                            userNames[i] = new String();
                            userNames[i] = obj.getUserName();
                        }
                        boolean appointTask = clientDelagate.appointTask(curtTaskName, tagActivityName, classNames, executionId, userNames );
                        if(appointTask){
                            VCIOptionPane.showMessage(LogonApplication.frame, "指派成功");
                        }else{
                            VCIOptionPane.showMessage(LogonApplication.frame, "指派失败");
                        }
                        dispose();
                    }
                });
            }
            {
                cancelBtn = new JButton();
                contentPanel.add(cancelBtn);
                contentPanel.add(getJButton1());
                contentPanel.add(getJButton2());
                cancelBtn.setText("关闭");
                cancelBtn.setBounds(232, 343, 62, 24);
                cancelBtn.addActionListener(new ActionListener() {
                    
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });
                addBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        CustomClassTableModel model = (CustomClassTableModel)eventTable.getModel();
                        model.addRow();
                    }
                });
                
                deleteBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        int[] selectedRows = eventTable.getSelectedRows();
                        CustomClassTableModel model = (CustomClassTableModel)eventTable.getModel();
                        model.deleteRow(selectedRows);
                    }
                });
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private JTable getCustomProperty() {
        if(eventTable == null) {
            eventTable = new JTable(new CustomClassTableModel());
            eventTable.setRowHeight(20);
 
            Dimension size = eventTable.getTableHeader().getPreferredSize();
            size.height = 22;
            eventTable.getTableHeader().setPreferredSize(size);
//            customTable.setPreferredScrollableViewportSize(new Dimension(300, 50));
            
            
            JComboBox c = new JComboBox(getEventTypes(eventType));//
            eventTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(c));
        }
        return eventTable;
    }
    private PropertyObject[] getEventTypes(String eventType) {
        /*String[] types = EventProperties.getStringProperty("workflow.event.type."+eventType).split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types =  null;
        try {
             types = new EventConfClientDelegate().getStringProperty("workflow.event.type."+eventType).split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
        List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
        taskTypes.add(new PropertyObject("", ""));
        for (int i = 0; i < types.length; i++) {
            if("".equals(types[i].trim())) continue;
            /*taskTypes.add(new PropertyObject(types[i],
                    EventProperties.getStringProperty("workflow.event.type.appoint." + types[i])));*/
            //add by caill start 2016.4.8 通过corba连接服务端
            try {
                taskTypes.add(new PropertyObject(types[i],
                        new EventConfClientDelegate().getStringProperty("workflow.event.type.appoint." + types[i])));
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //add by caill end
        }
        return taskTypes.toArray(new PropertyObject[0]);
    }
    private String getI18nForEvent(String key) {
        return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
    }
    
    private JButton getJButton1() {
        if(addBtn == null) {
            addBtn = new JButton();
            addBtn.setText("添加");
            addBtn.setBounds(346, 198, 62, 24);
        }
        return addBtn;
    }
    
    private JButton getJButton2() {
        if(deleteBtn == null) {
            deleteBtn = new JButton();
            deleteBtn.setText("删除");
            deleteBtn.setBounds(346, 228, 62, 24);
        }
        return deleteBtn;
    }
    private JPanel getUserSelectionPanel(){
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());
        JPanel panel = new JPanel();
        JPanel topPanel = new JPanel();
        ButtonGroup bgroup = new ButtonGroup();
        bgroup.add(userButton);
//        bgroup.add(roleButton);
//        bgroup.add(departButton);
        userButton.setSelected(true);
        topPanel.add(userButton);
//        topPanel.add(roleButton);
//        roleButton.setSelected(true);
//        topPanel.add(departButton);
        mainPanel.add(topPanel, BorderLayout.NORTH);
        mainPanel.add(panel, BorderLayout.CENTER);
        panel.setLayout(new BorderLayout(0, 0));
 
        JPanel panel_1 = new JPanel();
        panel.add(panel_1, BorderLayout.CENTER);
        GridBagLayout gbl_panel_1 = new GridBagLayout();
        panel_1.setLayout(gbl_panel_1);
 
        JPanel panel_2 = new JPanel();
        GridBagConstraints gbc_panel_2 = new GridBagConstraints();
        gbc_panel_2.weighty = 1.0;
        gbc_panel_2.weightx = 1.0;
        gbc_panel_2.insets = new Insets(0, 0, 0, 5);
        gbc_panel_2.fill = GridBagConstraints.BOTH;
        gbc_panel_2.gridx = 0;
        gbc_panel_2.gridy = 0;
        panel_1.add(panel_2, gbc_panel_2);
        panel_2.setLayout(new BorderLayout(0, 0));
        Dimension listDim = new Dimension(150, 200);
        JScrollPane scrollPane = new JScrollPane();
        panel_2.add(scrollPane);
        scrollPane.setPreferredSize(listDim);
 
        final VCIBaseTreeNode rootNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.stafforg.menu.staffOrg", "RMIPFramework", getLocale()), "root");
        treeModel = new VCIBaseTreeModel(rootNode);
        initUserTree(rootNode, "root");
//        initTree(rootNode, "root");
//        initDepartTree(rootNode, "root");
        userButton.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e) {
                rootNode.removeAllChildren();
                initUserTree(rootNode, "root");
                treeModel.reload();
//                int size = userListModel.getSize();
//                for(int i=0;i<size;i++){
//                    UserObject object = (UserObject) userListModel.getElementAt(i);
//                    userListModel.addElement(object);
//                }
                radioChoseFlag = "user";
                scrollPane_1.setViewportView(userList);
            }
        });
//        roleButton.addActionListener(new ActionListener() {
//            
//            public void actionPerformed(ActionEvent e) {
//                rootNode.removeAllChildren();
//                userListModel.removeAllElements();
//                initTree(rootNode, "root");
//                treeModel.reload();
////                int size = roleListModel.getSize();
////                for(int i=0;i<size;i++){
////                    RoleObject object = (RoleObject) roleListModel.getElementAt(i);
////                    roleListModel.addElement(object);
////                }
//                radioChoseFlag = "user";
//                scrollPane_1.setViewportView(userList);
//                
//                
//            }
//        });
//
//        departButton.addActionListener(new ActionListener() {
//            
//            public void actionPerformed(ActionEvent e) {
//                rootNode.removeAllChildren();
//                userListModel.removeAllElements();
//                initDepartTree(rootNode, "root");
//                treeModel.reload();
////                int size = deptListModel.getSize();
////                for(int i=0;i<size;i++){
////                    DeptObject object = (DeptObject) deptListModel.getElementAt(i);
////                    deptListModel.addElement(object);
////                }
//                radioChoseFlag = "user";
//                scrollPane_1.setViewportView(userList);
//            }
//        });
        
        rightManagementTree = new VCIBaseTree(treeModel, new RightManagementTreeCellRenderer());
        scrollPane.setViewportView(rightManagementTree);
 
        JPanel panel_5 = new JPanel();
        GridBagConstraints gbc_panel_5 = new GridBagConstraints();
        gbc_panel_5.weightx = 1.0;
        gbc_panel_5.weighty = 1.0;
        gbc_panel_5.insets = new Insets(0, 0, 0, 5);
        gbc_panel_5.fill = GridBagConstraints.NONE;
        gbc_panel_5.gridx = 1;
        gbc_panel_5.gridy = 0;
        panel_1.add(panel_5, gbc_panel_5);
        panel_5.setLayout(new BorderLayout(0, 0));
        JButton rightChose = new JButton(">>");
        panel_5.add(rightChose,BorderLayout.NORTH);
        JButton liftRight = new JButton("<<");
        panel_5.add(liftRight);
        
        JPanel panel_4 = new JPanel();
        GridBagConstraints gbc_panel_4 = new GridBagConstraints();
        gbc_panel_4.weightx = 1.0;
        gbc_panel_4.weighty = 1.0;
        gbc_panel_4.insets = new Insets(0, 0, 0, 5);
        gbc_panel_4.fill = GridBagConstraints.BOTH;
        gbc_panel_4.gridx = 2;
        gbc_panel_4.gridy = 0;
        panel_1.add(panel_4, gbc_panel_4);
        panel_4.setLayout(new BorderLayout(0, 0));
        panel_4.add(scrollPane_1);
        listModel = new DefaultListModel();
        list = new JList(listModel);
        list.setBackground(Color.WHITE);
        
        userListModel = new DefaultListModel();
        roleListModel = new DefaultListModel();
        deptListModel = new DefaultListModel();
        userList = new JList(userListModel);
        roleList = new JList(roleListModel);
        deptList = new JList(deptListModel);
        scrollPane_1.setViewportView(userList);
        scrollPane_1.setPreferredSize(listDim);
        
        rightChose.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addToUserListFromTreeNode(true);
            }
        });
        liftRight.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                removeUserFromUserList(true);
            }
        });
        userList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() != 2) return;
                removeUserFromUserList(false);
            }
        });
        roleList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() != 2) return;
                removeUserFromUserList(false);
            }
        });
        deptList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() != 2) return;
                removeUserFromUserList(false);
            }
        });
        
        init();
        pack();
        return mainPanel;
    }
    private void init() {
        rightManagementTree.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() != 2) return;
                TreePath path = rightManagementTree.getPathForLocation(e.getX(), e.getY());
                if(path == null) return;
                if(path != null && !(path.getLastPathComponent() instanceof VCIBaseTreeNode)) return;
                VCIBaseTreeNode clickedNode = (VCIBaseTreeNode)path.getLastPathComponent();
                if(clickedNode.getLevel()<3) return;
                transmitTreeObject.setCurrentTreeNode(clickedNode);
                addToUserListFromTreeNode(false);
            }
        });
        rightManagementTree.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
//                rightManagementTree_valueChanged(e);
                TreePath treePath = e.getPath();
                VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
                transmitTreeObject.setCurrentTreeNode(selectNode);
            }
        });
 
        /**
         * 树的展开事件
         */
        rightManagementTree.addTreeExpansionListener(new TreeExpansionListener() {
            public void treeExpanded(TreeExpansionEvent event) {
                TreePath treePath = event.getPath();
                VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
                transmitTreeObject.setCurrentTreeNode(selectNode);
                Object object = selectNode.getObj();
                if (!selectNode.isExpand()) {
                    selectNode.setExpand(true);
                    transmitTreeObject.getCurrentTreeNode().removeAllChildren();
                    
                    if (object instanceof UserObject) {
                        UserObject user = (UserObject) object;
                        if (user.getId().equals("root")) {
                            UserObject[] userInfos;
                            try {
                                userInfos = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfo();
                                for (UserObject userObject : userInfos) {
                                    treeModel.insertNodeInto(new VCIBaseTreeNode(userObject.toString(), userObject), selectNode, selectNode.getChildCount());
                                }
                            } catch (VCIException e) {
                                e.printStackTrace();
                            }
                        }
                    }
//                    if (object instanceof RoleObject) {
//                        RoleObject role = (RoleObject) object;
//                        if (role.getId().equals("root")) {
//                            try {
//                                RoleObject[] roleInfos = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchRoleInfo();
//
//                                for (RoleObject roleObject : roleInfos) {
//                                    treeModel.insertNodeInto(new VCIBaseTreeNode(roleObject.getName(), roleObject), selectNode, selectNode.getChildCount());
//                                }
//
//                            } catch (VCIError e) {
//                                e.printStackTrace();
//                            }
//                        }
////                        else{
////                            try {
////                                UserObject[] userObj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUsersByRoleId(role.getId());
////                                for(UserObject userobj:userObj){
////                                    treeModel.insertNodeInto(new VCIBaseTreeNode(userobj.toString(), userobj),selectNode, selectNode.getChildCount());
////                                }
////                            } catch (VCIException e) {
////                                VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
////                                e.printStackTrace();
////                            }
////                        }
//                    }
//                    if (object instanceof DeptObject){
//                        try {
//                            DeptObject[] DeptInfos = null;
//                            if (((DeptObject) object).getId().equals("root")){
//                                DeptInfos= new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
//                                                    .fetchDeptInfoRoot();
//                                if (DeptInfos == null){
//                                    return;
//                                }
//                                int len = DeptInfos.length;
//                                for (int i = 0; i < len; i++) {
//                                    treeModel.insertNodeInto(new VCIBaseTreeNode(DeptInfos[i].getName(), DeptInfos[i]),selectNode,selectNode.getChildCount());
//                                }
//                            }else if(((DeptObject) object).getId().equals("")){
//                                DeptInfos = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
//                                                      .fetchDeptInfoByParentId(((DeptObject) object).getId());
//                                if (DeptInfos == null){
//                                    return;
//                                }
//                                int len = DeptInfos.length;
//                                for (int i = 0; i < len; i++) {
//                                    treeModel.insertNodeInto(new VCIBaseTreeNode(DeptInfos[i].getName(), DeptInfos[i]),selectNode,selectNode.getChildCount());
//                                }
//                            }else{
////                                try {
//                                    UserObject[] userObj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).getUserByDeptList(((DeptObject) object).getId());
//                                    for (UserObject userobj : userObj) {
//                                        treeModel.insertNodeInto(new VCIBaseTreeNode(userobj.toString(), userobj), selectNode, selectNode.getChildCount());
//                                    }
////                                }catch (VCIException e) {
////                                    VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
////                                    e.printStackTrace();
////                                }
//                            }
//                        } catch (VCIException e) {
//                            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
//                            return;
//                        } catch (VCIError e) {
//                            e.printStackTrace();
//                        }            
//                    }
                }
            }
 
            public void treeCollapsed(TreeExpansionEvent arg0) {
 
            }
        });
        transmitTreeObject.setTreeModel(treeModel);
        transmitTreeObject.setTree(rightManagementTree);
 
    }
    private void initUserTree(VCIBaseTreeNode rootNode, String puid) {
//        try {
//            userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
//        } catch (VCIException e) {
//            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
//            return;
//        }
        UserObject userObject = new UserObject();
        userObject.setId("root");
        VCIBaseTreeNode userNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.stafforg.menu.staff", "RMIPFramework", getLocale()), userObject);
        rootNode.add(userNode);
        
    }
    /**
     * <p>
     * Description: 初始化人员组织结构树
     * </p>
     * 
     * @author wangxl
     * @time 2011-5-31
     * @param rootNode
     * @param puid
     */
    private void initTree(VCIBaseTreeNode rootNode, String puid) {
//        try {
//            userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
//        } catch (VCIException e) {
//            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
//            return;
//        }
        RoleObject roleObject = new RoleObject();
        roleObject.setId("root");
        VCIBaseTreeNode roleNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.stafforg.menu.role", "RMIPFramework", getLocale()), roleObject);
        rootNode.add(roleNode);
 
    }
 
    /**
     * 初始化部门树 
     * @param rootNode
     * @param puid
     */
    private void initDepartTree(VCIBaseTreeNode rootNode, String puid) {
//        try {
//            userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
//        } catch (VCIException e) {
//            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
//            return;
//        }
        DeptObject rootDepartment = new DeptObject();
        rootDepartment.setId("root");
        VCIBaseTreeNode departmentNode = new VCIBaseTreeNode(
                LocaleDisplay.getI18nString("rmip.stafforg.menu.department",
                        "RMIPFramework", getLocale()), rootDepartment);
        rootNode.add(departmentNode);
    }
    private void addToUserListFromTreeNode(boolean batch){
        LinkedList<VCIBaseTreeNode> nodeList = new LinkedList<VCIBaseTreeNode>();
        TreePath[] paths = rightManagementTree.getSelectionPaths();
        if(batch && paths != null){
            for(TreePath path : paths){
                nodeList.add((VCIBaseTreeNode)path.getLastPathComponent());
            }
        } else{
            nodeList.add(transmitTreeObject.getCurrentTreeNode());
        }
        for(VCIBaseTreeNode selectNode : nodeList){
            if(selectNode == null) continue;
            Object object = selectNode.getObj();
            if (object instanceof UserObject) {
                UserObject user = (UserObject) object;
                if("root".equals(user.getId())){
                    continue;
                }
                if(checkUserIdAdded(user)) return;
                userListModel.addElement(object);
            }
            if (object instanceof RoleObject) {
                RoleObject role = (RoleObject) object;
                if("root".equals(role.getId())){
                    continue;
                }
                if(checkRoleIdAdded(role)) return;
                roleListModel.addElement(object);
            }
            if (object instanceof DeptObject) {
                DeptObject dept = (DeptObject) object;
                if("root".equals(dept.getId())){
                    continue;
                }
                if(checkDeptIdAdded(dept)) return;
                deptListModel.addElement(object);
            }
        }
    }
    private boolean checkUserIdAdded(UserObject obj){
        boolean res = false;
        int size = userListModel.getSize();
        for(int i = 0; i < size; i++){
            if(userListModel.get(i) instanceof UserObject){
                res = obj.getId().equals(((UserObject)userListModel.get(i)).getId());
                if(res) break;
            }
        }
        return res;
    }
    private boolean checkRoleIdAdded(RoleObject obj){
        boolean res = false;
        int size = roleListModel.getSize();
        for(int i = 0; i < size; i++){
            if(roleListModel.get(i) instanceof RoleObject){
                res = obj.getId().equals(((RoleObject)roleListModel.get(i)).getId());
                if(res) break;
            }
        }
        return res;
    }
    private boolean checkDeptIdAdded(DeptObject obj){
        boolean res = false;
        int size = deptListModel.getSize();
        for(int i = 0; i < size; i++){
            if(deptListModel.get(i) instanceof DeptObject){
                res = obj.getId().equals(((DeptObject)deptListModel.get(i)).getId());
                if(res) break;
            }
        }
        return res;
    }
    private void removeUserFromUserList(boolean batch){
        if(radioChoseFlag.equals("user")){
            Object[] selectedIndices = userList.getSelectedValues();
            if(!batch){
                selectedIndices = new Object[]{userList.getSelectedValue()};
            }
            for(int i =0;i<selectedIndices.length;i++){
                userListModel.removeElement(selectedIndices[i]);
            }
        }
        if(radioChoseFlag.equals("role")){
            Object[] selectedIndices = roleList.getSelectedValues();
            if(!batch){
                selectedIndices = new Object[]{roleList.getSelectedValue()};
            }
            for(int i =0;i<selectedIndices.length;i++){
                roleListModel.removeElement(selectedIndices[i]);
            }
        }
        if(radioChoseFlag.equals("depart")){
            Object[] selectedIndices = deptList.getSelectedValues();
            if(!batch){
                selectedIndices = new Object[]{deptList.getSelectedValue()};
            }
            for(int i =0;i<selectedIndices.length;i++){
                deptListModel.removeElement(selectedIndices[i]);
            }
        }
    }
}