OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
21 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
 /*
15
 * Créé le 10 oct. 2011
16
 */
17
package org.openconcerto.erp.generationDoc.element;
18
 
156 ilm 19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
21 ilm 20
import org.openconcerto.sql.element.SQLComponent;
21
import org.openconcerto.sql.element.UISQLComponent;
132 ilm 22
import org.openconcerto.sql.model.DBRoot;
21 ilm 23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowListRSH;
25
import org.openconcerto.sql.model.SQLSelect;
132 ilm 26
import org.openconcerto.utils.ListMap;
21 ilm 27
 
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.HashSet;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.Set;
34
 
156 ilm 35
public class TypeModeleSQLElement extends ComptaSQLConfElement {
21 ilm 36
 
132 ilm 37
    public TypeModeleSQLElement(DBRoot root) {
156 ilm 38
        super(root.getTable("TYPE_MODELE"), "un type de modèle", "types de modèles");
132 ilm 39
    }
40
 
21 ilm 41
    protected List<String> getListFields() {
42
        final List<String> l = new ArrayList<String>();
43
        l.add("NOM");
44
        l.add("TABLE");
45
        return l;
46
    }
47
 
48
    protected List<String> getComboFields() {
49
        final List<String> l = new ArrayList<String>();
50
        l.add("NOM");
51
        return l;
52
    }
53
 
54
    @Override
132 ilm 55
    public ListMap<String, String> getShowAs() {
56
        ListMap<String, String> map = new ListMap<String, String>();
57
        map.putCollection(null, "NOM");
21 ilm 58
        return map;
59
    }
60
 
61
    public SQLComponent createComponent() {
62
        return new UISQLComponent(this) {
63
 
64
            @Override
65
            protected Set<String> createRequiredNames() {
66
                final Set<String> s = new HashSet<String>();
67
                // s.add("NOM");
68
                // s.add("TABLE");
69
                return s;
70
            }
71
 
72
            public void addViews() {
73
                this.addView("NOM");
74
                this.addView("TABLE");
75
            }
76
        };
77
    }
78
 
79
    public String getDescription(SQLRow fromRow) {
80
        return fromRow.getString("NOM");
81
    }
82
 
83
    Map<String, String> template;
84
 
85
    public Map<String, String> getTemplateMapping() {
86
 
87
        if (this.template == null) {
88
            this.template = new HashMap<String, String>();
156 ilm 89
            SQLSelect sel = new SQLSelect();
21 ilm 90
            sel.addSelectStar(getTable());
156 ilm 91
            for (SQLRow sqlRow : SQLRowListRSH.execute(sel)) {
92
                this.template.put(sqlRow.getString("TABLE"), sqlRow.getString("DEFAULT_MODELE"));
21 ilm 93
            }
94
 
95
        }
96
 
156 ilm 97
        return this.template;
21 ilm 98
 
99
    }
100
 
156 ilm 101
    @Override
102
    protected String createCode() {
103
        return "document.template-type";
104
    }
21 ilm 105
}