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 dataProvider = null; private VCIJTablePanel tablePanel = null; private LinkTypePopupDialog popupDialog = null; public LinkTypePopupTablePanel(LinkTypePopupDialog popupDialog){ this.popupDialog = popupDialog; } public void buildTablePanel(){ setLayout(new BorderLayout()); dataProvider = new AbstractVCIJTableDataProvider() { @Override public String[] getSpecialColumns() { return new String[]{COLUMN_NAME, COLUMN_LABEL}; } @Override public int getTotal() { return super.total; } @Override public VCIJTableNode getNewRowNode(LinkType obj) { VCIJTableNode res = new VCIJTableNode(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 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(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 getDatasByPageInfo(int pageIndex, int pageSize) throws VCIError{ List list = new ArrayList(); Map map = new HashMap(); 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 res = new ResData(); 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 list = new LinkedList(); // 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 res = new ResData(); // 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 getTablePanel() { return tablePanel; } public LinkTypePopupDialog getPopupDialog() { return popupDialog; } public void setPopupDialog(LinkTypePopupDialog popupDialog) { this.popupDialog = popupDialog; } }