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.bundle.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();
|
}
|
|
}
|