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 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 156
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.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
 
19
import net.minidev.json.JSONObject;
24
import net.minidev.json.JSONObject;
20
 
25
 
21
public class TableSpec implements Transferable {
26
public class TableSpec implements Transferable, Externalizable {
22
    private String id;
27
    private String id;
23
    private ColumnsSpec columns;
28
    private ColumnsSpec columns;
24
    private TableContent content;
29
    private TableContent content;
25
    private RowSelectionSpec selection;
30
    private RowSelectionSpec selection;
26
    private SearchSpec search;
31
    private SearchSpec search;
27
    private Boolean variableColumnsCount = false;
32
    private Boolean variableColumnsCount = false;
28
 
33
 
-
 
34
    public TableSpec() {
-
 
35
        // Serialization
-
 
36
    }
-
 
37
 
29
    public TableSpec(final String tableId, final RowSelectionSpec selection, final ColumnsSpec columns) {
38
    public TableSpec(final String tableId, final RowSelectionSpec selection, final ColumnsSpec columns) {
30
        this.id = tableId + ".spec";
39
        this.id = tableId + ".spec";
31
        if (selection == null) {
40
        if (selection == null) {
32
            throw new IllegalArgumentException("null RowSelectionSpec");
41
            throw new IllegalArgumentException("null RowSelectionSpec");
33
        }
42
        }
34
        if (columns == null) {
43
        if (columns == null) {
35
            throw new IllegalArgumentException("null ColumnsSpec");
44
            throw new IllegalArgumentException("null ColumnsSpec");
36
        }
45
        }
37
        this.selection = selection;
46
        this.selection = selection;
38
        this.columns = columns;
47
        this.columns = columns;
39
        this.content = new TableContent(tableId);
48
        this.content = new TableContent(tableId);
40
    }
49
    }
41
 
50
 
42
    public TableSpec(final JSONObject json) {
51
    public TableSpec(final JSONObject json) {
43
        this.fromJSON(json);
52
        this.fromJSON(json);
44
    }
53
    }
45
 
54
 
46
    public String getId() {
55
    public String getId() {
47
        return this.id;
56
        return this.id;
48
    }
57
    }
49
 
58
 
50
    public void setId(final String id) {
59
    public void setId(final String id) {
51
        this.id = id;
60
        this.id = id;
52
    }
61
    }
53
 
62
 
54
    public ColumnsSpec getColumns() {
63
    public ColumnsSpec getColumns() {
55
        return this.columns;
64
        return this.columns;
56
    }
65
    }
57
 
66
 
58
    public void setColumns(final ColumnsSpec columns) {
67
    public void setColumns(final ColumnsSpec columns) {
59
        this.columns = columns;
68
        this.columns = columns;
60
    }
69
    }
61
 
70
 
62
    public TableContent getContent() {
71
    public TableContent getContent() {
63
        return this.content;
72
        return this.content;
64
    }
73
    }
65
 
74
 
66
    public void setContent(final TableContent content) {
75
    public void setContent(final TableContent content) {
67
        this.content = content;
76
        this.content = content;
68
    }
77
    }
69
 
78
 
70
    public RowSelectionSpec getSelection() {
79
    public RowSelectionSpec getSelection() {
71
        return this.selection;
80
        return this.selection;
72
    }
81
    }
73
 
82
 
74
    public void setSelection(final RowSelectionSpec selection) {
83
    public void setSelection(final RowSelectionSpec selection) {
75
        this.selection = selection;
84
        this.selection = selection;
76
    }
85
    }
77
 
86
 
78
    public SearchSpec getSearch() {
87
    public SearchSpec getSearch() {
79
        return this.search;
88
        return this.search;
80
    }
89
    }
81
 
90
 
82
    public void setSearch(final SearchSpec search) {
91
    public void setSearch(final SearchSpec search) {
83
        this.search = search;
92
        this.search = search;
84
    }
93
    }
85
 
94
 
86
    public Boolean isVariableColumnsCount() {
95
    public Boolean isVariableColumnsCount() {
87
        return this.variableColumnsCount;
96
        return this.variableColumnsCount;
88
    }
97
    }
89
 
98
 
90
    public void setVariableColumnsCount(final Boolean variableColumnsCount) {
99
    public void setVariableColumnsCount(final Boolean variableColumnsCount) {
91
        this.variableColumnsCount = variableColumnsCount;
100
        this.variableColumnsCount = variableColumnsCount;
92
    }
101
    }
93
 
102
 
94
    @Override
103
    @Override
95
    public JSONObject toJSON() {
104
    public JSONObject toJSON() {
96
        final JSONObject result = new JSONObject();
105
        final JSONObject result = new JSONObject();
97
        result.put("class", "TableSpec");
106
        result.put("class", "TableSpec");
98
        result.put("id", this.id);
107
        result.put("id", this.id);
99
        if (this.columns != null) {
108
        if (this.columns != null) {
100
            result.put("columns", JSONConverter.getJSON(this.columns));
109
            result.put("columns", JSONConverter.getJSON(this.columns));
101
        }
110
        }
102
        if (this.content != null) {
111
        if (this.content != null) {
103
            result.put("content", JSONConverter.getJSON(this.content));
112
            result.put("content", JSONConverter.getJSON(this.content));
104
        }
113
        }
105
        if (this.selection != null) {
114
        if (this.selection != null) {
106
            result.put("selection", JSONConverter.getJSON(this.selection));
115
            result.put("selection", JSONConverter.getJSON(this.selection));
107
        }
116
        }
108
        if (this.search != null) {
117
        if (this.search != null) {
109
            result.put("search", JSONConverter.getJSON(this.search));
118
            result.put("search", JSONConverter.getJSON(this.search));
110
        }
119
        }
111
        if (this.variableColumnsCount) {
120
        if (this.variableColumnsCount) {
112
            result.put("variable-columns-count", JSONConverter.getJSON(true));
121
            result.put("variable-columns-count", JSONConverter.getJSON(true));
113
        }
122
        }
114
 
123
 
115
        return result;
124
        return result;
116
    }
125
    }
117
 
126
 
118
    @Override
127
    @Override
119
    public void fromJSON(final JSONObject json) {
128
    public void fromJSON(final JSONObject json) {
120
        this.id = (String) JSONConverter.getParameterFromJSON(json, "id", String.class);
129
        this.id = (String) JSONConverter.getParameterFromJSON(json, "id", String.class);
121
 
130
 
122
        final JSONObject jsonColumns = (JSONObject) JSONConverter.getParameterFromJSON(json, "columns", JSONObject.class);
131
        final JSONObject jsonColumns = (JSONObject) JSONConverter.getParameterFromJSON(json, "columns", JSONObject.class);
123
        if (jsonColumns != null) {
132
        if (jsonColumns != null) {
124
            this.columns = new ColumnsSpec(jsonColumns);
133
            this.columns = new ColumnsSpec(jsonColumns);
125
        }
134
        }
126
 
135
 
127
        final JSONObject jsonContent = (JSONObject) JSONConverter.getParameterFromJSON(json, "content", JSONObject.class);
136
        final JSONObject jsonContent = (JSONObject) JSONConverter.getParameterFromJSON(json, "content", JSONObject.class);
128
        if (jsonContent != null) {
137
        if (jsonContent != null) {
129
            this.content = new TableContent(jsonContent);
138
            this.content = new TableContent(jsonContent);
130
        }
139
        }
131
        final JSONObject jsonSelection = (JSONObject) JSONConverter.getParameterFromJSON(json, "selection", JSONObject.class);
140
        final JSONObject jsonSelection = (JSONObject) JSONConverter.getParameterFromJSON(json, "selection", JSONObject.class);
132
        if (jsonSelection != null) {
141
        if (jsonSelection != null) {
133
            this.selection = new RowSelectionSpec(jsonSelection);
142
            this.selection = new RowSelectionSpec(jsonSelection);
134
        } else {
143
        } else {
135
            throw new IllegalArgumentException("null selection");
144
            throw new IllegalArgumentException("null selection");
136
        }
145
        }
137
 
146
 
138
        final JSONObject jsonSearch = (JSONObject) JSONConverter.getParameterFromJSON(json, "search", JSONObject.class);
147
        final JSONObject jsonSearch = (JSONObject) JSONConverter.getParameterFromJSON(json, "search", JSONObject.class);
139
        if (jsonSearch != null) {
148
        if (jsonSearch != null) {
140
            this.search = new SearchSpec(jsonSearch);
149
            this.search = new SearchSpec(jsonSearch);
141
        }
150
        }
142
 
151
 
143
        this.variableColumnsCount = (Boolean) JSONConverter.getParameterFromJSON(json, "variable-columns-count", Boolean.class);
152
        this.variableColumnsCount = (Boolean) JSONConverter.getParameterFromJSON(json, "variable-columns-count", Boolean.class);
144
    }
153
    }
-
 
154
 
-
 
155
    @Override
-
 
156
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
157
        out.writeUTF(id);
-
 
158
        this.columns.writeExternal(out);
-
 
159
        this.content.writeExternal(out);
-
 
160
 
-
 
161
        this.selection.writeExternal(out);
-
 
162
        this.search.writeExternal(out);
-
 
163
 
-
 
164
        out.writeBoolean(this.variableColumnsCount);
-
 
165
 
-
 
166
    }
-
 
167
 
-
 
168
    @Override
-
 
169
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
170
        this.id = in.readUTF();
-
 
171
        this.columns = new ColumnsSpec();
-
 
172
        this.columns.readExternal(in);
-
 
173
        this.content = new TableContent();
-
 
174
        this.content.readExternal(in);
-
 
175
        this.selection = new RowSelectionSpec();
-
 
176
        this.selection.readExternal(in);
-
 
177
        this.search = new SearchSpec();
-
 
178
        this.search.readExternal(in);
-
 
179
        this.variableColumnsCount = in.readBoolean();
-
 
180
    }
-
 
181
 
145
}
182
}