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
package com.vci.client.framework.systemConfig.stafforgmanage;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
 
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.LogonApplication;
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.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;
 
/**
 * 角色增加成员界面管理
 * @author wangxl
 *
 */
public class RightRoleDialog 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 RoleObject rightRoleObj;
    private JTextField searceText = new JTextField();
    public RightRoleDialog(RoleObject rightRoleObj){
        super(LogonApplication.frame);
        this.rightRoleObj = rightRoleObj;
        this.setModal(true);
        init();
    }
     
    
    /**
     * 初始化界面
     */
    private void init() {
         JLabel titleLabel = new JLabel();
         titleLabel.setText("角色添加成员");
         titleLabel.setIcon(new BundleImage().createImageIcon ("role.png"));
         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 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());
        allUserList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() == 2){
                    addButton_actionPerformed();
                }
            }
        });
        
        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 roleId = rightRoleObj.getId();
        int userType = logonUserInfo.getUserType();
        try {
            UserObject[] selectUserObjs = new RightManagementClientDelegate().fetchUserInfoByRoleId(roleId ,userType );
            if (selectUserObjs.length != 0){
                for (int i = 0 ; i < selectUserObjs.length ; i ++){
                    selectListModel.addElement(selectUserObjs[i]);
                }
            }
        } 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);
        return contentPanel;
        
    }
    
    /**
     * 初始化成员信息
     */
    private void initUser(){
        try{
            // 1、查出当前用户所在类型低一级别的用户(userType>=2)
            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;
                    }
                }
                if (!hasSelect) {
                    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();
            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];
            }
            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]);
            }
            
        }
        
     /**
      * 右移
      */
        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++) {
                    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 roleId = this.rightRoleObj.getId();
            String[] userIds;
            UserObject[] selectedUserObj = this.getSelectedUserObj();
            
            userIds = new String[selectedUserObj.length];
            for (int i = 0 ; i < selectedUserObj.length ; i ++){
                userIds[i] = selectedUserObj[i].getId();
            }
            try{
                new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveRight(roleId , userIds);
            }catch(VCIException e){
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
                return;
            }
            this.dispose();
       }
        public void cancelCreate(){
              dispose();
        }
 
}