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
package com.vci.client.uif.actions.client;
 
import java.util.Map;
 
import com.vci.client.portal.utility.PLDefination;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
import com.vci.client.uif.engine.client.UIHelper;
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.corba.portal.data.PortalVI;
import com.vci.mw.ClientContextVariable;
 
/**
 * link类型创建按钮事件
 * 参数信息:
 *     type(创建业务对象类型)
 *     formName(创建时使用的表单,表单form和linkform都可)
 *     frombooid(from端OID)
 *     fromboBtmName(from端类型)
 *     linkType(链接的类型)
 * @author VCI-STGK006
 *
 */
public class AddLinkAction extends DoseNotSelectDataHasRightCheckAction{
    
    /**
     * 判断是创建有link属性的BO,还是创建没有link属性的BO
     * 0:无link属性(业务类型),1:有link属性(有链接属性)
     */
    private int operationType = 0;
    
    /**
     * 是否需要先选择数据然后执行创建操作
     * 默认为false
     */
    boolean needSelect = false;
    
    /**
     * 按钮参数信息
     */
    private Map<String, String> paramsMap;
    public AddLinkAction(){
        super();
    }
    
    @Override
    public String getKey() {
        return "addlink";
    }
    
    @Override
    public boolean checkHasRight(){
        // 按LBO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_FB);
        return super.checkHasRight();
    }
    
    /**
     * 判断执行Action任务之前是否需要先选择数据
     */
    public boolean beforePost() {
        
        //获得按钮参数
        paramsMap = getButtonParams();
        if(paramsMap.containsKey("needselect")){
            String value = paramsMap.get("needselect");
            if(value.equalsIgnoreCase("true")){
                needSelect = true;
            }
        }
        if(needSelect){
            if(!isSelectedObject()) return false;
            
            Object[] objs = getDataModel().getSelectObjects();
            if(objs.length > 1){
                VCIJOptionPane.showMessage(getParentComponent(), "只能选择一条数据执行创建操作!");
                return false;
            }
        }
        return true;
    }
    
    @Override
    public boolean doPost() {
        try {
            //获得按钮参数
            paramsMap = getButtonParams();
            //得到打开窗口的上下文信息
            String type = paramsMap.get("type");
            String context = paramsMap.get("context");
            String directionStr = paramsMap.get("direction");
            if(type == null || type.equals("") || context == null || context.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.parmerror", "");
                return false;
            }
            /**
             * 判断是否是正向还是反向
             */
            boolean direction = true;
            if(directionStr != null && directionStr.trim().equalsIgnoreCase("false")){
                direction = 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;
            }
            ObjectAddEditDialog oad = new ObjectAddEditDialog(type, context,
                    plDef, paramsMap, ObjectAddEditDialog.OperateType.ADD, null, this);
            oad.setSelectObjects(getDataModel().getSelectObjects());
            oad.setTypeFlag(operationType);
            oad.setDirection(direction);
            //获得sourceDate,source可能来自用户选择的数据,也可能来自父窗口传递的数据
            if(needSelect){
                oad.setSourceDataNode((IDataNode)getDataModel().getSelectObjects()[0]);
            } else {
                oad.setSourceDataNode(getRegionPanel().getSourceData());
            }
            // 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(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
            oad.setLocationRelativeTo(ClientContextVariable.getFrame());
            oad.setVisible(true);
            if(oad.getDialogResult() == DialogResult.OK){
                return true;
            } else {
                return false;
            }
        } catch (Throwable e) {
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
                    "uifmodel.plm.uif.actions.createloerror", e);
            return false;
        }
    }
}