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
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.common.portal.enums.PortalVIType;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.corba.portal.data.PortalVI;
 
public class UILayoutPopupTablePanel extends VCIJPanel{
 
    /**
     * 
     */
    private static final long serialVersionUID = 4648692230788439584L;
    
    private final String COLUMN_NAME = "名称"; 
    private final String COLUMN_CODE = "编码";
    
    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<PLUILayout> dataProvider = null; 
    private VCIJTablePanel<PLUILayout> tablePanel = null;
    private UILayoutPopupDialog popupDialog = null;
    
    public UILayoutPopupTablePanel(UILayoutPopupDialog popupDialog){
        this.popupDialog = popupDialog;
    }
    
    public void buildTablePanel(){
        setLayout(new BorderLayout());
        
        dataProvider = new AbstractVCIJTableDataProvider<PLUILayout>() {
            @Override
            public String[] getSpecialColumns() {
                return new String[]{COLUMN_CODE, COLUMN_NAME};
            }
            @Override
            public int getTotal() {
                return super.total;
            }
            @Override
            public VCIJTableNode<PLUILayout> getNewRowNode(PLUILayout obj) {
                VCIJTableNode<PLUILayout> res = new VCIJTableNode<PLUILayout>(obj);
                res.setPropertyValue(COLUMN_NAME, obj.plName);
                res.setPropertyValue(COLUMN_CODE, obj.plCode);
                return res;
            }
            @Override
            public PLUILayout[] getDatas(int pageIndex, int pageSize) {
                PLUILayout[] datas = new PLUILayout[0];
                try {
                    ResData<PLUILayout> 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<PLUILayout>(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<PLUILayout> getDatasByPageInfo(int pageIndex, int pageSize) throws VCIError{
        PLUILayout[] 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().getBtmTypeTxt() != null){
                text = getPopupDialog().getBtmTypeTxt().getText().trim();
                where += String.format(" and ui.PLRELATEDTYPE = '%s' ", text);
            }
//            if(getPopupDialog().getPortalVIType() != null){
//                where += String.format(" and vi.vitype = %d ", getPopupDialog().getPortalVIType().getIntVal());
//            }
            if(!getPopupDialog().isIgnoreTxtInputValue()){
                text = getPopupDialog().getSearchInputTxt().getText().trim();
                where += String.format(" and (ui.plname like '%%%s%%') ", text, text);
            }
        }
        String fromWhere = String.format(" from PLUILAYOUT ui where %s ", where);
        String fromWhereOrderBy = String.format(" %s order by ui.plname", fromWhere);
        String sql = String.format("select * from(" +
                "  select row_.*,rownum rownum_ from( " +
                "         select ui.plname, ui.plcode %s" +
                "  ) row_ " +
                ") where rownum_ >= %d and rownum_ <= %d ", fromWhereOrderBy, start, end);
        List<PLUILayout> list = new LinkedList<PLUILayout>();
        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        for(String[] kvs : kvss){
            PLUILayout bi = new PLUILayout();
            bi.plName = kvs[0];
            bi.plCode = kvs[1];
            list.add(bi);
        }
        datas = list.toArray(new PLUILayout[0]);
        
        sql = String.format("select count(1) count_ %s", fromWhere);
        kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        int total = Integer.valueOf(kvss[0][0]);
        
        ResData<PLUILayout> res = new ResData<PLUILayout>();
        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<PLUILayout> getTablePanel() {
        return tablePanel;
    }
 
    public UILayoutPopupDialog getPopupDialog() {
        return popupDialog;
    }
 
    public void setPopupDialog(UILayoutPopupDialog popupDialog) {
        this.popupDialog = popupDialog;
    }
    
}