OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Rev 142 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
80 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.ui.light;
15
 
16
import java.util.ArrayList;
17
import java.util.List;
18
 
94 ilm 19
import org.openconcerto.utils.io.JSONConverter;
20
import org.openconcerto.utils.io.Transferable;
21
import net.minidev.json.JSONArray;
22
import net.minidev.json.JSONObject;
23
 
93 ilm 24
public class TableContent implements Transferable {
80 ilm 25
    private static final long serialVersionUID = 3648381615123520834L;
94 ilm 26
    private String tableId;
80 ilm 27
    private List<Row> rows;
28
 
29
    public TableContent() {
30
        // Serialization
31
    }
32
 
94 ilm 33
    public TableContent(final String tableId) {
34
        this.init(tableId, null);
35
    }
36
 
37
    public TableContent(final String tableId, final List<Row> rows) {
38
        this.init(tableId, rows);
39
    }
40
 
41
    public TableContent(final JSONObject json) {
42
        this.fromJSON(json);
43
    }
44
 
45
    private void init(final String tableId, final List<Row> rows) {
46
        this.tableId = tableId;
47
        if (rows != null) {
48
            this.rows = rows;
49
        } else {
50
            this.rows = new ArrayList<Row>();
51
        }
52
    }
53
 
54
    public String getTableId() {
55
        return this.tableId;
56
    }
57
 
58
    public void setTableId(final String tableId) {
59
        this.tableId = tableId;
60
    }
61
 
80 ilm 62
    public List<Row> getRows() {
93 ilm 63
        return this.rows;
80 ilm 64
    }
65
 
66
    public void setRows(List<Row> rows) {
67
        this.rows = rows;
68
    }
69
 
94 ilm 70
    @Override
71
    public String toString() {
72
        return "TableContent of " + this.tableId + " lines count : " + getRows().size();
80 ilm 73
    }
74
 
75
    @Override
94 ilm 76
    public JSONObject toJSON() {
77
        final JSONObject result = new JSONObject();
78
        result.put("class", "TableContent");
79
        result.put("table-id", this.tableId);
80
        result.put("rows", JSONConverter.getJSON(this.rows));
81
        return result;
80 ilm 82
    }
93 ilm 83
 
84
    @Override
94 ilm 85
    public void fromJSON(final JSONObject json) {
86
        this.tableId = (String) JSONConverter.getParameterFromJSON(json, "table-id", String.class);
87
        final JSONArray jsonRows = (JSONArray) JSONConverter.getParameterFromJSON(json, "rows", JSONArray.class);
88
        if (jsonRows != null) {
89
            this.rows = new ArrayList<Row>();
90
            for (final Object o : jsonRows) {
91
                this.rows.add(new Row((JSONObject) JSONConverter.getObjectFromJSON(o, JSONObject.class)));
92
            }
93
        }
93 ilm 94
    }
80 ilm 95
}