田源
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
/**
 * <p>Title:</p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (C) 2011 </p>
 * <p>Company: VCI </p>
 * @author Bear
 * @time 2011-7-29
 * @version 1.0
 */
package com.vci.client.framework.systemConfig.stafforgmanage;
 
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
import com.vci.client.LogonApplication;
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.object.UserCompInfoObject;
import com.vci.client.framework.util.ClientHelper;
import com.vci.client.framework.util.RightControlUtil;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.table.ChoiceColumnTable;
import com.vci.client.ui.table.VCIBaseTableModel;
import com.vci.client.ui.table.VCIBaseTableNode;
 
public class DisplayTablePanel extends JPanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = -2763155025351308165L;
 
    private String[] columns = {};
    private Class[] classes = {};
    private VCIBaseTableModel tableModel = null;
    private ChoiceColumnTable choiseTable = null;
    private JTable table = null;
    public DisplayTablePanel(){
        init();
    }
    private void init(){
        initControl();
    }
    private void initControl(){
        initTable();
    }
    private void initTable(){
        columns = new String[5];
        classes = new Class[5];
        columns[0] = "";
        classes[0] = String.class;    
        
        columns[1] = "部门";
        classes[1] = String.class;    
        
        columns[2] = "用户名";
        classes[2] = String.class;    
        
        columns[3] = "真实姓名";
        classes[3] = String.class;
        
        columns[4] = "角色";
        classes[4] = String.class;    
        
        tableModel = new VCIBaseTableModel(columns, classes);
        choiseTable = new ChoiceColumnTable(tableModel);
        JScrollPane jspTable = choiseTable.createChoiceColumnTable();
        this.setLayout(new BorderLayout());
        this.add(jspTable, BorderLayout.CENTER);
        table = choiseTable.getPropertyTable();
    }
    
    private void fillTable(UserCompInfoObject[] objs){
        tableModel.list.clear();
        for(UserCompInfoObject obj:objs){
            VCIBaseTableNode tableNode = new VCIBaseTableNode(obj);
            String deptName = obj.getDeptObj()== null ? "" : obj.getDeptObj().getName(); 
            tableNode.setPropertyValueByName(columns[1], deptName);
            tableNode.setPropertyValueByName(columns[2], obj.getUserObj().getUserName());
            tableNode.setPropertyValueByName(columns[3], obj.getUserObj().getTrueName());
            tableNode.setPropertyValueByName(columns[4], obj.getRoleObj());
            tableModel.addRow(tableModel.getRowCount(), tableNode);
        }
        tableModel.fireTableDataChanged();
    }
    public String getI18nString(String spCode){
        return ClientHelper.getI18nStringForFramework(this.getClass().getName() + "." + spCode, this.getLocale());
    }
    /**
     * 返回数据的 JTable 对象
     * @return
     */
    public JTable getJTable(){
        return table;
    }
    
    /**
     * 返回数据的 TableModel 对象
     * @return
     */
    public VCIBaseTableModel getTableModel(){
        return tableModel;
    }
    /**
     * 返回表格选择的数据行的索引
     * @return
     */
    public int[] getSelectedRowIndexs(){
        return choiseTable.getPropertyTableSelectedRows();
    }
    
    /**
     * 加载用户信息
     * @param exportTempId
     */
    public int reloadUserCompList(String id,String type,String name){
        List<UserCompInfoObject> list = new ArrayList<UserCompInfoObject>();
        try {
            RightManagementClientDelegate del = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
            if("dept".equals(type)) {
                DeptObject[] deptObjs = null;
                if("root".equals(id)) {
                    deptObjs = del.fetchDepartmentInfo();
                }else {
                    deptObjs = del.fetchDepartmentInfosById(id);
                }
                for(DeptObject dept:deptObjs) {
                    UserObject[] objs = del.getUserByDeptId(dept.getId());
                    for(int i=0;i<objs.length;i++) {
                        String userName = objs[i].getUserName();
                        if(new RightControlUtil().isAdminOrDeveloperOrRoot(userName)) {
                            continue;
                        }
                        UserCompInfoObject compObj = new UserCompInfoObject();
                        compObj.setUserObj(objs[i]);
                        compObj.setDeptObj(dept);
                        RoleObject[] roles = del.fetchRoleInfoByUserId(objs[i].getId());
                        //获取角色
                        String roleName = "";
                        for(RoleObject role :roles) {
                            roleName +=role.getName()+",";
                        }
                        if(!"".equals(roleName)) {
                            compObj.setRoleObj(roleName.substring(0,roleName.length()-1));
                        }else {
                            compObj.setRoleObj("");
                        }
                        list.add(compObj);
                    }
                }
            }else if("role".equals(type)) {
                list.clear();
                UserObject[] userObjs = null;
                if("root".equals(id)){
                    userObjs = del.fetchUserInfo();
                }else {
                    userObjs = del.selectUserByRoleId(id);
                }
                for(UserObject user:userObjs) {
                    if(new RightControlUtil().isAdminOrDeveloperOrRoot(user.getUserName())) {
                        continue;
                    }
                    UserCompInfoObject compObj = new UserCompInfoObject();
                    if("root".equals(id)) {
                        RoleObject[] objs = del.fetchRoleInfoByUserId(user.getId());
                        String roleName = "";
                        for(int k=0;k<objs.length;k++) {
                            if(k == objs.length-1) {
                                roleName += objs[k].getName();
                            }else {
                                roleName += objs[k].getName()+",";
                            }
                        }
                        compObj.setRoleObj(roleName);
                    }else {
                        compObj.setRoleObj(name);
                    }
                    compObj.setUserObj(user);
                    DeptObject obj = del.fetchDeptByUserId(user.getId());
                    compObj.setDeptObj(obj);
                    list.add(compObj);
                }
            }
            this.fillTable(list.toArray(new UserCompInfoObject[]{}));
        }catch (VCIException e) {
            e.printStackTrace();
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
        }
        return list.size();
    }
    
}