田源
2024-11-08 d336c430e5d22ade703ff12f3d523889eb3d75d6
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package com.vci.client.tool.panel;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BtmAndApName;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.mw.ClientContextVariable;
import com.vci.client.omd.attribpool.ui.APClient;
import com.vci.client.omd.btm.ui.BtmClient;
import com.vci.client.omd.btm.wrapper.BtmItemWrapper;
import com.vci.client.omd.linktype.LinkTypeWrapper;
import com.vci.client.tool.FormAttrSettingPanel;
import com.vci.client.tool.dialog.UIContexBuilderWrapperDialog;
import com.vci.client.tool.wrapper.AttribItemWrapperEx;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.corba.common.VCIError;
 
 
/**
 * 业务类型 拥有的属性列表面板
 * @author xiongchao
 *
 */
public class BtmItemAttrTablePanel extends VCIJPanel implements ActionListener {
    /**
     * 
     */
    private static final long serialVersionUID = 4485213175457227347L;
 
    class DataProvider extends AbstractVCIJTableDataProvider<AttribItemWrapperEx>{
        @Override
        public AttribItemWrapperEx[] getDatas(int arg0, int arg1) {
            AttribItemWrapperEx[] res = getAttrItems();
            total = res.length;
            return res;
        }
        public VCIJTableNode<AttribItemWrapperEx> getNewRowNode(AttribItemWrapperEx obj) {
            VCIJTableNode<AttribItemWrapperEx> node = new VCIJTableNode<AttribItemWrapperEx>(obj);
            int i = 0;
            String[] names = getSpecialColumns();
            AttribItem ai = obj.getAttribItem();
            node.setPropertyValue(names[i++], obj.getOwnedType());
            node.setPropertyValue(names[i++], ai.name);
            node.setPropertyValue(names[i++], ai.label);
            node.setPropertyValue(names[i++], ai.description);    //modify by zgy 2015-03-10
            node.setPropertyValue(names[i++], ai.vtDataType);
            node.setPropertyValue(names[i++], obj.getRefBtmType());
            node.setPropertyValue(names[i++], obj.getAllowNull());
            node.setPropertyValue(names[i++], obj.getLength());
            node.setPropertyValue(names[i++], obj.getEnumName());
            node.setPropertyValue(names[i++], ai.other);
            return node;
        }
        @Override
        public String[] getSpecialColumns() {
            return "业务类型,名称,标签,描述,数据类型,参照类型,允许为空,长度,枚举类型,其它,                ".split(",");
        }
        @Override
        public int getTotal() {
            return super.total;
        }
    }
 
    private boolean isBtm = false;
    private BtmItemWrapper btmItemWrapper = null;
    private LinkTypeWrapper linkTypeWrapper = null;
    
    private Map<String, AttribItemWrapperEx> map = new LinkedHashMap<String, AttribItemWrapperEx>();
    private FormAttrSettingPanel ownedPanel = null;
    private AttribItemWrapperEx[] getAttrItems(){
        map.clear();
        AttribItemWrapperEx[] res = new AttribItemWrapperEx[0];
        try{
            List<AttribItemWrapperEx> list = new LinkedList<AttribItemWrapperEx>(){
                /**
                 * 
                 */
                private static final long serialVersionUID = 6917342504818179154L;
 
                @Override
                public boolean contains(Object o) {
                    AttribItemWrapperEx aiwe = (AttribItemWrapperEx)o;
                    return map.containsKey(aiwe.getOwnedType() + "." + aiwe.abItem.name);
                }
            };
            BtmItemWrapper biw = null;
            if(isBtm){
                biw = getBtmItemWrapper();
                if(biw == null) {
                    return res;
                }
                String btmName = biw.btmItem.name;
                addBtmItemToList(btmName, "", list, true);
            } else {
                // LINKTYPE
                LinkTypeWrapper ltwe = getLinkTypeWrapper();
                if(ltwe == null){
                    return res;
                } 
                addLinkTypeAttrToList(ltwe.linkType.name, ltwe.linkType.attributes, list);
                addLinkTypeBtmToList("f_oid.", ltwe.linkType.btmItemsFrom, list);
                addLinkTypeBtmToList("t_oid.", ltwe.linkType.btmItemsTo, list);
            }
            res = list.toArray(res);
            Arrays.sort(res, new Comparator<AttribItemWrapperEx>() {
                @Override
                public int compare(AttribItemWrapperEx o1, AttribItemWrapperEx o2) {
                    return o1.getPingYing().compareTo(o2.getPingYing());
                }
            });
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return res;
    }
    
    private void addLinkTypeAttrToList(String linkType, String[] attrs, List<AttribItemWrapperEx> list) throws VCIError{
        for(String attr : attrs){
            AttribItem ai = APClient.getService().getAttribItemByName(attr);
            AttribItemWrapperEx aiwe = new AttribItemWrapperEx(linkType, ai);
            list.add(aiwe);
        }
    }
    
    private void addLinkTypeBtmToList(String refPrefix, String[] btmNames, List<AttribItemWrapperEx> list) throws VCIError{
        for(String btmName : btmNames){
            addBtmItemToList(btmName, refPrefix, list, false);
        }
    }
    
 
    private void addFixedCommonAttrToList(String btmName, String refPrefix, List<AttribItemWrapperEx> list){
        //(String oid, String ts, String creator, String createTime, String modifier, String modifyTime, String name, String label, String description, String vtDataType, String defValue, String rage, String other) 
        AttribItem attribItem = new AttribItem();
        attribItem.name = refPrefix + "id";            //modify by zgy 2015-03-10
        attribItem.label = "编号";
        attribItem.vtDataType = "VTString";
        AttribItemWrapperEx id = new AttribItemWrapperEx(btmName, attribItem);//new AttribItem(refPrefix + "id", "编号", "", "VTString", "", "", "")
        if(!list.contains(id)){
            list.add(id);
            map.put(btmName + "." + id.abItem.name, id);
        }
        attribItem = new AttribItem();
        attribItem.name = refPrefix + "name";
        attribItem.label = "名称";
        attribItem.vtDataType = "VTString";
        AttribItemWrapperEx name = new AttribItemWrapperEx(btmName,attribItem);    // new AttribItem(refPrefix + "name", "名称", "", "VTString", "", "", "")
        if(!list.contains(name)){
            list.add(name);
            map.put(btmName + "." + name.abItem.name, name);
        }
        attribItem = new AttribItem();
        attribItem.name = refPrefix + "description";
        attribItem.label = "描述";
        attribItem.vtDataType = "VTString";
        AttribItemWrapperEx desc = new AttribItemWrapperEx(btmName,attribItem );//new AttribItem(refPrefix + "description", "描述", "", "VTString", "", "", "")
        if(!list.contains(desc)){
            list.add(desc);
            map.put(btmName + "." + desc.abItem.name, desc);
        }
        
    }
    private void addBtmItemToList(String btmName, String refPrefix, List<AttribItemWrapperEx> list, boolean recurrsion) throws VCIError{
        //BtmAndApName[] btmAndApNameArray = BtmClient.getService().getBtmAndApNameArray(btmName);
        BtmItem bt = BtmClient.getService().getBtmItemByName(btmName);
        BtmAndApName ban = new BtmAndApName(bt.name, bt.apNameArray);
        
        //for(BtmAndApName ban : btmAndApNameArray){
            AttribItem[] ais = APClient.getService().getAttribItemsByNames(ban.apName);
            addFixedCommonAttrToList(btmName, refPrefix, list);
            for (int i = 0; i < ais.length; i++) {
                AttribItem ai = ais[i];
                AttribItemWrapperEx aiw = new AttribItemWrapperEx(btmName, ai);
                aiw.abItem.name = refPrefix + aiw.abItem.name;
                if(list.contains(aiw)){
                    continue;
                }
                list.add(aiw);
                map.put(btmName + "." + aiw.abItem.name, aiw);
                if(recurrsion && !"".equals(aiw.getRefBtmType()) && !btmName.equals(aiw.getRefBtmType())){
                    addBtmItemToList(aiw.getRefBtmType(), refPrefix + aiw.abItem.name + ".", list, recurrsion);
                }
            }
        //}
    }
    
    private VCIJTablePanel<AttribItemWrapperEx> tablePanel = null; 
    public BtmItemAttrTablePanel(FormAttrSettingPanel ownedPanel){
        this.ownedPanel = ownedPanel;
        initActionMap();
        setLayout(new BorderLayout());
        tablePanel = new VCIJTablePanel<AttribItemWrapperEx>(new DataProvider());
        tablePanel.setShowColumnSetting(false);
        tablePanel.setColumnDefaultWidth(150);
        List<VCIJButton> custombButtons = new LinkedList<VCIJButton>();
        custombButtons.add(VCISwingUtil.createVCIJButton("buildForm", "生成表单", "生成表单", "wand.png", this));
        tablePanel.setCustomButtons(custombButtons);
        tablePanel.buildTablePanel();
        add(tablePanel, BorderLayout.CENTER);
    }
    public VCIJTablePanel<AttribItemWrapperEx> getTablePanel() {
        return tablePanel;
    }
    public void setTablePanel(VCIJTablePanel<AttribItemWrapperEx> tablePanel) {
        this.tablePanel = tablePanel;
    }
    
    private void showBuildForm(){
        VCISwingUtil.invokeLater(new Runnable() {
            @Override
            public void run() {
                showDialog();
            }
        }, 0);
    }
    private String showType = "";
    public String getShowType() {
        return showType;
    }
    public void setShowType(String showType) {
        this.showType = showType;
    }
 
    private void showDialog(){
        List<AttribItemWrapperEx> list = getOwnedPanel().getBtmItemAttrTablePanel().getTablePanel().getSelectedRowObjectsList();
        if(list.size() <= 0){
            VCIJOptionPane.showMessage(getOwnedPanel(), "请至少选择一个属性!");
            return;
        }
        if(!getOwnedPanel().isBtmType()){
            String showType = getShowType(list);
            setShowType(showType);
            if((showType == null || "".equals(showType))){
                VCIJOptionPane.showMessage(getOwnedPanel(), "当是生成链接类型表单&上下文时,必须选择业务(且只能选择一个)!");
                return;
            }
        }
        UIContexBuilderWrapperDialog dialog = new UIContexBuilderWrapperDialog(ClientContextVariable.getFrame());
        dialog.setBtmItemAttrItemTablePanel(this);
        dialog.setBtmItemWrapper(getOwnedPanel().getSelectedBtm());
        dialog.setAttribItemWrapper(list);
        dialog.buildDialog();
        dialog.setVisible(true);
    }
    
    private String getShowType(List<AttribItemWrapperEx> list){
        String showType = "";
        String linkType = getLinkTypeWrapper().linkType.name;
        Map<String, AttribItemWrapperEx> map = new HashMap<String, AttribItemWrapperEx>();
        for(AttribItemWrapperEx aiwe : list){
            String name = aiwe.getOwnedType();
            if(name.equals(linkType)){
                continue;
            }
            if(!map.containsKey(name)){
                map.put(name, aiwe);
                showType = name;
            }
            if(map.size() > 1){
                showType = "";
                break;
            }
        }
        return showType;
    }
    
    
    private Map<String, Runnable> actionMap = new HashMap<String, Runnable>();
    private void initActionMap(){
        actionMap.put("buildForm", new Runnable() {
            @Override
            public void run() {
                showBuildForm();
            }
        });
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
        if(actionMap.containsKey(actionCommand)){
            actionMap.get(actionCommand).run();
        }
    }
    public boolean isBtm() {
        return isBtm;
    }
    public void setBtm(boolean isBtm) {
        this.isBtm = isBtm;
    }
    public BtmItemWrapper getBtmItemWrapper() {
        return btmItemWrapper;
    }
    public void setBtmItemWrapper(BtmItemWrapper btmItemWrapper) {
        this.btmItemWrapper = btmItemWrapper;
    }
    public FormAttrSettingPanel getOwnedPanel() {
        return ownedPanel;
    }
    public void setOwnedPanel(FormAttrSettingPanel ownedPanel) {
        this.ownedPanel = ownedPanel;
    }
    public LinkTypeWrapper getLinkTypeWrapper() {
        return linkTypeWrapper;
    }
    public void setLinkTypeWrapper(LinkTypeWrapper linkTypeWrapper) {
        this.linkTypeWrapper = linkTypeWrapper;
    }
}