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.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
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.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;
|
|
/**
|
* <p>Title: RolingDialog</p>
|
* <p>Description: 分配角色界面</p>
|
* <p>Copyright: Copyright (c) 2012</p>
|
* <p>Company: VCI</p>
|
* @author wangxl
|
* @time 2012-5-11
|
* @version 1.0
|
*/
|
public class RolingDialog 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 allRoleList = new JList(); //所有的角色
|
private JList choosedRoleList = new JList(); //拥有的角色
|
private UserTablePanel userPanel;
|
private String userName = LogonApplication.getUserEntityObject().getUserName();
|
private UserObject logonUserInfo;
|
private List<UserObject> userList;
|
private JTextField searceText = new JTextField();
|
public RolingDialog(UserTablePanel userPanel ,List<UserObject> userList){
|
super(LogonApplication.frame);
|
this.userList = userList;
|
this.userPanel = userPanel;
|
this.setModal(true);
|
init();
|
}
|
|
|
/**
|
* 初始化界面
|
*/
|
private void init() {
|
JLabel titleLabel = new JLabel();
|
titleLabel.setText(LocaleDisplay.getI18nString("rmip.stafforg.logal.roling", "RMIPFramework", getLocale()));
|
titleLabel.setIcon(new BundleImage().createImageIcon ("role.png"));
|
JPanel bottomPanel = new JPanel();
|
bottomPanel.add(conformBut);
|
bottomPanel.add(cancelBut);
|
|
JPanel contentPanel = initCenterContentPanel();
|
initRole(); //初始化角色信息
|
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);
|
this.setVisible(true);
|
|
}
|
|
private JPanel initCenterContentPanel() {
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(null);
|
|
// JLabel roleLabel = new JLabel(LocaleDisplay.getI18nString("rmip.stafforg.menu.role", "RMIPFramework", getLocale()));
|
// roleLabel.setBounds(50, 30, 80, 25);
|
|
JScrollPane jspAllRole = new JScrollPane();
|
jspAllRole.getViewport().add(allRoleList);
|
|
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) allRoleList.getModel();
|
String queryStr = searceText.getText().trim();
|
allListModel.removeAllElements();
|
initRole();
|
if(!"".equals(queryStr)){
|
int size = allRoleList.getModel().getSize();
|
allListModel = new DefaultListModel();
|
for(int i=0;i<size;i++){
|
RoleObject roleObject = (RoleObject)allRoleList.getModel().getElementAt(i);
|
if(roleObject.getName().contains(queryStr)){
|
allListModel.addElement(roleObject);
|
}
|
}
|
allRoleList.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(LocaleDisplay.getI18nString("rmip.stafforg.logal.rolelist", "RMIPFramework", getLocale())));
|
// allRoleList.setCellRenderer(new ListLabelCellRender());
|
|
JScrollPane jspChooseRole = new JScrollPane();
|
jspChooseRole.getViewport().add(choosedRoleList);
|
jspChooseRole.setPreferredSize(new Dimension(210,300));
|
jspChooseRole.setBounds(new Rectangle(330,50,210,300));
|
jspChooseRole.setBorder(new TitledBorder(LocaleDisplay.getI18nString("rmip.stafforg.logal.choosedrolelist", "RMIPFramework", getLocale())));
|
// choosedRoleList.setCellRenderer(new ListLabelCellRender());
|
|
DefaultListModel selectListModel = new DefaultListModel();
|
if (userList.size()==1){
|
RoleObject[] selectRoles;
|
try {
|
selectRoles = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
|
.fetchRoleInfoByUserId(userList.get(0).getId());
|
int length = selectRoles.length;
|
for (int i = 0; i < length; i++) {
|
selectListModel.addElement(selectRoles[i]);
|
}
|
} catch (VCIException e1) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
|
}
|
|
}
|
|
choosedRoleList.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();
|
}
|
});
|
|
/**added by ligang 部门鼠标双击事件的添加**/
|
allRoleList.addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent mouseevent) {
|
if(mouseevent.getClickCount()==2){//鼠标双击
|
addButton_actionPerformed();
|
}
|
|
}
|
});
|
|
choosedRoleList.addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent mouseevent) {
|
if(mouseevent.getClickCount()==2){//鼠标双击
|
removeButton_actionPerformed();
|
}
|
|
}
|
});
|
|
contentPanel.add(jspChooseRole);
|
contentPanel.add(jspAllRole);
|
// contentPanel.add(roleLabel);
|
contentPanel.add(addButton);
|
contentPanel.add(removeButton);
|
return contentPanel;
|
|
}
|
|
/**
|
* 初始化角色信息
|
*/
|
private void initRole(){
|
try{
|
logonUserInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
|
.fetchUserInfoByName(userName);
|
RoleObject[] roleInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
|
.fetchRoleInfoByType(logonUserInfo.getUserType());
|
int length = roleInfo.length;
|
DefaultListModel alllistModel = new DefaultListModel();
|
DefaultListModel selectlistModel = (DefaultListModel) choosedRoleList.getModel();
|
int selectLenth = selectlistModel.getSize();
|
for (int i = 0; i < length; i++) {
|
boolean hasSelect = false;
|
for (int j = 0; j < selectLenth; j++) {
|
RoleObject selectRoleInfo = (RoleObject)selectlistModel.get(j);
|
if (selectRoleInfo.getId().equals(roleInfo[i].getId())) {
|
hasSelect = true;
|
break;
|
}
|
}
|
if ((!hasSelect)) {
|
alllistModel.addElement(roleInfo[i]);
|
}
|
}
|
allRoleList.setModel(alllistModel);
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
|
return ;
|
}
|
|
}
|
|
private void addButton_actionPerformed() {
|
|
Object[] objs = allRoleList.getSelectedValues();
|
if ((objs == null) || (objs.length == 0)) {
|
VCIOptionPane.showMessageDialog(this,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.toselectrole", "RMIPFramework", getLocale()));
|
return;
|
}
|
int len = objs.length;
|
RoleObject[] addRoleInfo = new RoleObject[len];
|
for (int i = 0; i < len; i++) {
|
addRoleInfo[i] = (RoleObject)objs[i];
|
}
|
DefaultListModel selectListModel = (DefaultListModel) choosedRoleList.getModel();
|
DefaultListModel allListModel = (DefaultListModel) allRoleList.getModel();
|
|
int size = selectListModel.getSize();
|
for (int i = 0; i < size; i++) {
|
RoleObject entity = (RoleObject) selectListModel.getElementAt(i);
|
for (int j = 0; j < len; j++) {
|
if (entity.getId().equals(addRoleInfo[j].getId())) {
|
VCIOptionPane.showMessageDialog(this,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.toreselectrole", "RMIPFramework", getLocale()));
|
return;
|
}
|
}
|
}
|
for (int i = 0; i < len; i++) {
|
selectListModel.addElement(addRoleInfo[i]);
|
allListModel.removeElement(addRoleInfo[i]);
|
}
|
|
}
|
|
private void removeButton_actionPerformed() {
|
|
Object[] objs = choosedRoleList.getSelectedValues();
|
if ((objs == null) || (objs.length == 0)) {
|
VCIOptionPane.showMessageDialog(this,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.toremoverole", "RMIPFramework", getLocale()));
|
return;
|
}
|
int len = objs.length;
|
RoleObject[] deleteRole = new RoleObject[len];
|
for (int i = 0; i < len; i++) {
|
deleteRole[i] = (RoleObject)objs[i];
|
}
|
DefaultListModel listModel = (DefaultListModel) choosedRoleList.getModel();
|
DefaultListModel allListModel = (DefaultListModel) allRoleList.getModel();
|
for (int i = 0; i < listModel.size(); i++) {
|
RoleObject entity = (RoleObject) listModel.getElementAt(i);
|
for (int j = 0; j < len; j++) {
|
if (entity.getId().equals(deleteRole[j].getId())) {
|
listModel.removeElement(entity);
|
allListModel.addElement(entity);
|
i--;
|
break;
|
}
|
}
|
}
|
}
|
|
public void conformCreate(){
|
RoleObject[] selectedRole = this.getSelectRoleObject();
|
String[] roleIds = new String[selectedRole.length];
|
for (int i = 0 ; i < selectedRole.length ; i ++){
|
roleIds[i] = selectedRole[i].getId();
|
}
|
String[] userIds = new String[userList.size()];
|
for (int i = 0 ; i < userList.size() ; i ++){
|
userIds[i] = userList.get(i).getId();
|
}
|
try {
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveRights(roleIds, userIds);
|
}catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
|
return ;
|
}
|
userPanel.tablePanel.refreshTableData();
|
this.dispose();
|
}
|
public void cancelCreate(){
|
this.dispose();
|
}
|
|
/**
|
* <p>Description:得到分配的角色 </p>
|
*
|
* @author wangxl
|
* @time 2012-5-11
|
* @return
|
*/
|
private RoleObject[] getSelectRoleObject() {
|
DefaultListModel listModel = (DefaultListModel) choosedRoleList.getModel();
|
int size = listModel.size();
|
RoleObject[] roleInfo = new RoleObject[size];
|
for (int i = 0; i < size; i++) {
|
roleInfo[i] = (RoleObject)listModel.get(i);
|
}
|
return roleInfo;
|
}
|
|
}
|