package com.vci.client.framework.systemConfig.stafforgmanage;
|
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
|
import javax.swing.JOptionPane;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.framework.systemConfig.object.CombinationObject;
|
import com.vci.client.framework.systemConfig.object.CombinationValueObject;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.components.VCIJComboBox;
|
|
public class CombinationValueActionListener implements ActionListener {
|
private CombinationValueTablePanel combValPanel;
|
private String optType;
|
private CombinationObject combObject;
|
|
public CombinationValueActionListener(CombinationValueTablePanel combValPanel,String optType){
|
this.combValPanel = combValPanel;
|
this.optType = optType;
|
}
|
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if (optType.equals("add")) {
|
createButton_actionEvent();
|
} else if (optType.equals("modify")) {
|
editButton_actionEvent();
|
} else if (optType.equals("delete")) {
|
deleteButton_actionEvent();
|
}
|
}
|
/**
|
* 添加
|
* <p>Description: </p>
|
*
|
* @author wangxl
|
* @time 2013-1-3
|
*/
|
private void createButton_actionEvent(){
|
VCIJComboBox combox = combValPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
|
return;
|
}
|
String value = combValPanel.getValueText();
|
boolean checkValue = checkValue(value);
|
if (!checkValue) {
|
return;
|
}
|
int length = value.length();
|
ArrayList<CombinationValueObject> list = new ArrayList<CombinationValueObject>();
|
for (int i = 0; i < length; i++) {
|
String values = String.valueOf(value.charAt(i)).trim();
|
if ("".equals(values)) {
|
continue;
|
}
|
CombinationValueObject combValObject = new CombinationValueObject();
|
combValObject.setValue(values);
|
list.add(combValObject);
|
}
|
|
try {
|
boolean rs = isCharacterHaveExist(list);
|
if (rs) {
|
return;
|
}
|
int size = list.size();
|
CombinationValueObject[] addCombValObject = new CombinationValueObject[size];
|
combObject = combValPanel.getCombinationObject();
|
for (int i = 0; i < size; i++) {
|
addCombValObject[i] = list.get(i);
|
addCombValObject[i].setParentId(combObject.getId());
|
}
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveCombinationValue(addCombValObject);
|
combValPanel.initTableProperty(combObject.getId());
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
|
}
|
}
|
/**
|
* 修改
|
* <p>Description: </p>
|
*
|
* @author wangxl
|
* @time 2013-1-3
|
*/
|
private void editButton_actionEvent(){
|
VCIJComboBox combox = combValPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
|
return;
|
}
|
String value = combValPanel.getValueText();
|
boolean checkValue = checkValue(value);
|
if (!checkValue) {
|
return;
|
}
|
CombinationValueObject combValObject = combValPanel.getCombinationValueObject();
|
String oldValue = combValObject.getValue();//选到的值
|
try {
|
combValObject.setValue(value);
|
if(!oldValue.equals(value)){ //add by liujw
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateCombinationValue(combValObject);
|
}
|
VCIOptionPane.showMessageDialog(combValPanel, "修改成功!");
|
} catch (VCIException e) {
|
combValObject.setValue(oldValue);
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
|
}
|
combObject = combValPanel.getCombinationObject();
|
combValPanel.initTableProperty(combObject.getId());
|
combValPanel.setValueText("");
|
}
|
/**
|
* 删除
|
* <p>Description: </p>
|
*
|
* @author wangxl
|
* @time 2013-1-3
|
*/
|
private void deleteButton_actionEvent(){
|
VCIJComboBox combox = combValPanel.getClassComBox();
|
if(combox.getSelectedIndex() < 0){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
|
return;
|
}
|
CombinationValueObject combValObject = combValPanel.getCombinationValueObject();
|
if(combValObject == null){
|
JOptionPane.showMessageDialog(combValPanel,"请选择要删除的取值范围");
|
return;
|
}
|
|
ArrayList<String> arrayListPuids = new ArrayList<String>(); //要删除的分割符id
|
arrayListPuids.add(combValObject.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, "您确定要删除选中的组合方式取值范围吗?","提醒",VCIOptionPane.YES_NO_OPTION);
|
if (i == 0){
|
try {
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deletCombinationValues(puids);
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
|
}
|
combObject = combValPanel.getCombinationObject();
|
combValPanel.initTableProperty(combObject.getId());
|
combValPanel.setValueText("");
|
}
|
}
|
private boolean checkValue(String value) {
|
if ("".equals(value)) {
|
VCIOptionPane.showMessageDialog(combValPanel,"值不能为空,请填写!");
|
return false;
|
}
|
if (optType.equals("modify")) {
|
if (value.length() != 1) {
|
VCIOptionPane.showMessageDialog(combValPanel, "一次只能修改一个对象,请重新选择!");
|
return false;
|
}
|
|
CombinationValueObject obj = combValPanel.getCombinationValueObject();
|
if (obj == null) {
|
VCIOptionPane.showMessageDialog(combValPanel, "请选择要修改的取值范围");
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/***
|
*
|
* @param list 要添加的字符
|
* @return 如果要添加的字符有的已经存在,则返回true,否则返回false
|
*/
|
private boolean isCharacterHaveExist( ArrayList<CombinationValueObject> list) {
|
int size = list.size();
|
StringBuffer stringbuffer = new StringBuffer();
|
for (int i = 0; i < size; i++) {
|
String addValue = list.get(i).getValue();
|
stringbuffer.append(addValue);
|
}
|
int stringbufferLength = stringbuffer.length();//要添加的数组间存不存在重复
|
for (int i = 0; i < stringbufferLength - 1; i++) {
|
String character = stringbuffer.substring(i, i+1);
|
if (stringbuffer.toString().indexOf(character) != stringbuffer.toString().lastIndexOf(character)) {
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "添加的 '" + character + "' 字符不能添加多个,请修改");
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|