package com.vci.rmip.code.client.codeapply.Apply410;
|
|
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.rmip.code.client.codeapply.Apply410.object.UIFormRefer;
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import java.awt.*;
|
import java.util.*;
|
import java.util.List;
|
|
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 Map<String,String> getAttrSearchFilterString(){
|
String result = "";
|
Map<String,String> customConditionMap=new HashMap<>();
|
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);
|
customConditionMap.put(key,text);
|
}
|
|
return customConditionMap;
|
}
|
|
/**
|
*
|
* <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("");
|
}
|
|
}
|
}
|