OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
Line 14... Line 14...
14
 package org.openconcerto.ui.light;
14
 package org.openconcerto.ui.light;
15
 
15
 
16
import org.openconcerto.utils.io.JSONConverter;
16
import org.openconcerto.utils.io.JSONConverter;
17
import org.openconcerto.utils.io.Transferable;
17
import org.openconcerto.utils.io.Transferable;
18
 
18
 
19
import java.io.Externalizable;
-
 
20
import java.io.IOException;
-
 
21
import java.io.ObjectInput;
-
 
22
import java.io.ObjectOutput;
-
 
23
import java.util.ArrayList;
19
import java.util.ArrayList;
24
import java.util.List;
20
import java.util.List;
25
 
21
 
26
import net.minidev.json.JSONArray;
22
import net.minidev.json.JSONArray;
27
import net.minidev.json.JSONObject;
23
import net.minidev.json.JSONObject;
28
 
24
 
29
public class TableContent implements Transferable, Externalizable {
25
public class TableContent implements Transferable {
30
    private static final long serialVersionUID = 3648381615123520834L;
26
    private static final long serialVersionUID = 3648381615123520834L;
31
    private String tableId;
27
    private String tableId;
32
    private List<Row> rows;
28
    private List<Row> rows;
33
 
29
 
34
    public TableContent() {
30
    public TableContent() {
Line 98... Line 94...
98
 
94
 
99
    /**
95
    /**
100
     * @return a copy of the list
96
     * @return a copy of the list
101
     */
97
     */
102
    public final synchronized List<Row> getRows() {
98
    public final synchronized List<Row> getRows() {
103
        return new ArrayList<Row>(this.rows);
99
        return new ArrayList<>(this.rows);
104
    }
100
    }
105
 
101
 
106
    @Override
102
    @Override
107
    public synchronized String toString() {
103
    public synchronized String toString() {
108
        return "TableContent of " + this.tableId + " lines count : " + this.getRowsCount();
104
        return "TableContent of " + this.tableId + " lines count : " + this.getRowsCount();
Line 120... Line 116...
120
    @Override
116
    @Override
121
    public synchronized void fromJSON(final JSONObject json) {
117
    public synchronized void fromJSON(final JSONObject json) {
122
        this.tableId = JSONConverter.getParameterFromJSON(json, "table-id", String.class);
118
        this.tableId = JSONConverter.getParameterFromJSON(json, "table-id", String.class);
123
        final JSONArray jsonRows = JSONConverter.getParameterFromJSON(json, "rows", JSONArray.class);
119
        final JSONArray jsonRows = JSONConverter.getParameterFromJSON(json, "rows", JSONArray.class);
124
        if (jsonRows != null) {
120
        if (jsonRows != null) {
125
            final List<Row> listRows = new ArrayList<Row>();
121
            final List<Row> listRows = new ArrayList<>();
126
            for (final Object o : jsonRows) {
122
            for (final Object o : jsonRows) {
127
                listRows.add(new Row(JSONConverter.getObjectFromJSON(o, JSONObject.class)));
123
                listRows.add(new Row(JSONConverter.getObjectFromJSON(o, JSONObject.class)));
128
            }
124
            }
129
            this.setRows(listRows);
125
            this.setRows(listRows);
130
        }
126
        }
131
    }
127
    }
132
 
128
 
133
    @Override
-
 
134
    public synchronized void writeExternal(ObjectOutput out) throws IOException {
-
 
135
        out.writeUTF(tableId);
-
 
136
        out.writeInt(rows.size());
-
 
137
        for (Row row : this.rows) {
-
 
138
            row.writeExternal(out);
-
 
139
        }
-
 
140
 
-
 
141
    }
-
 
142
 
-
 
143
    @Override
-
 
144
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
145
        tableId = in.readUTF();
-
 
146
        int size = in.readInt();
-
 
147
        this.rows = new ArrayList<>(size);
-
 
148
        for (int i = 0; i < size; i++) {
-
 
149
            final Row row = new Row();
-
 
150
            row.readExternal(in);
-
 
151
            this.rows.add(row);
-
 
152
        }
-
 
153
 
-
 
154
    }
-
 
155
 
-
 
156
}
129
}