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(); } } /** * 添加 *

Description:

* * @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 list = new ArrayList(); 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); } } /** * 修改 *

Description:

* * @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(""); } /** * 删除 *

Description:

* * @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 arrayListPuids = new ArrayList(); //要删除的分割符id arrayListPuids.add(combValObject.getId()); String[] puids=new String[arrayListPuids.size()]; for(int i=0;i 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; } }