田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
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
package com.vci.client.uif.actions.client;
 
import java.util.HashMap;
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.portal.utility.PLDefination;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
import com.vci.client.uif.engine.common.DefaultTableNode;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.corba.portal.data.PortalVI;
import com.vci.mw.ClientContextVariable;
 
/**
 * link类型修改按钮事件
 * 参数信息:
 *     oid(link对象的oid)
 *     linktypename
 *     t_oid
 *     t_btwname
 *     context
 * @author VCI-STGK006
 *
 */
public class EditLinkAction extends AbstractBusionessOperationAction {
    
    /**
     * 业务对象操作方法
     */
    private ClientBusinessObjectOperation boOperation = 
            new ClientBusinessObjectOperation();
    /**
     * 将操作的业务对象作为一个全局变量存储
     */
    private Map<String, Object> dataMap = null;
    
    /**
     * 判断form的类型
     * 不同的form类型得到属性的key是不同的
     * 0:业务类型,1:链接类型
     */
    private int operationType = 0;
    
    /**
     * 按钮参数
     */
    private Map<String, String> paramsMap = null;
    
    public EditLinkAction(){
        super();
    }
    
    @Override
    public String getKey() {
        return EDITLINK;
    }
    
    @Override
    public boolean checkHasRight(){
        // 按LBO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_L);
        return super.checkHasRight();
    }
    
    @Override
    public boolean doPost() {
        //显示创建窗口
        try{
            //获得按钮参数
            paramsMap = getButtonParams();
            //得到打开窗口的上下文信息
            String type = paramsMap.get("type");
            String context = paramsMap.get("context");
            if(type == null || type.equals("") || context == null || context.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.parmerror", "");
                return false;
            }
            //获得按钮打开窗口的PLDefination
            PLDefination plDef = getDefination(type, context);
            if(plDef == null){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.configerror.notformname", type, context);
                return false;
            }
            String formName = plDef.getTemplateId();
            if(formName == null || formName.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.configerror.notformname", type, context);
                return false;
            }
            //判断创建表单类型
            PortalVI sheet = UITools.getService().getPortalVIBySymbol(formName);
            if(sheet != null){
                this.operationType = sheet.typeFlag;
            }
            
            // 得到业务对象、设置需要显示的属性值
            dataMap = getBusinessObject();
            if(dataMap == null){
                return false;
            }
            //创建浏览窗口
            ObjectAddEditDialog oad = new ObjectAddEditDialog(type, context,
                    plDef, paramsMap, ObjectAddEditDialog.OperateType.EDIT, null, this);
            oad.setTypeFlag(operationType);
            oad.setSourceDataNode((IDataNode)getDataModel().getSelectObjects()[0]);
            // add by xchao 2015.08.12 
            // 设置新打开的上下文模块的inputdata 
            // 设置值类型:sourceData、inputData、selectData
            oad = super.setTargetUILayoutPanelInputData(oad);
            // add by xchao 2015.08.12 end
            oad.init();
            oad.setSize(600, 400);
            oad.setLocationRelativeTo(ClientContextVariable.getFrame());
            //设置属性的值
            setEditDialogValue(oad, dataMap);
            
            oad.setVisible(true);
            if(oad.getDialogResult() == DialogResult.OK){
                return true;
            } else {
                return false;
            }
        } catch(Throwable e){
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), 
                    "uifmodel.plm.uif.actions.editloerror", e);
            return false;
        }
    }
    
    /**
     * 设置窗口属性值
     * 需要在创建编辑窗口初始化完成后执行设置操作
     * @return
     */
    private void setEditDialogValue(ObjectAddEditDialog oad, Map<String,Object> dataMap){
        oad.getOaep().setValueToUIControl((ClientLinkObject)dataMap.get("lo"), (ClientBusinessObject)dataMap.get("to"));
    }
    
    /**
     * 得到用户选择的业务对象数据
     * @return
     */
    private Map<String, Object> getBusinessObject(){
        //获得业务对象数据
        Object[] objs = getDataModel().getSelectObjects();
        if(objs == null || objs.length < 1){
            return null;
        }
        //查询结果
        Map<String, Object> resultMap = new HashMap<String, Object>();
        DefaultTableNode dtn = (DefaultTableNode) objs[0];
        try {
            //判断主对象类型,修改link是主对象类型一定是link对象
            if (dtn.getMaterObject() instanceof ClientLinkObject){
                ClientLinkObject lo = (ClientLinkObject) dtn.getMaterObject();
                String foid = lo.getFromOid();
                String fbtmName = lo.getFromBTMName();
                String toid = lo.getToOid();
                String tbtmName = lo.getToBTMName();
                //如果操作所需参数不存在则直接停止操作
                if(foid == null || foid.equals("") ||fbtmName == null || fbtmName.equals("")
                        || toid == null || toid.equals("") ||tbtmName == null || tbtmName.equals("")){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.syserror.parmerror.bo");
                    return null;
                }
                //下载from对象
                //XXX 现在修改为通过查询模板设置修改窗口的所有值,所以此处对业务对象的重新加载就没有必要了
                ClientBusinessObject fcbo = boOperation.readBusinessObjectById(foid, fbtmName);
                //对象不存在或者已经被删除
                if(fcbo.getBusinessObject().oid == null || fcbo.getBusinessObject().oid.equals("")){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.notexistmsg", "父对象");
                    return null;
                }
                resultMap.put("from", fcbo);
                //下载to对象
                ClientBusinessObject tcbo = boOperation.readBusinessObjectById(toid, tbtmName);
                
                //对象不存在或者已经被删除
                if(tcbo.getBusinessObject().oid == null || tcbo.getBusinessObject().oid.equals("")){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.notexistmsg", "子对象");
                    return null;
                }
                resultMap.put("to", tcbo);
                //添加link
                resultMap.put("lo", lo);
            } else {
                //主对象为其他类型的处理
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.btnconferror");
                return null;
            }
        } catch (Exception e){
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),e);
            return null;
        }
        return resultMap;
    }
}