Refactored to use JSONWriter to be more efficient at generating output.

Added created and modified time fields to project metadata.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@18 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-01 19:16:09 +00:00
parent 17cbe6b62d
commit fe8810aa07
30 changed files with 309 additions and 246 deletions

View File

@ -0,0 +1,10 @@
package com.metaweb.gridlock;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
public interface Jsonizable {
public void write(JSONWriter writer, Properties options) throws JSONException;
}

View File

@ -1,21 +1,31 @@
package com.metaweb.gridlock;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
public class ProjectMetadata implements Serializable {
public class ProjectMetadata implements Serializable, Jsonizable {
private static final long serialVersionUID = 7959027046468240844L;
public String name;
public String password;
public Date created = new Date();
public Date modified = new Date();
public JSONObject getJSON() throws JSONException {
JSONObject o = new JSONObject();
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("name", name);
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
return o;
writer.object();
writer.key("name"); writer.value(name);
writer.key("created"); writer.value(sdf.format(created));
writer.key("modified"); writer.value(sdf.format(modified));
writer.endObject();
}
}

View File

@ -3,9 +3,11 @@ package com.metaweb.gridlock.browsing;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
public class DecoratedValue {
import com.metaweb.gridlock.Jsonizable;
public class DecoratedValue implements Jsonizable {
final public Object value;
final public String label;
@ -14,12 +16,12 @@ public class DecoratedValue {
this.label = label;
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
o.put("v", value);
o.put("l", label);
return o;
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("v"); writer.value(value);
writer.key("l"); writer.value(label);
writer.endObject();
}
}

View File

@ -1,6 +1,5 @@
package com.metaweb.gridlock.browsing;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@ -8,13 +7,15 @@ import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.browsing.facets.Facet;
import com.metaweb.gridlock.browsing.facets.ListFacet;
import com.metaweb.gridlock.browsing.filters.RowFilter;
import com.metaweb.gridlock.model.Project;
public class Engine {
public class Engine implements Jsonizable {
protected Project _project;
protected List<Facet> _facets = new LinkedList<Facet>();
@ -39,18 +40,6 @@ public class Engine {
return cfr;
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
List<JSONObject> a = new ArrayList<JSONObject>(_facets.size());
for (Facet facet : _facets) {
a.add(facet.getJSON(options));
}
o.put("facets", a);
return o;
}
public void initializeFromJSON(JSONObject o) throws Exception {
JSONArray a = o.getJSONArray("facets");
int length = a.length();
@ -78,4 +67,17 @@ public class Engine {
facet.computeChoices(_project, filteredRows);
}
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("facets"); writer.array();
for (Facet facet : _facets) {
facet.write(writer, options);
}
writer.endArray();
writer.endObject();
}
}

View File

@ -1,20 +1,16 @@
package com.metaweb.gridlock.browsing.facets;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.browsing.FilteredRows;
import com.metaweb.gridlock.browsing.filters.RowFilter;
import com.metaweb.gridlock.model.Project;
public interface Facet {
public interface Facet extends Jsonizable {
public RowFilter getRowFilter();
public void computeChoices(Project project, FilteredRows filteredRows);
public JSONObject getJSON(Properties options) throws JSONException;
public void initializeFromJSON(JSONObject o) throws Exception;
}

View File

@ -1,6 +1,5 @@
package com.metaweb.gridlock.browsing.facets;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@ -8,6 +7,7 @@ import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.browsing.DecoratedValue;
import com.metaweb.gridlock.browsing.FilteredRows;
@ -30,20 +30,20 @@ public class ListFacet implements Facet {
}
@Override
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("name", _name);
o.put("expression", _expression);
o.put("cellIndex", _cellIndex);
writer.object();
writer.key("name"); writer.value(_name);
writer.key("expression"); writer.value(_expression);
writer.key("cellIndex"); writer.value(_cellIndex);
List<JSONObject> a = new ArrayList<JSONObject>(_choices.size());
writer.key("choices"); writer.array();
for (NominalFacetChoice choice : _choices) {
a.add(choice.getJSON(options));
choice.write(writer, options);
}
o.put("choices", a);
return o;
writer.endArray();
writer.endObject();
}
@Override

View File

@ -3,11 +3,12 @@ package com.metaweb.gridlock.browsing.facets;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.browsing.DecoratedValue;
public class NominalFacetChoice {
public class NominalFacetChoice implements Jsonizable {
final public DecoratedValue decoratedValue;
public int count;
public boolean selected;
@ -16,13 +17,13 @@ public class NominalFacetChoice {
this.decoratedValue = decoratedValue;
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
o.put("v", decoratedValue.getJSON(options));
o.put("c", count);
o.put("s", selected);
return o;
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("v"); decoratedValue.write(writer, options);
writer.key("c"); writer.value(count);
writer.key("s"); writer.value(selected);
writer.endObject();
}
}

View File

@ -18,7 +18,9 @@ import org.apache.commons.lang.NotImplementedException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.ProjectManager;
import com.metaweb.gridlock.browsing.Engine;
import com.metaweb.gridlock.model.Project;
@ -70,9 +72,16 @@ public abstract class Command {
}
}
protected void respondJSON(HttpServletResponse response, JSONObject o) throws IOException {
protected void respondJSON(HttpServletResponse response, Jsonizable o) throws IOException, JSONException {
respondJSON(response, o, new Properties());
}
protected void respondJSON(HttpServletResponse response, Jsonizable o, Properties options) throws IOException, JSONException {
response.setHeader("Content-Type", "application/json");
respond(response, o.toString());
JSONWriter writer = new JSONWriter(response.getWriter());
o.write(writer, options);
}
protected void respondException(HttpServletResponse response, Exception e) throws IOException {
@ -89,7 +98,8 @@ public abstract class Command {
o.put("stack", sw.toString());
respondJSON(response, o);
response.setHeader("Content-Type", "application/json");
respond(response, o.toString());
} catch (JSONException e1) {
e.printStackTrace(response.getWriter());
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridlock.commands;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -21,8 +20,7 @@ public class ComputeFacetsCommand extends Command {
engine.computeFacets();
Properties options = new Properties();
respondJSON(response, engine.getJSON(options));
respondJSON(response, engine);
} catch (Exception e) {
respondException(response, e);
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridlock.commands;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -17,10 +16,9 @@ public class GetColumnModelCommand extends Command {
throws ServletException, IOException {
Project project = getProject(request);
Properties options = new Properties();
try {
respondJSON(response, project.columnModel.getJSON(options));
respondJSON(response, project.columnModel);
} catch (JSONException e) {
respondException(response, e);
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridlock.commands;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -17,10 +16,8 @@ public class GetHistoryCommand extends Command {
throws ServletException, IOException {
Project project = getProject(request);
Properties options = new Properties();
try {
respondJSON(response, project.history.getJSON(options));
respondJSON(response, project.history);
} catch (JSONException e) {
respondException(response, e);
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridlock.commands;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -19,9 +18,7 @@ public class GetProcessesCommand extends Command {
Project project = getProject(request);
try {
Properties options = new Properties();
respondJSON(response, project.processManager.getJSON(options));
respondJSON(response, project.processManager);
} catch (JSONException e) {
respondException(response, e);
}

View File

@ -19,7 +19,7 @@ public class GetProjectMetadataCommand extends Command {
Project project = getProject(request);
try {
respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id).getJSON());
respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id));
} catch (JSONException e) {
respondException(response, e);
}

View File

@ -1,8 +1,6 @@
package com.metaweb.gridlock.commands;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletException;
@ -10,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.browsing.Engine;
import com.metaweb.gridlock.browsing.FilteredRows;
@ -31,17 +29,18 @@ public class GetRowsCommand extends Command {
int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
Properties options = new Properties();
JSONObject o = new JSONObject();
response.setHeader("Content-Type", "application/json");
List<JSONObject> a = new ArrayList<JSONObject>(limit);
try {
FilteredRows filteredRows = engine.getAllFilteredRows();
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
{
RowAccumulator acc = new RowAccumulator(start, limit) {
List<JSONObject> list;
JSONWriter writer;
Properties options;
public RowAccumulator init(List<JSONObject> list, Properties options) {
this.list = list;
public RowAccumulator init(JSONWriter writer, Properties options) {
this.writer = writer;
this.options = options;
return this;
}
@ -49,27 +48,28 @@ public class GetRowsCommand extends Command {
@Override
public boolean internalVisit(int rowIndex, Row row) {
try {
JSONObject ro = row.getJSON(options);
ro.put("i", rowIndex);
list.add(ro);
options.put("rowIndex", rowIndex);
row.write(writer, options);
} catch (JSONException e) {
}
return false;
}
}.init(a, options);
}.init(writer, options);
FilteredRows filteredRows = engine.getAllFilteredRows();
writer.key("rows"); writer.array();
filteredRows.accept(project, acc);
writer.endArray();
o.put("filtered", acc.total);
} catch (JSONException e) {
respondException(response, e);
writer.key("filtered"); writer.value(acc.total);
}
o.put("start", start);
o.put("limit", limit);
o.put("rows", a);
o.put("total", project.rows.size());
respondJSON(response, o);
writer.key("start"); writer.value(start);
writer.key("limit"); writer.value(limit);
writer.key("total"); writer.value(project.rows.size());
writer.endObject();
} catch (Exception e) {
respondException(response, e);
}

View File

@ -2,8 +2,6 @@ package com.metaweb.gridlock.expr;
import java.util.Properties;
import org.json.JSONObject;
public class VariableExpr implements Evaluable {
final protected String _name;

View File

@ -2,16 +2,18 @@ package com.metaweb.gridlock.history;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.ProjectManager;
import com.metaweb.gridlock.model.Project;
public class History implements Serializable {
public class History implements Serializable, Jsonizable {
private static final long serialVersionUID = -1529783362243627391L;
protected long _projectID;
@ -31,7 +33,13 @@ public class History implements Serializable {
_futureEntries.clear();
_pastEntries.add(entry);
entry.apply(ProjectManager.singleton.getProject(_projectID));
setModified();
}
protected void setModified() {
ProjectManager.singleton.getProjectMetadata(_projectID).modified = new Date();
}
public List<HistoryEntry> getLastPastEntries(int count) {
@ -84,6 +92,7 @@ public class History implements Serializable {
_futureEntries.add(0, entry);
}
setModified();
}
protected void redo(int times) {
@ -97,23 +106,27 @@ public class History implements Serializable {
_pastEntries.add(entry);
}
setModified();
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
List<JSONObject> a = new ArrayList<JSONObject>(_pastEntries.size());
writer.object();
writer.key("past"); writer.array();
for (HistoryEntry entry : _pastEntries) {
a.add(entry.getJSON(options));
entry.write(writer, options);
}
o.put("past", a);
writer.endArray();
List<JSONObject> b = new ArrayList<JSONObject>(_futureEntries.size());
writer.key("future"); writer.array();
for (HistoryEntry entry : _futureEntries) {
b.add(entry.getJSON(options));
entry.write(writer, options);
}
o.put("future", b);
writer.endArray();
return o;
writer.endObject();
}
}

View File

@ -12,12 +12,13 @@ import java.util.Date;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.ProjectManager;
import com.metaweb.gridlock.model.Project;
public class HistoryEntry implements Serializable {
public class HistoryEntry implements Serializable, Jsonizable {
private static final long serialVersionUID = 532766467813930262L;
public long id;
@ -38,16 +39,17 @@ public class HistoryEntry implements Serializable {
saveChange();
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
o.put("id", id);
o.put("description", description);
o.put("time", sdf.format(time));
return o;
writer.object();
writer.key("id"); writer.value(id);
writer.key("description"); writer.value(description);
writer.key("time"); writer.value(sdf.format(time));
writer.endObject();
}
public void apply(Project project) {

View File

@ -3,7 +3,7 @@ package com.metaweb.gridlock.history;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.model.Project;
import com.metaweb.gridlock.process.Process;
@ -49,14 +49,14 @@ public class HistoryProcess extends Process {
}
@Override
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("description", _description);
o.put("immediate", true);
o.put("status", _done ? "done" : "pending");
return o;
writer.object();
writer.key("description"); writer.value(_description);
writer.key("immediate"); writer.value(true);
writer.key("status"); writer.value(_done ? "done" : "pending");
writer.endObject();
}
@Override

View File

@ -1,6 +1,5 @@
package com.metaweb.gridlock.history;
import java.util.ArrayList;
import java.util.List;
import com.metaweb.gridlock.model.Project;

View File

@ -4,27 +4,17 @@ import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.expr.HasFields;
public class Cell implements Serializable, HasFields {
public class Cell implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = -5891067829205458102L;
public Object value;
public Recon recon;
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
o.put("v", value);
if (recon != null && options.containsKey("cell-recon")) {
o.put("recon", recon.getJSON(options));
}
return o;
}
@Override
public Object getField(String name, Properties bindings) {
if ("value".equals(name)) {
@ -34,4 +24,17 @@ public class Cell implements Serializable, HasFields {
}
return null;
}
@Override
public void write(JSONWriter writer, Properties options) throws JSONException {
writer.object();
writer.key("v");
writer.value(value);
if (recon != null && options.containsKey("cell-recon")) {
writer.key("recon");
recon.write(writer, options);
}
writer.endObject();
}
}

View File

@ -4,22 +4,25 @@ import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
public class Column implements Serializable {
import com.metaweb.gridlock.Jsonizable;
public class Column implements Serializable, Jsonizable {
private static final long serialVersionUID = -1063342490951563563L;
public int cellIndex;
public String headerLabel;
public Class valueType;
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("cellIndex", cellIndex);
o.put("headerLabel", headerLabel);
o.put("valueType", valueType == null ? null : valueType.getSimpleName());
return o;
writer.object();
writer.key("cellIndex"); writer.value(cellIndex);
writer.key("headerLabel"); writer.value(headerLabel);
writer.key("valueType"); writer.value(valueType == null ? null : valueType.getSimpleName());
writer.endObject();
}
}

View File

@ -1,34 +1,23 @@
package com.metaweb.gridlock.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
public class ColumnModel implements Serializable {
import com.metaweb.gridlock.Jsonizable;
public class ColumnModel implements Serializable, Jsonizable {
private static final long serialVersionUID = 7679639795211544511L;
public List<Column> columns = new LinkedList<Column>();
transient protected Map<String, Column> _nameToColumn;
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
List<JSONObject> a = new ArrayList<JSONObject>(columns.size());
for (Column column : columns) {
a.add(column.getJSON(options));
}
o.put("columns", a);
return o;
}
public Column getColumnByName(String name) {
if (_nameToColumn == null) {
for (Column column : columns) {
@ -46,4 +35,18 @@ public class ColumnModel implements Serializable {
}
return null;
}
@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();
}
}

View File

@ -8,11 +8,12 @@ import java.util.Map;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.expr.HasFields;
public class Recon implements Serializable, HasFields {
public class Recon implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = 8906257833709315762L;
static public enum Judgment {
@ -26,13 +27,6 @@ public class Recon implements Serializable, HasFields {
public Judgment judgment = Judgment.None;
public ReconCandidate match = null;
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
o.put("j", judgmentToString());
return o;
}
@Override
public Object getField(String name, Properties bindings) {
if ("best".equals(name)) {
@ -65,4 +59,14 @@ public class Recon implements Serializable, HasFields {
return features.get(name);
}
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("j");
writer.value(judgmentToString());
writer.endObject();
}
}

View File

@ -4,11 +4,12 @@ import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.expr.HasFields;
public class ReconCandidate implements Serializable, HasFields {
public class ReconCandidate implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = -8013997214978715606L;
public String topicID;
@ -17,18 +18,6 @@ public class ReconCandidate implements Serializable, HasFields {
public String[] typeIDs;
public double score;
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
o.put("id", topicID);
o.put("guid", topicGUID);
o.put("name", topicName);
o.put("types", typeIDs);
o.put("score", score);
return o;
}
@Override
public Object getField(String name, Properties bindings) {
if ("id".equals(name)) {
@ -44,4 +33,23 @@ public class ReconCandidate implements Serializable, HasFields {
}
return null;
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("id"); writer.value(topicID);
writer.key("guid"); writer.value(topicGUID);
writer.key("name"); writer.value(topicName);
writer.key("score"); writer.value(score);
writer.key("types"); writer.array();
for (String typeID : typeIDs) {
writer.value(typeID);
}
writer.endArray();
writer.endObject();
}
}

View File

@ -6,11 +6,12 @@ import java.util.List;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.Jsonizable;
import com.metaweb.gridlock.expr.HasFields;
public class Row implements Serializable, HasFields {
public class Row implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = -689264211730915507L;
public boolean flagged;
@ -21,20 +22,6 @@ public class Row implements Serializable, HasFields {
cells = new ArrayList<Cell>(cellCount);
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
List<JSONObject> a = new ArrayList<JSONObject>(cells.size());
for (Cell cell : cells) {
a.add(cell.getJSON(options));
}
o.put("cells", a);
o.put("flagged", flagged);
o.put("starred", starred);
return o;
}
@Override
public Object getField(String name, Properties bindings) {
if ("flagged".equals(name)) {
@ -61,4 +48,25 @@ public class Row implements Serializable, HasFields {
}
}
@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();
}
}

View File

@ -3,7 +3,7 @@ package com.metaweb.gridlock.process;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
abstract public class LongRunningProcess extends Process {
final protected String _description;
@ -25,16 +25,15 @@ abstract public class LongRunningProcess extends Process {
}
@Override
public
JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("description", _description);
o.put("immediate", false);
o.put("status", _thread == null ? "pending" : (_thread.isAlive() ? "running" : "done"));
o.put("progress", _progress);
return o;
writer.object();
writer.key("description"); writer.value(_description);
writer.key("immediate"); writer.value(false);
writer.key("status"); writer.value(_thread == null ? "pending" : (_thread.isAlive() ? "running" : "done"));
writer.key("progress"); writer.value(_progress);
writer.endObject();
}
@Override

View File

@ -1,11 +1,8 @@
package com.metaweb.gridlock.process;
import java.util.Properties;
import com.metaweb.gridlock.Jsonizable;
import org.json.JSONException;
import org.json.JSONObject;
public abstract class Process {
public abstract class Process implements Jsonizable {
abstract public boolean isImmediate();
abstract public boolean isRunning();
@ -15,6 +12,4 @@ public abstract class Process {
abstract public void startPerforming(ProcessManager manager);
abstract public void cancel();
public abstract JSONObject getJSON(Properties options) throws JSONException;
}

View File

@ -1,30 +1,34 @@
package com.metaweb.gridlock.process;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
public class ProcessManager {
import com.metaweb.gridlock.Jsonizable;
public class ProcessManager implements Jsonizable {
protected List<Process> _processes = new LinkedList<Process>();
public ProcessManager() {
}
public JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
List<JSONObject> a = new ArrayList<JSONObject>(_processes.size());
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("processes"); writer.array();
for (Process p : _processes) {
a.add(p.getJSON(options));
p.write(writer, options);
}
o.put("processes", a);
writer.endArray();
return o;
writer.endObject();
}
public boolean queueProcess(Process process) {

View File

@ -3,7 +3,7 @@ package com.metaweb.gridlock.process;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridlock.history.HistoryEntry;
import com.metaweb.gridlock.model.Project;
@ -45,17 +45,17 @@ public class QuickHistoryEntryProcess extends Process {
}
@Override
public
JSONObject getJSON(Properties options) throws JSONException {
JSONObject o = new JSONObject();
public void write(JSONWriter writer, Properties options)
throws JSONException {
o.put("description", _historyEntry.description);
o.put("immediate", true);
o.put("status", _done ? "done" : "pending");
return o;
writer.object();
writer.key("description"); writer.value(_historyEntry.description);
writer.key("immediate"); writer.value(true);
writer.key("status"); writer.value(_done ? "done" : "pending");
writer.endObject();
}
@Override
public boolean isDone() {
return _done;

View File

@ -25,7 +25,7 @@
.history-past {
padding-bottom: 3px;
border-bottom: 2px solid #aaa;
border-bottom: 2px solid #f88;
}
.history-future {
padding-top: 3px;
@ -33,9 +33,12 @@
a.history-entry {
display: block;
padding: 3px 5px;
border-bottom: 1px solid #eee;
text-decoration: none;
color: black;
border-top: 1px solid #eee;
}
a.history-entry:first-child {
border-top: none;
}
a.history-entry:hover {
background: #eee;