package com.vci.client.framework.specialrole;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.Rectangle;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
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.UserEntityObject;
|
import com.vci.client.common.objects.UserObject;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.framework.systemConfig.stafforgmanage.ListLabelCellRenderForRightRole;
|
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.framework.data.RoleInfo;
|
|
/**
|
* 角色增加成员界面管理
|
* @author wangxl
|
*
|
*/
|
public class SelectUserDialog 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 RightManagementClientDelegate _RMCDelegate = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
|
|
private JTextField searceText = new JTextField();
|
public SelectUserDialog(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();
|
conformBut.setPreferredSize(new Dimension(50,25));
|
bottomPanel.add(conformBut);
|
cancelBut.setPreferredSize(new Dimension(50,25));
|
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(250,300));
|
jspAllRole.setBounds(new Rectangle(10,50,250,300));
|
jspAllRole.setBorder(new TitledBorder("角色外成员"));
|
allUserList.setCellRenderer(new ListLabelCellRenderForRightRole());
|
|
JScrollPane jspChooseRole = new JScrollPane();
|
jspChooseRole.getViewport().add(choosedUserList);
|
jspChooseRole.setPreferredSize(new Dimension(250,300));
|
jspChooseRole.setBounds(new Rectangle(330,50,250,300));
|
jspChooseRole.setBorder(new TitledBorder("角色内成员"));
|
choosedUserList.setCellRenderer(new ListLabelCellRenderForRightRole());
|
|
DefaultListModel selectListModel = new DefaultListModel();
|
String roleId = rightRoleObj.getId();
|
int userType = logonUserInfo.getUserType();
|
try {
|
UserObject[] selectUserObjs = _RMCDelegate.fetchUserInfoByRoleId(roleId ,userType );
|
if (selectUserObjs.length != 0){
|
for (int i = 0 ; i < selectUserObjs.length ; i ++){
|
// // 三员管理中,不能移除自己的三员角色 Jason 2019.7.2
|
// if (selectUserObjs[i].getId().equals(logonUserInfo.getId()))
|
// continue;
|
|
selectListModel.addElement(selectUserObjs[i]);
|
}
|
}
|
} catch (VCIException e1) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e1);
|
}
|
|
choosedUserList.setModel(selectListModel);
|
JButton addButton = new JButton(">>");
|
addButton.setBounds(270, 100, 50, 25);
|
|
JButton removeButton = new JButton("<<");
|
removeButton.setBounds(270, 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、可选的用户是全部的用户
|
// UserObject[] userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
|
// .fetchUserInfo();
|
UserObject[] userInfo = _RMCDelegate.fetchUserInfo();
|
|
List<String> lstThreeRoleUserID = new ArrayList<String>();
|
Boolean isThreeRole = isThreeRole(rightRoleObj.getId());
|
if (isThreeRole) {
|
getRoleUserIDs("系统管理员", lstThreeRoleUserID);
|
getRoleUserIDs("安全管理员", lstThreeRoleUserID);
|
getRoleUserIDs("审计管理员", lstThreeRoleUserID);
|
// RoleObject role = _RMCDelegate.fetchRoleByName("系统管理员");
|
// UserObject[] users = _RMCDelegate.fetchUsersByRoleId(role.getId());
|
// for (UserObject user : users) {
|
// lstThreeRoleUserID.add(user.getId());
|
// }
|
}
|
|
int length = userInfo.length;
|
DefaultListModel alllistModel = new DefaultListModel();
|
DefaultListModel selectlistModel = (DefaultListModel) choosedUserList.getModel();
|
int selectLenth = selectlistModel.getSize();
|
for (int i = 0; i < length; i++) {
|
// 2、二次过滤
|
// 为三员角色分配成员时,可行的用户是普通用户
|
if (userInfo[i].getUserType() < 2 || userInfo[i].getStatus() == 1){
|
continue;
|
}
|
// 对三员角色分配用户时,不能给自己添加三员角色,Jason 2019.7.2
|
if (userInfo[i].getId().equalsIgnoreCase(logonUserInfo.getId())){
|
continue;
|
}
|
|
// 用户只能具有一个三员角色
|
if (isThreeRole && lstThreeRoleUserID.contains(userInfo[i].getId()))
|
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 getRoleUserIDs(String roleName, List<String> lstId) {
|
try {
|
RoleObject role = _RMCDelegate.fetchRoleByName(roleName);
|
UserObject[] users = _RMCDelegate.fetchUsersByRoleId(role.getId());
|
for (UserObject user : users) {
|
lstId.add(user.getId());
|
}
|
} catch (VCIException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
private Boolean isThreeRole(String roleId){
|
try{
|
RoleObject role = _RMCDelegate.fetchRoleInfoById(roleId);
|
String sRole = role.getName();
|
if (sRole.equalsIgnoreCase("系统管理员") || sRole.equalsIgnoreCase("安全管理员") || sRole.equalsIgnoreCase("审计管理员"))
|
return true;
|
|
return false;
|
}catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
|
return false;
|
}
|
}
|
|
|
private Boolean hasThreeRole(UserObject user){
|
try{
|
RoleObject[] roles = _RMCDelegate.fetchRoleInfoByUserId(user.getId());
|
for (RoleObject role : roles){
|
String sRole = role.getName();
|
if (sRole.equalsIgnoreCase("系统管理员") || sRole.equalsIgnoreCase("安全管理员") || sRole.equalsIgnoreCase("审计管理员"))
|
return true;
|
}
|
}catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
|
return false;
|
}
|
|
return false;
|
}
|
|
|
/**
|
* 左移
|
*/
|
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;
|
List<UserObject> deleteUser = new ArrayList<UserObject>();
|
for (int i = 0; i < len; i++) {
|
UserObject user = (UserObject)objs[i];
|
// 三员管理中,不能移除自己的三员角色 Jason 2019.7.2
|
if (user.getId().equals(logonUserInfo.getId()))
|
continue;
|
|
deleteUser.add(user);
|
}
|
|
len = deleteUser.size();
|
|
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.get(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();
|
}
|
|
}
|