Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.ui.light;
import org.openconcerto.utils.io.Transferable;
import java.util.ArrayList;
import java.util.List;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
public class TableSearchParameter implements Transferable {
private String id;
private String label;
private List<TableSearchParameterType> types = new ArrayList<>();
public TableSearchParameter() {
// For serialization
}
public String getId() {
return this.id;
}
public String getLabel() {
return this.label;
}
public List<TableSearchParameterType> getTypes() {
return this.types;
}
public TableSearchParameter(String id, String label) {
this.id = id;
this.label = label;
}
public void add(TableSearchParameterType type) {
this.types.add(type);
}
public void remove(TableSearchParameterType type) {
this.types.remove(type);
}
@Override
public JSONObject toJSON() {
if (this.id == null) {
throw new IllegalStateException("null id");
}
if (this.label == null) {
throw new IllegalStateException("null label");
}
final JSONObject obj = new JSONObject();
obj.put("id", this.id);
obj.put("label", this.label);
if (!this.types.isEmpty()) {
final JSONArray array = new JSONArray();
for (TableSearchParameterType type : this.types) {
array.add(type.toJSON());
}
obj.put("types", array);
}
return obj;
}
@Override
public void fromJSON(JSONObject json) {
this.id = json.getAsString("id");
this.label = json.getAsString("label");
if (this.id == null) {
throw new IllegalStateException("null id");
}
if (this.label == null) {
throw new IllegalStateException("null label");
}
this.types.clear();
if (json.containsKey("types")) {
final JSONArray array = (JSONArray) json.get("types");
for (Object object : array) {
final TableSearchParameterType t = new TableSearchParameterType();
t.fromJSON(((JSONObject) object));
this.types.add(t);
}
}
}
}