package com.vci.client.framework.systemConfig.specialCharacter; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Locale; import javax.swing.JPanel; import javax.swing.tree.TreePath; import com.vci.client.LogonApplication; import com.vci.client.common.TransmitTreeObject; import com.vci.client.framework.delegate.SystemCfgClientDelegate; import com.vci.client.framework.systemConfig.object.SpecialCharClsfObject; 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; /*** * 特殊字符分类删除监听 * @author Administrator * */ public class SpecialCharacterClsActionListener implements ActionListener{ /****************************国际化信息**********************************/ //请选择要删除的节点! private String SELECTDELETENODE = LocaleDisplay.getI18nString("rmip.framework.sysconfig.selectDeleteNode", "RMIPFramework",Locale.getDefault()); //选择删除的节点包括非特殊字符分类节点,请重新选择! private String DELETECLSFALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteClsfAlert", "RMIPFramework",Locale.getDefault()); //您确定要删除选中的分类吗? private String DELETECLSFCONFIRM = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteClsfConfirm", "RMIPFramework",Locale.getDefault()); //名称不能为空,请重新填写! private String NAMEALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.nameAlert", "RMIPFramework",Locale.getDefault()); //名称的长度不能超过128个字符! private String ROLELENGTHALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.nameLengthAlert", "RMIPFramework",Locale.getDefault()); //描述的长度不能超过255个字符! private String DESCLENGTHALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.descLengthAlert", "RMIPFramework",Locale.getDefault()); //修改成功! private String MODIFYSUCCESS = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifySuccess", "RMIPFramework",Locale.getDefault()); private TransmitTreeObject transmitTreeObject; private String type = ""; private SpecialCharacterPanel specialCharacterPanel = null; private String name = ""; //分类的名称 private String des = ""; //分类的描述 private JPanel jpanel = null; private SpecialCharacterDialog dialog; private SpecialCharacterPanel panel; private SpecialCharClsfObject obj; public SpecialCharacterClsActionListener(SpecialCharacterDialog dialog,String type,SpecialCharacterPanel panel,SpecialCharClsfObject obj) { this.type = type; this.dialog = dialog; this.panel = panel; this.obj = obj; } public void actionPerformed(ActionEvent e) { if (type.equals("add")) { add_actionPerformed(); } else if (type.equals("modify")) { edit_actionPerformed(); } else if (type.equals("delete")) { delete_actionPerformed(); } } private SpecialCharClsfObject getSpecialCharacterClsInfo() { SpecialCharClsfObject specialCharClsfInfo = new SpecialCharClsfObject(); specialCharClsfInfo.setName(dialog.getNameFieldText()); specialCharClsfInfo.setDesc(dialog.getDescriptionArea()); if("modify".equalsIgnoreCase(type)){ specialCharClsfInfo.setId(obj.getId()); } return specialCharClsfInfo; } private void delete_actionPerformed() { TreePath[] treePaths = transmitTreeObject.getTree().getSelectionPaths(); if (treePaths.length < 1) { VCIOptionPane.showMessageDialog(LogonApplication.frame, SELECTDELETENODE); return; } deleteSpecialCharClsfInfo(treePaths); } private void deleteSpecialCharClsfInfo(TreePath[] deleteTreePaths) { 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; //选择的节点是否可以删除 SpecialCharClsfObject specialCharClsfObject = null; if (!(treeNode.getObj() instanceof SpecialCharClsfObject)) { canDelete = false; } else { specialCharClsfObject = (SpecialCharClsfObject) treeNode.getObj(); if ("root".equals(specialCharClsfObject.getId())) { canDelete = false; } } if (!canDelete) { VCIOptionPane.showMessageDialog(LogonApplication.frame, DELETECLSFALERT); return; } removeNodes[i] = treeNode; puids[i] = specialCharClsfObject.getId(); } int ok=VCIOptionPane.showQuestion(LogonApplication.frame,DELETECLSFCONFIRM); if (ok == 0) { boolean rs=true; try { rs = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).deletSpecialCharClsf(puids); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e); return; } if (!rs) { return; } VCIBaseTreeNode parentNode = (VCIBaseTreeNode) transmitTreeObject.getCurrentTreeNode().getParent(); for (int i = 0; i < len; i++) { transmitTreeObject.getTreeModel().removeNodeFromParent(removeNodes[i]); } transmitTreeObject.getTree().setSelectionPath(new TreePath(parentNode.getPath())); } } private boolean checkName(boolean isAddOrEdit){ name = dialog.getNameFieldText(); des = dialog.getDescriptionArea(); if("".equalsIgnoreCase(name)){ VCIOptionPane.showMessageDialog(LogonApplication.frame,NAMEALERT); return false; } if (name.getBytes().length > 128) { VCIOptionPane.showMessageDialog(LogonApplication.frame, ROLELENGTHALERT); return false; } if (des.getBytes().length > 255) { VCIOptionPane.showMessageDialog(LogonApplication.frame, DESCLENGTHALERT); return false; } SpecialCharClsfObject[] objs = getSpecialCharClsfObjs(); /***特殊字符分类名称重复的校验**/ if(isAddOrEdit) { for(SpecialCharClsfObject obj : objs) { if(name.equals(obj.getName())) { VCIOptionPane.showMessageDialog(this.dialog, "分类名称存在重复,请重新输入!"); return false; } } } else { for(SpecialCharClsfObject clsfObj : objs) { if(name.equals(clsfObj.getName()) && !(clsfObj.getId().equals(obj.getId()))) { VCIOptionPane.showMessageDialog(this.dialog, "分类名称存在重复,请重新输入!"); return false; } } } return true; } public SpecialCharClsfObject[] getSpecialCharClsfObjs() { SpecialCharClsfObject[] Objects = null; try { Objects = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()) .getSpecialCharClsfList(1,10000); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); return null; } return Objects; } private void add_actionPerformed() { boolean rs = checkName(true); if (!rs) { return; } SpecialCharClsfObject specialCharClsfInfo = getSpecialCharacterClsInfo(); try { String id = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).saveSpecialCharClsf(specialCharClsfInfo); specialCharClsfInfo.setId(id); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e); return; } VCIOptionPane.showMessage(LogonApplication.frame, "保存成功!"); dialog.dispose(); } private void edit_actionPerformed() { boolean rs = checkName(false); if (!rs) { return; } SpecialCharClsfObject specialCharClsfInfo = getSpecialCharacterClsInfo(); try { new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).updateSpecialCharClsf(specialCharClsfInfo); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e); return; } VCIOptionPane.showMessage(LogonApplication.frame, "修改成功!"); dialog.dispose(); } }