OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Go to most recent revision | Details | 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
 
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.element.ConfSQLElement;
21
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.element.UISQLComponent;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowListRSH;
25
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.utils.CollectionMap;
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
 
35
public class TypeModeleSQLElement extends ConfSQLElement {
36
 
37
    public TypeModeleSQLElement() {
38
        super("TYPE_MODELE", "un type_modele ", "type_modeles");
39
    }
40
 
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
55
    public CollectionMap<String, String> getShowAs() {
56
        CollectionMap<String, String> map = new CollectionMap<String, String>();
57
        map.put(null, "NOM");
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>();
89
            SQLSelect sel = new SQLSelect(getTable().getBase());
90
            sel.addSelectStar(getTable());
91
            List<SQLRow> rows = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
92
            for (SQLRow sqlRow : rows) {
93
                template.put(sqlRow.getString("TABLE"), sqlRow.getString("DEFAULT_MODELE"));
94
            }
95
 
96
        }
97
 
98
        return template;
99
 
100
    }
101
 
102
}