wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.vci.client.framework.appConfig;
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Locale;
 
import com.vci.client.LogonApplication;
import com.vci.client.framework.appConfig.object.AppConfigDetailObject;
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;
import com.vci.client.ui.swing.components.VCIJPanel;
 
public class AppConfigDetailPanelActionListener implements ActionListener {
 
    private IConfigDetailPanel owner = null;
    private LinkedHashMap<String, Runnable> actionMaps = new LinkedHashMap<String, Runnable>();
    
    public AppConfigDetailPanelActionListener(IConfigDetailPanel owner){
        this.owner = owner;
        this.initActionMap();
    }
    
    private void initActionMap(){
        actionMaps.put("create", new Runnable() { public void run() {
            createAppConfigDetail();//
        }});
        actionMaps.put("edit", new Runnable() { public void run() {
            editAppConfigDetail();//
        }});
        actionMaps.put("delete", new Runnable() { public void run() {
            deleteAppConfigDetail();//
        }});
    
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        String key = e.getActionCommand();
        if(actionMaps.containsKey(key)){
            actionMaps.get(key).run();
        }
    }
 
    private void createAppConfigDetail() {
        String clsfId = owner.getConfigCategory();
        if (clsfId == null || clsfId.equals("")) {
            VCIOptionPane.showMessage((VCIJPanel)owner, "请先选择分类!");    
            return;
        }
        AppConfigDetailDialog dialog = new AppConfigDetailDialog(LogonApplication.frame, owner, clsfId);
        owner.getTablePanel().refreshTableData();
    }
    
    private void editAppConfigDetail() {
        int[] chk = owner.getTablePanel().getSelectedRowIndexs();
        Integer[] chkSelRows = new Integer[chk.length];
        for (int i = 0 ;i<chk.length;i++){
            chkSelRows[i]= new Integer(chk[i]);
        }
        int len = chkSelRows.length;
        if(len == 0){
            VCIOptionPane.showMessage(((VCIJPanel)owner), 
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.deptedit1", "RMIPFramework", ((VCIJPanel)owner).getLocale()));
            return;
        }
        if (len > 1){
            VCIOptionPane.showMessage(((VCIJPanel)owner), 
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.deptedit2", "RMIPFramework", ((VCIJPanel)owner).getLocale()));
            return;
        }
        AppConfigDetailObject obj = owner.getTablePanel().getSelectedRowObjects().get(0);
        new AppConfigDetailDialog(LogonApplication.frame, owner, obj);
        owner.getTablePanel().refreshTableData();
    }
    
    private void deleteAppConfigDetail() {
        int[] chk =owner.getTablePanel().getSelectedRowIndexs();
        Integer[] chkSelRows = new Integer[chk.length];
        for (int i = 0 ;i<chk.length;i++){
            chkSelRows[i]= new Integer(chk[i]);
        }
        int len = chkSelRows.length;
        if(len == 0){
            VCIOptionPane.showMessage(((VCIJPanel)owner),  "请选择要删除的对象!");
            return;
        }
        String[] puids = new String[len];
        for (int i = 0; i < len; i++) {
            LinkedList<AppConfigDetailObject> list= owner.getTablePanel().getSelectedRowObjects();
            puids[i] = list.get(i).getId();
            int ok=VCIOptionPane.showQuestion(LogonApplication.frame,"您确定要删除选中的对象吗?");
            if (ok == 0) {
                boolean rs=true;
                try {
                    rs = new AppConfigDetailClientDelegate(LogonApplication.getUserEntityObject()).deleteAppConfigDetail(puids);
                } catch (VCIException e) {
                    VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e, "RMIPFramework", Locale.getDefault()));
                    return;
                }
                if (!rs) {
                    return;
                }
                owner.getTablePanel().refreshTableData();
            }
        }
    }
}