Added option to "transpose columns into rows" operation for filling in other columns.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2367 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2011-11-07 19:39:23 +00:00
parent 1e876a6d43
commit d01745284b
4 changed files with 43 additions and 13 deletions

View File

@ -58,6 +58,7 @@ public class TransposeColumnsIntoRowsCommand extends Command {
String startColumnName = request.getParameter("startColumnName");
int columnCount = Integer.parseInt(request.getParameter("columnCount"));
boolean ignoreBlankCells = Boolean.parseBoolean(request.getParameter("ignoreBlankCells"));
boolean fillDown = Boolean.parseBoolean(request.getParameter("fillDown"));
String combinedColumnName = request.getParameter("combinedColumnName");
if (combinedColumnName != null) {
@ -65,16 +66,16 @@ public class TransposeColumnsIntoRowsCommand extends Command {
String separator = request.getParameter("separator");
op = new TransposeColumnsIntoRowsOperation(
startColumnName, columnCount,
combinedColumnName, prependColumnName, separator,
ignoreBlankCells);
ignoreBlankCells, fillDown,
combinedColumnName, prependColumnName, separator);
} else {
String keyColumnName = request.getParameter("keyColumnName");
String valueColumnName = request.getParameter("valueColumnName");
op = new TransposeColumnsIntoRowsOperation(
startColumnName, columnCount,
keyColumnName, valueColumnName,
ignoreBlankCells);
ignoreBlankCells, fillDown,
keyColumnName, valueColumnName);
}
Process process = op.createProcess(project, new Properties());

View File

@ -55,6 +55,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
final protected String _startColumnName;
final protected int _columnCount;
final protected boolean _ignoreBlankCells;
final protected boolean _fillDown;
final protected String _combinedColumnName;
final protected boolean _prependColumnName;
@ -69,18 +70,20 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
return new TransposeColumnsIntoRowsOperation(
obj.getString("startColumnName"),
obj.getInt("columnCount"),
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
JSONUtilities.getBoolean(obj, "fillDown", false),
combinedColumnName,
obj.getBoolean("prependColumnName"),
obj.getString("separator"),
obj.getBoolean("ignoreBlankCells")
obj.getString("separator")
);
} else {
return new TransposeColumnsIntoRowsOperation(
obj.getString("startColumnName"),
obj.getInt("columnCount"),
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
JSONUtilities.getBoolean(obj, "fillDown", false),
obj.getString("keyColumnName"),
obj.getString("valueColumnName"),
obj.getBoolean("ignoreBlankCells")
obj.getString("valueColumnName")
);
}
}
@ -88,14 +91,16 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
public TransposeColumnsIntoRowsOperation(
String startColumnName,
int columnCount,
boolean ignoreBlankCells,
boolean fillDown,
String combinedColumnName,
boolean prependColumnName,
String separator,
boolean ignoreBlankCells
String separator
) {
_startColumnName = startColumnName;
_columnCount = columnCount;
_ignoreBlankCells = ignoreBlankCells;
_fillDown = fillDown;
_combinedColumnName = combinedColumnName;
_prependColumnName = prependColumnName;
@ -108,13 +113,15 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
public TransposeColumnsIntoRowsOperation(
String startColumnName,
int columnCount,
boolean ignoreBlankCells,
boolean fillDown,
String keyColumnName,
String valueColumnName,
boolean ignoreBlankCells
String valueColumnName
) {
_startColumnName = startColumnName;
_columnCount = columnCount;
_ignoreBlankCells = ignoreBlankCells;
_fillDown = fillDown;
_combinedColumnName = null;
_prependColumnName = false;
@ -134,6 +141,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
writer.key("startColumnName"); writer.value(_startColumnName);
writer.key("columnCount"); writer.value(_columnCount);
writer.key("ignoreBlankCells"); writer.value(_ignoreBlankCells);
writer.key("fillDown"); writer.value(_fillDown);
if (_combinedColumnName != null) {
writer.key("combinedColumnName"); writer.value(_combinedColumnName);
writer.key("prependColumnName"); writer.value(_prependColumnName);
@ -266,6 +274,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
for (int r = 0; r < oldRows.size(); r++) {
Row oldRow = project.rows.get(r);
Row firstNewRow = new Row(newColumns.size());
int firstNewRowIndex = newRows.size();
newRows.add(firstNewRow);
@ -325,6 +334,21 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
cell);
}
}
if (_fillDown) {
for (int r2 = firstNewRowIndex + 1; r2 < newRows.size(); r2++) {
Row newRow = newRows.get(r2);
for (int c = 0; c < newColumns.size(); c++) {
Column column = newColumns.get(c);
int cellIndex = column.getCellIndex();
Cell cellToCopy = firstNewRow.getCell(cellIndex);
if (cellToCopy != null && newRow.getCell(cellIndex) == null) {
newRow.setCell(cellIndex, cellToCopy);
}
}
}
}
}
return new HistoryEntry(

View File

@ -253,7 +253,8 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
var config = {
startColumnName: elmts.fromColumnSelect[0].value,
columnCount: elmts.toColumnSelect[0].value,
ignoreBlankCells: elmts.ignoreBlankCellsCheckbox[0].checked
ignoreBlankCells: elmts.ignoreBlankCellsCheckbox[0].checked,
fillDown: elmts.fillDownCheckbox[0].checked
};
var mode = dialog.find('input[name="transpose-dialog-column-choices"]:checked')[0].value;

View File

@ -54,6 +54,10 @@
<td><input type="checkbox" bind="ignoreBlankCellsCheckbox" checked id="$transpose-dialog-ignore" /></td>
<td><label for="$transpose-dialog-ignore">Ignore blank cells</label></td>
</tr>
<tr>
<td><input type="checkbox" bind="fillDownCheckbox" id="$transpose-dialog-fill-down" /></td>
<td><label for="$transpose-dialog-fill-down">Fill down in other columns</label></td>
</tr>
</table></div></td>
</tr>
</table></div>