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;
|
}
|
}
|