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
package com.vci.client.uif.actions.client;
 
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
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.IDataNode;
 
public class AddSaveAction extends DoseNotSelectDataAction {
 
    @Override
    public String getKey() {
        return ADD_SAVE;
    }
 
    @Override
    public boolean checkHasRight() {
        return true;
    }
 
    @SuppressWarnings("deprecation")
    @Override
    public boolean doPost() {
        // 获得按钮所属窗口
        ObjectAddEditDialog oaed = null;
        VCIJDialog dialog = getOwnerDialog();
        if (dialog instanceof ObjectAddEditDialog) {
            oaed = (ObjectAddEditDialog) dialog;
        }
        if (oaed == null) {
            return false;
        }
        // 判断创建的是否是文件夹
        IDataNode idn = oaed.getSourceDataNode();
        boolean createFolder = false;
        if(idn != null) {
            Map<String, String> valueMap = idn.getValueMap();
            if (valueMap.containsKey("AddCreateFolder")) {
                createFolder = true;
            }
        }
        Object obj = getDataModel().getRootObject();
        if (obj instanceof IDataNode) {
            IDataNode dataNode = (IDataNode) obj;
            obj = dataNode.getMaterObject();
            if (obj instanceof ClientBusinessObject) {
                ClientBusinessObject cbo = (ClientBusinessObject) obj;
                ClientBusinessObjectOperation boOperation = new ClientBusinessObjectOperation();
                try {
                    // 如果是创建文件夹
                    if (createFolder) {
                        // 获得用于存储父对象ID的属性名称
                        Map<String, String> valueMap = idn.getValueMap();
                        String attrName = "";
                        String showLinkAbs = valueMap.get("AddShowLinkAbs");
                        String separator = valueMap.get("AddSeparator");
                        if (showLinkAbs != null && separator != null
                                && !separator.equals("")) {
                            if (showLinkAbs.indexOf(separator) != -1) {
                                attrName = showLinkAbs.substring(0,
                                        showLinkAbs.indexOf(","));
                            } else {
                                attrName = showLinkAbs;
                            }
                        }
                        if (idn.getMaterObject() instanceof String) {
                            // 如果是文件夹的根节点
                            cbo.setAttributeValue(attrName,
                                    (String) idn.getMaterObject(), true);
 
                        } else {
                            cbo.setAttributeValue(attrName,
                                    ((ClientBusinessObject) idn
                                            .getMaterObject())
                                            .getBusinessObject().oid, true);
                        }
                    }
                    // 上传文件
                    if (!UploadFile(oaed, cbo)) {
                        // operation.showMessage(ClientContextVariable.getFrame(),
                        // "uifmodel.plm.uif.actions.createlinkerror");
                        // return false;
                    }
                    boOperation.saveCreateBuinessObject(cbo);
                    closeOwnerDailog(getOwnerDialog(), DialogResult.OK);
                    // 调用此按钮所在Dialog注册的回调函数
                    super.invokeOwnedDialogCallback();
                    UIFUtils.showMessage(getParentComponent(),
                            "uifmodel.plm.uif.actions.createsuccessmsg",
                            cbo.getName());
                } catch (Exception e) {
                    UIFUtils.showErrorMessage(getParentComponent(), e);
                }
            }
        }
        return true;
    }
}