package com.vci.client.framework.specialrole; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.TitledBorder; import org.apache.commons.lang3.StringUtils; import com.vci.client.LogonApplication; import com.vci.client.common.TransmitTreeObject; import com.vci.client.common.VCIBasePanel; import com.vci.client.common.objects.DeptObject; import com.vci.client.common.objects.RoleObject; import com.vci.client.common.objects.UserEntityObject; import com.vci.client.common.objects.UserLogonObject; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow; import com.vci.client.framework.systemConfig.object.PasswordStrategyObject; 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.KJButton; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider; import com.vci.client.ui.swing.components.table.VCIJTableNode; import com.vci.client.ui.swing.components.table.VCIJTablePanel; /** * 成员管理界面,带Table页,便于客户查询 * @author liud * */ public class UserTablePanel extends VCIBasePanel implements IModuleShow{ private static final long serialVersionUID = 1L; private String userName = LogonApplication.getUserEntityObject().getUserName(); private UserEntityObject userEntityObj = LogonApplication.getUserEntityObject(); private TransmitTreeObject transmitTreeObject = null; Hashtable hashTable = new Hashtable(); // 控件的坐标位置变量 private int x = 10; private int y = 20; private int width = 50; private int height = 25; private int hspan = 5; private JLabel trueNameLabel = new JLabel(LocaleDisplay.getI18nString("rmip.stafforg.logal.firstname", "RMIPFramework", getLocale())); private JTextField trueNameText = new JTextField(); private JLabel nameLabel = new JLabel(LocaleDisplay.getI18nString("rmip.stafforg.logal.username", "RMIPFramework", getLocale())); private JTextField userNameText = new JTextField(); private JComboBox departmentComBox = new JComboBox(); private KJButton searchButton = new KJButton("查询","search.png"); private KJButton clearButton = new KJButton("清空","clear.gif"); private VCIJButton addButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.add", "RMIPFramework", getLocale()) , LocaleDisplay.getI18nString("rmip.stafforg.operate.add", "RMIPFramework", getLocale()),"create.gif",null); private VCIJButton editButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.modify", "RMIPFramework", getLocale()) ,LocaleDisplay.getI18nString("rmip.stafforg.operate.modify", "RMIPFramework", getLocale()), "modify.gif",null); private VCIJButton deleteButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.delete", "RMIPFramework", getLocale()) ,LocaleDisplay.getI18nString("rmip.stafforg.operate.delete", "RMIPFramework", getLocale()), "delete.gif",null); private VCIJButton rightButton = VCISwingUtil.createVCIJButton("", "分配成员","分配成员", "user.gif" ,null); //三员模块的角色id private String roleId = ""; private String logonUserId = "",logonRoleId; private String moduleName = "成员管理"; private String iconName,moduleShowInfo ; private SpecialRoleClientObject specialRoleObject = new SpecialRoleClientObject(); public SpecialRoleClientObject getSpecialRoleObject() { return specialRoleObject; } public void setSpecialRoleObject(SpecialRoleClientObject specialRoleObject) { this.specialRoleObject = specialRoleObject; } public String getRoleId() { return roleId; } public void setRoleId(String roleId) { this.roleId = roleId; } public String getLogonUserId() { return logonUserId; } public void setLogonUserId(String logonUserId) { this.logonUserId = logonUserId; } public String getLogonRoleId() { return logonRoleId; } public void setLogonRoleId(String logonRoleId) { this.logonRoleId = logonRoleId; } public String getModuleName() { if (this.getFuncObj() != null && this.getFuncObj().getName() != null) return this.getFuncObj().getName(); else if (moduleName != null && !moduleName.isEmpty()) return moduleName; else return this.getClass().getName(); } public void setModuleName(String moduleName) { this.moduleName = moduleName; } public String getIconName() { return iconName; } public void setIconName(String iconName) { this.iconName = iconName; } public String getModuleShowInfo() { return moduleShowInfo; } public void setModuleShowInfo(String moduleShowInfo) { this.moduleShowInfo = moduleShowInfo; } private LinkedList selfCustomButtons = new LinkedList(); private void setButtons(){ if(RightControlUtil.isRoot(userName)){ selfCustomButtons.add(addButton); selfCustomButtons.add(editButton); selfCustomButtons.add(deleteButton); } // SpecialRoleClientObject[] specialRoleList; // try { // specialRoleList = new SpecialRoleClientDelegate().getSpecialRoleList(); // for(SpecialRoleClientObject o : specialRoleList){ // boolean roleIdFlag = false; // RoleObject[] userRoleObjects = getUserRoleObjects(userName); // String logonRoleId = o.getLogonRoleId(); // for(RoleObject roleObj : userRoleObjects){ // String id = roleObj.getId(); // if(logonRoleId.equals(id)){ // roleIdFlag = true; // } // } // if(roleIdFlag){ // selfCustomButtons.add(rightButton); // } // } // } catch (VCIError e) { // e.printStackTrace(); // } } public UserTablePanel(FunctionObject funcObj,String roleID){ super(funcObj); this.roleId = roleID; init(); // checkPermission(); } private void init() { LogonApplication.getUserEntityObject().setModules(this.getModuleName()); initComponents(); initAction();//初始化按钮点击事件 } private void initComponents() { setLayout(new BorderLayout()); initDepartment(); add(initTablePanel(), BorderLayout.CENTER); } /** 权限检查的模块标识 **/ private void checkPermission(){ checkRight(RightControlUtil.CREATE, addButton); checkRight(RightControlUtil.UPDATE, editButton); checkRight(RightControlUtil.DELETE, deleteButton); } class MyDataProvider extends AbstractVCIJTableDataProvider { private searchInfoClass searchInfos = new searchInfoClass(); public searchInfoClass getSearchInfos() { return searchInfos; } public void setSearchInfos(searchInfoClass searchInfos) { this.searchInfos = searchInfos; } @Override public UserObject[] getDatas(int pageNo, int pageSize) { UserObject[] userObj = null; try { userObj = new RightManagementClientDelegate(userEntityObj).fetchUserInfoByCondition( searchInfos.getName() ,searchInfos.getUserName() , searchInfos.getDeptId(),roleId,userName,pageNo,pageSize); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return null; } return userObj; } @Override public VCIJTableNode getNewRowNode(UserObject dataObj) { VCIJTableNode node = new VCIJTableNode(dataObj); node.setPropertyValue(getSpecialColumns()[0], dataObj.getTrueName()); node.setPropertyValue(getSpecialColumns()[1], dataObj.getUserName()); node.setPropertyValue(getSpecialColumns()[2], dataObj.getStatus()==1 ? "停用":"启用"); /********BEGIN***********/ /**密码策略**/ try { PasswordStrategyObject userPasswordStrategyObj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchPasswordStrategyByUserId(dataObj.getId()); node.setPropertyValue(getSpecialColumns()[3], userPasswordStrategyObj == null ? "" : userPasswordStrategyObj); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); } /**锁定状态**/ try { UserLogonObject lockObj = new RightManagementClientDelegate().getUserLogonObj(dataObj.getId()); if (!StringUtils.isEmpty(lockObj.getPluserOid())) node.setPropertyValue(getSpecialColumns()[4], lockObj.getPlWrongNum() == 0 ? "未锁定" : "锁定"); else node.setPropertyValue(getSpecialColumns()[4], "未锁定"); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); } /********END***********/ // CompanyObject companyObj = null; DeptObject obj = null; RoleObject[] roles = null; String deptName = ""; try { obj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchDeptByUserId(dataObj.getId()); if (obj != null){ if(!hashTable.containsKey((obj.getId()))){ deptName = getDeptObjectAllByDeptId(obj); hashTable.put(obj.getId(), deptName); }else{ deptName = hashTable.get(obj.getId()); } } roles = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchRoleInfoByUserId(dataObj.getId()); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e); } node.setPropertyValue(getSpecialColumns()[5], deptName); String roleNames = ""; if (roles.length != 0){ for(int j = 0 ; j < roles.length ; j ++){ if (j < roles.length -1){ roleNames += roles[j].getName() + ","; }else { roleNames += roles[j].getName(); } } } node.setPropertyValue(getSpecialColumns()[6], roleNames); node.setPropertyValue(getSpecialColumns()[7], dataObj.getEmail()); node.setPropertyValue(getSpecialColumns()[8], dataObj.getDesc()); node.setPropertyValue(getSpecialColumns()[9], dataObj.getIsDeptLeader().equals("1") ? "是" : "否"); return node; } @Override public String[] getSpecialColumns() { return "姓名, 账号, 状态,密码策略,锁定状态, 所属部门, 拥有角色, 电子邮件, 描述,是否是部门领导".split(","); } //根据子部门查询所属的父类部门,并拼接成字符串形式,返回 public String getDeptObjectAllByDeptId(DeptObject obj){ String fetchDepName = ""; try{ DeptObject[] depObjectAll = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchDepartmentInfosBySonId(obj.getId()); for(int i=depObjectAll.length-1;i>=0; i--){ fetchDepName += depObjectAll[i].getName()+"/"; } if(fetchDepName.length() != 0){ fetchDepName = fetchDepName.substring(0, fetchDepName.length() - 1); } }catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); } return fetchDepName; } @Override public int getTotal() { try { total = new RightManagementClientDelegate(userEntityObj).getUserTotalByCondition( searchInfos.getName() ,searchInfos.getUserName() , searchInfos.getDeptId(), roleId,userName); } catch (VCIException e) { e.printStackTrace(); VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e); } return this.total; } } MyDataProvider dataProvider = new MyDataProvider(); VCIJTablePanel tablePanel = new VCIJTablePanel(dataProvider); private VCIJPanel tablePanel(){ setButtons(); int startIndex = dataProvider.getDataColumnStartIndex()+5; LinkedHashMap widthMaps = new LinkedHashMap(); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); tablePanel.setColumnWidthMaps(widthMaps); tablePanel.setCustomButtons(selfCustomButtons); tablePanel.setShowPaging(true); tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER); tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER); tablePanel.setShowExport(false); tablePanel.buildTablePanel(); tablePanel.refreshTableData(); return tablePanel; } private JPanel initTablePanel(){ JPanel pal = new JPanel(); pal.setLayout(new BorderLayout()); pal.setBorder(new TitledBorder("成员管理")); JPanel searchPal = new JPanel(); searchPal.setLayout(null); searchPal.setPreferredSize(new Dimension(600, 40)); x = 20; y = 7; width = 40; height = 23; trueNameLabel.setBounds(x, y, width, height); x = trueNameLabel.getX() + trueNameLabel.getWidth(); width = 120; trueNameText.setBounds(x, y, width, height); x = trueNameText.getX() + trueNameText.getWidth() + height;width = 40; nameLabel.setBounds(x, y, width, height); x = nameLabel.getX() + nameLabel.getWidth() ; width = 120; userNameText.setBounds(x, y, width, height); //x = 20; y = 50; width = 40; height = 25; width=80; x += userNameText.getWidth() + hspan*3; searchButton.setBounds(x, y, width, height); x += searchButton.getBounds().width + hspan; clearButton.setBounds(x, y, width, height); searchPal.add(trueNameLabel); searchPal.add(trueNameText); searchPal.add(nameLabel); searchPal.add(userNameText); searchPal.add(searchButton); searchPal.add(clearButton); pal.add(searchPal, BorderLayout.NORTH); pal.add(tablePanel(), BorderLayout.CENTER); pal.setVisible(true); return pal; } /** * 初始化部门 * */ private void initDepartment() { departmentComBox.addItem(new DeptObject()); } private void initAction(){ tablePanel.getTable().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { mousePressed(e); } public void mousePressed(MouseEvent e) { Point p = e.getPoint(); int row = tablePanel.getTable().rowAtPoint(p); if(row < 0) return; // UserObject obj = tablePanel.getTableModel().getList().get(row).getObject(); /**解锁状态是否启用**/ // String lockName = (String) tablePanel.getTableModel().getList().get(row).getPropertyValue("锁定状态"); // boolean lockFlag = lockName == "未锁定" ? true : false; // if(lockFlag) { // deblockButton.setEnabled(false); // }else { // deblockButton.setEnabled(true); // } } }); searchButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ searchButton_actionPerformed(); } }); clearButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ clearButton_actionPerformed(); } }); addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { addButton_conform(); } }); editButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { editButton_conform(); } }); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { deleteButton_actionPerformed(); } }); rightButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { rightButton_conform(); } }); } /** * 分配成员事件 */ private void rightButton_conform(){ RoleObject rightRoleObj = new RoleObject(); rightRoleObj.setId(roleId); rightRoleObj.setType((short)1); SelectUserDialog dialog = new SelectUserDialog(rightRoleObj); dialog.setVisible(true); tablePanel.refreshTableData(); } /** * 搜索事件 */ private void searchButton_actionPerformed(){ searchInfoClass searchInfo = new searchInfoClass(); searchInfo.setName(this.gettrueNameText().trim()); searchInfo.setUserName(this.getUserNameText().trim()); searchInfo.setDeptId(this.getDeptId()); dataProvider.setSearchInfos(searchInfo); this.tablePanel.refreshTableData(); } private void clearButton_actionPerformed(){ this.userNameText.setText(""); this.trueNameText.setText(""); this.departmentComBox.setSelectedIndex(0); departmentComBox.setToolTipText(""); searchInfoClass info = new searchInfoClass(); dataProvider.setSearchInfos(info); tablePanel.refreshTableData(); } /** * 添加事件 */ private void addButton_conform(){ new UserDialog(this,transmitTreeObject,"add"); } /** * 修改事件 */ private void editButton_conform(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, "请选择人员再进行操作!"); return; } if (len > 1){ VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString("rmip.stafforg.operate.useredit2", "RMIPFramework", getLocale())); return; } UserObject obj = tablePanel.getSelectedRowObjects().get(0); new UserDialog(this,transmitTreeObject , obj ,"edit"); } /** * 删除事件 */ private void deleteButton_actionPerformed(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString("rmip.stafforg.operate.userdelete1", "RMIPFramework", getLocale())); return; } List objList = tablePanel.getSelectedRowObjects(); for(int i=0;iDescription: 获取部门ID

* * @author wangxl * @time 2012-5-14 * @return */ public String getDeptId(){ String deptId = ""; if ((DeptObject)departmentComBox.getSelectedItem() != null && ((DeptObject)departmentComBox.getSelectedItem()).getId() != null ){ deptId = ((DeptObject)departmentComBox.getSelectedItem()).getId(); } return deptId; } public class searchInfoClass { private String name = ""; private String userName = ""; private String roleId = ""; private String deptId = ""; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getRoleId() { return roleId; } public void setRoleId(String roleId) { this.roleId = roleId; } public String getDeptId() { return deptId; } public void setDeptId(String deptId) { this.deptId = deptId; } } public static void main(String[] args){ // UserEntityObject userEntityObject = new UserEntityObject(); // userEntityObject.setUserName("admin"); // LogonApplication.userEntityObject =userEntityObject; // UserObject userObject = new UserObject(); // userObject.setUserName("admin"); // LogonApplication.userObject = userObject; // VciFrame frame = new VciFrame(userObject); // LogonApplication.frame = frame; // funcObj= new FunctionObject(); // UserTablePanel utp = new UserTablePanel(funcObj); // utp.init(); // frame.add(utp); // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // frame.setFocusableWindowState(true); // frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Dimension frameSize = frame.getPreferredSize(); // frameSize.height = screenSize.height / 5 * 4; // frameSize.width = screenSize.width / 5 * 4 + 20; // frame.setSize(frameSize); // frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); // frame.setVisible(true); // frame.setExtendedState(JFrame.MAXIMIZED_BOTH); } private RoleObject[] getUserRoleObjects(String userName){ RoleObject[] roles = {}; try { UserObject userObject = LogonApplication.getUserObject(); String userId = userObject.getId(); roles = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchRoleInfoByUserId(userId); } catch (VCIException e) { e.printStackTrace(); } return roles; } @Override public String getUserID() { return logonUserId; } @Override public String getRoleID() { return logonRoleId; } @Override public JPanel getModuleComponent() { this.setButtons(); tablePanel.setCustomButtons(selfCustomButtons); tablePanel.buildTablePanel(); tablePanel.refreshTableData(); return this; } }