田源
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
package com.vci.client.uif.actions.client;
 
import java.util.ArrayList;
import java.util.List;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.uif.engine.common.DefaultTableNode;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.mw.ClientContextVariable;
 
/**
 * 复制对象及关系
 * @author VCI-STGK006
 *
 */
public class CopyAction extends AbstractBatchBusionessOperationAction {
    /**
     * 操作方法集合
     */
    private UIFUtils operation = 
            new UIFUtils();
    
    public CopyAction(){
        super();
    }
    
    @Override
    public String getKey() {
        return COPY;
    }
 
    @Override
    public boolean doPost() {
        try {
            //获得业务对象数据
            Object[] objs = getDataModel().getSelectObjects();
            if(objs == null || objs.length < 1){
                return false;
            }
            String loName = "";
            List<ClientLinkObject> loList = new ArrayList<ClientLinkObject>();
            for(int i = 0; i < objs.length; i++){
                IDataNode dtn = (DefaultTableNode) objs[i];
                try {
                    //判断主对象类型,修改link是主对象类型一定是link对象
                    if (dtn.getMaterObject() instanceof ClientLinkObject){
                        ClientLinkObject lo = (ClientLinkObject) dtn.getMaterObject();
                        loName = this.getParameterValue(ValueType.RuntimeData, "linktypename", i);
                        String foid = this.getParameterValue(ValueType.RuntimeData, "f_oid", i);
                        String fbtmName = this.getParameterValue(ValueType.RuntimeData, "f_btwname", i);;
                        String toid = this.getParameterValue(ValueType.RuntimeData, "t_oid", i);
                        String tbtmName = this.getParameterValue(ValueType.RuntimeData, "t_btwname", i);
                        //如果操作所需参数不存在则直接停止操作
                        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 false;
                        }
                        //下载from对象
                        ClientBusinessObject fcbo = operation
                                .reloadClientBusinessObject(ClientContextVariable.getFrame(), foid, fbtmName);
                        //对象不存在或者已经被删除
                        if(fcbo.getBusinessObject().oid == null || fcbo.getBusinessObject().oid.equals("")){
                            UIFUtils.showMessage(ClientContextVariable.getFrame(),
                                    "uifmodel.plm.uif.actions.notexistmsg", "父对象");
                            return false;
                        }
                        //下载to对象
                        ClientBusinessObject tcbo = operation
                                .reloadClientBusinessObject(ClientContextVariable.getFrame(), toid, tbtmName);
                        //对象不存在或者已经被删除
                        if(tcbo.getBusinessObject().oid == null || tcbo.getBusinessObject().oid.equals("")){
                            UIFUtils.showMessage(ClientContextVariable.getFrame(),
                                    "uifmodel.plm.uif.actions.notexistmsg", 
                                    this.getParameterValue(ValueType.RuntimeData, "t_oid.name", i));
                            return false;
                        }
                        //添加link
                        if(dtn.isForward()){
                            lo.setFromBO(fcbo);
                            lo.setToBO(tcbo);
                            loList.add(lo);
                        } else {
                            lo.setFromBO(tcbo);
                            lo.setToBO(fcbo);
                            loList.add(lo);
                        }
                    } else {
                        //主对象为其他类型的处理
                        
                    }
                } catch (Exception e){
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),e);
                    return false;
                }
            }
            //modify 2014.03.09 end
            //直接复制link对象(数据、link信息等)
            //将复制的所有to端对象对应的link对象存储到剪切板
            if(loList.isEmpty()){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.copynotexistmsg");
                return false;
            } else {
                ClipboardData cd = new ClipboardData(
                        ClipboardData.ClipboardOperation.copy, 
                        ClipboardData.ClipboardDataType.LO,
                        loName, loList.toArray(new ClientLinkObject[0]));
                ClientBusinessObjectClipboard.getInstance().setContents(cd);
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.copysuccessmsg","");
                return false;
            }            
        } catch (Exception e) {
            UIFUtils.showErrorMessage(
                    ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.copyerror", e);
            return false;
        }
    }
}