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;
|
2010-01-24 22:09:50 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
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;
|
|
|
|
|
2010-02-01 00:15:50 +01:00
|
|
|
import com.metaweb.gridlock.expr.HasFields;
|
|
|
|
|
|
|
|
public class Row implements Serializable, HasFields {
|
2010-01-25 23:51:25 +01:00
|
|
|
private static final long serialVersionUID = -689264211730915507L;
|
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
public boolean flagged;
|
|
|
|
public boolean starred;
|
|
|
|
public List<Cell> cells;
|
|
|
|
|
|
|
|
public Row(int cellCount) {
|
2010-01-25 23:51:25 +01:00
|
|
|
cells = new ArrayList<Cell>(cellCount);
|
|
|
|
}
|
|
|
|
|
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>(cells.size());
|
|
|
|
for (Cell cell : cells) {
|
2010-01-27 02:48:42 +01:00
|
|
|
a.add(cell.getJSON(options));
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
|
|
|
o.put("cells", a);
|
|
|
|
o.put("flagged", flagged);
|
|
|
|
o.put("starred", starred);
|
|
|
|
|
|
|
|
return o;
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|
2010-02-01 00:15:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
if ("flagged".equals(name)) {
|
|
|
|
return flagged;
|
|
|
|
} else if ("starred".equals(name)) {
|
|
|
|
return starred;
|
|
|
|
} else if ("cells".equals(name)) {
|
|
|
|
return new Cells();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Cells implements HasFields {
|
|
|
|
private Cells() {};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
Project project = (Project) bindings.get("project");
|
|
|
|
Column column = project.columnModel.getColumnByName(name);
|
|
|
|
if (column != null) {
|
|
|
|
return cells.get(column.cellIndex);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|