package com.vci.client.framework.systemConfig.specialCharacter;
|
|
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.Locale;
|
|
import javax.swing.JOptionPane;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
|
import com.vci.client.framework.systemConfig.object.SpecialCharClsfObject;
|
import com.vci.client.framework.systemConfig.object.SpecialCharObject;
|
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.components.VCIJComboBox;
|
|
|
/***
|
* 特殊字符
|
* @author Administrator
|
*
|
*/
|
public class SpecialCharacterActionListener implements ActionListener{
|
|
/****************************国际化信息**********************************/
|
//要修改的值只能是一个字符!
|
private String MODIFYALERT2 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifyCharAlert2", "RMIPFramework",Locale.getDefault());
|
//请选中要修改的字符进行修改操作!
|
private String MODIFYALERT3 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifyCharAlert3", "RMIPFramework",Locale.getDefault());
|
//值不能为空!
|
private String VALUEALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.valueAlert", "RMIPFramework",Locale.getDefault());
|
//添加的 '
|
private String ADDALERT1 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.addCharAlert1", "RMIPFramework",Locale.getDefault());
|
//' 字符不能添加多个,请修改!
|
private String ADDALERT2 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.addCharAlert2", "RMIPFramework",Locale.getDefault());
|
//修改成功!
|
private String MODIFYSUCCESS = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifySuccess", "RMIPFramework",Locale.getDefault());
|
//请选择要删除的字符!
|
private String DELETEALERT1 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteCharAlert1", "RMIPFramework",Locale.getDefault());
|
//您确定要删除选中的字符吗?
|
private String DELETECONFIRM = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteConfirm", "RMIPFramework",Locale.getDefault());
|
//温馨提示
|
private String WARMTIP = LocaleDisplay.getI18nString("rmip.framework.sysconfig.warmTip", "RMIPFramework",Locale.getDefault());
|
|
private SpecialCharacterPanel characterPanel = null;
|
private String type = ""; //相应类型 添加:add 修改:modify 删除delete
|
private SpecialCharClsfObject obj;
|
|
public SpecialCharacterActionListener(SpecialCharacterPanel characterPanel , String type ) {
|
this.characterPanel = characterPanel;
|
this.type = type;
|
}
|
|
public void actionPerformed(ActionEvent e) {
|
if (type.equals("add")) {
|
createCharacterButton_actionEvent();
|
} else if (type.equals("modify")) {
|
editCharacterButton_actionEvent();
|
} else if (type.equals("delete")) {
|
deleteCharacterButton_actionEvent();
|
}
|
|
}
|
|
private boolean checkValue() {
|
String value = characterPanel.getValueText();
|
if ("".equals(value)) {
|
VCIOptionPane.showMessageDialog(characterPanel,VALUEALERT);
|
return false;
|
}
|
if (type.equals("modify")) {
|
if (value.length() != 1) {
|
VCIOptionPane.showMessageDialog(characterPanel, MODIFYALERT2);
|
return false;
|
}
|
SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
|
if (specialCharObject == null) {
|
VCIOptionPane.showMessageDialog(characterPanel, MODIFYALERT3);
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/***
|
* 添加特殊字符
|
*
|
*/
|
private void createCharacterButton_actionEvent() {
|
VCIJComboBox combox = characterPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
|
return;
|
}
|
String value = characterPanel.getValueText();
|
boolean checkValue = checkValue();
|
if (!checkValue) {
|
return;
|
}
|
int length = value.length();
|
ArrayList<SpecialCharObject> list = new ArrayList<SpecialCharObject>();
|
for (int i = 0; i < length; i++) {
|
String values = String.valueOf(value.charAt(i)).trim();
|
if ("".equals(values)) {
|
continue;
|
}
|
SpecialCharObject specialCharObject = new SpecialCharObject();
|
specialCharObject.setValue(values);
|
list.add(specialCharObject);
|
}
|
|
try {
|
SpecialCharClsfObject clsfObj = (SpecialCharClsfObject) combox.getSelectedItem();
|
String plsfoId = clsfObj.getId();
|
boolean rs = isCharacterHaveExist(list, plsfoId);
|
if (rs) {
|
return;
|
}
|
int size = list.size();
|
SpecialCharObject[] addSpecialCharObject = new SpecialCharObject[size];
|
obj = characterPanel.getSpecialCharClsfObject();
|
for (int i = 0; i < size; i++) {
|
addSpecialCharObject[i] = list.get(i);
|
addSpecialCharObject[i].setParentId(obj.getId());
|
}
|
new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).saveSpecialChar(addSpecialCharObject);
|
characterPanel.initTableProperty(obj.getId());
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
|
}
|
|
}
|
|
/***
|
*
|
* @param list 要添加的字符
|
* @return 如果要添加的字符有的已经存在,则返回true,否则返回false
|
*/
|
private boolean isCharacterHaveExist(ArrayList<SpecialCharObject> list,String plsfoId) {
|
int size = list.size();
|
int count=0;
|
|
SpecialCharObject[] specialCharObjects = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).getBychar(plsfoId);
|
ArrayList<String> importValues = new ArrayList<String>();
|
for (int i = 0; i < list.size(); i++) {
|
//判断输入字符中是否包含重复值
|
if(importValues.contains(list.get(i).getValue())){
|
return true;
|
}
|
importValues.add(list.get(i).getValue());
|
if(specialCharObjects.length>0){
|
for (int t = 0; t < specialCharObjects.length; t++) {
|
if(list.get(i).getValue().equals(specialCharObjects[t].getValue())){
|
|
count+=1;
|
}
|
|
}
|
|
}
|
}
|
if(count>0){
|
|
return true;
|
}else{
|
return false;
|
}
|
|
|
}
|
|
/***
|
* 修改监听事件
|
*
|
*/
|
private void editCharacterButton_actionEvent() {
|
VCIJComboBox combox = characterPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
|
return;
|
}
|
String value = characterPanel.getValueText();
|
boolean checkValue = checkValue();
|
if (!checkValue) {
|
return;
|
}
|
|
SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
|
String oldValue = specialCharObject.getValue();
|
try {
|
specialCharObject.setValue(value);
|
|
//add by liujw
|
if(!oldValue.equals(value)){
|
new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).updateSpecialChar(specialCharObject);
|
}
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, MODIFYSUCCESS);
|
} catch (VCIException e) {
|
specialCharObject.setValue(oldValue);
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
|
}
|
obj = characterPanel.getSpecialCharClsfObject();
|
characterPanel.initTableProperty(obj.getId());
|
characterPanel.setValueText("");
|
}
|
|
/***
|
* 删除监听事件
|
*
|
*/
|
private void deleteCharacterButton_actionEvent(){
|
VCIJComboBox combox = characterPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
|
return;
|
}
|
SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
|
if(specialCharObject == null){
|
JOptionPane.showMessageDialog(LogonApplication.frame,DELETEALERT1);
|
return;
|
}
|
|
ArrayList<String> arrayListPuids = new ArrayList<String>(); //要删除的分割符id
|
arrayListPuids.add(specialCharObject.getId());
|
String[] puids=new String[arrayListPuids.size()];
|
for(int i=0;i<puids.length;i++){
|
puids[i]=arrayListPuids.get(i);
|
}
|
int i = VCIOptionPane.showConfirmDialog(null, DELETECONFIRM,WARMTIP,VCIOptionPane.YES_NO_OPTION);
|
if (i == 0){
|
try {
|
new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).deletSpecialChar(puids);
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
|
}
|
obj = characterPanel.getSpecialCharClsfObject();
|
characterPanel.initTableProperty(obj.getId());
|
characterPanel.setValueText("");
|
}
|
}
|
|
|
}
|