wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.vci.client.uif.engine.client;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashMap;
import java.util.LinkedList;
 
import com.vci.client.common.objects.RoleObject;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.mw.ClientContextVariable;
 
public class SelectRoleDialog extends VCIJDialog{
    private VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "确定", "确定", "accept.png");
    private VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.png");
    
    private RoleObject roleObject;
    
    
    public RoleObject getRoleObject() {
        return roleObject;
    }
    public void setRoleObject(RoleObject roleObject) {
        this.roleObject = roleObject;
    }
 
    private UserEntityObject userEntityObj = null; 
    private Component parentComponent = null;
    public SelectRoleDialog(Component parentComponent){
        super(ClientContextVariable.getFrame(), true);
         this.userEntityObj = new UserEntityObject(
                ClientContextVariable.getInvocationInfo().userName, 
                ClientContextVariable.getInvocationInfo().clientIPInfo);
        init();
        setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
        this.parentComponent = parentComponent;
        setLocationRelativeTo(parentComponent);
        setVisible(true);
    }
    public void init(){
        setLayout(new BorderLayout());
        this.setTitle("选择角色");
        add(tablePanel(), BorderLayout.CENTER);
        initAction();//初始化按钮点击事件
    }
    
     private LinkedList<VCIJButton> selfCustomButtons = new LinkedList<VCIJButton>();
     {
         selfCustomButtons.add(btnOk);
         selfCustomButtons.add(btnCancel);
     }
     
    MyDataProvider dataProvider = new MyDataProvider();
    VCIJTablePanel<RoleObject> tablePanel = new VCIJTablePanel<RoleObject>(dataProvider);
    private VCIJPanel tablePanel(){
        int startIndex = dataProvider.getDataColumnStartIndex()+5;
        LinkedHashMap<Integer, Integer> widthMaps = new LinkedHashMap<Integer, Integer>();
        widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);
        widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);
        tablePanel.setColumnWidthMaps(widthMaps);
        tablePanel.setCustomButtons(selfCustomButtons);
        tablePanel.setShowPaging(true);
        tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setShowExport(false);
        tablePanel.buildTablePanel();
        tablePanel.refreshTableData();
        return tablePanel;
    }
    
    
    class MyDataProvider extends AbstractVCIJTableDataProvider<RoleObject>{
        RoleObject[]  roleObjs = null;
        @Override
        public RoleObject[] getDatas(int arg0, int arg1) {
            try {
                roleObjs = new RightManagementClientDelegate(userEntityObj).fetchRoleInfo();
            } catch (VCIException e) {
                    // TODO Auto-generated catch block
                e.printStackTrace();
                    VCIOptionPane.showError(parentComponent,"RMIPFramework", e);
            } 
            // TODO Auto-generated method stub
            return roleObjs;
        }
 
        @Override
        public VCIJTableNode<RoleObject> getNewRowNode(RoleObject dataObj) {
            // TODO Auto-generated method stub
            VCIJTableNode<RoleObject> node = new VCIJTableNode<RoleObject>(dataObj);
            node.setPropertyValue(getSpecialColumns()[0], dataObj.getName());
            node.setPropertyValue(getSpecialColumns()[1], dataObj.getDescription());
            return node;
        }
 
        @Override
        public String[] getSpecialColumns() {
            // TODO Auto-generated method stub
            return "名称,描述".split(",");
        }
 
        @Override
        public int getTotal() {
            // TODO Auto-generated method stub
            return roleObjs.length;
        }
 
    }
    private void initAction(){
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                cancelButton_ActionPerformed(e);
            }
        });
        btnOk.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                addButton_ActionPerformed();
            }
        });
    }
    /**
     * 确认按钮事件
     * <p>Description: </p>
     * @author heyj
     * @time 2014-3-25
     */
    private void addButton_ActionPerformed(){
        int len = tablePanel.getSelectedRowIndexs().length;
        if(len == 0){
            VCIOptionPane.showMessage(this, "请选择角色再进行操作!");
            return;
        }
        if (len > 1){
            VCIOptionPane.showMessage(this, "一次只能选择一个角色进行操作");
            return;
        }
        RoleObject obj = tablePanel.getSelectedRowObjects().get(0);
        this.setRoleObject(obj);
        this.dispose();
    }
    /**
     * 取消按钮事件
     * @param e
     */
    private void cancelButton_ActionPerformed(ActionEvent e) {
        this.roleObject = null;
        this.dispose();
    }
    
}