package com.vci.client.framework.systemConfig.stafforgmanage;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import com.vci.client.LogonApplication;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.framework.appConfig.object.AppConfigDetailObject;
import com.vci.client.framework.delegate.AppConfigDetailClientDelegate;
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.CombinationObject;
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.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;
/**
*
Title: PasswordStrategyTablePanel
* Description: 密码策略
* Copyright: Copyright (c) 2012
* Company: VCI
* @author wangxl
* @time 2012-5-21
* @version 1.0
*/
public class PasswordStrategyTablePanel 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 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);
//添加密码策略修改限制,只有在系统配置项中配置为true才显示修改按钮
String editAppConfigValue = "true";
String key = "";
UserEntityObject userEntityObject = LogonApplication.getUserEntityObject();
userEntityObject.setModules("密级策略修改控制");
try {
AppConfigDetailObject[] appConfigDetails = new AppConfigDetailClientDelegate(userEntityObject).getAppConfigDetails();
if(appConfigDetails!=null&&appConfigDetails.length>0){
for (AppConfigDetailObject appConfigDetailObject : appConfigDetails) {
key = appConfigDetailObject.getKey();
if("password_policy_changeable".equals(key)){
editAppConfigValue = appConfigDetailObject.getValue();
}
}
}
} catch (VCIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if("true".equalsIgnoreCase(editAppConfigValue)){
selfCustomButtons.add(editButton);
}
//over
selfCustomButtons.add(deleteButton);
}
public PasswordStrategyTablePanel(FunctionObject funcObj){
super(funcObj);
init();
// checkPermission();
}
private void init() {
//LogonApplication.getUserEntityObject().setModules(this.getClass().getName());
//LogonApplication.getUserEntityObject().setModules("密码策略");
initComponents();
initAction();//初始化按钮点击事件
}
private void initComponents() {
setLayout(new BorderLayout());
// add(initControl(), BorderLayout.SOUTH);
add(initTablePanel(), BorderLayout.CENTER);
}
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 checkPermission(){
checkRight(RightControlUtil.CREATE, addButton);
checkRight(RightControlUtil.UPDATE, editButton);
checkRight(RightControlUtil.DELETE, deleteButton);
}
class MyDataProvider extends AbstractVCIJTableDataProvider{
@Override
public PasswordStrategyObject[] getDatas(int pageNo, int pageSize) {
PasswordStrategyObject[] psdStgObjs = null;
try {
psdStgObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
.fetchAllPasswordStrategy(pageNo,pageSize);
} catch (VCIException re) {
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", re);
}
return psdStgObjs;
}
@Override
public VCIJTableNode getNewRowNode(
PasswordStrategyObject dataObj) {
VCIJTableNode node = new VCIJTableNode(dataObj);
node.setPropertyValue(getSpecialColumns()[0], dataObj.getName());
node.setPropertyValue(getSpecialColumns()[1], dataObj.getPasswordLen());
node.setPropertyValue(getSpecialColumns()[2], dataObj.getPasswordMaxLen());
String charSpeics = "";
//CombinationObject[] combinationObjs = null;
int cts = dataObj.getCharTypes();
if ((cts & 0x01) == 0x01)
charSpeics +="数字;";
if ((cts & 0x02) == 0x02)
charSpeics +="小写字母;";
if ((cts & 0x04) == 0x04)
charSpeics +="大写字母;";
if ((cts & 0x08) == 0x08)
charSpeics +="符号;";
if (charSpeics.length() > 1)
charSpeics = charSpeics.substring(0, charSpeics.length() - 1);
node.setPropertyValue(getSpecialColumns()[3], charSpeics);
node.setPropertyValue(getSpecialColumns()[4], dataObj.getRequiredType());
node.setPropertyValue(getSpecialColumns()[5], dataObj.getOverdueDay());
node.setPropertyValue(getSpecialColumns()[6], dataObj.getRemideDay());
node.setPropertyValue(getSpecialColumns()[7], dataObj.getRetryTime());
node.setPropertyValue(getSpecialColumns()[8], dataObj.getLockTime());
node.setPropertyValue(getSpecialColumns()[9], dataObj.getDesc()== null ? "" : dataObj.getDesc());
node.setPropertyValue(getSpecialColumns()[10], dataObj.getIsDefault() ? "是" : "否");
return node;
}
@Override
public String[] getSpecialColumns() {
return "策略名称, 密码最小长度, 密码最大长度, 组合方式, 必填种类, 过期时间(天), 提醒时间(天), 重试次数(次), 锁定时间(分钟), 描述, 是否为默认策略".split(",");
}
@Override
public int getTotal() {
try {
total = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).getPasswordStrategyTotal();
} 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++, 100);
widthMaps.put(startIndex++, 100);
widthMaps.put(startIndex++, 100);
widthMaps.put(startIndex++, 250);
tablePanel.setColumnWidthMaps(widthMaps);
tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
tablePanel.setCustomButtons(selfCustomButtons);
tablePanel.setShowPaging(true);
tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER);
tablePanel.setShowExport(false);
tablePanel.buildTablePanel();
tablePanel.refreshTableData();
return tablePanel;
}
/**
* 事件
*/
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();
}
});
}
/**
* 添加事件
*/
private void addButton_conform(){
PasswordSrategyDialog dialog = new PasswordSrategyDialog(this ,"addPwdStg");
dialog.setVisible(true);
}
/**
* 修改事件
*/
private void editButton_conform(){
int len = tablePanel.getSelectedRowIndexs().length;
if(len == 0){
VCIOptionPane.showMessage(this,
"请选择密级策略!");
return;
}
if (len > 1){
VCIOptionPane.showMessage(this,
"一次只能对一个密级策略进行修改操作,请重新选择");
return;
}
LinkedList objects = tablePanel.getSelectedRowObjects();
PasswordSrategyDialog dialog = new PasswordSrategyDialog (this,objects.get(0),"editPwdStg");
dialog.setVisible(true);
}
/**
* 删除事件
*/
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++) {
LinkedList objects = tablePanel.getSelectedRowObjects();
PasswordStrategyObject pwdStgObj = objects.get(i);
if(pwdStgObj.getIsDefault()) {
VCIOptionPane.showMessageDialog(this, "要删除的密码策略 "+pwdStgObj.getName()+" 是默认策略,不允许删除\n如果要删除请先把其他密码策略设置成默认的,在进行删除操作!");
map.clear();
return;
}
puids[i] = pwdStgObj.getId();
try {
int count = new RightManagementClientDelegate().checkPasswordStrategyIsquotedCount(puids[i]);
if(count > 0){
VCIOptionPane.showMessageDialog(this, "要删除的密码策略 "+pwdStgObj.getName()+" 已被引用,不允许删除!");
map.clear();
return;
}
} catch (VCIException e) {
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
}
map.put(pwdStgObj.getId(), pwdStgObj.getName());
}
int ok=VCIOptionPane.showQuestion(LogonApplication.frame,
"确定要删除选中的对象吗?");
if (ok == 0) {
boolean rs=true;
try {
rs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deletePasswordStrategy(puids);
} catch (VCIException e) {
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
return ;
}
if (!rs) {
return;
}
}else{
return;
}
tablePanel.refreshTableData();
}
@Override
public String getUserID() {
return logonUserId;
}
@Override
public String getRoleID() {
return logonRoleId;
}
@Override
public JPanel getModuleComponent() {
return this;
}
@Override
public String getModuleName() {
return moduleName;
}
@Override
public String getIconName() {
return iconName;
}
@Override
public String getModuleShowInfo() {
return moduleShowInfo;
}
}