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