package com.vci.client.workflow.editor.user;
|
|
import java.awt.BorderLayout;
|
import java.awt.FlowLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.lang.reflect.InvocationTargetException;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.swing.BoxLayout;
|
import javax.swing.ButtonGroup;
|
import javax.swing.DefaultListModel;
|
import javax.swing.JButton;
|
import javax.swing.JComponent;
|
import javax.swing.JList;
|
import javax.swing.JPanel;
|
import javax.swing.JRadioButton;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.border.TitledBorder;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.objects.DeptObject;
|
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.ui.exception.VCIException;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
|
import com.vci.common.resource.CommonProperties;
|
|
public class RMUserComponent extends UserPanel {
|
|
private static final long serialVersionUID = -990618910839831914L;
|
|
private JPanel userComponent;
|
|
private JList list;
|
|
private DefaultListModel listModel;
|
|
private JList userList;
|
private JList roleList;
|
private JList deptList;
|
// protected List<String> userNameList = new ArrayList<String>();
|
private DefaultListModel userListModel;
|
private DefaultListModel roleListModel;
|
private DefaultListModel deptListModel;
|
private List<UserObject> userObjs = new ArrayList<UserObject>();
|
private List<RoleObject> roleObjs = new ArrayList<RoleObject>();
|
private List<DeptObject> deptObjs = new ArrayList<DeptObject>();
|
|
private JButton btnNewButton ;
|
private JButton btnNewButton_1 ;
|
|
private JTextArea custText = new JTextArea();
|
JScrollPane scrollPane = new JScrollPane();
|
//选中某一按钮,记录下所选按钮的对象名称
|
private String radioChoseFlag = "user";
|
|
private CustomEditPanel customUserPanel;
|
|
public RMUserComponent() {
|
setLayout(new BorderLayout(0, 0));
|
|
userComponent = new JPanel();
|
|
add(userComponent);
|
GridBagLayout gbl_panel_3 = new GridBagLayout();
|
userComponent.setLayout(gbl_panel_3);
|
userComponent.setBorder(new TitledBorder("候选人"));
|
// JScrollPane scrollPane = new JScrollPane();
|
|
JPanel userListPanel = new JPanel();
|
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
userListPanel.setLayout(new BorderLayout());
|
JRadioButton userRadioBtn = new JRadioButton("成员");
|
JRadioButton roleRadioBtn = new JRadioButton("角色");
|
JRadioButton depRadioBtn = new JRadioButton("部门");
|
JRadioButton custRadioBtn = new JRadioButton("自定义用户规则");
|
|
listModel = new DefaultListModel();
|
list = new JList(listModel);
|
scrollPane.setViewportView(list);
|
|
JPanel panel = new JPanel();
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
gbc_panel.fill = GridBagConstraints.BOTH;
|
gbc_panel.gridx = 1;
|
gbc_panel.gridy = 0;
|
userComponent.add(panel, gbc_panel);
|
panel.setLayout(new BorderLayout(0, 0));
|
|
JPanel panel_1 = new JPanel();
|
panel.add(panel_1, BorderLayout.WEST);
|
panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
|
|
btnNewButton = new JButton("添加");
|
btnNewButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent actionevent) {
|
add();
|
// selectUser();
|
}
|
|
});
|
panel_1.add(btnNewButton);
|
|
btnNewButton_1 = new JButton("删除");
|
btnNewButton_1.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent actionevent) {
|
delete();
|
// int selectedIndex = list.getSelectedIndex();
|
// if (selectedIndex == -1) {
|
// VCIOptionPane.showMessage(LogonApplication.frame, "请选择记录");
|
// return;
|
// }
|
// Object elementAt = listModel.getElementAt(selectedIndex);
|
//// idList.remove(elementAt.getId());
|
// listModel.remove(selectedIndex);
|
// list.setSelectedIndex(selectedIndex - 1);
|
// list.updateUI();
|
}
|
});
|
panel_1.add(btnNewButton_1);
|
|
|
ButtonGroup bg = new ButtonGroup();
|
bg.add(userRadioBtn);
|
bg.add(roleRadioBtn);
|
bg.add(depRadioBtn);
|
bg.add(custRadioBtn);
|
userRadioBtn.setSelected(true);
|
radioPanel.add(userRadioBtn);
|
String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
if(userDialogControl==null||"".equals(userDialogControl)){
|
radioPanel.add(roleRadioBtn);
|
radioPanel.add(depRadioBtn);
|
radioPanel.add(custRadioBtn);
|
}
|
userRadioBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
radioChoseFlag = "user";
|
scrollPane.setViewportView(userList);
|
controlBtn(radioChoseFlag);
|
}
|
});
|
roleRadioBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
radioChoseFlag = "role";
|
scrollPane.setViewportView(roleList);
|
controlBtn(radioChoseFlag);
|
}
|
});
|
|
depRadioBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
radioChoseFlag = "depart";
|
scrollPane.setViewportView(deptList);
|
controlBtn(radioChoseFlag);
|
}
|
});
|
|
custRadioBtn.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
radioChoseFlag = "cust";
|
scrollPane.getViewport().add(customUserPanel);
|
controlBtn(radioChoseFlag);
|
}
|
|
});
|
|
userListPanel.add(radioPanel,BorderLayout.NORTH);
|
userListPanel.add(scrollPane,BorderLayout.CENTER);
|
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
gbc_scrollPane.weighty = 1.0;
|
gbc_scrollPane.weightx = 1.0;
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
gbc_scrollPane.anchor = GridBagConstraints.CENTER;
|
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
gbc_scrollPane.gridx = 0;
|
gbc_scrollPane.gridy = 0;
|
userComponent.add(userListPanel, gbc_scrollPane);
|
|
listModel = new DefaultListModel();
|
list = new JList(listModel);
|
// scrollPane.setViewportView(list);
|
|
userListModel = new DefaultListModel();
|
roleListModel = new DefaultListModel();
|
deptListModel = new DefaultListModel();
|
userList = new JList(userListModel);
|
roleList = new JList(roleListModel);
|
deptList = new JList(deptListModel);
|
scrollPane.setViewportView(userList);
|
}
|
|
private void controlBtn(String str) {
|
if("cust".equals(str)){
|
btnNewButton.setEnabled(false);
|
btnNewButton_1.setEnabled(false);
|
}else{
|
btnNewButton.setEnabled(true);
|
btnNewButton_1.setEnabled(true);
|
}
|
}
|
|
private void add(){
|
String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
if(userDialogControl!=null&&!"".equals(userDialogControl)){
|
Class<?> cls;
|
try {
|
cls = Class.forName(userDialogControl);
|
CustomUserDialog res = (CustomUserDialog) cls.getConstructor(UserPanel.class).newInstance(this);
|
res.setLocationRelativeTo(null);
|
res.setVisible(true);
|
|
if(interFaceResult!=null&&!"".equals(interFaceResult)){
|
for(int i=0;i<userNameList.size();i++){
|
String name = userNameList.get(i);
|
if(interFaceResult.equals(name)){
|
VCIOptionPane.showMessage(LogonApplication.frame, "名称重复,请重新选择!");
|
return;
|
}
|
}
|
if(interFaceResult.contains(":")){
|
userNameList.add(interFaceResult);
|
userListModel.addElement(interFaceResult.split(":")[0]);
|
}else{
|
userListModel.addElement(interFaceResult);
|
}
|
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
}
|
}else{
|
UserSelectionDialog userSelectionDialog = new UserSelectionDialog();
|
userSelectionDialog.setLocationRelativeTo(null);
|
|
userSelectionDialog.setUserObjectlist(userObjs);
|
userSelectionDialog.setRoleObjectlist(roleObjs);
|
userSelectionDialog.setDeptObjectlist(deptObjs);
|
//
|
userSelectionDialog.setVisible(true);
|
if(userSelectionDialog.getDialogResult() == DialogResult.CANCEL) return;
|
|
List<UserObject> userObjectlist = userSelectionDialog.getUserObjectlist();
|
List<RoleObject> roleObjectlist = userSelectionDialog.getRoleObjectlist();
|
List<DeptObject> deptObjectlist = userSelectionDialog.getDeptObjectlist();
|
userListModel.removeAllElements();
|
roleListModel.removeAllElements();
|
deptListModel.removeAllElements();
|
userObjs = userObjectlist;
|
roleObjs = roleObjectlist;
|
deptObjs = deptObjectlist;
|
if (userObjectlist != null) {
|
for (UserObject userObject : userObjectlist) {
|
if(!userListModel.contains(userObject)) {
|
userListModel.addElement(userObject);
|
}
|
}
|
}
|
if (roleObjectlist != null) {
|
for (RoleObject roleObject : roleObjectlist) {
|
if(!roleListModel.contains(roleObject)) {
|
roleListModel.addElement(roleObject);
|
}
|
}
|
}
|
if (deptObjectlist != null) {
|
for (DeptObject deptObject : deptObjectlist) {
|
if(!deptListModel.contains(deptObject)) {
|
deptListModel.addElement(deptObject);
|
}
|
}
|
}
|
}
|
}
|
|
private void delete(){
|
int userIndex = userList.getSelectedIndex();
|
int roleIndex = roleList.getSelectedIndex();
|
int deptIndex = deptList.getSelectedIndex();
|
if(radioChoseFlag.equals("user")){
|
if (userIndex == -1) {
|
VCIOptionPane.showMessage(LogonApplication.frame, "请选择记录");
|
return;
|
}
|
if(userNameList!=null&&userNameList.size()>0){
|
userNameList.remove(userIndex);
|
}
|
userListModel.remove(userIndex);
|
userList.setSelectedIndex(userIndex - 1);
|
userList.setModel(userListModel);
|
userList.updateUI();
|
/**
|
* 删除时,修改UserObjs里的对象,
|
* 解决“加过责任人后后删除该责任人,再次添加,之前添加过的用户会显示在添加用户框右侧,不友好”问题
|
* added by wangxl 2012-11-30
|
*/
|
List list = new ArrayList();
|
String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
if(userDialogControl!=null&&!"".equals(userDialogControl)){
|
for (int i = 0 ; i < userListModel.getSize() ; i ++){
|
list.add(userListModel.getElementAt(i));
|
}
|
|
}else{
|
for (int i = 0 ; i < userListModel.getSize() ; i ++){
|
list.add((UserObject) userListModel.getElementAt(i));
|
}
|
}
|
userObjs = list;
|
}
|
if(radioChoseFlag.equals("role")){
|
if (roleIndex == -1) {
|
VCIOptionPane.showMessage(LogonApplication.frame, "请选择记录");
|
return;
|
}
|
roleListModel.remove(roleIndex);
|
roleList.setSelectedIndex(roleIndex - 1);
|
roleList.updateUI();
|
|
/**
|
* 删除时,修改roleObjs里的对象
|
* 解决“加过责任人后后删除该责任人,再次添加,之前添加过的用户会显示在添加用户框右侧,不友好”问题
|
* added by wangxl 2012-11-30
|
*/
|
List<RoleObject> list = new ArrayList<RoleObject>();
|
for (int i = 0 ; i < roleListModel.getSize() ; i ++){
|
list.add((RoleObject) roleListModel.getElementAt(i));
|
}
|
roleObjs = list;
|
|
}
|
if(radioChoseFlag.equals("depart")){
|
if (deptIndex == -1) {
|
VCIOptionPane.showMessage(LogonApplication.frame, "请选择记录");
|
return;
|
}
|
deptListModel.remove(deptIndex);
|
deptList.setSelectedIndex(deptIndex - 1);
|
deptList.updateUI();
|
/**
|
* 删除时,修改deptObjs里的对象
|
* 解决“加过责任人后后删除该责任人,再次添加,之前添加过的用户会显示在添加用户框右侧,不友好”问题
|
* added by wangxl 2012-11-30
|
*/
|
List<DeptObject> list = new ArrayList<DeptObject>();
|
for (int i = 0 ; i < deptListModel.getSize() ; i ++){
|
list.add((DeptObject) deptListModel.getElementAt(i));
|
}
|
deptObjs = list;
|
}
|
}
|
|
private void selectUser() {
|
String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
if(userDialogControl!=null&&!"".equals(userDialogControl)){
|
Class<?> cls;
|
try {
|
cls = Class.forName(userDialogControl);
|
CustomUserDialog res = (CustomUserDialog) cls.getConstructor(RMUserComponent.class).newInstance(this);
|
res.setLocationRelativeTo(null);
|
res.setVisible(true);
|
|
if(interFaceResult!=null&&!"".equals(interFaceResult)){
|
listModel.addElement(interFaceResult);
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
}
|
}else{
|
UserSelectionDialog userSelectionDialog = new UserSelectionDialog();
|
userSelectionDialog.setLocationRelativeTo(null);
|
userSelectionDialog.setVisible(true);
|
|
List<UserObject> userObjectlist = userSelectionDialog.getUserObjectlist();
|
if (userObjectlist != null) {
|
for (UserObject userObject : userObjectlist) {
|
if(!listModel.contains(userObject)) {
|
listModel.addElement(userObject);
|
}
|
}
|
}
|
}
|
}
|
public JComponent getUserComponent() {
|
return userComponent;
|
}
|
|
/*
|
* 获取已选择的用户信息
|
* @see com.vci.rmip.workflow.client.editor.user.IUserComponent#getSelectedUsers()
|
*/
|
public List<String> getSelectedUsers() {
|
if(userNameList != null && userNameList.size() > 0){
|
return userNameList;
|
}else{
|
List<String> list = new ArrayList<String>();
|
|
int size = userListModel.size();
|
for (int i = 0; i < size; i++) {
|
Object elementAt = userListModel.getElementAt(i);
|
if(elementAt instanceof String){
|
list.add((String) elementAt);
|
}else if(elementAt instanceof UserObject){
|
UserObject userObject = (UserObject) elementAt;
|
list.add(userObject.getUserName());
|
}
|
}
|
|
return list;
|
}
|
}
|
|
// public void setSelectedUsers(List<String> users) {
|
// listModel.removeAllElements();
|
// try {
|
// for (String userName : users) {
|
// String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
// if(userDialogControl!=null&&!"".equals(userDialogControl)){
|
// listModel.addElement(userName);
|
// }else{
|
// UserObject user = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
|
// if (!"".equals(user.getUserName())){
|
// listModel.addElement(user);
|
// }
|
// }
|
//
|
// }
|
// } catch (VCIError e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
public JComponent getUserComponent(CustomEditPanel customUserPanel) {
|
this.customUserPanel = customUserPanel;
|
return userComponent;
|
}
|
|
// /* 获取用户列表
|
// * @see com.vci.rmip.workflow.client.editor.user.IUserComponent#getSelectedUsers()
|
// */
|
// public List<String> getSelectedUsers() {
|
// List<String> list = new ArrayList<String>();
|
//
|
// int usersize = userListModel.size();
|
// for (int i = 0; i < usersize; i++) {
|
// UserObject userObject = (UserObject) userListModel.getElementAt(i);
|
// list.add(userObject.getUserName());
|
// }
|
// return list;
|
// }
|
|
/**获取角色列表
|
* @return
|
*/
|
public List<String> getSelectedRoles() {
|
List<String> list = new ArrayList<String>();
|
|
int rolesize = roleListModel.size();
|
for (int i = 0; i < rolesize; i++) {
|
RoleObject roleObject = (RoleObject) roleListModel.getElementAt(i);
|
list.add(roleObject.getId());
|
}
|
return list;
|
}
|
/**获取部门列表
|
* @return
|
*/
|
public List<String> getSelectedDepts() {
|
List<String> list = new ArrayList<String>();
|
|
int deptsize = deptListModel.size();
|
for (int i = 0; i < deptsize; i++) {
|
DeptObject deptObject = (DeptObject) deptListModel.getElementAt(i);
|
list.add(deptObject.getId());
|
}
|
return list;
|
}
|
RightManagementClientDelegate rmgrDel = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
|
public void setSelectedUsers(List<String> users) {
|
userListModel.removeAllElements();
|
userObjs.clear();
|
try {
|
String[] userNames = users.get(0).split(",");
|
for (int k =0;k<userNames.length;k++) {
|
String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
|
if(userDialogControl!=null&&!"".equals(userDialogControl)){
|
if(userNames[k].contains(":")){//需不需要对所有的userName判断后再分情况
|
userNameList.add(userNames[k]);
|
userListModel.addElement(userNames[k].split(":")[0]);
|
}else{
|
userListModel.addElement(userNames[k]);
|
}
|
}else{
|
// UserObject user = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName);
|
// if (!"".equals(user.getUserName())){
|
// listModel.addElement(user);
|
// }
|
if("".equals(userNames[k].trim())) {
|
continue;
|
}
|
UserObject userObj = new UserObject();
|
if ("#CURRENTUSER#".equals(userNames[k])) {
|
userObj.setId("currentUser");
|
userObj.setTrueName("当前登录用户");
|
userObj.setUserName("#CURRENTUSER#");
|
} else {
|
userObj = rmgrDel.fetchUserInfoByName(userNames[k]);
|
}
|
userListModel.addElement(userObj);
|
userObjs.add(userObj);
|
}
|
|
}
|
|
} catch (VCIException e) {
|
e.printStackTrace();
|
return;
|
}
|
}
|
public void setSelectedRoles(List<String> roles) {
|
roleListModel.removeAllElements();
|
roleObjs.clear();
|
try {
|
String[] roleNames = roles.get(0).split(",");
|
for (int k=0;k<roleNames.length;k++) {
|
if("".equals(roleNames[k])) {
|
continue;
|
}
|
RoleObject roleObj = rmgrDel.fetchRoleInfoById(roleNames[k]);
|
roleListModel.addElement(roleObj);
|
roleObjs.add(roleObj);
|
}
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return;
|
}
|
}
|
public void setSelectedDepts(List<String> depts) {
|
deptListModel.removeAllElements();
|
deptObjs.clear();
|
try {
|
String[] deptNames = depts.get(0).split(",");
|
for (int k=0;k<deptNames.length;k++) {
|
if("".equals(deptNames[k])) {
|
continue;
|
}
|
DeptObject deptObj = rmgrDel.fetchDepartmentInfoById(deptNames[k]);
|
deptListModel.addElement(deptObj);
|
deptObjs.add(deptObj);
|
}
|
} catch (VCIException e) {
|
e.printStackTrace();
|
}
|
}
|
|
public String getSelectedCust() {
|
return custText.getText().trim();
|
}
|
|
public void setSelectedCust(String cust) {
|
custText.setText(cust);
|
}
|
|
public List<String> getSelectedUserDepartment() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public List<String> getSelectedUserRole() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public List<String> getSelectedUserOrg() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public List<String> getSelectedUserLine() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public List<String> getSelectedDeptAddUser() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public void setSelectedUserDepartment(List<String> users) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void setSelectedUserRole(List<String> users) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void setSelectedUserDept(List<String> users) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void setSelectedUserLine(List<String> users) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void setSelectedDeptAndUser(List<String> users) {
|
// TODO Auto-generated method stub
|
|
}
|
|
}
|