OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 174
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.sql.ui.light;
14
 package org.openconcerto.sql.ui.light;
15
 
15
 
16
import org.openconcerto.sql.Log;
16
import org.openconcerto.sql.Log;
17
import org.openconcerto.sql.PropsConfiguration;
17
import org.openconcerto.sql.PropsConfiguration;
-
 
18
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.model.Constraint;
19
import org.openconcerto.sql.model.Constraint;
19
import org.openconcerto.sql.model.SQLField;
20
import org.openconcerto.sql.model.SQLField;
20
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLSyntax.ConstraintType;
22
import org.openconcerto.sql.model.SQLSyntax.ConstraintType;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.model.SQLTable;
Line 29... Line 30...
29
import org.openconcerto.ui.light.LightUIPanel;
30
import org.openconcerto.ui.light.LightUIPanel;
30
import org.openconcerto.utils.io.JSONConverter;
31
import org.openconcerto.utils.io.JSONConverter;
31
 
32
 
32
import java.util.Calendar;
33
import java.util.Calendar;
33
import java.util.Date;
34
import java.util.Date;
-
 
35
import java.util.HashMap;
-
 
36
import java.util.List;
-
 
37
import java.util.Map;
34
import java.util.Set;
38
import java.util.Set;
35
 
39
 
36
/**
40
/**
37
 * Fill value from default or database
41
 * Fill value from default or database
38
 */
42
 */
Line 56... Line 60...
56
                }
60
                }
57
            }
61
            }
58
        }
62
        }
59
    }
63
    }
60
 
64
 
61
    public void fillFromRow(final PropsConfiguration configuration, final SQLRowAccessor row) {
65
    public void fillFromRow(final PropsConfiguration configuration, SQLElement element, final SQLRowAccessor row, String sessionSecurityToken) {
62
        this.fillFromRow(this.panel, configuration, row);
66
        this.fillFromRow(this.panel, configuration, element, row, sessionSecurityToken);
-
 
67
    }
-
 
68
 
-
 
69
    private void fillFromRow(final LightUIPanel panel, final PropsConfiguration configuration, SQLElement sqlElement, SQLRowAccessor sqlRow, String sessionSecurityToken) {
-
 
70
        List<CustomRowEditor> editors = sqlElement.getCustomRowEditors(configuration, sessionSecurityToken);
-
 
71
        Map<String, CustomRowEditor> mapEditor = new HashMap<>(editors.size());
-
 
72
        for (CustomRowEditor e : editors) {
-
 
73
            mapEditor.put(e.getItemId(), e);
63
    }
74
        }
64
 
75
 
65
    private void fillFromRow(final LightUIPanel panel, final PropsConfiguration configuration, SQLRowAccessor sqlRow) {
-
 
66
        final int panelChildCount = panel.getChildrenCount();
76
        final int panelChildCount = panel.getChildrenCount();
67
        // Convert as sqlrow if possible to get all values from db
77
        // Convert as sqlrow if possible to get all values from db
68
        if (sqlRow.hasID()) {
78
        if (sqlRow.hasID()) {
69
            sqlRow = sqlRow.asRow();
79
            sqlRow = sqlRow.asRow();
70
        }
80
        }
71
        for (int i = 0; i < panelChildCount; i++) {
81
        for (int i = 0; i < panelChildCount; i++) {
72
            final LightUILine panelChild = panel.getChild(i, LightUILine.class);
82
            final LightUILine panelChild = panel.getChild(i, LightUILine.class);
73
            final int lineChildCount = panelChild.getChildrenCount();
83
            final int lineChildCount = panelChild.getChildrenCount();
74
            for (int j = 0; j < lineChildCount; j++) {
84
            for (int j = 0; j < lineChildCount; j++) {
75
                final LightUIElement element = panelChild.getChild(j);
85
                final LightUIElement element = panelChild.getChild(j);
-
 
86
                if (mapEditor.containsKey(element.getId())) {
-
 
87
                    mapEditor.get(element.getId()).fillFrom(element, sqlRow);
-
 
88
                } else {
-
 
89
 
76
                final SQLField sqlField = configuration.getFieldMapper().getSQLFieldForItem(element.getId());
90
                    final SQLField sqlField = configuration.getFieldMapper().getSQLFieldForItem(element.getId());
77
 
91
 
78
                SQLRowAccessor sqlRowTmp = this.getSQLRowForField(sqlRow, sqlField);
92
                    SQLRowAccessor sqlRowTmp = this.getSQLRowForField(sqlRow, sqlField);
79
                if (sqlRowTmp == null) {
93
                    if (sqlRowTmp == null) {
80
                    throw new IllegalArgumentException("Impossible to reach the field: " + sqlField.getName() + " from table " + sqlRow.getTable().getName());
94
                        throw new IllegalArgumentException("Impossible to reach the field: " + sqlField.getName() + " from table " + sqlRow.getTable().getName());
Line 113... Line 127...
113
                    Calendar date = sqlRowTmp.getDate(sqlField.getName());
127
                        Calendar date = sqlRowTmp.getDate(sqlField.getName());
114
                    if (date != null) {
128
                        if (date != null) {
115
                        element.setValue(JSONConverter.getJSON(date).toString());
129
                            element.setValue(JSONConverter.getJSON(date).toString());
116
                    }
130
                        }
117
                } else if (type == LightUIElement.TYPE_PANEL) {
131
                    } else if (type == LightUIElement.TYPE_PANEL) {
118
                    this.fillFromRow((LightUIPanel) element, configuration, sqlRowTmp);
132
                        this.fillFromRow((LightUIPanel) element, configuration, sqlElement, sqlRowTmp, sessionSecurityToken);
119
                } else if (type == LightUIElement.TYPE_SLIDER) {
133
                    } else if (type == LightUIElement.TYPE_SLIDER) {
120
                    final Integer value = sqlRowTmp.getInt(sqlField.getName());
134
                        final Integer value = sqlRowTmp.getInt(sqlField.getName());
121
                    if (value != null) {
135
                        if (value != null) {
122
                        element.setValue(value.toString());
136
                            element.setValue(value.toString());
123
                    }
137
                        }
124
                }
138
                    }
125
            }
139
                }
126
        }
140
            }
127
    }
141
        }
-
 
142
    }
128
 
143
 
129
    public SQLRowAccessor getSQLRowForField(final SQLRowAccessor sqlRow, final SQLField sqlField) {
144
    public SQLRowAccessor getSQLRowForField(final SQLRowAccessor sqlRow, final SQLField sqlField) {
130
        SQLRowAccessor sqlRowResult = sqlRow;
145
        SQLRowAccessor sqlRowResult = sqlRow;
131
        if (sqlField != null && !sqlField.getTable().getName().equals(sqlRow.getTable().getName())) {
146
        if (sqlField != null && !sqlField.getTable().getName().equals(sqlRow.getTable().getName())) {
132
            sqlRowResult = this.findSQLRow(sqlRow, sqlField);
147
            sqlRowResult = this.findSQLRow(sqlRow, sqlField);