OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 174
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql.ui.light;
14
 package org.openconcerto.sql.ui.light;
15
 
15
 
16
import org.openconcerto.sql.Configuration;
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.model.SQLField;
17
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLRowValues;
18
import org.openconcerto.sql.model.SQLRowValues;
-
 
19
import org.openconcerto.sql.model.Where;
19
import org.openconcerto.sql.view.list.ITableModel;
20
import org.openconcerto.sql.view.list.ITableModel;
20
import org.openconcerto.sql.view.list.SQLTableModelLinesSourceOffline;
21
import org.openconcerto.sql.view.list.SQLTableModelLinesSourceOffline;
21
import org.openconcerto.ui.light.LightUIElement;
22
import org.openconcerto.ui.light.LightUIElement;
22
import org.openconcerto.ui.light.SearchSpec;
-
 
23
import org.openconcerto.ui.light.TableContent;
23
import org.openconcerto.ui.light.TableContent;
-
 
24
import org.openconcerto.ui.light.UserSearch;
24
 
25
 
25
import java.util.concurrent.Future;
26
import java.util.concurrent.Future;
26
 
27
 
27
import net.minidev.json.JSONObject;
28
import net.minidev.json.JSONObject;
28
 
29
 
29
public class LightForeignRowValuesTableOffline extends LightRowValuesTable {
30
public class LightForeignRowValuesTableOffline extends LightRowValuesTable {
30
 
31
 
31
    private SQLField foreignField;
32
    private SQLField foreignField;
32
    private Number parentRowId;
33
    private Number parentRowId;
33
 
34
 
34
    public LightForeignRowValuesTableOffline(final Configuration configuration, final Number userId, final String id, final ITableModel model, final SQLField foreignField, final Number parentRowId) {
35
    public LightForeignRowValuesTableOffline(final Configuration configuration, final Number userId, final String id, final ITableModel model, final SQLField foreignField) {
35
        super(configuration, userId, id, model);
36
        super(configuration, userId, id, model);
36
 
-
 
37
        this.foreignField = foreignField;
37
        this.foreignField = foreignField;
38
        this.parentRowId = parentRowId;
-
 
39
        this.init();
38
        this.init();
40
    }
39
    }
41
 
40
 
-
 
41
    public void setParentRowId(Number parentRowId) {
-
 
42
        this.parentRowId = parentRowId;
-
 
43
        // FIXME : d'apres Sylvain, on pourrait ne pas a utiliser le ITableMobel car on veut du
-
 
44
        // synchrone
-
 
45
        this.getModel().getReq().getReq().setWhere(new Where(this.foreignField, "=", parentRowId));
-
 
46
    }
-
 
47
 
42
    public LightForeignRowValuesTableOffline(final LightForeignRowValuesTableOffline table) {
48
    public LightForeignRowValuesTableOffline(final LightForeignRowValuesTableOffline table) {
43
        super(table);
49
        super(table);
44
 
50
 
45
        this.foreignField = table.foreignField;
51
        this.foreignField = table.foreignField;
46
        this.parentRowId = table.parentRowId;
52
        this.parentRowId = table.parentRowId;
47
        this.init();
53
        this.init();
48
    }
54
    }
49
 
55
 
50
    private final void init() {
56
    private final void init() {
51
        if (this.getTableSpec().getContent() == null) {
57
        if (this.getTableSpec().getContent() == null) {
52
            this.getTableSpec().setContent(new TableContent(this.getId()));
58
            this.getTableSpec().setContent(new TableContent(this.getId()));
53
        }
59
        }
54
    }
60
    }
55
 
61
 
56
    public final SQLField getForeignField() {
62
    public final SQLField getForeignField() {
57
        return this.foreignField;
63
        return this.foreignField;
58
    }
64
    }
59
 
65
 
60
    public final Number getParentRowId() {
66
    public final Number getParentRowId() {
61
        return this.parentRowId;
67
        return this.parentRowId;
62
    }
68
    }
63
 
69
 
64
    public Future<?> commitRows() {
70
    public Future<?> commitRows() {
65
        return ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).commit();
71
        return ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).commit();
66
    }
72
    }
67
 
73
 
68
    public void addNewRow(final SQLRowValues sqlRow) {
74
    public void addNewRow(final SQLRowValues sqlRow) {
69
        ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).add(sqlRow);
75
        ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).add(sqlRow);
70
    }
76
    }
71
 
77
 
72
    @Override
78
    @Override
73
    public void doSearch(final Configuration configuration, final SearchSpec searchSpec, final int offset) {
79
    public void doSearch(final Configuration configuration, final UserSearch searchSpec, final int offset) {
74
        // TODO: Implement search in offline table
80
        // TODO: Implement search in offline table
75
        this.getModel().fireTableRowsInserted(0, Integer.MAX_VALUE);
81
        this.getModel().fireTableRowsInserted(0, Integer.MAX_VALUE);
76
    }
82
    }
77
 
83
 
78
    @Override
84
    @Override
79
    public LightUIElement clone() {
85
    public LightUIElement clone() {
80
        return new LightForeignRowValuesTableOffline(this);
86
        return new LightForeignRowValuesTableOffline(this);
81
    }
87
    }
82
 
88
 
83
    @Override
89
    @Override
84
    public void fromJSON(final JSONObject json) {
90
    public void fromJSON(final JSONObject json) {
85
        super.fromJSON(json);
91
        super.fromJSON(json);
86
 
92
 
87
        if (this.getTableSpec().getContent() != null) {
93
        if (this.getTableSpec().getContent() != null) {
88
            this.getTableSpec().getContent().clearRows();
94
            this.getTableSpec().getContent().clearRows();
89
        }
95
        }
90
    }
96
    }
91
}
97
}