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;
|
2010-02-01 20:16:09 +01:00
|
|
|
import org.json.JSONWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-01 20:16:09 +01:00
|
|
|
import com.metaweb.gridlock.Jsonizable;
|
2010-02-01 00:15:50 +01:00
|
|
|
import com.metaweb.gridlock.expr.HasFields;
|
|
|
|
|
2010-02-01 20:16:09 +01:00
|
|
|
public class Row implements Serializable, HasFields, Jsonizable {
|
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-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-02-01 20:16:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("flagged"); writer.value(flagged);
|
|
|
|
writer.key("starred"); writer.value(starred);
|
|
|
|
|
|
|
|
writer.key("cells"); writer.array();
|
|
|
|
for (Cell cell : cells) {
|
|
|
|
cell.write(writer, options);
|
|
|
|
}
|
|
|
|
writer.endArray();
|
|
|
|
|
|
|
|
if (options.containsKey("rowIndex")) {
|
|
|
|
writer.key("i"); writer.value(options.get("rowIndex"));
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|