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.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-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
|
|
|
import com.metaweb.gridworks.expr.HasFields;
|
2010-02-01 00:15:50 +01:00
|
|
|
|
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;
|
2010-02-03 22:57:38 +01:00
|
|
|
final public List<Cell> cells;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-02-03 21:55:48 +01:00
|
|
|
transient public List<Integer> contextRows;
|
|
|
|
transient public List<Integer> contextCells;
|
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-05 00:38:40 +01:00
|
|
|
public void setCell(int cellIndex, Cell cell) {
|
|
|
|
if (cellIndex < cells.size()) {
|
|
|
|
cells.set(cellIndex, cell);
|
|
|
|
} else {
|
|
|
|
while (cellIndex > cells.size()) {
|
|
|
|
cells.add(null);
|
|
|
|
}
|
|
|
|
cells.add(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:15:50 +01:00
|
|
|
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) {
|
2010-02-03 22:57:38 +01:00
|
|
|
return cells.get(column.getCellIndex());
|
2010-02-01 00:15:50 +01:00
|
|
|
}
|
|
|
|
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) {
|
2010-02-05 00:38:40 +01:00
|
|
|
if (cell != null) {
|
|
|
|
cell.write(writer, options);
|
|
|
|
} else {
|
|
|
|
writer.value(null);
|
|
|
|
}
|
2010-02-01 20:16:09 +01:00
|
|
|
}
|
|
|
|
writer.endArray();
|
|
|
|
|
|
|
|
if (options.containsKey("rowIndex")) {
|
|
|
|
writer.key("i"); writer.value(options.get("rowIndex"));
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|