xiejun
2023-08-24 b28da4c353e50fc2491c733889fef5f79e5926f2
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
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("");
        }
 
    }
}