ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.client.framework.systemConfig.volumn;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
 
import com.vci.client.ClientSession;
import com.vci.client.LogonApplication;
import com.vci.client.common.objects.UserObject;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.systemConfig.stafforgmanage.ListLabelCellRenderForRightRole;
import com.vci.client.framework.systemConfig.volumn.object.PvolumeObject;
import com.vci.client.logon.base.BaseJDialog;
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.swing.VCIOptionPane;
import com.vci.corba.common.VCIError;
import com.vci.corba.framework.data.UserInfo;
import com.vci.corba.framework.data.PvolumeInfo;
 
/**
 * 文件柜增加成员界面管理
 * 
 * @author lw
 * 
 */
public class PvolumeUserDialog extends BaseJDialog {
 
    private static final long serialVersionUID = 1L;
    private JButton conformBut = new JButton(
            LocaleDisplay.getI18nString("rmip.stafforg.operate.conform", "RMIPFramework", getLocale()));
    private JButton cancelBut = new JButton(
            LocaleDisplay.getI18nString("rmip.stafforg.operate.cancel", "RMIPFramework", getLocale()));
    private JList allUserList = new JList(); // 所有成员
    private JList choosedUserList = new JList(); // 拥有成员
    private UserObject logonUserInfo = LogonApplication.getUserObject();
    private PvolumeObject pvolumeObj;
    private JTextField searceText = new JTextField();
 
    public PvolumeUserDialog(PvolumeObject pvolumeObject) {
        super(LogonApplication.frame);
        this.pvolumeObj = pvolumeObject;
        this.setModal(true);
        init();
    }
 
    /**
     * 初始化界面
     */
    private void init() {
        JLabel titleLabel = new JLabel();
        titleLabel.setText("文件柜添加成员");
        titleLabel.setIcon(new BundleImage().createImageIcon("pvolume.gif"));
        JPanel bottomPanel = new JPanel();
        bottomPanel.add(conformBut);
        bottomPanel.add(cancelBut);
 
        JPanel contentPanel = initCenterContentPanel();
        initUser(); // 初始化成员信息
        JPanel midPanel = new JPanel();
        midPanel.setLayout(new BorderLayout());
        JTextField jTextField1 = new JTextField();// instead of up line
        JTextField jTextField2 = new JTextField();// instead of down line
        jTextField1.setPreferredSize(new Dimension(63, 2));
        jTextField2.setPreferredSize(new Dimension(63, 2));
        midPanel.add(jTextField1, BorderLayout.NORTH);
        midPanel.add(jTextField2, BorderLayout.SOUTH);
        midPanel.add(contentPanel, BorderLayout.CENTER);
 
        this.setLayout(new BorderLayout());
        this.add(titleLabel, BorderLayout.NORTH);
        this.add(midPanel, BorderLayout.CENTER);
        this.add(bottomPanel, BorderLayout.SOUTH);
        // int x = (int)(this.getParent().getLocationOnScreen().getX()) + 200;
        // int y = (int)(this.getParent().getLocationOnScreen().getY()) + 80;
        // this.setLocation(x , y);
        // this.setSize(600, 450);
        initDialogSize(600, 450);
 
    }
 
    private UserObject[] selectUserObjs = null;
    private UserObject[] selectUserObj2 = null;
 
    private JPanel initCenterContentPanel() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
 
        JScrollPane jspAllRole = new JScrollPane();
        jspAllRole.getViewport().add(allUserList);
 
        JLabel searchName = new JLabel("文件柜人员");
        JButton queryBtn = new JButton("查询");
        searchName.setBounds(new Rectangle(100, 10, 90, 26));
        searceText.setBounds(new Rectangle(160, 10, 180, 26));
        queryBtn.setBounds(new Rectangle(370, 10, 60, 26));
        queryBtn.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent arg0) {
                DefaultListModel allListModel = (DefaultListModel) allUserList.getModel();
                String queryStr = searceText.getText().trim();
                allListModel.removeAllElements();
                initUser();
                if (!"".equals(queryStr)) {
                    int size = allUserList.getModel().getSize();
                    allListModel = new DefaultListModel();
                    for (int i = 0; i < size; i++) {
                        UserObject userObject = (UserObject) allUserList.getModel().getElementAt(i);
                        if (userObject.getTrueName().contains(queryStr)
                                || userObject.getUserName().contains(queryStr)) {
                            allListModel.addElement(userObject);
                        }
                    }
                    allUserList.setModel(allListModel);
                }
            }
        });
        contentPanel.add(searchName);
        contentPanel.add(searceText);
        contentPanel.add(queryBtn);
 
        jspAllRole.setPreferredSize(new Dimension(210, 300));
        jspAllRole.setBounds(new Rectangle(30, 50, 210, 300));
        jspAllRole.setBorder(new TitledBorder("文件柜外成员"));
        allUserList.setCellRenderer(new ListLabelCellRenderForRightRole());
 
        JScrollPane jspChooseRole = new JScrollPane();
        jspChooseRole.getViewport().add(choosedUserList);
        jspChooseRole.setPreferredSize(new Dimension(210, 300));
        jspChooseRole.setBounds(new Rectangle(330, 50, 210, 300));
        jspChooseRole.setBorder(new TitledBorder("文件柜内成员"));
        choosedUserList.setCellRenderer(new ListLabelCellRenderForRightRole());
 
        DefaultListModel selectListModel = new DefaultListModel();
        String pvolumeId = pvolumeObj.getId();
        short userType = logonUserInfo.getUserType();
 
        try {
            selectUserObjs = new RightManagementClientDelegate().fetchUserInfoByPvolumeId(pvolumeId, userType);
 
            for (int i = 0; i < 3; i++) {// 特殊处理,查询出不再当前角色中的选中人员
                if (userType == 0) {
                    selectUserObj2 = new RightManagementClientDelegate().fetchUserInfoByPvolumeId(pvolumeId, (short)1);
                } else if (userType == 1) {
                    selectUserObj2 = new RightManagementClientDelegate().fetchUserInfoByPvolumeId(pvolumeId, (short)0);
                } else {
                    selectUserObj2 = new RightManagementClientDelegate().fetchUserInfoByPvolumeId(pvolumeId, (short)3);
                }
            }
 
            int selectUserlength = 0;
            if (selectUserObjs.length == 0) {
                selectUserlength = selectUserObj2.length;
            } else if (selectUserObj2.length == 0) {
                selectUserlength = selectUserObjs.length;
            } else {
                selectUserlength = selectUserObjs.length + selectUserObj2.length;
            }
 
            if (selectUserlength != 0) {
                for (int i = 0; i < selectUserlength; i++) {
                    if (i < selectUserObjs.length) {
                        selectListModel.addElement(selectUserObjs[i]);
                    } else {
                        selectListModel.addElement(selectUserObj2[i - selectUserObjs.length]);
                    }
                }
            }
        } catch (VCIException e1) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
        }
 
        choosedUserList.setModel(selectListModel);
        JButton addButton = new JButton(">>");
        addButton.setBounds(260, 100, 50, 25);
 
        JButton removeButton = new JButton("<<");
        removeButton.setBounds(260, 250, 50, 25);
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_actionPerformed();
            }
        });
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                removeButton_actionPerformed();
            }
        });
 
        conformBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                conformCreate();
            }
        });
        cancelBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancelCreate();
            }
        });
        contentPanel.add(jspChooseRole);
        contentPanel.add(jspAllRole);
        contentPanel.add(addButton);
        contentPanel.add(removeButton);
        if (LogonApplication.getUserObject().getUserType() == 2) {
            addButton.setEnabled(false);
            removeButton.setEnabled(false);
        }
        return contentPanel;
 
    }
 
    /**
     * 初始化成员信息
     */
    private void initUser() {
        try {
            UserObject[] userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                    .fetchUserInfoByType(logonUserInfo.getUserType());
            int length = userInfo.length;
            DefaultListModel alllistModel = new DefaultListModel();
            DefaultListModel selectlistModel = (DefaultListModel) choosedUserList.getModel();
            int selectLenth = selectlistModel.getSize();
            for (int i = 0; i < length; i++) {
                if (userInfo[i].getStatus() == 1) {
                    continue;
                }
                boolean hasSelect = false;
                for (int j = 0; j < selectLenth; j++) {
                    UserObject selectUserInfo = (UserObject) selectlistModel.get(j);
                    if (selectUserInfo.getId().equals(userInfo[i].getId())) {
                        hasSelect = true;
                        break;
                    }
                }
                int userType = logonUserInfo.getUserType();// 登录用户类型 addBy:thq
                if (!hasSelect) {
                    // 只添加当前用户的下级人员
                    if (userInfo[i].getUserType() == (userType + 1)) {
                        alllistModel.addElement(userInfo[i]);
                    }
                }
            }
            allUserList.setModel(alllistModel);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
            return;
        }
 
    }
 
    /**
     * 左移
     */
    private void addButton_actionPerformed() {
        Object[] objs = allUserList.getSelectedValues();
        try {
 
            if ((objs == null) || (objs.length == 0)) {
                VCIOptionPane.showMessageDialog(this, "请选择要增加的成员!");
                return;
            }
            int len = objs.length;
            UserObject[] addUserInfo = new UserObject[len];
            for (int i = 0; i < len; i++) {
                addUserInfo[i] = (UserObject) objs[i];
            }
 
            PvolumeInfo[] pvolumeInfos = ServiceProvider.getFrameService().getAllPvolumes();
            for (PvolumeInfo pvolumeInfo : pvolumeInfos) {
                UserInfo[] userInfos = ServiceProvider.getFrameService().fetchUserInfoByPvolumeId(pvolumeInfo.id,
                        logonUserInfo.getUserType());
                for (UserInfo userInfo : userInfos) {
                    if (addUserInfo[0].getId().equals(userInfo.id)) {
                        VCIOptionPane.showMessageDialog(this, "该用户已被分配文件柜,请重新选择分配用户!");
                        return;
                    }
                }
            }
 
            DefaultListModel selectListModel = (DefaultListModel) choosedUserList.getModel();
            DefaultListModel allListModel = (DefaultListModel) allUserList.getModel();
 
            int size = selectListModel.getSize();
            for (int i = 0; i < size; i++) {
                UserObject entity = (UserObject) selectListModel.getElementAt(i);
 
                for (int j = 0; j < len; j++) {
                    if (entity.getId().equals(addUserInfo[j].getId())) {
                        VCIOptionPane.showMessageDialog(this, "要增加的成员已经存在,请重新选择!");
                        return;
                    }
                }
            }
            for (int i = 0; i < len; i++) {
                selectListModel.addElement(addUserInfo[i]);
                allListModel.removeElement(addUserInfo[i]);
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 右移
     */
    private void removeButton_actionPerformed() {
        Object[] objs = choosedUserList.getSelectedValues();
        if ((objs == null) || (objs.length == 0)) {
            VCIOptionPane.showMessageDialog(this, "请选择要移除的成员!");
            return;
        }
        int len = objs.length;
        UserObject[] deleteUser = new UserObject[len];
        for (int i = 0; i < len; i++) {
            deleteUser[i] = (UserObject) objs[i];
        }
        DefaultListModel listModel = (DefaultListModel) choosedUserList.getModel();
        DefaultListModel allListModel = (DefaultListModel) allUserList.getModel();
        for (int i = 0; i < listModel.size(); i++) {
            UserObject entity = (UserObject) listModel.getElementAt(i);
            for (int j = 0; j < len; j++) {
                int a = deleteUser[j].getUserType() - logonUserInfo.getUserType();// 只有当前用户的下级人员才能被有移
                if (a != 1) {
                    VCIOptionPane.showMessageDialog(this, "该用户没有权限移除,请选择其它用户!");
                    return;
                } else {
                    if (entity.getId().equals(deleteUser[j].getId())) {
                        listModel.removeElement(entity);
                        allListModel.addElement(entity);
                        i--;
                        break;
                    }
                }
            }
        }
    }
 
    /**
     * 得到选中的文件柜
     * 
     * @return
     */
    public UserObject[] getSelectedUserObj() {
        DefaultListModel listModel = (DefaultListModel) choosedUserList.getModel();
        int size = listModel.size();
        UserObject[] userInfo = new UserObject[size];
        for (int i = 0; i < size; i++) {
            userInfo[i] = (UserObject) listModel.get(i);
        }
        return userInfo;
    }
 
    /**
     * 确定事件
     */
    public void conformCreate() {
        String pvolumId = this.pvolumeObj.getId();
        String[] userIds;
        UserObject[] selectedUserObj = this.getSelectedUserObj();
 
        int arrayLength = selectedUserObj.length + selectUserObj2.length;
        userIds = new String[arrayLength];
 
        for (int i = 0; i < arrayLength; i++) {
            if (i < selectedUserObj.length) {
                userIds[i] = selectedUserObj[i].getId();
            } else {
                userIds[i] = selectUserObj2[i - selectedUserObj.length].getId();
            }
        }
 
        try {
            new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).savePvolume(pvolumId, userIds);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
            return;
        }
        this.dispose();
    }
 
    public void cancelCreate() {
        dispose();
    }
 
}