ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.client.portal.UI.v3.comptdesign.compt;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.swing.DefaultComboBoxModel;
import javax.swing.text.JTextComponent;
 
import com.vci.client.omd.linktype.LinkTypeStart;
import com.vci.client.oq.QTClient;
import com.vci.client.portal.UI.v3.comptdesign.UIComptDesignDialog;
import com.vci.client.portal.UI.v3.comptdesign.compt.al.BaseActionListener;
import com.vci.client.portal.utility.PLDefination;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.components.VCIJComboBox;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.VCIJTextArea;
import com.vci.client.ui.swing.components.VCIJTextField;
import com.vci.common.portal.enums.PortalVIType;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.portal.data.PLPageDefination;
 
/**
 * UI 组件基础面板
 * 
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company: VCI</p>
 * @author xiongchao
 * @time 2017-2-22
 * @version 1.0
 */
public abstract class BaseComptPanel extends VCIJPanel implements ComptPanelInterface{
 
    /**
     * 
     */
    private static final long serialVersionUID = 968715722185037438L;
 
    
    private PLPageDefination pageDefination = null;
    private PLDefination defination = null;
    protected boolean isCompleted = false;
    private UIComptDesignDialog ownedUIComptDesignDialog = null;
    
    protected Map<Integer, BaseActionListener<?>> txtRefBtnALMap = new LinkedHashMap<Integer, BaseActionListener<?>>();
    
    public BaseComptPanel(UIComptDesignDialog ownedUIComptDesignDialog){
        this.ownedUIComptDesignDialog = ownedUIComptDesignDialog;
    }
    
    public abstract boolean checkInputIsOk();
    public abstract void buildPanel();
    
    
    private List<BaseActionListener<?>> actions = new LinkedList<BaseActionListener<?>>();
    public void initActionListener(){
        initBtmTypeActionListener();
        initLinkTypeActionListener();
        initActionListenerObservers();
    }
    /**
     * 由子类实现的初始化BtmType模式下各按钮的ActionListener
     */
    protected abstract void initBtmTypeActionListener();
    /**
     * 由子类实现的初始化LinkType模式下各按钮的ActionListener
     */
    protected abstract void initLinkTypeActionListener();
    /**
     * 为各按钮的ActionListeners之间配置观察\被观察关系
     */
    protected void initActionListenerObservers(){
        for (BaseActionListener<?> ba : actions) {
            for (BaseActionListener<?> baa : actions) {
                if(!ba.equals(baa)){
                    ba.addObserver(baa);
                }
            }
        }
    }
    public List<BaseActionListener<?>> getActions() {
        return actions;
    }
    public void setActions(List<BaseActionListener<?>> actions) {
        this.actions = actions;
    }
 
    @Override
    public void setDataToUI(PLPageDefination pageDefination){
        if(isCompleted) return;
        setPageDefination(pageDefination);
        if(pageDefination != null){
            try {
                defination = UITools.getPLDefination(pageDefination.plDefination);
                if(defination != null){
                    setDefination(defination);
                    setDataToUISpec(defination);
                }
            } catch (Throwable e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            };
        }
        isCompleted = true;
    }
    @Override
    public boolean isCompleted(){
        return isCompleted;
    }
    
    public abstract void setDataToUISpec(PLDefination defination);
    
    public void setPageDefination(PLPageDefination pageDefination){
        this.pageDefination = pageDefination;
    }
    public PLPageDefination getPageDefination() {
        return pageDefination;
    }
    public PLDefination getDefination() {
        return defination;
    }
    public void setDefination(PLDefination defination) {
        this.defination = defination;
    }
    /**
     * 
     * @param srcCombox
     * @param destQTNamesCombox
     */
    protected void refrechQueryTemplateNamesCombox(VCIJComboBox srcCombox, VCIJComboBox destQTNamesCombox){
        destQTNamesCombox.removeAllItems();
        String selectedItem = (String) srcCombox.getSelectedItem();
        if (selectedItem == null) {
            return;
        }
        try{
            String[] qtNames = getQTNamesFromMap(selectedItem);
            destQTNamesCombox.setModel(new DefaultComboBoxModel(qtNames));
        } catch (VCIError e) {
            e.printStackTrace();
        }
        destQTNamesCombox.updateUI();
    }
    /**
     * 
     * @param srcCombox
     * @param destRefCombox
     * @param viType
     */
    protected void refreshChangableTablePortalVIs(VCIJComboBox srcCombox, VCIJComboBox destRefCombox,
            PortalVIType viType) {
        destRefCombox.removeAllItems();
        String selectedItem = (String) srcCombox.getSelectedItem();
        if (selectedItem == null) {
            return;
        }
        try {
            String[] viNames = getTypePortalVINamesFromMap(viType, selectedItem);
            destRefCombox.setModel(new DefaultComboBoxModel(viNames));
        } catch (VCIError e) {
            e.printStackTrace();
        }
        destRefCombox.updateUI();
    }
    /**
     * 刷新业务类型选择后 可以选择的链接类型(linktype)下拉列表数据
     * @param btmCombox
     * @param destLinkTypeCombox
     */
    protected void refrechChangableLinkType(VCIJComboBox btmCombox, VCIJComboBox destLinkTypeCombox){
        destLinkTypeCombox.removeAllItems();
        String selectedItem = (String) btmCombox.getSelectedItem();
        if (selectedItem == null) {
            return;
        }
        try{
            List<String> list = new ArrayList<String>();
            list.add("");
            LinkType[] lts = LinkTypeStart.getService().getLinkTypes();
            for (LinkType lt : lts) {
                boolean exist = existInArray(selectedItem, lt.btmItemsFrom);
                if(!exist){
                    exist = existInArray(selectedItem, lt.btmItemsTo);
                }
                if(exist){
                    if(!list.contains(lt.name)){
                        list.add(lt.name);
                    }
                }
            }
            destLinkTypeCombox.setModel(new DefaultComboBoxModel(list.toArray(new String[0])));
        } catch (VCIError e) {
            e.printStackTrace();
        }
        destLinkTypeCombox.updateUI();
    }
    private boolean existInArray(String value, String[] values){
        boolean res = false;
        for (String string : values) {
            if(string.equals(value)){
                res = true;
                break;
            }
        }
        return res;
    }
 
    protected Map<String, String[]> qtNamesMap = new HashMap<String, String[]>();
    protected  String[] getQTNamesFromMap(String type) throws VCIError{
        String[] qtNames = new String[0];
        if(qtNamesMap.containsKey(type)){
            qtNames = qtNamesMap.get(type);
        } else {
            qtNames = getTypeQTNames(type);
            qtNamesMap.put(type, qtNames);
        }
        return qtNames;
    }
    /**
     * 业务类型下全部的表单名缓存Map
     * key:业务类型名
     * value:Map
     *         key:    表单类型(1:表单、0:表格)
     *         value:  表单名称的一维数组
     */
    protected Map<String, Map<Short, String[]>> typePortalVINames = new HashMap<String, Map<Short,String[]>>();
    /**
     * 从Dialog组件页面缓存中取出业务类型下指定表单类型的表单名
     * @param viType 表单类型
     * @param type 业务类型
     * @return
     * @throws VCIError
     */
    private String[] getTypePortalVINamesFromMap(PortalVIType viType, String type) throws VCIError{
        if(typePortalVINames.containsKey(type)){
            if(typePortalVINames.get(type).containsKey(viType.getIntVal())){
                return     typePortalVINames.get(type).get(viType.getIntVal());
            } else {
                String[] viNames = getTypePortalVINames(viType, type);
                Map<Short, String[]> map = typePortalVINames.get(type);
                map.put(viType.getIntVal(), viNames);
                typePortalVINames.put(type, map);
                return viNames;
            }
        } else {
            String[] viNames = getTypePortalVINames(viType, type);
            Map<Short, String[]> map = new HashMap<Short, String[]>();
            map.put(viType.getIntVal(), viNames);
            typePortalVINames.put(type, map);
            return viNames;
        }
    }
    /**
     * 查出指定业务类型下全部的表单名称
     * @param viType 表单类型
     * @param type 业务类型名
     * @return
     * @throws VCIError
     */
    protected String[] getTypePortalVINames(PortalVIType viType, String type) throws VCIError{
        String sql = String.format("" +
                "select vi.viname from plportalvi vi " +
                "where vi.vitype='%s' and vi.typename='%s' " +
                "order by vi.viname ",
                String.valueOf(viType.getIntVal()),
                type);
        List<String> viNameList = new LinkedList<String>();
        viNameList.add("");
        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        for(String[] kvs : kvss){
            viNameList.add(kvs[0]);
        }
        String[] viNames = viNameList.toArray(new String[]{});
        Map<Short, String[]> map = new HashMap<Short, String[]>();
        map.put(viType.getIntVal(), viNames);
        return viNameList.toArray(new String[]{});
    }
    /**
     * 返回指定类型下的查询模板名称
     * @param type
     * @return
     * @throws VCIError
     */
    private String[] getTypeQTNames(String type) throws VCIError{
        String sql = String.format(
                "select qt.qtname from PL_QTEMPLATE qt where qt.btmname='%s'", 
                type);
        List<String> qtNameList = new LinkedList<String>();
        qtNameList.add("");
        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        for(String[] kvs : kvss){
            qtNameList.add(kvs[0]);
        }
        return qtNameList.toArray(new String[]{});
    }
    
    private String[] btmNames = null;
    protected void loadBtmTypeDataToCombox(VCIJComboBox cbox) throws VCIError{
        loadBtmTypeDataToCombox(cbox, -1);
    }
    protected void loadBtmTypeDataToCombox(VCIJComboBox cbox, int selectedIndex) throws VCIError{
        if(btmNames == null){
            String sql = "select bt.name from plbtmtype bt";
            List<String> list = new LinkedList<String>();
            list.add("");
            String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
            for(String[] kvs : kvss){
                list.add(kvs[0]);
            }
            btmNames = list.toArray(new String[]{});
        }
        cbox.setModel(new DefaultComboBoxModel(btmNames));
        if(btmNames.length > 0 && selectedIndex >= 0 && selectedIndex <= btmNames.length - 1){
            cbox.setSelectedIndex(selectedIndex);
        }
    }
 
    public UIComptDesignDialog getOwnedUIComptDesignDialog() {
        return ownedUIComptDesignDialog;
    }
 
    public void setOwnedUIComptDesignDialog(
            UIComptDesignDialog ownedUIComptDesignDialog) {
        this.ownedUIComptDesignDialog = ownedUIComptDesignDialog;
    }
 
    public Map<Integer, BaseActionListener<?>> getTxtRefBtnALMap() {
        return txtRefBtnALMap;
    }
 
    public void setTxtRefBtnALMap(Map<Integer, BaseActionListener<?>> txtRefBtnALMap) {
        this.txtRefBtnALMap = txtRefBtnALMap;
    }
    
    /**
     * 隐藏\关闭本组件中可能弹出的PopupDialog
     */
    public void hidePopupDialog(){
        if(getTxtRefBtnALMap() != null){
            Iterator<Integer> its = getTxtRefBtnALMap().keySet().iterator();
            while(its.hasNext()){
                Integer key = its.next();
                BaseActionListener<?> bal = getTxtRefBtnALMap().get(key);
                bal.hidePopupDialog();
            }
        }
    }
 
    /**
     * 检查BtmType输入是否有效
     * @param lbl
     * @param txtBtmName
     * @return
     */
    protected boolean checkBtmTypeTxtIsOk(VCIJLabel lbl, JTextComponent txtBtmName){
        boolean res = false;
        if(lbl == null) return true;
        if(txtBtmName == null) return true;
        if(!checkRequiredIsOk(lbl, txtBtmName)){
            res = false;
        } else if(!checkBtmNameIsExist(lbl, txtBtmName)){
            res = false;
        } else {
            res = true;
        }
        return res;
    }
 
    /**
     * 检查LinkType输入是否有效
     * @param lbl
     * @param txtLinkTypeName
     * @return
     */
    protected boolean checkLinkTypeTxtIsOk(VCIJLabel lbl, JTextComponent txtLinkTypeName){
        boolean res = false;
        if(lbl == null) return true;
        if(txtLinkTypeName == null) return true;
        if(!checkRequiredIsOk(lbl, txtLinkTypeName)){
            res = false;
        } else if(!checkLinkTypeIsExist(lbl, txtLinkTypeName)){
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    /**
     * 检查表单输入是否有效
     * @param lbl
     * @param txtVIName
     * @param btmLinkType
     * @return
     */
    protected boolean checkPortalVITxtIsOk(VCIJLabel lbl, JTextComponent txtVIName, JTextComponent btmLinkType){
        boolean res = false;
        if(lbl == null) return true;
        if(txtVIName == null) return true;
        if(!checkRequiredIsOk(lbl, txtVIName)){
            res = false;
        } else if(!checkPortalVIIsExist(lbl, txtVIName, btmLinkType)){
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    
    /**
     * 检查表单输入是否有效
     * @param lbl
     * @param txtVIName
     * @param btmLinkType
     * @return
     */
    protected boolean checkUILayoutTxtIsOk(VCIJLabel lbl, JTextComponent txtUIName, JTextComponent btmLinkType){
        boolean res = false;
        if(lbl == null) return true;
        if(txtUIName == null) return true;
        if(!checkRequiredIsOk(lbl, txtUIName)){
            res = false;
        } else if(!checkUILayoutIsExist(lbl, txtUIName, btmLinkType)){
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    /**
     * 检查查询模板输入是否有效
     * @param lbl
     * @param txtQTName
     * @param btmLinkType
     * @return
     */
    protected boolean checkQTNameTxtIsOk(VCIJLabel lbl, JTextComponent txtQTName, JTextComponent btmLinkType){
        boolean res = false;
        if(lbl == null) return true;
        if(txtQTName == null) return true;
        if(!checkRequiredIsOk(lbl, txtQTName)){
            res = false;
        } else if(!"".equals(txtQTName.getText()) && !checkQTIsExist(lbl, txtQTName, btmLinkType)){
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    protected boolean checkRequiredIsOk(VCIJLabel lbl, JTextComponent txt){
        boolean res = false;
        String text = txt.getText().trim();
        boolean isRequired = false;
        if(txt instanceof VCIJTextField){
            isRequired = ((VCIJTextField)txt).isRequired();
        } else if(txt instanceof VCIJTextArea){
            isRequired = ((VCIJTextArea)txt).isRequired();
        }
        if("".equals(text) && isRequired){
            txt.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), lbl.getText() + " 不能为空!");
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    private boolean checkBtmNameIsExist(VCIJLabel lbl, JTextComponent txt){
        boolean res = false;
        String sql = "select count(1) count_ from plbtmtype bt where bt.name='" + txt.getText().trim() + "'";
        res = checkCountNotEqualZero(sql);
        if(!res){
            txt.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), 
                    String.format("%s %s 无效!", lbl.getText(), txt.getText()));
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    private boolean checkLinkTypeIsExist(VCIJLabel lbl, JTextComponent txt){
        boolean res = false;
        String sql = "select count(1) count_ from pllinktype lt " +
                "where lt.name ='" + txt.getText().trim() + "'";
        res = checkCountNotEqualZero(sql);
        if(!res){
            txt.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), 
                    String.format("%s %s 无效!", lbl.getText(), txt.getText()));
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    
    private boolean checkPortalVIIsExist(VCIJLabel lbl, JTextComponent txtVIName, JTextComponent txtType){
        boolean res = false;
        String sql = "select count(1) count_ from plportalvi vi " +
                "where vi.typename='" + txtType.getText().trim() + "' " +
                "and vi.viname='" + txtVIName.getText().trim() + "'";
        res = checkCountNotEqualZero(sql);
        if(!res){
            txtVIName.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), 
                    String.format("%s %s 无效!", lbl.getText(), txtVIName.getText()));
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    private boolean checkUILayoutIsExist(VCIJLabel lbl, JTextComponent txtUIName, JTextComponent txtType){
        boolean res = false;
        String sql = "select count(1) count_ from PLUILAYOUT ui " +
                "where ui.PLRELATEDTYPE='" + txtType.getText().trim() + "' " +
                "and ui.plcode='" + txtUIName.getText().trim() + "'";
        res = checkCountNotEqualZero(sql);
        if(!res){
            txtUIName.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), 
                    String.format("%s %s 无效!", lbl.getText(), txtUIName.getText()));
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    
    
    private boolean checkQTIsExist(VCIJLabel lbl, JTextComponent txtQTName, JTextComponent txtType){
        boolean res = false;
        String sql = "select count(1) count_ from PL_QTEMPLATE qt " +
                "where qt.btmname ='" + txtType.getText().trim() + "' " +
                "and qt.qtname='" + txtQTName.getText().trim() + "'";
        res = checkCountNotEqualZero(sql);
        if(!res){
            txtQTName.requestFocus();
            VCIJOptionPane.showMessage(getOwnedUIComptDesignDialog(), 
                    String.format("%s %s 无效!", lbl.getText(), txtQTName.getText()));
            res = false;
        } else {
            res = true;
        }
        return res;
    }
    private boolean checkCountNotEqualZero(String sql){
        boolean res = false;
        try{
            String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
            res = Integer.valueOf(kvss[0][0]) > 0;
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return res;
    }
}