Fixed bug in which editing a single cell and then starring the same row seemed to revert the cell back to its original content.

Added an option for not guessing cell value type during import.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@446 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-04-11 21:54:56 +00:00
parent 75ea8304a3
commit f7e830e709
14 changed files with 68 additions and 49 deletions

View File

@ -403,10 +403,6 @@ public class CreateProjectCommand extends Command {
InputStream rawInputStream,
String encoding
) throws Exception {
int limit = getIntegerOption("limit",options,-1);
int skip = getIntegerOption("skip",options,0);
if (importer.takesReader()) {
BufferedInputStream inputStream = new BufferedInputStream(rawInputStream);
@ -449,9 +445,9 @@ public class CreateProjectCommand extends Command {
new InputStreamReader(inputStream);
}
importer.read(reader, project, options, skip, limit);
importer.read(reader, project, options);
} else {
importer.read(rawInputStream, project, options, skip, limit);
importer.read(rawInputStream, project, options);
}
}
@ -461,11 +457,7 @@ public class CreateProjectCommand extends Command {
Properties options,
Reader reader
) throws Exception {
int limit = getIntegerOption("limit",options,-1);
int skip = getIntegerOption("skip",options,0);
importer.read(reader, project, options, skip, limit);
importer.read(reader, project, options);
}
protected Importer guessImporter(
@ -509,16 +501,4 @@ public class CreateProjectCommand extends Command {
return new TsvCsvImporter();
}
private int getIntegerOption(String name, Properties options, int def) {
int value = def;
if (options.containsKey(name)) {
String s = options.getProperty(name);
try {
value = Integer.parseInt(s);
} catch (Exception e) {
}
}
return value;
}
}

View File

@ -37,14 +37,13 @@ public class ExcelImporter implements Importer {
return false;
}
public void read(Reader reader, Project project, Properties options, int skip, int limit)
throws Exception {
public void read(Reader reader, Project project, Properties options) throws Exception {
throw new NotImplementedException();
}
public void read(InputStream inputStream, Project project,
Properties options, int skip, int limit) throws Exception {
public void read(InputStream inputStream, Project project, Properties options) throws Exception {
int limit = ImporterUtilities.getIntegerOption("limit",options,-1);
int skip = ImporterUtilities.getIntegerOption("skip",options,0);
Workbook wb = null;
try {

View File

@ -9,6 +9,6 @@ import com.metaweb.gridworks.model.Project;
public interface Importer {
public boolean takesReader();
public void read(Reader reader, Project project, Properties options, int skip, int limit) throws Exception;
public void read(InputStream inputStream, Project project, Properties options, int skip, int limit) throws Exception;
public void read(Reader reader, Project project, Properties options) throws Exception;
public void read(InputStream inputStream, Project project, Properties options) throws Exception;
}

View File

@ -1,6 +1,7 @@
package com.metaweb.gridworks.importers;
import java.io.Serializable;
import java.util.Properties;
public class ImporterUtilities {
@ -25,5 +26,29 @@ public class ImporterUtilities {
}
return text;
}
static public int getIntegerOption(String name, Properties options, int def) {
int value = def;
if (options.containsKey(name)) {
String s = options.getProperty(name);
try {
value = Integer.parseInt(s);
} catch (Exception e) {
}
}
return value;
}
static public boolean getBooleanOption(String name, Properties options, boolean def) {
boolean value = def;
if (options.containsKey(name)) {
String s = options.getProperty(name);
try {
value = Boolean.parseBoolean(s);
} catch (Exception e) {
}
}
return value;
}
}

View File

@ -20,9 +20,11 @@ import com.metaweb.gridworks.model.Row;
public class TsvCsvImporter implements Importer {
public void read(Reader reader, Project project, Properties options, int skip, int limit)
throws Exception {
public void read(Reader reader, Project project, Properties options) throws Exception {
int limit = ImporterUtilities.getIntegerOption("limit",options,-1);
int skip = ImporterUtilities.getIntegerOption("skip",options,0);
boolean guessValueType = ImporterUtilities.getBooleanOption("guess-value-type", options, true);
LineNumberReader lnReader = new LineNumberReader(reader);
String sep = options.getProperty("separator"); // auto-detect if not present
String line = null;
@ -76,7 +78,7 @@ public class TsvCsvImporter implements Importer {
} else {
Row row = new Row(cellCount);
if (parser.parseRow(row, line)) {
if (parser.parseRow(row, line, guessValueType)) {
rowsWithData++;
if (skip <= 0 || rowsWithData > skip) {
@ -92,9 +94,7 @@ public class TsvCsvImporter implements Importer {
}
}
public void read(InputStream inputStream, Project project,
Properties options, int skip, int limit) throws Exception {
public void read(InputStream inputStream, Project project, Properties options) throws Exception {
throw new NotImplementedException();
}

View File

@ -19,7 +19,7 @@ public class XmlImporter implements Importer {
return false;
}
public void read(Reader reader, Project project, Properties options, int skip, int limit)
public void read(Reader reader, Project project, Properties options)
throws Exception {
throw new NotImplementedException();
@ -28,9 +28,7 @@ public class XmlImporter implements Importer {
public void read(
InputStream inputStream,
Project project,
Properties options,
int skip,
int limit
Properties options
) throws Exception {
PushbackInputStream pis = new PushbackInputStream(inputStream,BUFFER_SIZE);

View File

@ -60,12 +60,12 @@ public class CSVRowParser extends RowParser {
return results;
}
public boolean parseRow(Row row, String line) {
public boolean parseRow(Row row, String line, boolean guessValueType) {
boolean hasData = false;
List<String> strings = split(line);
for (String s : strings) {
Serializable value = ImporterUtilities.parseCellValue(s);
Serializable value = guessValueType ? ImporterUtilities.parseCellValue(s) : s;
if (ExpressionUtils.isNonBlankData(value)) {
row.cells.add(new Cell(value, null));

View File

@ -7,5 +7,5 @@ import com.metaweb.gridworks.model.Row;
public abstract class RowParser {
public abstract List<String> split(String line);
public abstract boolean parseRow(Row row, String line);
public abstract boolean parseRow(Row row, String line, boolean guessValueType);
}

View File

@ -30,14 +30,14 @@ public class SeparatorRowParser extends RowParser {
return results;
}
public boolean parseRow(Row row, String line) {
public boolean parseRow(Row row, String line, boolean guessValueType) {
boolean hasData = false;
String[] cells = StringUtils.splitPreserveAllTokens(line, sep);
for (int c = 0; c < cells.length; c++) {
String text = cells[c];
Serializable value = ImporterUtilities.parseCellValue(text);
Serializable value = guessValueType ? ImporterUtilities.parseCellValue(text) : text;
if (ExpressionUtils.isNonBlankData(value)) {
row.cells.add(new Cell(value, null));
hasData = true;

View File

@ -1 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Freebase Gridworks</title> <link rel="stylesheet" href="/styles/common.css" /> <link rel="stylesheet" href="/styles/index.css" /> <script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script> <script type="text/javascript" src="externals/date.js"></script> <script type="text/javascript" src="scripts/util/string.js"></script> <script type="text/javascript" src="scripts/version.js"></script> <script type="text/javascript" src="scripts/index.js"></script> <script type="text/javascript" src="http://www.freebase.com/labs/gridworks.js"></script> </head> <body> <div id="header"> <a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a> <div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div> </div> <div id="body"> <div id="body-empty"> <table><tr> <td id="body-empty-logo-container"><img src="images/gridworks.png" /> Gridworks</td> <td id="body-empty-create-project-panel-container"></td> </tr></table> </div> <div id="body-nonempty"> <table><tr> <td id="body-nonempty-logo-container"><img src="images/gridworks.png" /> Gridworks</td> <td id="body-nonempty-projects-container"> <div id="projects"></div> </td> <td id="body-nonempty-create-project-panel-container"></td> </tr></table> </div> </div> <div id="footer"> <a href="about.html">About Freebase Gridworks</a> &bull; &copy; 2010 <a href="http://www.metaweb.com/">Metaweb Technologies, Inc.</a> </div> <div id="body-template"> <div id="create-project-panel"> <h1>Upload Data File</h1> <form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload" accept-charset="UTF-8"> <div class="grid-layout layout-tight"><table> <tr><td>Data File:</td><td> <input type="file" id="project-file-input" name="project-file" /> </td></tr> <tr><td>Project Name:</td><td> <input type="text" size="20" id="project-name-input" name="project-name" /> </td></tr> <tr><td>Load up to:</td><td> <input id="limit-input" name="limit" size="5" /> data rows (optional) </td></tr> <tr><td>Skip:</td><td> > </td></tr> > > > <tr><td>Data File:</td><td> </td></tr> > <input type="file" id="project-file-input" name="project-file" /> > </td></tr> </td></tr> </table></div> </form> <h1>Import Existing Project</h1> <form id="project-upload-form" method="post" enctype="multipart/form-data" action="/command/import-project" accept-charset="UTF-8"> <table id="import-project-panel-layout"> <tr><td>Project .tar or .tar.gz File:</td><td><input type="file" id="project-tar-file-input" name="project-file" /></td></tr> <tr><td>Re-name Project:</td><td><input type="text" size="20" id="project-name-input" name="project-name" /> (optional)</td></tr> <tr><td></td><td><input type="submit" value="Import Project" id="import-project-button" /></td></tr> </table> </form> </div> </div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Freebase Gridworks</title> <link rel="stylesheet" href="/styles/common.css" /> <link rel="stylesheet" href="/styles/index.css" /> <script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script> <script type="text/javascript" src="externals/date.js"></script> <script type="text/javascript" src="scripts/util/string.js"></script> <script type="text/javascript" src="scripts/version.js"></script> <script type="text/javascript" src="scripts/index.js"></script> <script type="text/javascript" src="http://www.freebase.com/labs/gridworks.js"></script> </head> <body> <div id="header"> <a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a> <div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div> </div> <div id="body"> <div id="body-empty"> <table><tr> <td id="body-empty-logo-container"><img src="images/gridworks.png" /> Gridworks</td> <td id="body-empty-create-project-panel-container"></td> </tr></table> </div> <div id="body-nonempty"> <table><tr> <td id="body-nonempty-logo-container"><img src="images/gridworks.png" /> Gridworks</td> <td id="body-nonempty-projects-container"> <div id="projects"></div> </td> <td id="body-nonempty-create-project-panel-container"></td> </tr></table> </div> </div> <div id="footer"> <a href="about.html">About Freebase Gridworks</a> &bull; &copy; 2010 <a href="http://www.metaweb.com/">Metaweb Technologies, Inc.</a> </div> <div id="body-template"> <div id="create-project-panel"> <h1>Upload Data File</h1> <form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload" accept-charset="UTF-8"> <div class="grid-layout layout-tight"><table <tr><td>Data File:</td><td> > <tr><td>Data File:</td><td> <tr><td>Data File:</td><td> <tr><td>Data File:</td><td> <input type="file" id="project-file-input" name="project-file" /> <tr><td>Data File:</td><td> </td></tr> <tr><td>Data File:</td><td> <tr><td>Project Name:</td><td> <tr><td>Data File:</td><td> <input type="text" size="20" id="project-name-input" name="project-name" /> <tr><td>Data File:</td><td> <tr><td>Load up to:</td><td> <tr><td>Data File:</td><td> <input id="limit-input" name="limit" size="5" /> data rows (optional) <tr><td>Data File:</td><td> <tr><td>Skip:</td><td> <input type="file" id="project-file-input" name="project-file" /> <input type="file" id="project-file-input" name="project-file" /> > <input type="file" id="project-file-input" name="project-file" /> <tr><td>Data File:</td><td> <input type="file" id="project-file-input" name="project-file" /> <input type="file" id="project-file-input" name="project-file" /> <input type="file" id="project-file-input" name="project-file" /> </td></tr> <tr><td></td><td><input type="submit" value="Create Project" id="upload-file-button" /></td></tr> </table></div> </form> <h1>Import Existing Project</h1> <form id="project-upload-form" method="post" enctype="multipart/form-data" action="/command/import-project" accept-charset="UTF-8"> <table class="import-project-panel-layout"> <tr><td>Project .tar or .tar.gz File:</td><td><input type="file" id="project-tar-file-input" name="project-file" /></td></tr> <tr><td>Re-name Project:</td><td><input type="text" size="20" id="project-name-input" name="project-name" /> (optional)</td></tr> <tr><td></td><td><input type="submit" value="Import Project" id="import-project-button" /></td></tr> </table> </form> </div> </div> </body> </html>

View File

@ -10,7 +10,8 @@ function onClickUploadFileButton(evt) {
"/command/create-project-from-upload?" + [
"skip=" + $("#skip-input")[0].value,
"limit=" + $("#limit-input")[0].value,
"separator=" + $("#separator-input")[0].value
"separator=" + $("#separator-input")[0].value,
"guess-value-type=" + $("#guess-value-type-input")[0].checked
].join("&"));
}
}

View File

@ -275,6 +275,7 @@ DataTableCellUI.prototype._postProcessOneCell = function(command, params, column
{
onDone: function(o) {
self._cell = o.cell;
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
self._render();
}
}
@ -412,6 +413,7 @@ DataTableCellUI.prototype._startEdit = function(elmt) {
{
onDone: function(o) {
self._cell = o.cell;
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
self._render();
}
}

View File

@ -388,6 +388,20 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
], elmt, { width: "80px", horizontal: false });
};
DataTableView.prototype._updateCell = function(rowIndex, cellIndex, cell) {
var rows = theProject.rowModel.rows;
for (var r = 0; r < rows.length; r++) {
var row = rows[r];
if (row.i === rowIndex) {
while (cellIndex >= row.cells.length) {
row.cells.push(null);
}
row.cells[cellIndex] = cell;
break;
}
}
};
DataTableView.sampleVisibleRows = function(column) {
var rowIndices = [];
var values = [];

View File

@ -43,7 +43,7 @@
margin: 2em 0 1em 0;
}
#import-project-panel-layout {
table.import-project-panel-layout {
white-space: pre;
}