package com.vci.client.framework.systemConfig.stafforgmanage; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.border.TitledBorder; import org.apache.poi.ss.formula.functions.T; import com.vci.client.LogonApplication; import com.vci.client.common.VCIBasePanel; import com.vci.client.common.objects.RoleObject; import com.vci.client.common.objects.UserEntityObject; 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.util.RightControlUtil; import com.vci.client.logon.client.LogonFrame; 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.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; import com.vci.client.ui.util.UIHelper; import com.vci.mw.ClientContextVariable; /** *

Title:RoleTablePanel

*

Description: 角色管理界面

*

Copyright: Copyright (c) 2012

*

Company: VCI

* @author wangxl * @time 2012-5-11 * @version 1.0 */ public class RoleTablePanel extends VCIBasePanel implements IModuleShow{ private static final long serialVersionUID = 1L; 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 btnDisplay = VCISwingUtil.createVCIJButton("", "统计","统计","group.gif",null); private VCIJButton rightButton = VCISwingUtil.createVCIJButton("", "分配成员","分配成员", "user.gif" ,null); private VCIJButton btnImport = VCISwingUtil.createVCIJButton("", "导入角色","导入角色", "usertask.gif" ,null); private RightManagementClientDelegate rightDel = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()); private String userName = LogonApplication.getUserEntityObject().getUserName(); private String logonUserId = "",logonRoleId; private String moduleName = ""; private String iconName,moduleShowInfo ; // private SpecialRoleObject specialRoleObject = new SpecialRoleObject(); // public SpecialRoleObject getSpecialRoleObject() { // return specialRoleObject; // } // // public void setSpecialRoleObject(SpecialRoleObject specialRoleObject) { // this.specialRoleObject = specialRoleObject; // } 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 void setModuleName(String moduleName) { this.moduleName = moduleName; } public void setIconName(String iconName) { this.iconName = iconName; } public void setModuleShowInfo(String moduleShowInfo) { this.moduleShowInfo = moduleShowInfo; } private LinkedList selfCustomButtons = new LinkedList(); { selfCustomButtons.add(addButton); selfCustomButtons.add(editButton); selfCustomButtons.add(deleteButton); UserObject user = LogonApplication.getUserObject(); if (RightControlUtil.isAdminOrDeveloperOrRoot(user.getUserName()) || RightControlUtil.isThreeAdmin(RightControlUtil.ThreeAdminEnum.SECADMIN)) selfCustomButtons.add(rightButton); selfCustomButtons.add(btnDisplay); selfCustomButtons.add(btnImport); } public RoleTablePanel(FunctionObject funcObj){ super(funcObj); init(); // checkPermission(); } private void init() { //LogonApplication.getUserEntityObject().setModules(this.getClass().getName()); LogonApplication.getUserEntityObject().setModules(this.getModuleName());//"角色管理"); initComponents(); initAction();//初始化按钮点击事件 } private void initComponents() { setLayout(new BorderLayout()); add(initTablePanel(), BorderLayout.CENTER); } private void checkPermission(){ checkRight(RightControlUtil.CREATE, addButton); checkRight(RightControlUtil.UPDATE, editButton); checkRight(RightControlUtil.DELETE, deleteButton); checkRight(RightControlUtil.FREEZE, rightButton); checkRight(RightControlUtil.DISCARD, btnDisplay); } class MyDataProvider extends AbstractVCIJTableDataProvider{ @Override public RoleObject[] getDatas(int pageNo, int pageSize) { RoleObject[] roleObjs = null; try { roleObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchRoleInfoByUserName(pageNo,pageSize,userName); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); return null; } return roleObjs; } @Override public VCIJTableNode getNewRowNode(RoleObject dataObj) { VCIJTableNode node = new VCIJTableNode(dataObj); node.setPropertyValue(getSpecialColumns()[0], dataObj.getName()); node.setPropertyValue(getSpecialColumns()[1], dataObj.getDescription()); return node; } @Override public String[] getSpecialColumns() { return "名称, 描述".split(","); } @Override public int getTotal() { try { total = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .getRoleTotalByUserName(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(){ int startIndex = dataProvider.getDataColumnStartIndex(); LinkedHashMap widthMaps = new LinkedHashMap(); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); tablePanel.setColumnWidthMaps(widthMaps); tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER); tablePanel.setCustomButtons(selfCustomButtons); tablePanel.setShowPaging(true); tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER); //add by caill 2016.1.20 tablePanel.setShowExport(true); tablePanel.buildTablePanel(); tablePanel.refreshTableData(); return tablePanel; } private JPanel initTablePanel(){ JPanel pal = new JPanel(); pal.setLayout(new BorderLayout()); pal.setBorder(new TitledBorder("角色管理")); pal.add(tablePanel(), BorderLayout.CENTER); pal.setVisible(true); return pal; } /** * 事件 */ private void initAction(){ 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_conform(); } }); rightButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { rightButton_conform(); } }); btnDisplay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { btnDisplay_conform(); } }); //add by caill start 2016.1.20为角色管理添加导入功能 btnImport.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ImportData(); tablePanel.refreshTableData(); //刷新界面 }}); //add by caill end } //add by caill start 2016.1.20 创建角色导入的界面 private void ImportData(){ RolesImportDialog eid = new RolesImportDialog(this); eid.init(); eid.setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT); eid.setLocationRelativeTo(ClientContextVariable.getFrame()); eid.setVisible(true); } //add by caill end /** * 添加事件 */ private void addButton_conform(){ new RoleDialog(this,"addRole"); } /** * 修改事件 */ 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.deptedit2", "RMIPFramework", getLocale())); return; } RoleObject obj = tablePanel.getSelectedRowObjects().get(0); try { UserObject fetchUserInfoByName = rightDel.fetchUserInfoByName(LogonApplication.getUserEntityObject().getUserName()); if(fetchUserInfoByName.getUserType()!=0){ if(obj.getType()==1){ VCIOptionPane.showMessage(this, "当前用户不可以修改三员角色"); return; } } } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); } new RoleDialog (this,obj,"editRole"); } /** * 删除事件 */ private void deleteButton_conform(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, "请选择要删除的对象!"); return; } String[] puids = new String[len]; Map map = new HashMap(); for (int i = 0; i < len; i++) { RoleObject roleInfo = tablePanel.getSelectedRowObjects().get(i); try { UserObject fetchUserInfoByName = rightDel.fetchUserInfoByName(LogonApplication.getUserEntityObject().getUserName()); if(fetchUserInfoByName.getUserType()!=0){ if(roleInfo.getType()==1){ VCIOptionPane.showMessage(this, "当前用户不可以删除三员角色"); return; } } } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); } puids[i] = roleInfo.getId(); map.put(roleInfo.getId(), roleInfo.getName()); } RightManagementClientDelegate del = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()); for(int k=0;k 0) { VCIOptionPane.showMessageDialog(LogonApplication.frame, "角色:"+map.get(puids[k]) +"已经被引用,不能对其进行删除操作!"); return; } } catch (VCIException e) { e.printStackTrace(); VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); return ; } } int ok=VCIOptionPane.showQuestion(LogonApplication.frame, LocaleDisplay.getI18nString("rmip.stafforg.operate.conformdelrole", "RMIPFramework", getLocale())); if (ok == 0) { boolean rs=true; try { rs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deleteRole(puids); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); return ; } if (!rs) { return; } }else{ return; } tablePanel.refreshTableData(); } /** * 分配成员事件 */ private void rightButton_conform(){ int len = tablePanel.getSelectedRowIndexs().length; if (len == 0){ VCIOptionPane.showMessage(this, "请选择角色进行成员分配!"); return; }else if (len > 1){ VCIOptionPane.showMessage(this, "一次只能对一个角色进行分配人员操作!"); return; }else { RoleObject rightRoleObj = tablePanel.getSelectedRowObjects().get(0); RightRoleDialog dialog = new RightRoleDialog(rightRoleObj); dialog.setVisible(true); } } private void btnDisplay_conform(){ int len = tablePanel.getSelectedRowIndexs().length; DisplayDialog dialog = null; if(len == 0){ VCIOptionPane.showMessage(this, "请选择角色!"); return; }else if (len > 1){ VCIOptionPane.showMessage(this, "最多只能选择一个角色进行统计!"); return; }else{ RoleObject[] roleObjs = new RoleObject[len]; for (int i = 0 ; i < len ; i ++){ roleObjs[i] = tablePanel.getSelectedRowObjects().get(i); } dialog = new DisplayDialog(roleObjs); } dialog.setModal(true); dialog.setVisible(true); } @Override public String getUserID() { return logonUserId; } @Override public String getRoleID() { return logonRoleId; } @Override public JPanel getModuleComponent() { return this; } @Override 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(); } @Override public String getIconName() { return iconName; } @Override public String getModuleShowInfo() { return moduleShowInfo; } }