package com.vci.client.framework.specialrole;
|
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.Date;
|
|
import javax.swing.JPanel;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.objects.UserObject;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.framework.systemConfig.object.TransmitMethod;
|
import com.vci.client.framework.util.RightControlUtil;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.locale.LocaleDisplay;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.tree.VCIBaseTreeNode;
|
|
public class UserActionListener extends JPanel implements ActionListener {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private UserDialog panel = null;
|
private UserTablePanel userTablePanel=null;
|
private String type = null;
|
private String userName = LogonApplication.getUserEntityObject().getUserName();
|
private UserObject logonUserInfo;
|
private UserObject userObj;
|
|
public UserActionListener(UserDialog panel, UserTablePanel userTablePanel ,String type , UserObject userObj) {
|
this.panel = panel;
|
this.userTablePanel = userTablePanel;
|
this.userObj = userObj;
|
this.type = type;
|
}
|
|
public void actionPerformed(ActionEvent e) {
|
if (type.equals("add")) {
|
add_actionPerformed();
|
} else if (type.equals("edit")) {
|
edit_actionPerformed();
|
} else if (type.equals("delete")) {
|
delete_actionPerformed();
|
}
|
}
|
|
@SuppressWarnings("static-access")
|
private boolean check(){
|
String userName = panel.getUserNameText();
|
String pwd = panel.getPasswordText();
|
String configPwd = panel.getConformPwdText();
|
String trueName = panel.gettrueNameText();
|
String email = panel.getEmailText();
|
String desc = panel.getDescriptionArea();
|
// String companyId = panel.getCompanyId();
|
if(new RightControlUtil().isAdminOrDeveloperOrRoot(userName)){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.usernameerror1", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if("".equals(userName)){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.usernameerror2", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if("".equals(pwd)){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.pwderror1", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if ("".equals(configPwd)){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.conformpwderror", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if(!configPwd.equals(pwd)){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.pwderror2", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if (userName.getBytes().length > 128){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.usernameerror3", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if (pwd.getBytes().length > 128){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.pwderror3", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if (trueName.getBytes().length > 64){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.firstnameerror", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if (email.getBytes().length > 128){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.emailerror", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if (desc.getBytes().length > 255 ){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.descerror", "RMIPFramework", getLocale()));
|
return false;
|
}
|
|
String regEx = "^[A-Za-z0-9_]+$";
|
if (!TransmitMethod.checkCharacter(userName, regEx)) {
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.usernameerror4", "RMIPFramework", getLocale()));
|
return false;
|
}
|
if(trueName.equals("")){
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.firstnameerror1", "RMIPFramework", getLocale()));
|
return false;
|
}
|
// if("".equals(email)){
|
// VCIOptionPane.showMessageDialog(panel,"请输入电子邮箱地址!");
|
// return false;
|
// }
|
|
|
if (!email.equals("")){
|
regEx = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
|
if (!TransmitMethod.checkCharacter(email, regEx)) {
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.emailerror1", "RMIPFramework", getLocale()));
|
return false;
|
}
|
}
|
|
boolean rs = checkName(userName);
|
if (!rs) {
|
return rs;
|
}
|
return true;
|
}
|
|
/***
|
* 看用户名是否重复
|
* @param name 用户名
|
* @return
|
*/
|
private boolean checkName(String name) {
|
UserObject[] userInfo = null;
|
try {
|
userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfo();
|
|
int size = userInfo.length;
|
for(int i = 0; i < size; i++){
|
if (name.equals(userInfo[i].getUserName())) {
|
if("edit".equalsIgnoreCase(type)){ //如果是要进行修改,名称不变的情况下可以成功修改,这种情况下不是名称重复。
|
if (userObj.getId().equals(userInfo[i].getId())) {
|
continue;
|
}
|
}
|
VCIOptionPane.showMessageDialog(panel,
|
"该用户名在所系统中已经存在,请修改!");
|
return false;
|
|
|
}
|
|
}
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return false;
|
}
|
return true;
|
}
|
|
|
/***
|
* 得到操作对象的用户信息
|
*
|
*/
|
private UserObject getUserInfo() {
|
UserObject userInfo = new UserObject();
|
userInfo.setUserName(panel.getUserNameText());
|
userInfo.setPwd(panel.getPasswordText());
|
userInfo.setEmail(panel.getEmailText());
|
userInfo.setTrueName(panel.gettrueNameText());
|
userInfo.setDesc(panel.getDescriptionArea());
|
userInfo.setPwdUpdateTime(0);//"1970-1-1 00:00:00");
|
if("edit".equalsIgnoreCase(type)){
|
userInfo.setId(userObj.getId());
|
if (!panel.getPasswordText().equals(userObj.getPwd())){
|
userInfo.setPwdUpdateTime(0);//"1970-1-1 00:00:00");
|
}else {
|
userInfo.setPwdUpdateTime(userObj.getPwdUpdateTime());
|
}
|
userInfo.setGrantor(userObj.getGrantor());
|
}
|
userInfo.setUserType(logonUserInfo.getUserType());
|
userInfo.setCreateTime(System.currentTimeMillis());
|
userInfo.setCreateUser(userName);
|
userInfo.setUpdateTime(System.currentTimeMillis());
|
userInfo.setUpdateUser(userName);
|
return userInfo;
|
}
|
|
/**
|
* 注册成员添加事件
|
*/
|
private void add_actionPerformed() {
|
try{
|
logonUserInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
|
}catch(VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return;
|
}
|
|
boolean rs = check();
|
if (!rs) {
|
return;
|
}
|
UserObject userInfo = getUserInfo();
|
userInfo.setStatus((short)0);
|
try {
|
String id = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveUser(userInfo);
|
userInfo.setId(id);
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveSpecialRole(userTablePanel.getRoleId(), new String[]{id});
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
|
return;
|
}
|
|
VCIOptionPane.showMessageDialog(LogonApplication.frame,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.usercreateok", "RMIPFramework", getLocale()));
|
panel.dispose();
|
userTablePanel.tablePanel.refreshTableData();
|
}
|
|
/**
|
* 注册成员修改事件
|
*/
|
private void edit_actionPerformed() {
|
try{
|
logonUserInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
|
}catch(VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,
|
LocaleDisplay.getI18nString(e, "RMIPFramework", getLocale()));
|
return;
|
}
|
boolean rs = check();
|
if (!rs) {
|
return;
|
}
|
UserObject userInfo = getUserInfo();
|
userInfo.setStatus(userObj.getStatus());
|
try {
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateUser(userInfo);
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return;
|
}
|
panel.dispose();
|
userTablePanel.tablePanel.refreshTableData();
|
// VCIOptionPane.showMessageDialog(LogonApplication.frame,
|
// LocaleDisplay.getI18nString("rmip.stafforg.operate.updateok", "RMIPFramework", getLocale()));
|
}
|
/**
|
* 注册成员删除事件
|
*/
|
@SuppressWarnings("unused")
|
private void delete_actionPerformed() {
|
TreePath[] deleteTreePaths = panel.getTransmitTreeObject().getTree().getSelectionPaths();
|
if (deleteTreePaths.length < 1) {
|
VCIOptionPane.showMessageDialog(panel,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.toselectdel", "RMIPFramework", getLocale()));
|
return;
|
}
|
//2012.01.10 ligang 添加用户时更新用户总数
|
int count = 0;
|
try{
|
logonUserInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
|
count = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByType(logonUserInfo.getUserType()).length;
|
}catch(VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,
|
LocaleDisplay.getI18nString(e, "RMIPFramework", getLocale()));
|
return;
|
}
|
|
int len = deleteTreePaths.length;
|
String[] puids = new String[len];
|
VCIBaseTreeNode[] removeNodes = new VCIBaseTreeNode[len];
|
for (int i = 0; i < len; i++) {
|
VCIBaseTreeNode treeNode = (VCIBaseTreeNode)deleteTreePaths[i].getLastPathComponent();
|
boolean canDelete = true; //选择的节点是否可以删除
|
UserObject userInfo = null;
|
if (!(treeNode.getObj() instanceof UserObject)) {
|
canDelete = false;
|
} else {
|
userInfo = (UserObject) treeNode.getObj();
|
if ("root".equals(userInfo.getId())) {
|
canDelete = false;
|
}
|
}
|
if (!canDelete) {
|
VCIOptionPane.showMessageDialog(LogonApplication.frame,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.toshowdelusererror", "RMIPFramework", getLocale()));
|
return;
|
}
|
|
removeNodes[i] = treeNode;
|
puids[i] = userInfo.getId();
|
}
|
|
int ok=VCIOptionPane.showQuestion(LogonApplication.frame,
|
LocaleDisplay.getI18nString("rmip.stafforg.operate.conformdeluser", "RMIPFramework", getLocale()));
|
|
if (ok == 0) {
|
boolean rs=true;
|
try {
|
rs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deleteUser(puids);
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return;
|
}
|
if (!rs) {
|
return;
|
}
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode) panel.getTransmitTreeObject().getCurrentTreeNode().getParent();
|
for (int i = 0; i < len; i++) {
|
panel.getTransmitTreeObject().getTreeModel().removeNodeFromParent(removeNodes[i]);
|
}
|
panel.getTransmitTreeObject().getTree().setSelectionPath(new TreePath(parentNode.getPath()));
|
|
panel.getTransmitTreeObject().getTree().updateUI();
|
|
}
|
}
|
|
}
|