¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.codeapply; |
| | | |
| | | import com.vci.base.ui.swing.VCISwingUtil; |
| | | import com.vci.base.ui.swing.components.VCIJButton; |
| | | import com.vci.base.ui.swing.components.VCIJLabel; |
| | | import com.vci.base.ui.swing.components.VCIJPanel; |
| | | import com.vci.base.ui.swing.components.VCIJTextField; |
| | | import com.vci.ubcs.code.vo.webserviceModel.coderule.CodeShowFieldConfigVO; |
| | | import com.vci.ubcs.codeapply.object.UIFormRefer; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | |
| | | import java.awt.*; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | public class attarSearchPanel extends VCIJPanel { |
| | | |
| | | private LinkedHashMap<String , VCIJTextField> attrInerNameValMap = new LinkedHashMap<String,VCIJTextField>(); |
| | | private UIFormRefer uiFormRefer; |
| | | public attarSearchPanel(UIFormRefer uiFormRefer){ |
| | | this.uiFormRefer = uiFormRefer; |
| | | init(); |
| | | } |
| | | private void init(){ |
| | | initcomponam(); |
| | | } |
| | | private void initcomponam(){ |
| | | this.setLayout(new GridBagLayout()); |
| | | setAttrSearch(); |
| | | this.setVisible(true); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * <p>æåºæ¬å±æ§ä¿¡æ¯åå§åå°ç»ä»¶ä¸é¢ãå¹¶ä¿å屿§å°Mapï¼å±æ§å
é¨åç§°--textFieldï¼ä¸</p> |
| | | * |
| | | * @time 2013-3-17 |
| | | */ |
| | | private void setAttrSearch(){ |
| | | List<CodeShowFieldConfigVO> codeShowFieldConfigVOS=this.uiFormRefer.getCodeShowFieldConfigVOS(); |
| | | if(!CollectionUtils.isEmpty(codeShowFieldConfigVOS)){ |
| | | CodeShowFieldConfigVO[] objs=codeShowFieldConfigVOS.toArray(new CodeShowFieldConfigVO []{}); |
| | | GridBagConstraints cons = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.EAST , GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0); |
| | | for(int i = 0 ;i<objs.length;i++){ |
| | | if(cons.gridx == 1 ){ |
| | | cons.gridwidth = GridBagConstraints.REMAINDER; |
| | | cons.anchor = GridBagConstraints.WEST; |
| | | }else if(cons.gridx >1){ |
| | | cons.gridx = 0; |
| | | cons.anchor = GridBagConstraints.EAST; |
| | | cons.gridy++; |
| | | cons.gridwidth = 1; |
| | | } |
| | | VCIJPanel oneSearch = new VCIJPanel(); |
| | | oneSearch.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
| | | String attrName = objs[i].getTitle(); |
| | | |
| | | VCIJLabel attarLabel = new VCIJLabel(attrName+":"); |
| | | VCIJTextField attrText = new VCIJTextField(""); |
| | | attrInerNameValMap.put(objs[i].getField(), attrText); |
| | | attrText.setPreferredSize(new Dimension(300, 30)); |
| | | oneSearch.add(attarLabel); |
| | | oneSearch.add(attrText); |
| | | cons.gridx++; |
| | | this.add(oneSearch,cons); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * <p>è¿ååä¸ªå±æ§ç»è¿æ¼æ¥åçæ¥è¯¢SQLè¯å¥</p> |
| | | * |
| | | * @time 2013-3-17 |
| | | * @return |
| | | */ |
| | | public String getAttrSearchFilterString(){ |
| | | String result = ""; |
| | | StringBuilder sql = new StringBuilder(); |
| | | Set<String> keys = attrInerNameValMap.keySet(); |
| | | for (Iterator it = keys.iterator(); it.hasNext();) { |
| | | String key = (String)it.next(); |
| | | VCIJTextField textField = attrInerNameValMap.get(key); |
| | | String message = textField.getText().replaceAll(" ", "").trim(); |
| | | if(message.equals("")) continue; |
| | | String text = getTextQueryVal(message); |
| | | sql.append(" "+key+" "); |
| | | sql.append(" like "); |
| | | sql.append("'"+text+"'"); |
| | | sql.append(" and"); |
| | | } |
| | | if(sql.length() != 0){ |
| | | result = sql.substring(0, sql.lastIndexOf("and")); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * <p>æ ¹æ®ææ¬æ¡è¾å
¥å
å®¹ï¼æé æ¥è¯¢æ¡ä»¶ã |
| | | * è¿èç»æï¼ 1ãå½å
å®¹æ¯ ä»¥*å¼å¤´ï¼å¦'*abc',åè¿åå
容"%abc"ï¼ |
| | | * 2ãå½å
容以*ç»æï¼å¦"abc*"ï¼åè¿åå
容"abc%"ï¼ |
| | | * 3ãå½å
容ä¸é´å
å«*ï¼å¦"abc*def"ï¼åè¿åå
容"abc%def"ï¼ |
| | | * 4ãè¾å
¥çå
容妿æ¯ç©ºï¼åè¿å"%" |
| | | * 5ãå
¶ä»æ
åµåè¿åå
容æ¬èº« |
| | | * </p> |
| | | * @time 2013-3-17 |
| | | * @param text |
| | | * @return |
| | | */ |
| | | private String getTextQueryVal(String text){ |
| | | if(text.equals("")){ |
| | | return "%"; |
| | | } |
| | | StringBuilder result = new StringBuilder(); |
| | | // update by xchao 2013.05.21 begin |
| | | // æ¯ææ´çµæ´»çæç´¢ |
| | | // ä¸»ææ³æ§å¶é»è¾ |
| | | // 1ãå°è¾å
¥çæ¡ä»¶ä¸ç*æ¿æ¢ä¸º%ï¼XXX*XXX-> XXX%XXX |
| | | // 2ã妿è¾å
¥çæ¡ä»¶ä¸å
å«*ï¼å卿¡ä»¶çååé½å ä¸%ï¼ä»¥å®æå
¨æ¨¡ç³ï¼'%XXX%' |
| | | // 3ãåé¢ä¸è¾å
¥*ãåé¢ä¸è¾å
¥*ä¸ä¹åä¸è´ |
| | | // å³ï¼åé¢ä¸å
å«*ï¼åè¡¨ææ¥è¯¢çæ¯â以XXXå¼å¤´âçæ°æ®ï¼'XXX%' |
| | | // åé¢ä¸å
å«*ï¼åè¡¨é¢æ¥è¯¢çæ¯â以XXXç»æâçæ°æ®ï¼'%XXX' |
| | | // 4ã |
| | | if(text.indexOf("*") >= 0){ |
| | | // result.append(text.replace("*", "%")); |
| | | // ä¸å¥å¯ä»¥æ¯æä¸é´* |
| | | result.append("%").append(text.replace("*", "%")).append("%"); |
| | | } else { |
| | | result.append("%").append(text).append("%"); |
| | | } |
| | | // update by xchao 2013.05.21 end |
| | | |
| | | // int midel = text.lastIndexOf("*"); |
| | | // if(text.startsWith("*")){ |
| | | // result.append("%"); |
| | | // result.append(text.substring(1)); |
| | | // }else if(text.endsWith("*")){ |
| | | // result.append(text.substring(0, text.length()-1)); |
| | | // result.append("%"); |
| | | // }else if(midel > 0){ |
| | | // String before = text.substring(0, midel); |
| | | // result.append(before); |
| | | // result.append("%"); |
| | | // String after = text.substring(midel+1); |
| | | // result.append(after); |
| | | // }else{ |
| | | // result.append(text); |
| | | // } |
| | | return result.toString(); |
| | | } |
| | | public void clear(){ |
| | | Set<String> keys = attrInerNameValMap.keySet(); |
| | | for (Iterator it = keys.iterator(); it.hasNext();) { |
| | | String key = (String)it.next(); |
| | | VCIJTextField textField = attrInerNameValMap.get(key); |
| | | textField.setText(""); |
| | | } |
| | | |
| | | } |
| | | } |