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
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.vci.client.omd.linktype.LinkTypeStart;
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.ltm.LinkType;
 
public class LinkTypePopupTablePanel extends VCIJPanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = 769447874783154406L;
    private final String COLUMN_NAME = "名称"; 
    private final String COLUMN_LABEL = "标签";
    
    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<LinkType> dataProvider = null; 
    private VCIJTablePanel<LinkType> tablePanel = null;
    private LinkTypePopupDialog popupDialog = null;
    
    public LinkTypePopupTablePanel(LinkTypePopupDialog popupDialog){
        this.popupDialog = popupDialog;
    }
    
    public void buildTablePanel(){
        setLayout(new BorderLayout());
        
        dataProvider = new AbstractVCIJTableDataProvider<LinkType>() {
            @Override
            public String[] getSpecialColumns() {
                return new String[]{COLUMN_NAME, COLUMN_LABEL};
            }
            @Override
            public int getTotal() {
                return super.total;
            }
            @Override
            public VCIJTableNode<LinkType> getNewRowNode(LinkType obj) {
                VCIJTableNode<LinkType> res = new VCIJTableNode<LinkType>(obj);
                res.setPropertyValue(COLUMN_NAME, obj.name);
                res.setPropertyValue(COLUMN_LABEL, obj.tag);
                return res;
            }
            @Override
            public LinkType[] getDatas(int pageIndex, int pageSize) {
                LinkType[] datas = new LinkType[0];
                try {
                    ResData<LinkType> 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<LinkType>(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 boolean existInArray(String value, String[] values){
        boolean res = false;
        for (String string : values) {
            if(string.equals(value)){
                res = true;
                break;
            }
        }
        return res;
    }
    
    private ResData<LinkType> getDatasByPageInfo(int pageIndex, int pageSize) throws VCIError{
        List<LinkType> list = new ArrayList<LinkType>();
        Map<String, LinkType> map = new HashMap<String, LinkType>();
        LinkType[] lts = LinkTypeStart.getService().getLinkTypes();
        for (LinkType lt : lts) {
            if(getPopupDialog().getBtmLinKTypeTxt() != null){
                String btmType = getPopupDialog().getBtmLinKTypeTxt().getText().trim();
                boolean existFrom = existInArray(btmType, lt.btmItemsFrom);
                boolean existTo = existInArray(btmType, lt.btmItemsTo);
                if(existFrom || existTo){
                    if(!map.containsKey(lt.name)){
                        map.put(lt.name, lt);
                        list.add(lt);
                    }
                }
            }
        }
        LinkType[] datas = list.toArray(new LinkType[]{});
        ResData<LinkType> res = new ResData<LinkType>();
        res.setDatas(datas);
        res.setTotal(lts.length);
        return res;
        
//        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 lt.typename = '%s' ", text);
//            }
//            if(!getPopupDialog().isIgnoreTxtInputValue()){
//                text = getPopupDialog().getSearchInputTxt().getText().trim();
//                where += String.format(" and (lt.name like '%%%s%%' or lt.label like '%%%s%%')", text, text);
//            }
//        }
//        String fromWhere = String.format(" from from pllinktype lt where %s ", where);
//        String fromWhereOrderBy = String.format(" %s order by lt.name", fromWhere);
//        String sql = String.format("select * from(" +
//                "  select row_.*,rownum rownum_ from( " +
//                "         select lt.name,lt.label %s" +
//                "  ) row_ " +
//                ") where rownum_ >= %d and rownum_ <= %d ", fromWhereOrderBy, start, end);
//        List<LinkType> list = new LinkedList<LinkType>();
//        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
//        for(String[] kvs : kvss){
//            LinkType bi = new LinkType();
//            bi.name = kvs[0];
//            bi.tag = kvs[1];
//            list.add(bi);
//        }
//        datas = list.toArray(new LinkType[]{});
//        
//        sql = String.format("select count(1) count_ %s", fromWhere);
//        kvss = QTClient.getService().queryBySqlWithoutKey(sql);
//        int total = Integer.valueOf(kvss[0][0]);
//        
//        ResData<LinkType> res = new ResData<LinkType>();
//        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<LinkType> getTablePanel() {
        return tablePanel;
    }
 
    public LinkTypePopupDialog getPopupDialog() {
        return popupDialog;
    }
 
    public void setPopupDialog(LinkTypePopupDialog popupDialog) {
        this.popupDialog = popupDialog;
    }
    
}