2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks.model;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.Serializable;
|
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;
|
2010-02-01 20:16:09 +01:00
|
|
|
import org.json.JSONWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
2010-02-01 20:16:09 +01:00
|
|
|
|
|
|
|
public class ColumnModel implements Serializable, Jsonizable {
|
2010-01-25 23:51:25 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
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-02-01 20:16:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("columns");
|
|
|
|
writer.array();
|
|
|
|
for (Column column : columns) {
|
|
|
|
column.write(writer, options);
|
|
|
|
}
|
|
|
|
writer.endArray();
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|