2010-01-24 22:09:50 +01:00
|
|
|
package com.metaweb.gridlock.model;
|
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.ArrayList;
|
2010-01-24 22:09:50 +01:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2010-02-01 00:15:50 +01:00
|
|
|
import java.util.Map;
|
2010-01-27 02:48:42 +01:00
|
|
|
import java.util.Properties;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
public class ColumnModel implements Serializable {
|
|
|
|
private static final long serialVersionUID = 7679639795211544511L;
|
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
public List<Column> columns = new LinkedList<Column>();
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-01 00:15:50 +01:00
|
|
|
transient protected Map<String, Column> _nameToColumn;
|
|
|
|
|
2010-01-27 02:48:42 +01:00
|
|
|
public JSONObject getJSON(Properties options) throws JSONException {
|
2010-01-25 23:51:25 +01:00
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
|
|
|
|
List<JSONObject> a = new ArrayList<JSONObject>(columns.size());
|
|
|
|
for (Column column : columns) {
|
2010-01-27 02:48:42 +01:00
|
|
|
a.add(column.getJSON(options));
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
|
|
|
o.put("columns", a);
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
2010-02-01 00:15:50 +01:00
|
|
|
|
|
|
|
public Column getColumnByName(String name) {
|
|
|
|
if (_nameToColumn == null) {
|
|
|
|
for (Column column : columns) {
|
|
|
|
_nameToColumn.put(column.headerLabel, column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _nameToColumn.get(name);
|
|
|
|
}
|
2010-02-01 04:22:35 +01:00
|
|
|
|
|
|
|
public Column getColumnByCellIndex(int cellIndex) {
|
|
|
|
for (Column column : columns) {
|
|
|
|
if (column.cellIndex == cellIndex) {
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|