OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 142
Line 18... Line 18...
18
import java.io.ObjectInput;
18
import java.io.ObjectInput;
19
import java.io.ObjectOutput;
19
import java.io.ObjectOutput;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.List;
21
import java.util.List;
22
 
22
 
-
 
23
import org.openconcerto.utils.CollectionUtils;
23
import org.openconcerto.utils.io.JSONAble;
24
import org.openconcerto.utils.io.JSONAble;
24
import org.openconcerto.utils.io.JSONConverter;
25
import org.openconcerto.utils.io.JSONConverter;
25
import net.minidev.json.JSONArray;
26
import net.minidev.json.JSONArray;
26
import net.minidev.json.JSONObject;
27
import net.minidev.json.JSONObject;
27
 
28
 
28
public class RowSelectionSpec implements Externalizable, JSONAble {
29
public class RowSelectionSpec implements Externalizable, JSONAble {
29
    private String tableId;
30
    private String tableId;
30
 
31
 
31
    private List<Long> ids;
32
    private List<Number> ids;
32
 
33
 
33
    /**
34
    /**
34
     * Define selected ids of a table. ids are ids from selected lines
35
     * Define selected ids of a table. ids are ids from selected lines
35
     */
36
     */
36
    public RowSelectionSpec() {
37
    public RowSelectionSpec() {
Line 39... Line 40...
39
 
40
 
40
    public RowSelectionSpec(final JSONObject json) {
41
    public RowSelectionSpec(final JSONObject json) {
41
        this.fromJSON(json);
42
        this.fromJSON(json);
42
    }
43
    }
43
 
44
    
44
    public RowSelectionSpec(String tableId, List<Long> ids) {
-
 
45
        this.init(tableId, ids);
-
 
46
    }
-
 
47
 
-
 
48
    public RowSelectionSpec(String tableId) {
45
    public RowSelectionSpec(String tableId) {
49
        this.init(tableId, null);
46
        this(tableId, new ArrayList<Number>());
50
    }
47
    }
51
 
48
 
52
    private void init(final String tableId, final List<Long> ids) {
49
    public RowSelectionSpec(final String tableId, final List<Number> selectedIds) {
53
        this.tableId = tableId;
50
        this.tableId = tableId;
54
        if (ids != null) {
-
 
55
            this.ids = ids;
51
        this.ids = selectedIds;
56
        } else {
-
 
57
            this.ids = new ArrayList<Long>();
-
 
58
        }
-
 
59
    }
52
    }
60
 
53
 
61
    public List<Long> getIds() {
54
    public final List<Number> getIds() {
62
        return this.ids;
55
        return this.ids;
63
    }
56
    }
64
 
57
    
-
 
58
    public final void setIds(List<Number> ids) {
-
 
59
        this.ids = ids;
-
 
60
    }
-
 
61
 
65
    public String getTableId() {
62
    public String getTableId() {
66
        return this.tableId;
63
        return this.tableId;
67
    }
64
    }
68
 
65
    
-
 
66
    public boolean hasSelectedId(){
-
 
67
        return this.getIds() != null && !this.getIds().isEmpty();
-
 
68
    }
-
 
69
 
69
    @Override
70
    @Override
70
    public String toString() {
71
    public String toString() {
71
        final StringBuilder r = new StringBuilder("RowSelectionSpec: ").append(this.tableId).append(" : ");
72
        final StringBuilder r = new StringBuilder("RowSelectionSpec: ").append(this.tableId).append(" : ");
72
        final int idsSize = this.ids.size();
73
        final int idsSize = this.ids.size();
73
        for (int i = 0; i < idsSize; i++) {
74
        for (int i = 0; i < idsSize; i++) {
Line 93... Line 94...
93
    }
94
    }
94
 
95
 
95
    @Override
96
    @Override
96
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
97
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
97
        this.tableId = in.readUTF();
98
        this.tableId = in.readUTF();
98
        this.ids = (List<Long>) in.readObject();
99
        this.ids = CollectionUtils.castList((List<?>) in.readObject(), Number.class);
99
 
100
 
100
    }
101
    }
101
 
102
 
102
    @Override
103
    @Override
103
    public JSONObject toJSON() {
104
    public JSONObject toJSON() {
Line 108... Line 109...
108
        return json;
109
        return json;
109
    }
110
    }
110
 
111
 
111
    @Override
112
    @Override
112
    public void fromJSON(JSONObject json) {
113
    public void fromJSON(JSONObject json) {
113
        this.tableId = (String) JSONConverter.getParameterFromJSON(json, "table-id", String.class);
114
        this.tableId = JSONConverter.getParameterFromJSON(json, "table-id", String.class);
114
        final JSONArray jsonIds = (JSONArray) JSONConverter.getParameterFromJSON(json, "ids", JSONArray.class);
115
        final JSONArray jsonIds = JSONConverter.getParameterFromJSON(json, "ids", JSONArray.class);
115
        this.ids = new ArrayList<Long>();
116
        this.ids = new ArrayList<Number>();
116
        for (final Object jsonId : jsonIds) {
117
        for (final Object jsonId : jsonIds) {
117
            this.ids.add((Long) JSONConverter.getObjectFromJSON(jsonId, Long.class));
118
            this.ids.add(JSONConverter.getObjectFromJSON(jsonId, Number.class));
118
        }
119
        }
119
    }
120
    }
120
 
121
 
121
    public void setTableId(String id) {
122
    public void setTableId(String id) {
122
        this.tableId = id;
123
        this.tableId = id;