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
142 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
 
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLRowValues;
174 ilm 19
import org.openconcerto.sql.model.Where;
142 ilm 20
import org.openconcerto.sql.view.list.ITableModel;
21
import org.openconcerto.sql.view.list.SQLTableModelLinesSourceOffline;
22
import org.openconcerto.ui.light.LightUIElement;
23
import org.openconcerto.ui.light.TableContent;
174 ilm 24
import org.openconcerto.ui.light.UserSearch;
142 ilm 25
 
26
import java.util.concurrent.Future;
27
 
28
import net.minidev.json.JSONObject;
29
 
30
public class LightForeignRowValuesTableOffline extends LightRowValuesTable {
31
 
32
    private SQLField foreignField;
33
    private Number parentRowId;
34
 
174 ilm 35
    public LightForeignRowValuesTableOffline(final Configuration configuration, final Number userId, final String id, final ITableModel model, final SQLField foreignField) {
142 ilm 36
        super(configuration, userId, id, model);
37
        this.foreignField = foreignField;
38
        this.init();
39
    }
40
 
174 ilm 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
 
142 ilm 48
    public LightForeignRowValuesTableOffline(final LightForeignRowValuesTableOffline table) {
49
        super(table);
50
 
51
        this.foreignField = table.foreignField;
52
        this.parentRowId = table.parentRowId;
53
        this.init();
54
    }
55
 
56
    private final void init() {
57
        if (this.getTableSpec().getContent() == null) {
58
            this.getTableSpec().setContent(new TableContent(this.getId()));
59
        }
60
    }
61
 
62
    public final SQLField getForeignField() {
63
        return this.foreignField;
64
    }
65
 
66
    public final Number getParentRowId() {
67
        return this.parentRowId;
68
    }
69
 
70
    public Future<?> commitRows() {
71
        return ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).commit();
72
    }
73
 
74
    public void addNewRow(final SQLRowValues sqlRow) {
75
        ((SQLTableModelLinesSourceOffline) this.getModel().getLinesSource()).add(sqlRow);
76
    }
77
 
78
    @Override
174 ilm 79
    public void doSearch(final Configuration configuration, final UserSearch searchSpec, final int offset) {
142 ilm 80
        // TODO: Implement search in offline table
81
        this.getModel().fireTableRowsInserted(0, Integer.MAX_VALUE);
82
    }
83
 
84
    @Override
85
    public LightUIElement clone() {
86
        return new LightForeignRowValuesTableOffline(this);
87
    }
88
 
89
    @Override
90
    public void fromJSON(final JSONObject json) {
91
        super.fromJSON(json);
92
 
93
        if (this.getTableSpec().getContent() != null) {
94
            this.getTableSpec().getContent().clearRows();
95
        }
96
    }
97
}