Also let user decide what to do on expression evaluation error when creating a new column.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@182 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-04 00:32:54 +00:00
parent c07431fb88
commit eaef7b2394
5 changed files with 42 additions and 11 deletions

View File

@ -8,6 +8,7 @@ import com.metaweb.gridworks.commands.EngineDependentCommand;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.operations.ColumnAdditionOperation;
import com.metaweb.gridworks.operations.TextTransformOperation;
public class AddColumnCommand extends EngineDependentCommand {
@Override
@ -18,11 +19,13 @@ public class AddColumnCommand extends EngineDependentCommand {
String expression = request.getParameter("expression");
String headerLabel = request.getParameter("headerLabel");
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
String onError = request.getParameter("onError");
return new ColumnAdditionOperation(
engineConfig,
baseColumnName,
expression,
TextTransformOperation.stringToOnError(onError),
headerLabel,
columnInsertIndex
);

View File

@ -27,8 +27,9 @@ import com.metaweb.gridworks.model.changes.ColumnAdditionChange;
public class ColumnAdditionOperation extends EngineDependentOperation {
private static final long serialVersionUID = -5672677479629932356L;
final protected String _baseColumnName;
final protected String _baseColumnName;
final protected String _expression;
final protected OnError _onError;
final protected String _headerLabel;
final protected int _columnInsertIndex;
@ -40,6 +41,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
engineConfig,
obj.getString("baseColumnName"),
obj.getString("expression"),
TextTransformOperation.stringToOnError(obj.getString("onError")),
obj.getString("headerLabel"),
obj.getInt("columnInsertIndex")
);
@ -47,15 +49,17 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
public ColumnAdditionOperation(
JSONObject engineConfig,
String baseColumnName,
String baseColumnName,
String expression,
OnError onError,
String headerLabel,
int columnInsertIndex
int columnInsertIndex
) {
super(engineConfig);
_baseColumnName = baseColumnName;
_expression = expression;
_onError = onError;
_headerLabel = headerLabel;
_columnInsertIndex = columnInsertIndex;
@ -72,6 +76,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
writer.key("columnInsertIndex"); writer.value(_columnInsertIndex);
writer.key("baseColumnName"); writer.value(_baseColumnName);
writer.key("expression"); writer.value(_expression);
writer.key("onError"); writer.value(TextTransformOperation.onErrorToString(_onError));
writer.endObject();
}
@ -136,7 +141,15 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object v = eval.evaluate(bindings);
if (ExpressionUtils.isNonBlankData(v)) {
if (ExpressionUtils.isError(v)) {
if (_onError == OnError.SetToBlank) {
return false;
} else if (_onError == OnError.KeepOriginal) {
v = cell != null ? cell.value : null;
}
}
if (v != null) {
Cell newCell = new Cell(v, null);
cellsAtRows.add(new CellAtRow(rowIndex, newCell));

View File

@ -0,0 +1,10 @@
/**
*
*/
package com.metaweb.gridworks.operations;
public enum OnError {
KeepOriginal,
SetToBlank,
StoreError
}

View File

@ -21,12 +21,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
public class TextTransformOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L;
static public enum OnError {
KeepOriginal,
SetToBlank,
StoreError
}
final protected String _expression;
final protected OnError _onError;
final protected boolean _repeat;

View File

@ -622,6 +622,16 @@ DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) {
'<input bind="columnNameInput" size="40" />' +
'</td>' +
'</tr>' +
'<tr>' +
'<td width="1%" style="white-space: pre;">' +
'On error' +
'</td>' +
'<td>' +
'<input type="radio" name="create-column-dialog-onerror-choice" value="set-to-blank" checked /> set to blank ' +
'<input type="radio" name="create-column-dialog-onerror-choice" value="store-error" /> store error ' +
'<input type="radio" name="create-column-dialog-onerror-choice" value="keep-original" /> keep original' +
'</td>' +
'</tr>' +
'<tr>' +
'<td colspan="2">' + ExpressionPreviewDialog.generateWidgetHtml() + '</td>' +
'</tr>' +
@ -653,7 +663,8 @@ DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) {
baseColumnName: self._column.headerLabel,
expression: previewWidget.getExpression(true),
headerLabel: columnName,
columnInsertIndex: self._columnIndex + 1
columnInsertIndex: self._columnIndex + 1,
onError: $('input[name="create-column-dialog-onerror-choice"]:checked')[0].value
},
null,
{ modelsChanged: true }