xiejun
2023-10-17 9e341acec731503f1540b65727441e771b8ef9b4
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
 
package com.vci.rmip.code.client.codeapply.Apply410;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
 
import com.vci.base.ui.swing.VCIOptionPane;
import com.vci.base.ui.swing.components.VCIJDialog.DialogResult;
import com.vci.base.ui.tree.VCIBaseTreeNode;
import com.vci.rmip.code.client.codeapply.Apply410.enums.CodeReferConfigTypeEnum;
import com.vci.rmip.code.client.codeapply.Apply410.object.UIFormRefer;
import com.vci.rmip.code.client.codeapply.Apply410.object.tree.Tree;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.model.BaseModel;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.vo.KeyValue;
import com.vci.rmip.code.client.codeapply.Apply410.utils.VciBaseUtil;
 
import javax.swing.tree.TreePath;
 
public class RMDataReferTempDialogActionListener implements ActionListener {
 
    private RMDataReferTempDialog owner = null;
    public RMDataReferTempDialogActionListener(RMDataReferTempDialog owner){
        this.owner = owner;
        this.initActionMap();
    }
 
    private LinkedHashMap<String, Runnable> actionMaps = new LinkedHashMap<String, Runnable>();
    private void initActionMap(){
        actionMaps.put("ok", new Runnable() { public void run() {
            ok();
        }});
        actionMaps.put("cancel", new Runnable() { public void run() {
            cancel();
        }});
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        String key = e.getActionCommand();
        if(actionMaps.containsKey(key)){
            actionMaps.get(key).run();
        }
    }
 
    private void ok(){
        //if(!owner.isFromTableDoubleClick()){
        /*    LinkedList<RMDataObject> list = this.owner.getRMDataMainPanel().getTablePanel().getSelectedRowObjects();
            if(list.size() > 1) {
                VCIOptionPane.showMessageDialog(this.owner, "不允许选择多条数据进行操作!");
                return;
            } else if(list.size() <= 0) {
                VCIOptionPane.showMessageDialog(this.owner, "请选择数据进行操作!");
                return;
            }*/
 
            UIFormRefer uiFormRefer=owner.getUiFormRefer();
            String textField=uiFormRefer.getTextField();
            String valueField=uiFormRefer.getValueField();
            if(uiFormRefer !=null&&(uiFormRefer.getType().equals(CodeReferConfigTypeEnum.TREE.getValue())
                ||uiFormRefer.getType().equals(CodeReferConfigTypeEnum.ORGDEPARTMENTREFER.getValue()))){
                TreePath treePath=this.owner.getTypeTreePanel().getTree().getSelectionPath();
                VCIBaseTreeNode treeNode = (VCIBaseTreeNode)treePath.getLastPathComponent();
                if(treeNode.getObj() instanceof Tree) {
                    Tree tree =(Tree)treeNode.getObj();
                    Map<String,String> attibuteMap=    tree.getAttributes();
                    String fieldValue=attibuteMap.containsKey(valueField) ? attibuteMap.get(valueField) : "";
                    String textValue=attibuteMap.containsKey(textField) ? attibuteMap.get(textField) : "";
                    KeyValue keyValue=new KeyValue();
                    keyValue.setKey(fieldValue);
                    keyValue.setValue(textValue);
                    this.owner.setKeyValue(keyValue);
                }
 
            }else{
                LinkedList<BaseModel> list =this.owner.getCodeDataMainPanel().getTablePanel().getSelectedRowObjects();
                if(list.size() > 1) {
                    VCIOptionPane.showMessageDialog(this.owner, "不允许选择多条数据进行操作!");
                    return;
                } else if(list.size() <= 0) {
                    VCIOptionPane.showMessageDialog(this.owner, "请选择数据进行操作!");
                    return;
                }
                BaseModel baseModel=list.get(0);
                Map<String, String> defaultDataMap= VciBaseUtil.objectToMapString(list.get(0));
                defaultDataMap.putAll(baseModel.getData());
                String fieldValue=defaultDataMap.containsKey(valueField) ? defaultDataMap.get(valueField) : "";
                String textValue=defaultDataMap.containsKey(textField) ? defaultDataMap.get(textField) : "";
                KeyValue keyValue=new KeyValue();
                keyValue.setKey(fieldValue);
                keyValue.setValue(textValue);
                this.owner.setKeyValue(keyValue);
            }
        //}
        owner.setDialogResult(DialogResult.OK);
        close();
        owner.getDialogCallback().run();
    }
 
    private void cancel(){
        owner.setDialogResult(DialogResult.CANCEL);
        close();
    }
 
    private void close(){
        owner.setVisible(false);
    }
}