OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.sql.ui.light;
15
 
142 ilm 16
import org.openconcerto.sql.Log;
132 ilm 17
import org.openconcerto.sql.view.search.SearchList;
18
import org.openconcerto.sql.view.search.TextSearchSpec;
19
import org.openconcerto.sql.view.search.TextSearchSpec.Mode;
174 ilm 20
import org.openconcerto.ui.light.UserSearchItem;
21
import org.openconcerto.ui.light.UserSearch;
132 ilm 22
 
23
import java.util.ArrayList;
24
import java.util.List;
25
 
26
public class SearchInfo {
142 ilm 27
    // TODO: add notion of operator
132 ilm 28
    private final SearchList list = new SearchList();
29
    private final List<String> texts = new ArrayList<String>();
30
 
174 ilm 31
    public SearchInfo(final UserSearch params) {
132 ilm 32
        int stop = params.getContent().size();
33
        for (int i = 0; i < stop; i++) {
174 ilm 34
            final UserSearchItem param = params.getContent().get(i);
132 ilm 35
            final String col = param.getColumn();
36
            final String type = param.getType();
142 ilm 37
            final String[] tTexts = param.getText().split(" ");
132 ilm 38
 
39
            Mode mode = Mode.CONTAINS;
40
            if (type.equals("contains")) {
41
                mode = Mode.CONTAINS;
42
            } else if (type.equals("equals")) {
43
                mode = Mode.EQUALS;
44
            } else if (type.equals("lth")) {
45
                mode = Mode.LESS_THAN;
46
            } else if (type.equals("gth")) {
47
                mode = Mode.GREATER_THAN;
48
            } else {
49
                throw new IllegalArgumentException("mode " + type + " not supported");
50
            }
51
 
142 ilm 52
            for (final String text : tTexts) {
53
                this.list.addSearchItem(new TextSearchSpec(text, mode));
54
                this.texts.add(text);
55
                Log.get().info("searching column:" + col + "type:" + type + " text:" + text);
56
            }
132 ilm 57
        }
58
    }
59
 
60
    public List<String> getTexts() {
61
        return this.texts;
62
    }
63
 
64
    private final List<Object> t = new ArrayList<Object>();
65
 
66
    public boolean match(Object value) {
67
        this.t.clear();
68
        this.t.add(value);
69
        return this.list.match(this.t);
70
    }
71
}