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
package com.vci.client.uif.actions.client;
 
import java.util.HashMap;
import java.util.List;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.ui.swing.components.VCIJDialog;
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.ClientLOAndBOData;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.mw.ClientContextVariable;
 
/**
 * 编辑保存按钮
 * 
 * 现在调整BO或LO对象的设置属性值在编辑窗口中进行
 * 在Action中不再执行校验吗,设置等操作
 * @author VCI-STGK006
 *
 */
public class EditLinkSaveAction extends DoseNotSelectDataAction {
 
    /**
     * 方法集合
     */
    private UIFUtils operation =
            new UIFUtils();
    
    /**
     * 判断是创建有link属性的BO,还是创建没有link属性的BO
     * 0:无link属性(业务类型),1:有link属性(有链接属性)
     */
    private int operationType = 0;
    
    @Override
    public String getKey() {
        return "editlinksave";
    }
    
    @Override
    public boolean checkHasRight(){
        return true;
    }
 
    @Override
    public boolean doPost() {
        try {
            //用户输入属性 期中以t_oid开始的为业务对象属性,其它为link对象属性
            //获得按钮所属窗口,此窗口一定要是一个弹出窗口
            //并且窗口的类型一定是ObjectAddEditDialog
            ObjectAddEditDialog oaed = null;
            VCIJDialog dialog = getOwnerDialog();
            if(dialog instanceof ObjectAddEditDialog){
                oaed = (ObjectAddEditDialog) dialog;
            }
            if(oaed == null){
                return false;
            }
            //获得使用的表单类型
            operationType = oaed.getTypeFlag();
            //获得用户编辑数据
            Object obj = getDataModel().getRootObject();
            if(obj == null){
                return false;
            }
            
            //根据表单类型判断要执行的操作
            ClientLinkObject clo = null;
            ClientBusinessObject to = null;
            IDataNode idn = (IDataNode) obj;
            if(this.operationType == 0){
                //如果表单类型是0,表示编辑的是无属性的link
                //获得to端对象
                to = (ClientBusinessObject) idn.getMaterObject();    
            } else if(this.operationType == 1){
                //编辑LO和BO
                //如果表单类型是1,可以再Form中直接获得要创建的LO和BO对象
                ClientLOAndBOData clbo = (ClientLOAndBOData) idn.getMaterObject();
                List<ClientLinkObject> loList = clbo.getLoDatas();
                if(loList.isEmpty()){
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.createloerror", new Exception("系统异常:没有找到link对象"));
                    return false;
                }
                //在创建保存link中只会有一个LO对象
                clo = loList.get(0);
                to = clbo.getBOData(clo.getLinkObject().oid);
            }
            
            //设置link对象属性并修改link对象
            boolean result = false;
            //判断是否需要修改LO对象 
            if(this.operationType == 1){
                result = operation.updateLinkObject(
                        ClientContextVariable.getFrame(), clo, null, new HashMap<String, String>());
                if(!result){
                    UIFUtils.showMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.updateError", "");
                    return false;
                }
            }
            //上传文件
            if(!UploadFile(oaed, to)){
                //operation.showMessage(ClientContextVariable.getFrame(),
                //        "uifmodel.plm.uif.actions.createlinkerror");
                //return false;
            }
            //设置业务对象属性并修改业务对象
            result = operation.updateBusinessObject(
                    ClientContextVariable.getFrame(), to, new HashMap<String, String>());
            //业务对象保存失败
            if(!result){
                return false;
            }
            
            // 调用后台保存数据
            // 保存成功刷新UI
            // add by xchao 2014.08.07 begin
            // 取消调用 getDataModel().refresh(null); 解决数据修改后刷新时,数据重复显示的问题。 
            //getDataModel().refresh(null);
            // add by xchao 2014.08.07 end
            closeOwnerDailog(getOwnerDialog(), DialogResult.OK);
 
            // 调用此按钮所在Dialog注册的回调函数
            super.invokeOwnedDialogCallback();
            return true;
        } catch (Exception e){
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
            "uifmodel.plm.uif.actions.editloerror", e);
            return false;
        }
    }
 
}