2010-02-03 21:55:48 +01:00
|
|
|
package com.metaweb.gridworks.model;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
|
|
|
|
|
|
|
public class ColumnGroup implements Serializable, Jsonizable {
|
|
|
|
private static final long serialVersionUID = 2161780779920066118L;
|
|
|
|
|
2010-02-05 02:27:14 +01:00
|
|
|
final public int startColumnIndex;
|
|
|
|
final public int columnSpan;
|
|
|
|
final public int keyColumnIndex; // could be -1 if there is no key cell
|
2010-02-03 21:55:48 +01:00
|
|
|
|
|
|
|
transient public ColumnGroup parentGroup;
|
|
|
|
transient public List<ColumnGroup> subgroups;
|
|
|
|
|
2010-02-05 02:27:14 +01:00
|
|
|
public ColumnGroup(int startColumnIndex, int columnSpan, int keyColumnIndex) {
|
|
|
|
this.startColumnIndex = startColumnIndex;
|
|
|
|
this.columnSpan = columnSpan;
|
|
|
|
this.keyColumnIndex = keyColumnIndex;
|
2010-02-03 21:55:48 +01:00
|
|
|
internalInitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
|
2010-02-05 02:27:14 +01:00
|
|
|
writer.key("startColumnIndex"); writer.value(startColumnIndex);
|
|
|
|
writer.key("columnSpan"); writer.value(columnSpan);
|
|
|
|
writer.key("keyColumnIndex"); writer.value(keyColumnIndex);
|
2010-02-03 21:55:48 +01:00
|
|
|
|
|
|
|
if (subgroups != null && subgroups.size() > 0) {
|
|
|
|
writer.key("subgroups"); writer.array();
|
|
|
|
for (ColumnGroup g : subgroups) {
|
|
|
|
g.write(writer, options);
|
|
|
|
}
|
|
|
|
writer.endArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.endObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean contains(ColumnGroup g) {
|
2010-02-05 02:27:14 +01:00
|
|
|
return (g.startColumnIndex >= startColumnIndex &&
|
|
|
|
g.startColumnIndex < startColumnIndex + columnSpan);
|
2010-02-03 21:55:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
|
|
|
in.defaultReadObject();
|
|
|
|
internalInitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void internalInitialize() {
|
|
|
|
subgroups = new LinkedList<ColumnGroup>();
|
|
|
|
}
|
|
|
|
}
|