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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package com.vci.client.uif.actions.client;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
import javax.swing.JFrame;
import javax.swing.WindowConstants;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.common.FreeMarkerCommon;
import com.vci.client.common.FreemarkerParamObject;
import com.vci.client.logon.client.VciFrame;
import com.vci.client.uif.engine.client.UIHelper;
import com.vci.client.uif.engine.client.UILayoutPanel;
import com.vci.client.uif.engine.common.DefaultTableNode;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.mw.ClientContextVariable;
 
/**
 * 浏览操作
 * 在新的frame页中根据type、context打开窗口
 * 接受参数信息为:
 *     btmname(业务对象类型)
 *     context
 *     oid(业务对象oid)
 * @author VCI-STGK006
 *
 */
public class ViewFrameAction extends AbstractBusionessOperationAction{
 
    /**
     * 方法集合
     */
    protected UIFUtils operation =
            new UIFUtils();
    /**
     * 按钮参数
     */
    private Map<String, String> paramsMap = null;
    
    /**
     * BO对象
     */
    protected ClientBusinessObject cbo = null;
    
    public ViewFrameAction(){
        super();
    }
    
    @Override
    public String getKey() {
        return VIEW;
    }
    
    @Override
    public boolean checkHasRight(){
        // 按BO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B);
        return super.checkHasRight();
    }
    
    @Override
    public boolean doPost() {
        try{
            //获得按钮参数
            paramsMap = getButtonParams();
            //得到打开窗口的上下文信息
            String type = paramsMap.get("type");
            String context = paramsMap.get("context");
            String oidKey = paramsMap.get("oid");
            String showName = paramsMap.get("showname");
            if(type == null || type.equals("") || context == null || context.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.parmerror", "");
                return false;
            }
            if(oidKey == null){
                oidKey = "";
            }
            // 得到业务对象、设置需要显示的属性值
            IDataNode idn = getBusinessObject(type, oidKey);
            if(idn.getMaterObject() == null){
                return false;
            }
            Map<String, String> map = idn.getValueMap();
             
            // 从主管理界面的数据列表中跳转到数据对象明细数据展示(Navigation\MainData\TabPage)
            map.put(UIHelper.TYPE,  type);
            map.put(UIHelper.CONTEXT, context);
            map.put(UIHelper.OID, cbo.getBusinessObject().oid);
            
            Object[] objs = getDataModel().getSelectObjects();
            IDataNode inputData = (IDataNode)objs[objs.length - 1];
            UILayoutPanel uipl = new UILayoutPanel(map);
            // 注入此action当前选择的数据
            uipl.setInputData(inputData);
            uipl.setSourceDataNode(idn);
            uipl.setDataValueMap(map);
            uipl.prep();
            uipl.initMainPanel();
            //在按钮参数中增加一个参数 showName 用来作为tab页的名称
            String tabName = "";
            if(showName == null || showName.equals("")){
                tabName = map.get("name");
            } else {
                if(showName.indexOf("${") != -1){
                    Map<String, FreemarkerParamObject> freeMap = getFreemarkerParamMap(map);
                    tabName = FreeMarkerCommon.getValueByTempRule(freeMap, showName);
                } else {
                    tabName = showName;
                }
            }
            JFrame frame = new JFrame();
            frame.setTitle(tabName);
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(uipl, BorderLayout.CENTER);
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            setSizeAndLocation(frame);
            frame.setVisible(true);
            return false;
        } catch(Throwable e){
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
            return false;
        }
    }
    
    private void setSizeAndLocation(final JFrame frame){
        Insets insets  = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
        Dimension size = getCurrentSizeAndSetLocation(frame);
        frame.setPreferredSize(size);
        frame.setSize(size);
        Point location = new Point(insets.left, insets.top);
        frame.setLocation(location);
        frame.setLocationByPlatform(true);
        frame.setLocationRelativeTo(null);
        frame.addComponentListener(new ComponentAdapter() {
            
            @Override
            public void componentResized(ComponentEvent e) {
                if(e.getSource() instanceof VciFrame){
                    JFrame vf = (JFrame)e.getSource();
                    int extendedState = vf.getExtendedState();
                    if((extendedState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH){
                        Dimension size = getCurrentSizeAndSetLocation(frame);
                        frame.setPreferredSize(size);
                        frame.setSize(size);
                        return;
                    }
                }
            }
        });
    }
    
    private Dimension getCurrentSizeAndSetLocation(JFrame frame){
        Dimension d = new Dimension();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        Insets insets  = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
        int top = insets.top;
        int left = insets.left;
        int right = insets.right;
        int bottom = insets.bottom;
        int width = dim.width - left - right;
        int height = dim.height - top - bottom;
        int x = insets.left;
        int y = insets.top;
        frame.setLocation(x, y);
        d = new Dimension(width, height);
        return d;
    }
    
    /**
     * 根据用户所选数据获得打开上下文的SourceData
     * 判断oidKey是否为空
     *     如果oidKey为空,如果是BO则只用BO作为From
     *                     如果是LO则使用LO的to端对象作为From
     *     如果oidKey不为空,则根据上下文类型和oidKey对应的oid获得BO作为From
     * @return
     */
    protected IDataNode getBusinessObject(String type, String oidKey){
        IDataNode idn = new DefaultTableNode();
        //获得业务对象数据
        Object[] objs = getDataModel().getSelectObjects();
        if(objs == null || objs.length < 1){
            cbo = null;
        }
        
        //modify 2014.03.07 start
        DefaultTableNode dtn = (DefaultTableNode) objs[0];
        try {
            if(dtn.getMaterObject() instanceof ClientBusinessObject){
                Map<String, String> valueMap = dtn.getValueMap();
                if(!oidKey.equals("")){
                    String oid = valueMap.get(oidKey);;
                    String btmName = type;
                    if(oid != null && !oid.equals("") 
                            && btmName != null && !btmName.equals("")) {
                        //需要重新下载cbo对象
                        cbo = UIFUtils.queryBusinessObject(oid, btmName, true);
                        //对象不存在或者已经被删除
                        if(cbo.getBusinessObject().oid == null 
                                || cbo.getBusinessObject().oid.equals("")){
                            UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                                    "uifmodel.plm.uif.actions.notexistmsg", "");
                            idn.setMasterObject(null);
                            return idn;
                        }
                    }
                } else {
                    cbo = (ClientBusinessObject) dtn.getMaterObject();
                }
                if(cbo == null){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                    "uifmodel.plm.uif.actions.notexistmsg", dtn.getValueMap().get("name"));
                    idn.setMasterObject(null);
                    return idn;
                }                 
            } else if (dtn.getMaterObject() instanceof String){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.engine.folder.root.disabled");
                idn.setMasterObject(null);
                return idn;
            } else if(dtn.getMaterObject() instanceof ClientLinkObject){
                ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject();
                Map<String, String> valueMap = dtn.getValueMap();
                if(!oidKey.equals("")){
                    String oid = valueMap.get(oidKey);
                    String btmName = type;
                    if(oid != null && !oid.equals("") 
                            && btmName != null && !btmName.equals("")) {
                        //需要重新下载cbo对象
                        cbo = UIFUtils.queryBusinessObject(oid, btmName, true);
 
                        //对象不存在或者已经被删除
                        if(cbo.getBusinessObject().oid == null 
                                || cbo.getBusinessObject().oid.equals("")){
                            UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                                    "uifmodel.plm.uif.actions.notexistmsg", "");
                            idn.setMasterObject(null);
                            return idn;
                        }
                    }
                } else {
                    //如果是LO,获得头端对象信
                    String oid = clo.getLinkObject().toOid;
                    String btmName = clo.getLinkObject().toBTName;
                    if(oid != null && !oid.equals("") 
                            && btmName != null && !btmName.equals("")) {
                        //需要重新下载cbo对象
                        cbo = UIFUtils.queryBusinessObject(oid, btmName, true);
                        //对象不存在或者已经被删除
                        if(cbo.getBusinessObject().oid == null 
                                || cbo.getBusinessObject().oid.equals("")){
                            UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                                    "uifmodel.plm.uif.actions.notexistmsg", "");
                            idn.setMasterObject(null);
                            return idn;
                        }
                    }
                }
            }
            Map<String, String> boMap = getValueMap(cbo);
            idn.setMasterObject(cbo);
            idn.setValueMap(boMap);
        } catch (Exception e){
            e.printStackTrace();
            UIFUtils.showMessage(
                    ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.syserror.btnconferror");
            idn.setMasterObject(null);
            return idn;
        }
        return idn;
        //modify 2014.03.07 end
    }
    
    /**
     * 获得属性集合
     * @param cbo
     * @return
     */
    public Map<String, String> getValueMap(ClientBusinessObject cbo){
        if(cbo == null){
            return new HashMap<String, String>();
        }
        Map<String, String> valueMap = new HashMap<String, String>();
        AttributeValue[] arrts = cbo.getBusinessObject().hisAttrValList;
        if(arrts != null){
            for(AttributeValue attr : arrts){
                if(attr != null){
                    try{
                        valueMap.put(attr.attrName.toLowerCase(), attr.attrVal);
                    } catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }
        return valueMap;
    }
    /**
     * 获得木板数据
     * @param map
     * @return
     */
    public Map<String, FreemarkerParamObject> getFreemarkerParamMap(Map<String, String> map){
        Map<String, FreemarkerParamObject> freeMap = new HashMap<String, FreemarkerParamObject>();
        if(map == null){
            return freeMap;
        }
        Iterator it = map.keySet().iterator();
        while(it.hasNext()){
            String key = (String) it.next();
            FreemarkerParamObject fpo = new FreemarkerParamObject();
            fpo.setName(key);
            fpo.setValue(map.get(key));
            key = key.replaceAll("\\.", "Ψ");
            freeMap.put(key, fpo);
        }
        return freeMap;
    }
 
}