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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
package com.vci.client.uif.engine.client.objopt;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.portal.utility.DataModelFactory;
import com.vci.client.portal.utility.PLDefination;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.client.uif.actions.client.AbstractBatchBusionessOperationAction;
import com.vci.client.uif.actions.client.BusinessOperationAction;
import com.vci.client.uif.engine.client.AbstractDataModel;
import com.vci.client.uif.engine.client.AbstractRegionPanel;
import com.vci.client.uif.engine.client.BasePanel;
import com.vci.client.uif.engine.client.IDataModel;
import com.vci.client.uif.engine.client.IRegionPanel;
import com.vci.client.uif.engine.client.tableArea.TablePanel;
import com.vci.client.uif.engine.client.tableArea.TablePanelDataModel;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.portal.data.PLPageDefination;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.corba.portal.data.PLTabPage;
import com.vci.corba.portal.data.PortalVI;
import com.vci.mw.ClientContextVariable;
 
/**
 * 对象 add 窗口
 * @author VCI-STGK002
 *
 */
public class ObjectDBClickAddEditDialog extends VCIJDialog {
    
    public enum OperateType{
        ADD,
        EDIT,
        BROWSER,
        SELECT
    }
 
    /**
     * 
     */
    private static final long serialVersionUID = 6400165410571370254L;
 
    private String btmType = "";
    private String context = "";
    private PLDefination defination = null;
    private PortalVI portalVI = null;
    private DataModelFactory factory = new DataModelFactory();;
    private Map<String, String> paramsMap = new HashMap<String, String>();
    private OperateType operateType = OperateType.ADD;
    private VCIJTablePanel<IDataNode> dataTablePanel = null;
    /**
     * 如果OperateType是SELECT时记录用户选择的数据
     * 其余时selectedDatas为空
     */
    private Object[] selectedDatas = null;
 
    /**
     *  当前窗口的表单类型
     *     0:业务类型,1:链接类型
     *  对于不同类型的表单,窗口中属性的命名规则不同
     */
    private int typeFlag = 0;
    /**
     * 在创建link时:sourceDataNode
     *     如果传入的是BO对象,则作为创建link的From端,如果传入的是LO对象,
     *     则使用LO的t_oid所对应的BO对象作为Form
     * 在修改link时:sourceDataNode 
     *     为用户选择的数据,数据的类型有可能是LO,也有可能是BO
     */
    private IDataNode sourceDataNode = null;
    
    private IDataNode inputDataNode = null;
    
    
    /**
     * 如果是基于表格中选择的数据弹出对话框
     * selectObjects用于存储选中的数据
     */
    private Object[] selectObjects = null;
    
    /**
     * 判断是正向还是反响向
     */
    private boolean direction = true;
    
    private BusinessOperationAction boa = null;
 
    
    private VCIJButton btnPrev = VCISwingUtil.createVCIJButton("viewPrevData", "上一条", "上一条", "pagination_previous.png", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeViewDataPrev();
        }
    });
    private VCIJButton btnNext = VCISwingUtil.createVCIJButton("viewNextData", "下一条", "下一条", "pagination_next.png", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeViewDataNext();
        }
    });
 
    
    private boolean thisBOAOwnedIsTablePanel(){
        if(this.boa.getRegionPanel() instanceof TablePanel){
            return true;
        }
        return false;
    }
    
    private void resetRowIndex(){
        //TablePanel tablePanel = (TablePanel)this.boa.getRegionPanel();
        if(rowIndex == -1){
            rowIndex = dataTablePanel.getSelectedRowIndexs()[0];
        }
    }
    private int rowIndex = -1;
    private void changeViewDataPrev(){
        rowIndex -= 1;
        if(rowIndex < 0){
            rowIndex = 0;
        }
        changeViewData(rowIndex);
    }
    private void changeViewDataNext(){
        rowIndex += 1;
        int maxIndex = dataTablePanel.getTable().getRowCount();
        if(rowIndex >= maxIndex){
            rowIndex = maxIndex - 1;
        }
        changeViewData(rowIndex);
    }
    private void changeViewData(int rowIndex){
        IDataNode dataNode = dataTablePanel.getSpecialObjectByRowIndex(rowIndex);
        if(dataNode.getMaterObject() instanceof ClientBusinessObject){
            this.oaep.setValueToUIControl(dataNode.getMaterObject());
        }else if(dataNode.getMaterObject() instanceof ClientLinkObject){
            this.oaep.setValueToUIControl(dataNode.getMaterObject());    //add by caill 增加当数据时lo类型时的判断
        }
    }
    
    /**
     * 创建和编辑窗口不对控件处理,
     * 如果是浏览窗口,所有控件禁用
     * 如果是选择窗口,所有to端对象的属性控件都禁用
     * @param type
     * @param context
     * @param defination
     * @param paramsMap
     * @param operateType
     * @param actionExecute
     * @param dataTablePanel 
     */
    public ObjectDBClickAddEditDialog(String type, String context,
            PLDefination defination,PortalVI portalVI, Map<String, String> paramsMap,
            OperateType operateType, ObjectAddEditDialogExecute actionExecute,
            BusinessOperationAction boa, VCIJTablePanel<IDataNode> dataTablePanel) {
        
        super(ClientContextVariable.getFrame(), true);
        this.btmType = type;
        this.context = context;
        this.defination = defination;
        this.portalVI = portalVI;
        this.paramsMap = paramsMap;
        this.operateType = operateType;
        this.dataTablePanel = dataTablePanel;
        //this.actionExecute = actionExecute;
        this.boa = boa;
    }
    
    public void init(){
        //***************
        //setTitle(this.getBoa().getButton().plDesc);
        setLayout(new BorderLayout());
//        add(new VCIJScrollPane(getCenterPanel()), BorderLayout.CENTER);
        add(getCenterPanel(), BorderLayout.CENTER);
        add(getSouthButtonPanel(), BorderLayout.SOUTH);
        /*String widthStr = paramsMap.get("width");
        String heightStr = paramsMap.get("height");
        if(widthStr != null && widthStr.length() > 0 && widthStr.matches("[0-9]*")
                && heightStr != null && heightStr.length() > 0 && heightStr.matches("[0-9]*")) {
            int width = Integer.parseInt(widthStr);
            int height = Integer.parseInt(heightStr);
            this.setSizeAndLocation(width, height);
        }*/
    }
    
    private AbstractBatchBusionessOperationAction getSourceBtm(){
        if (this.getBoa() != null && this.getBoa() instanceof AbstractBatchBusionessOperationAction) {
            return (AbstractBatchBusionessOperationAction)this.getBoa();
        }else {
            return null;
        }
    }
    
    private ObjectDBClickAddEditPanel oaep = null;
    private ObjectDBClickAddEditPanel getCenterPanel(){
        oaep = new ObjectDBClickAddEditPanel(btmType, context, defination,portalVI, 
                factory, paramsMap, operateType, this.getBoa().getRegionPanel());
        oaep.setTypeFlag(typeFlag);
        oaep.setDirection(direction);
        oaep.init();
        // 仅在添加模式下处理默认值
        //***************
        /*if(operateType == OperateType.ADD || operateType == OperateType.SELECT || operateType == OperateType.EDIT){
            String needselect = paramsMap.get("needselect");
            Object[] objs = null;
            if(needselect != null && needselect.equalsIgnoreCase("true")){
                objs = this.boa.getDataModel().getSelectObjects();
            } else {
                objs = new Object[]{this.boa.getRegionPanel().getSourceData()};
            }
            if(objs != null && objs.length > 0 && objs[0] instanceof IDataNode){
                //oaep.setUIControlDefaultValue((IDataNode)objs[0]);
                oaep.setUIFormFieldDefaultValue(this.getSourceBtm(),(IDataNode)objs[0]);
            } else {
                //oaep.setUIGloableDefaultValue();
                oaep.setUIFormFieldDefaultValue(this.getSourceBtm(),null);
            }
        }*/
        return oaep;
    }
    private VCIJPanel getSouthButtonPanel(){
        VCIJPanel pal = new VCIJPanel();
//        //修改当为浏览时显示关闭按钮
//        if(this.operateType.equals(OperateType.BROWSER)){
//            pal.add(btnClose);
//        } else {
//            if(this.operateType.equals(OperateType.SELECT)){
//                pal.add(btnSelect);
//            }
//            pal.add(btnSave);
//            pal.add(btnCancel);
//        }
        //if(thisBOAOwnedIsTablePanel() && this.operateType == OperateType.BROWSER){
            resetRowIndex();
            pal.add(btnPrev);
            pal.add(btnNext);
        //}
        addFormButtonsToUI(pal);
        pal.setLayout(new FlowLayout());
        return pal;
    }
 
    //private IDataModel dataModel = null;
    private IRegionPanel regionPanel = null;
    private void addFormButtonsToUI(VCIJPanel pal){
        String tabId = "";
        //dataModel = new ObjectAddEditDataModel();
        regionPanel = new ObjectAddEditRegionPanel();
        //regionPanel.setDataModel(dataModel);
        try {
            PLUILayout plDef = getContext(getBtmType(), getContext());
            
            //this.setTitle("");
            
            BasePanel basePal = new BasePanel();
            // get form definations
            Map<PLTabPage, PLPageDefination> pageDefinition = new HashMap<PLTabPage, PLPageDefination>();
            Map<PLTabPage, PLDefination> tabPageMap = getTabPage(plDef.plOId, (short)2, pageDefinition);
            Iterator<PLTabPage> it = tabPageMap.keySet().iterator();
            while(it.hasNext()){
                PLTabPage tabPage = it.next();
                PLDefination btnOwnDefinatio = tabPageMap.get(tabPage);
                tabId = tabPage.plOId;
                regionPanel.setTab(tabPage);
                regionPanel.setTabId(tabId);
                // 设置Form中的Buttong与Defination之间的关联关系
                regionPanel.setDefination(tabPageMap.get(tabPage));
                regionPanel.setPageDefinition(pageDefinition.get(tabPage));
                // TODO
                // 将Button上配置的type\context对应的一个唯一(约定、必须)设置到Action
                this.oaep.setDefination(btnOwnDefinatio);
                // 添加Button到Panel
                /*VCIJButton[] btns = basePal.getButtonsByTabPageId(tabId, regionPanel);
                for(VCIJButton btn : btns){
                    pal.add(btn);
                    for(ActionListener al : btn.getActionListeners()){
                        //  设置Action所在的Dialog
                        if(al instanceof ButtonActionListener){
                            ButtonActionListener bal = (ButtonActionListener)al;
                            bal.setOwnerDialog(this);
                        }
                    }
                }*/
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Throwable e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * 获取当前context的详细信息
     * @return
     * @throws Throwable 
     * @throws Exception 
     */
    private PLUILayout getContext(String type, String context) throws Exception, Throwable {
        DataModelFactory factory = new DataModelFactory();
        PLUILayout contextDef = factory.getContextDefination(
                type, context);
        if (contextDef == null || contextDef.plOId.equals("")) {
            BtmItem item = BtmProvider.getInstance().getBtmItemByName(type);
            if (item.fName == null || item.fName.equals("")) {
                return null;
            }
            return getContext(item.fName, item.fName);
        }
        return contextDef;
    }
    
    /**
     * 获得当前上下文的所有tab page
     * @return
     * @throws Throwable
     */
    private Map<PLTabPage, PLDefination> getTabPage(String contextOid, short areaType, 
            Map<PLTabPage, PLPageDefination> pageDefinition) throws Throwable {
        PLTabPage[] tabs = UITools.getService().getTabPagesByContextIdAndType(contextOid, areaType);
        Map<PLTabPage, PLDefination> defMap = new LinkedHashMap<PLTabPage, PLDefination>(); 
        for (int i = 0; i < tabs.length; i++) {
            PLPageDefination[] definations = UITools.getService().getPLPageDefinationsByPageContextOId(tabs[i].plOId);
            if (definations != null && definations.length < 1) {
                continue;
            }
            pageDefinition.put(tabs[i], definations[0]);
            PLDefination defination = UITools.getPLDefination(definations[0].plDefination);
            defMap.put(tabs[i], defination);
        }
        return defMap;
    }
 
    /**
     * 添加到本窗口中的ActionButton所在的RegionPanel
     * @author xiongchao
     *
     */
    private class ObjectAddEditRegionPanel extends AbstractRegionPanel{
        /**
         * 
         */
        private static final long serialVersionUID = 3800158389231268060L;
        
        public ObjectAddEditRegionPanel(){
            IDataModel dataModel = new ObjectAddEditDataModel();
            this.setDataModel(dataModel);
        }
        
        @Override
        public Component init() {
            setComponentPanel(this);
            setBuilt(true);
            return this;
        }
 
        @Override
        public void refreshUI() {
            // TODO Auto-generated method stub
            
        }
    }
    
    /**
     * 直接调用dataModel中的getRootObject()方法获得数据
     * @param isCheck 判断获得form中的数据时是否需要进行数据校验
     * @return
     */
    public Object getRootObject(boolean isCheck){
        return ((ObjectAddEditDataModel)this.regionPanel.getDataModel()).getRootObject(isCheck);
    }
    
    /**
     * 添加到本窗口中的ActionButton所在的DataModel
     * @author xiongchao
     *
     */
    private class ObjectAddEditDataModel extends AbstractDataModel {
        @Override
        public int[] getSelectObjectRowIndexs() {
            return new int[]{0};
        }
 
        @Override
        public Object[] getSelectObjects() {
            return new Object[]{oaep.getDataNodeObject(true)};
        }
 
        @Override
        public void refresh(IDataModel fromDataModel) {
            // 添加到Dialog中的Button的刷新,是向上刷新
            // 即 调用 调用显示此Dialog的Action的dataModel.refresh(fromDataModel)
            if(fromDataModel == null && getBoa() != null){
                getBoa().getDataModel().refresh(fromDataModel);
            }
            
            // update by xchao 2014.03.26 begin
            // 修复来自Dialog底部的button执行完成后
            // 刷新 调用弹出此窗口的button所在的table的数据时,刷新失败的BUG
            if(fromDataModel instanceof ObjectAddEditDataModel){
                if(getBoa().getDataModel() instanceof TablePanelDataModel){
                    ((TablePanelDataModel)getBoa().getDataModel()).setClickObject(
                            getBoa().getRegionPanel().getSourceData());
                }
            }
            // update by xchao 2014.03.26 end
        }
 
        @Override
        public Object getRootObject() {
            return getRootObject(true);
        }
        
        /**
         * 判断是否需要进行校验
         * @param ischeck
         * @return
         */
        public Object getRootObject(boolean isCheck){
            return oaep.getDataNodeObject(isCheck);
        }
        
        /**
         * 将属性值发生更改后业务对象或链接对象刷新到UIPanel
         * @param clientObject
         */
        @Override
        public void refreshCache(Object clientObject){
            // default is nothing
            getOaep().setValueToUIControlByAttrValChange(clientObject);
        }
    }
    
    
    public VCIJTablePanel<IDataNode> getDataTablePanel() {
        return dataTablePanel;
    }
 
    public void setDataTablePanel(VCIJTablePanel<IDataNode> dataTablePanel) {
        this.dataTablePanel = dataTablePanel;
    }
 
    public PortalVI getPortalVI() {
        return portalVI;
    }
 
    public void setPortalVI(PortalVI portalVI) {
        this.portalVI = portalVI;
    }
 
    public String getBtmType() {
        return btmType;
    }
 
    public void setBtmType(String type) {
        this.btmType = type;
    }
 
    public String getContext() {
        return context;
    }
 
    public void setContext(String context) {
        this.context = context;
    }
 
    public PLDefination getDefination() {
        return defination;
    }
 
    public void setDefination(PLDefination defination) {
        this.defination = defination;
    }
 
    public DataModelFactory getFactory() {
        return factory;
    }
 
    public void setFactory(DataModelFactory factory) {
        this.factory = factory;
    }
 
    public Map<String, String> getParamsMap() {
        return paramsMap;
    }
 
    public void setParamsMap(Map<String, String> paramsMap) {
        this.paramsMap = paramsMap;
    }
 
    public HashMap<String, Component> getCtrlComptMap() {
        return oaep.getCtrlComptMap();
    }
 
    public void setCtrlComptMap(HashMap<String, Component> ctrlComptMap) {
        this.oaep.setCtrlComptMap(ctrlComptMap);
    }
 
    public Map<String, String> getValueMapNew() {
        return oaep.getValueMapNew();
    }
 
    public void setValueMapNew(Map<String, String> valueMapNew) {
        this.oaep.setValueMapNew(valueMapNew);
    }
 
    public Map<String, String> getValueMapOriginal() {
        return oaep.getValueMapOriginal();
    }
 
    public void setValueMapOriginal(HashMap<String, String> valueMapOriginal) {
        this.oaep.setValueMapOriginal(valueMapOriginal);
    }
 
    public OperateType getOperateType() {
        return oaep.getOperateType();
    }
 
//    public ObjectAddEditDialogExecute getActionExecute() {
//        return actionExecute;
//    }
//
//    public void setActionExecute(ObjectAddEditDialogExecute actionExecute) {
//        this.actionExecute = actionExecute;
//    }
 
    public ObjectDBClickAddEditPanel getOaep() {
        return oaep;
    }
 
    public void setOaep(ObjectDBClickAddEditPanel oaep) {
        this.oaep = oaep;
    }
 
    public Object[] getSelectedDatas() {
        return selectedDatas;
    }
 
    public void setSelectedDatas(Object[] selectedDatas) {
        this.selectedDatas = selectedDatas;
        this.oaep.setSelectedDatas(selectedDatas);
    }
    
    public int getTypeFlag() {
        return typeFlag;
    }
 
    public void setTypeFlag(int typeFlag) {
        this.typeFlag = typeFlag;
    }
    
    public BusinessOperationAction getBoa() {
        return boa;
    }
 
    public void setBoa(BusinessOperationAction boa) {
        this.boa = boa;
    }
 
    public IDataNode getSourceDataNode() {
        return sourceDataNode;
    }
 
    public void setSourceDataNode(IDataNode sourceDataNode) {
        this.sourceDataNode = sourceDataNode;
    }
 
    public IDataNode getInputDataNode() {
        return inputDataNode;
    }
 
    public void setInputDataNode(IDataNode inputDataNode) {
        this.inputDataNode = inputDataNode;
    }
 
    public boolean isDirection() {
        return direction;
    }
 
    public void setDirection(boolean direction) {
        this.direction = direction;
    }
 
    public Object[] getSelectObjects() {
        return selectObjects;
    }
 
    public void setSelectObjects(Object[] selectObjects) {
        this.selectObjects = selectObjects;
    }
    
    public void setSize(int width, int height){
        super.setSize(width, height);
        //如果paramsMap中传递长宽参数了,则自定义dialog的大小,并位置是居中的,lmh20150925
        /*String widthStr = paramsMap.get("width");
        String heightStr = paramsMap.get("height");
        if(widthStr != null && widthStr.length() > 0 && widthStr.matches("[0-9]*")
                && heightStr != null && heightStr.length() > 0 && heightStr.matches("[0-9]*")) {
            width = Integer.parseInt(widthStr);
            height = Integer.parseInt(heightStr);
            this.setSizeAndLocation(width, height);
        } else {
            super.setSize(width, height);
        }*/        
    }
}