package com.vci.client.framework.appConfig; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedHashMap; import java.util.Locale; import com.vci.client.LogonApplication; import com.vci.client.framework.appConfig.object.AppConfigCategoryObject; import com.vci.client.framework.appConfig.object.AppConfigDetailObject; import com.vci.client.framework.delegate.AppConfigCategoryClientDelegate; import com.vci.client.framework.delegate.AppConfigDetailClientDelegate; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.VCIOptionPane; public class AppConfigCategoryDialogActionListener implements ActionListener { private AppConfigCategoryDialog dialog = null; private LinkedHashMap actionMaps = new LinkedHashMap(); public AppConfigCategoryDialogActionListener(AppConfigCategoryDialog dialog){ this.dialog = dialog; this.initActionMap(); } private void initActionMap(){ actionMaps.put("confirm", new Runnable() { public void run() { saveOrUpdateConfig();// }}); } @Override public void actionPerformed(ActionEvent e) { String key = e.getActionCommand(); if(actionMaps.containsKey(key)){ actionMaps.get(key).run(); } } private void saveOrUpdateConfig() { AppConfigCategoryObject obj = dialog.getConfigDetail(); boolean isValid = check(obj); if (!isValid) { return; } boolean rs = false; if (obj.getId().equals("")) { rs = saveAppConfigCategory(obj); } else { rs = updateAppConfigCategory(obj); } if (rs) { dialog.dispose(); dialog.getAppConfigCategoryPanel().getTablePanel().refreshTableData(); } } private boolean saveAppConfigCategory(AppConfigCategoryObject obj) { boolean rs = false; try { AppConfigCategoryClientDelegate delegate = new AppConfigCategoryClientDelegate(LogonApplication.getUserEntityObject()); String id = delegate.saveAppConfigCategory(obj); obj.setId(id); rs = true; } catch (VCIException e) { VCIOptionPane.showError(dialog, LocaleDisplay.getI18nString(e, "RMIPFramework", Locale.getDefault())); rs = false; } return rs; } private boolean updateAppConfigCategory(AppConfigCategoryObject obj) { boolean rs = false; try { AppConfigCategoryClientDelegate delegate = new AppConfigCategoryClientDelegate(LogonApplication.getUserEntityObject()); rs = delegate.updateAppConfigCategory(obj); } catch (VCIException e) { VCIOptionPane.showError(dialog, LocaleDisplay.getI18nString(e, "RMIPFramework", Locale.getDefault())); rs = false; } return rs; } private boolean check(AppConfigCategoryObject obj) { if ("".equals(obj.getName())) { VCIOptionPane.showMessageDialog(dialog, "名称不能为空!"); return false; } return true; } }