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
package com.vci.client.portal.UI.v3.comptdesign.compt.popupcompt;
 
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
 
import com.vci.client.oq.QTClient;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
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.VCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.qtm.QTInfo;
 
public class QTPopupTablePanel  extends VCIJPanel{
 
    /**
     * 
     */
    private static final long serialVersionUID = -718487619680889638L;
 
 
    private final String COLUMN_NAME = "名称"; 
    private final String COLUMN_TYPE = "类型";
    
    private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "查询", "查询", "search.gif", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnSearch_actionPerformed(e);
        }
    });
    private VCIJButton btnClear = VCISwingUtil.createVCIJButton("clear", "清空", "清空查询条件", "clear.gif", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnClear_actionPerformed(e);
        }
    });
    
    private VCIJPanel searchInfoPanel = null;
    private VCIJTableDataProvider<QTInfo> dataProvider = null; 
    private VCIJTablePanel<QTInfo> tablePanel = null;
    private QTPopupDialog popupDialog = null;
    
    public QTPopupTablePanel(QTPopupDialog popupDialog){
        this.popupDialog = popupDialog;
    }
    
    public void buildTablePanel(){
        setLayout(new BorderLayout());
        
        dataProvider = new AbstractVCIJTableDataProvider<QTInfo>() {
            @Override
            public String[] getSpecialColumns() {
                return new String[]{COLUMN_NAME, COLUMN_TYPE};
            }
            @Override
            public int getTotal() {
                return super.total;
            }
            @Override
            public VCIJTableNode<QTInfo> getNewRowNode(QTInfo obj) {
                VCIJTableNode<QTInfo> res = new VCIJTableNode<QTInfo>(obj);
                res.setPropertyValue(COLUMN_NAME, obj.qtName);
                res.setPropertyValue(COLUMN_TYPE, obj.btmName);
                return res;
            }
            @Override
            public QTInfo[] getDatas(int pageIndex, int pageSize) {
                QTInfo[] datas = new QTInfo[0];
                try {
                    ResData<QTInfo> res = getDatasByPageInfo(pageIndex, pageSize);
                    datas = res.getDatas();
                    super.total = res.getTotal();
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return datas;
            }
        };
        tablePanel = new VCIJTablePanel<QTInfo>(dataProvider);
        tablePanel.setShowExport(false);
        tablePanel.setColumnDefaultWidth(250);
        tablePanel.setPageSizeList(new int[]{10,20,30,40,50,100, 10});
        tablePanel.buildTablePanel();
        
        searchInfoPanel = getNorthSearchPanel();
        add(searchInfoPanel, BorderLayout.NORTH);
        add(tablePanel, BorderLayout.CENTER);
    }
 
    private VCIJPanel getNorthSearchPanel(){
        VCIJPanel pal = new VCIJPanel(new GridBagLayout());
        pal.add(btnSearch, getGBC(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, 1));
        pal.add(btnClear, getGBC(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, 1));
        searchInfoPanel = pal;
        return pal;
    }
    private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int padxy) {
        return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy);
    }
    
    
    private ResData<QTInfo> getDatasByPageInfo(int pageIndex, int pageSize) throws VCIError{
        QTInfo[] datas = null;
        int start = pageIndex <= 1 ? 1 : (pageIndex - 1) * pageSize + 1;
        int end = pageIndex <= 1 ? pageSize : (pageIndex * pageSize);
        
        String where = " 1=1 ";
        String text = "";
 
        if(getPopupDialog() != null){
            if(getPopupDialog().getBtmLinKTypeTxt() != null){
                text = getPopupDialog().getBtmLinKTypeTxt().getText().trim();
                where += String.format(" and qt.btmname = '%s' ", text);
            }
            if(!getPopupDialog().isIgnoreTxtInputValue()){
                text = getPopupDialog().getSearchInputTxt().getText().trim();
                where += String.format(" and (qt.qtname like '%%%s%%') ", text, text);
            }
        }
        String fromWhere = String.format(" from PL_QTEMPLATE qt where %s ", where);
        String fromWhereOrderBy = String.format(" %s order by qt.qtname ", fromWhere);
        String sql = String.format("select * from(" +
                "  select row_.*,rownum rownum_ from( " +
                "         select qt.qtname,qt.btmname  %s" +
                "  ) row_ " +
                ") where rownum_ >= %d and rownum_ <= %d ", fromWhereOrderBy, start, end);
        List<QTInfo> list = new LinkedList<QTInfo>();
        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        for(String[] kvs : kvss){
            QTInfo bi = new QTInfo();
            bi.qtName = kvs[0];
            bi.btmName = kvs[1];
            list.add(bi);
        }
        datas = list.toArray(new QTInfo[]{});
        
        sql = String.format("select count(1) count_ %s", fromWhere);
        kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        int total = Integer.valueOf(kvss[0][0]);
        
        ResData<QTInfo> res = new ResData<QTInfo>();
        res.setDatas(datas);
        res.setTotal(total);
        return res;
    }
 
    private void btnSearch_actionPerformed(ActionEvent e){
        tablePanel.setPageIndex(1);
        tablePanel.refreshTableData();
    }
    
    private void btnClear_actionPerformed(ActionEvent e){
        tablePanel.setPageIndex(1);
        if(getPopupDialog() != null && getPopupDialog().getSearchInputTxt() != null){
            getPopupDialog().getSearchInputTxt().setText("");
        }
        tablePanel.refreshTableData();
    }
    
    public VCIJTablePanel<QTInfo> getTablePanel() {
        return tablePanel;
    }
 
    public QTPopupDialog getPopupDialog() {
        return popupDialog;
    }
 
    public void setPopupDialog(QTPopupDialog popupDialog) {
        this.popupDialog = popupDialog;
    }
    
}