wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package com.vci.client.uif.engine.client.tableArea;
 
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
 
import com.vci.client.ClientSession;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.uif.actions.client.AbstractBatchBusionessOperationAction;
import com.vci.client.uif.actions.client.BusinessOperationAction;
import com.vci.client.uif.engine.client.IRegionPanel;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLCommandParameter;
import com.vci.corba.portal.data.PLTabButton;
import com.vci.mw.ClientContextVariable;
 
public class ButtonActionListener implements ActionListener {
        private String type = "";
        private String context = "";
        
        private PLTabButton button = null;
        private PLAction action = null;
        
        private IRegionPanel regionPanel = null;
        private BusinessOperationAction boa = null;
        private VCIJDialog ownerDialog = null;
        private Component buttonComponent = null;
        
        public ButtonActionListener(String type, String context,
                PLTabButton button, PLAction action, IRegionPanel regionPanel,
                Component buttonComponent) {
            super();
            this.type = type;
            this.context = context;
            this.button = button;
            this.action = action;
            this.regionPanel = regionPanel;
            this.buttonComponent = buttonComponent;
        }
 
        private BusinessOperationAction createBusinessOperationActionInstance(String actionClass){
            BusinessOperationAction boa = null;
            if(actionClass != null && !"".equals(actionClass)){
                try {
                    Object obj = Class.forName(actionClass).getConstructor().newInstance();
                    if(obj instanceof BusinessOperationAction && obj instanceof AbstractBatchBusionessOperationAction){
                        boa = (BusinessOperationAction)obj;
                    }
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return boa;
        }
        
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isExpired = ClientSession.checkExpired();
            if(isExpired){
                ClientSession.relogin();
                return;
            }
            invoke(e);
        }
        
        private void invoke(ActionEvent e){
            //TODO 从定义中取出KEY
            String key = getAction().plCode;
            String actionClass = getAction().plCSClass;
            
            // 根据Action的 Class,动态创建实例
            boa = createBusinessOperationActionInstance(actionClass);
            if(boa != null){
                boa.setButtonComponent(getButtonComponent());
                boa.setOwnerDialog(getOwnerDialog());
                
                //  组织参数Map
                HashMap<String, String> paramsMap = buildActionParamsMap();
                boa.setButtonParams(paramsMap);
                //将button参数加入到全局变量中
                ClientContextVariable.cleanOtherGlobalVariable();
                Iterator<String> itor = paramsMap.keySet().iterator();
                while (itor.hasNext()) {
                    String cKey = itor.next();
                    String cValue = paramsMap.get(cKey);
                    if (cValue == null) {
                        cValue = "";
                    }
                    ClientContextVariable.putGlobalVariable(cKey, cValue);
                }
                
                boa.setButton(getButton());
                boa.setAction(getAction());
                boa.setDefination(getRegionPanel().getDefination());
                boa.setRegionPanel(regionPanel);
                // 设置父容器对象
                boa.setParentComponent(getRegionPanel().getComponentPanel());
                // 设置Button所在区域的DataModel
                boa.setDataModel(regionPanel.getDataModel());
                // 执行 Action 
                ((AbstractBatchBusionessOperationAction)boa).doAction();
                
            } else {
                VCIJOptionPane.showError(ClientContextVariable.getFrame(), " 未能根据  " + actionClass + " 创建出对应的 Action 实例");
            }
        }
        
        public HashMap<String, String> buildActionParamsMap(){
 
            HashMap<String, String> paramsMap = new HashMap<String, String>();
            paramsMap.put("buttonOid", getButton().plOId);
            paramsMap.put("actionOid", getAction().plOId);
 
            // 查询出Button上定义的参数,传递给Action
            // 一般必须要定义 type、context
            // 即:表明该Buttonr要操作哪个业务类型、使用该业务类型的哪个上下文
            // 在Action 的具体的实现中,将提取上面两个参数,进行相关初始化操作
            try {
                PLCommandParameter[] btnParams = UITools.getService().getPLCommandParametersByCommandOId(getButton().plOId);
                for(PLCommandParameter cp : btnParams){
                    String key = cp.plKey;
                    String value = cp.plValue;
                    paramsMap.put(key, value);
                }
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             return paramsMap;
        }
        
        public PLTabButton getButton() {
            return button;
        }
 
        public void setButton(PLTabButton button) {
            this.button = button;
        }
 
        public PLAction getAction() {
            return action;
        }
 
        public void setAction(PLAction action) {
            this.action = action;
        }
 
        public String getType() {
            return type;
        }
 
        public void setType(String type) {
            this.type = type;
        }
 
        public String getContext() {
            return context;
        }
 
        public void setContext(String context) {
            this.context = context;
        }
 
 
        public IRegionPanel getRegionPanel() {
            return regionPanel;
        }
 
        public void setRegionPanel(IRegionPanel regionPanel) {
            this.regionPanel = regionPanel;
        }
 
        public BusinessOperationAction getBoa() {
            return boa;
        }
 
        public void setBoa(BusinessOperationAction boa) {
            this.boa = boa;
        }
 
        public VCIJDialog getOwnerDialog() {
            return ownerDialog;
        }
 
        public void setOwnerDialog(VCIJDialog ownerDialog) {
            this.ownerDialog = ownerDialog;
            if(boa != null){
                boa.setOwnerDialog(ownerDialog);
            }
        }
 
        /**
         * action 所在的
         * @return
         */
        public Component getButtonComponent() {
            return buttonComponent;
        }
 
        public void setButtonComponent(Component buttonComponent) {
            this.buttonComponent = buttonComponent;
        }
        
        
}