ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
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
package com.vci.client.omd.attribpool.ui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
 
import com.vci.client.omd.attribpool.toOutside.InterAP;
import com.vci.client.omd.attribpool.toOutside.InterAPManager;
import com.vci.client.omd.inter.impl.InterAPForLinkType;
 
public class LinkTypeSelectDialog extends JDialog{
 
    /**
     * 
     */
    private static final long serialVersionUID = -706946271792634086L;
    private String selectLTName = "";
    private JXTable table;
    private DefaultTableModel tableModel;
    private String[] tableHeader = {"链接类型 "};
    private final int rowHeight = 40;
    private final int headerHeight = 40;
    private List<String> ltNameList;
    private JPanel northPanel;
    private JPanel centerPanel;
    private JPanel southPanel;
    private JScrollPane scrollPane;
    private JButton btnOK;
    private JButton btnCancel;
    public JTextField textField=new JTextField(20);
    private JButton sel;
    
    public LinkTypeSelectDialog(){
        this.ltNameList = getLtNameList();
        initUI();
        initTable("");
        addListener();
    }
 
    private void initUI(){
        this.setTitle("链接类型选择框");
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(screenSize.width/2, screenSize.height/2);
        this.setModal(true);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        
        this.setLayout(new BorderLayout(5, 5));
        //add by caill
        //查询按钮
        northPanel=new JPanel();
        //业务类型列表
        centerPanel = new JPanel();
        //确定,取消按钮
        southPanel = new JPanel();
        this.add(northPanel,BorderLayout.NORTH);
        this.add(centerPanel, BorderLayout.CENTER);
        this.add(southPanel, BorderLayout.SOUTH);
        
        northPanel.add(new JLabel("链接类型名"));
        northPanel.add(textField);
        //add by caill start
        sel=new JButton("查询");
        northPanel.add(sel);
        sel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                 String textValue = textField.getText().trim();
                 ltNameList = getLtNameList();
                 initTable(textValue);
                 scrollPane.setViewportView(table);
                 //scrollPane.setViewportView(null);
            }
        });
        //add by caill end
        centerPanel.setLayout(new BorderLayout());
        scrollPane = new JScrollPane();
        centerPanel.add(scrollPane, BorderLayout.CENTER);
        tableModel = new DefaultTableModel();
        tableModel.setColumnCount(tableHeader.length);
        tableModel.setColumnIdentifiers(tableHeader);
        table = new JXTable(tableModel);
        
        table.setHighlighters(HighlighterFactory.createSimpleStriping());
        table.setHorizontalScrollEnabled(true);
        table.setSortable(false);
        table.setRowHeight(rowHeight);
        JTableHeader tableHeader = table.getTableHeader();
        Dimension size = tableHeader.getPreferredSize();
        size.height = headerHeight;
        tableHeader.setPreferredSize(size);
        scrollPane.setViewportView(table);
        
        btnOK = new JButton("确定");
        btnCancel = new JButton("取消");
        southPanel.add(btnOK);
        southPanel.add(btnCancel);
    }
    
    private void initTable(String textValue){
        if(ltNameList == null){
            return;
        }    
        //tableModel.setRowCount(ltNameList.size());
        table.setEditable(true);
        //add by caill start
        if(textValue.equals("")){
            tableModel.setRowCount(ltNameList.size());
            for(int i = 0; i < ltNameList.size(); i++){
                table.setValueAt(ltNameList.get(i), i, 0);
            }
        } else{    
            int count=0;
            for(int i = 0; i < ltNameList.size(); i++){
                
                if(ltNameList.get(i).indexOf(textValue)==0){
                    count+=1;
                    tableModel.setRowCount(count);
                    table.setValueAt(ltNameList.get(i), count-1, 0);
                    
                }else if(count==0){
                    tableModel.setRowCount(0);
                }
            /*    if(ltNameList.get(i).contains(textValue)){
                    count+=1;
                    tableModel.setRowCount(count);
                    System.out.println("HHHHHHHHHHHHHHHHHHHHHHH"+count);
                    table.setValueAt(ltNameList.get(i), count-1, 0);
                    
                }else if(count==0){
                    tableModel.setRowCount(0);
                }*/
            }
            
            //add by caill end
        } 
        /*for(int i = 0; i < ltNameList.size(); i++){
            table.setValueAt(ltNameList.get(i), i, 0);
        }*/
        table.setEditable(false);
    }
    
    private void addListener(){
        btnOK.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                int selectRow = table.getSelectedRow();
                selectLTName = (String) table.getValueAt(selectRow, 0);
                dispose();
            }
        });
        
        btnCancel.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
    }
    
    public String getSelectedltName(){
        return selectLTName;
    }
    
    /**
     * 获取注入的业务Table
     * @return
     */
    private List<String> getLtNameList(){
        List<String> list = null;
        ArrayList<InterAP> interAPList = InterAPManager.getInstance().getInterAPList();
        for(InterAP interAP : interAPList ){
            if(interAP instanceof InterAPForLinkType){
                list = ((InterAPForLinkType) interAP).getAllLtName();
                break;
            }
        }
        return list;
    }
}