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:
parent
1e876a6d43
commit
d01745284b
@ -58,6 +58,7 @@ public class TransposeColumnsIntoRowsCommand extends Command {
|
|||||||
String startColumnName = request.getParameter("startColumnName");
|
String startColumnName = request.getParameter("startColumnName");
|
||||||
int columnCount = Integer.parseInt(request.getParameter("columnCount"));
|
int columnCount = Integer.parseInt(request.getParameter("columnCount"));
|
||||||
boolean ignoreBlankCells = Boolean.parseBoolean(request.getParameter("ignoreBlankCells"));
|
boolean ignoreBlankCells = Boolean.parseBoolean(request.getParameter("ignoreBlankCells"));
|
||||||
|
boolean fillDown = Boolean.parseBoolean(request.getParameter("fillDown"));
|
||||||
|
|
||||||
String combinedColumnName = request.getParameter("combinedColumnName");
|
String combinedColumnName = request.getParameter("combinedColumnName");
|
||||||
if (combinedColumnName != null) {
|
if (combinedColumnName != null) {
|
||||||
@ -65,16 +66,16 @@ public class TransposeColumnsIntoRowsCommand extends Command {
|
|||||||
String separator = request.getParameter("separator");
|
String separator = request.getParameter("separator");
|
||||||
op = new TransposeColumnsIntoRowsOperation(
|
op = new TransposeColumnsIntoRowsOperation(
|
||||||
startColumnName, columnCount,
|
startColumnName, columnCount,
|
||||||
combinedColumnName, prependColumnName, separator,
|
ignoreBlankCells, fillDown,
|
||||||
ignoreBlankCells);
|
combinedColumnName, prependColumnName, separator);
|
||||||
} else {
|
} else {
|
||||||
String keyColumnName = request.getParameter("keyColumnName");
|
String keyColumnName = request.getParameter("keyColumnName");
|
||||||
String valueColumnName = request.getParameter("valueColumnName");
|
String valueColumnName = request.getParameter("valueColumnName");
|
||||||
|
|
||||||
op = new TransposeColumnsIntoRowsOperation(
|
op = new TransposeColumnsIntoRowsOperation(
|
||||||
startColumnName, columnCount,
|
startColumnName, columnCount,
|
||||||
keyColumnName, valueColumnName,
|
ignoreBlankCells, fillDown,
|
||||||
ignoreBlankCells);
|
keyColumnName, valueColumnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
|
@ -55,6 +55,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
final protected String _startColumnName;
|
final protected String _startColumnName;
|
||||||
final protected int _columnCount;
|
final protected int _columnCount;
|
||||||
final protected boolean _ignoreBlankCells;
|
final protected boolean _ignoreBlankCells;
|
||||||
|
final protected boolean _fillDown;
|
||||||
|
|
||||||
final protected String _combinedColumnName;
|
final protected String _combinedColumnName;
|
||||||
final protected boolean _prependColumnName;
|
final protected boolean _prependColumnName;
|
||||||
@ -69,18 +70,20 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
return new TransposeColumnsIntoRowsOperation(
|
return new TransposeColumnsIntoRowsOperation(
|
||||||
obj.getString("startColumnName"),
|
obj.getString("startColumnName"),
|
||||||
obj.getInt("columnCount"),
|
obj.getInt("columnCount"),
|
||||||
|
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
|
||||||
|
JSONUtilities.getBoolean(obj, "fillDown", false),
|
||||||
combinedColumnName,
|
combinedColumnName,
|
||||||
obj.getBoolean("prependColumnName"),
|
obj.getBoolean("prependColumnName"),
|
||||||
obj.getString("separator"),
|
obj.getString("separator")
|
||||||
obj.getBoolean("ignoreBlankCells")
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return new TransposeColumnsIntoRowsOperation(
|
return new TransposeColumnsIntoRowsOperation(
|
||||||
obj.getString("startColumnName"),
|
obj.getString("startColumnName"),
|
||||||
obj.getInt("columnCount"),
|
obj.getInt("columnCount"),
|
||||||
|
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
|
||||||
|
JSONUtilities.getBoolean(obj, "fillDown", false),
|
||||||
obj.getString("keyColumnName"),
|
obj.getString("keyColumnName"),
|
||||||
obj.getString("valueColumnName"),
|
obj.getString("valueColumnName")
|
||||||
obj.getBoolean("ignoreBlankCells")
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,14 +91,16 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
public TransposeColumnsIntoRowsOperation(
|
public TransposeColumnsIntoRowsOperation(
|
||||||
String startColumnName,
|
String startColumnName,
|
||||||
int columnCount,
|
int columnCount,
|
||||||
|
boolean ignoreBlankCells,
|
||||||
|
boolean fillDown,
|
||||||
String combinedColumnName,
|
String combinedColumnName,
|
||||||
boolean prependColumnName,
|
boolean prependColumnName,
|
||||||
String separator,
|
String separator
|
||||||
boolean ignoreBlankCells
|
|
||||||
) {
|
) {
|
||||||
_startColumnName = startColumnName;
|
_startColumnName = startColumnName;
|
||||||
_columnCount = columnCount;
|
_columnCount = columnCount;
|
||||||
_ignoreBlankCells = ignoreBlankCells;
|
_ignoreBlankCells = ignoreBlankCells;
|
||||||
|
_fillDown = fillDown;
|
||||||
|
|
||||||
_combinedColumnName = combinedColumnName;
|
_combinedColumnName = combinedColumnName;
|
||||||
_prependColumnName = prependColumnName;
|
_prependColumnName = prependColumnName;
|
||||||
@ -108,13 +113,15 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
public TransposeColumnsIntoRowsOperation(
|
public TransposeColumnsIntoRowsOperation(
|
||||||
String startColumnName,
|
String startColumnName,
|
||||||
int columnCount,
|
int columnCount,
|
||||||
|
boolean ignoreBlankCells,
|
||||||
|
boolean fillDown,
|
||||||
String keyColumnName,
|
String keyColumnName,
|
||||||
String valueColumnName,
|
String valueColumnName
|
||||||
boolean ignoreBlankCells
|
|
||||||
) {
|
) {
|
||||||
_startColumnName = startColumnName;
|
_startColumnName = startColumnName;
|
||||||
_columnCount = columnCount;
|
_columnCount = columnCount;
|
||||||
_ignoreBlankCells = ignoreBlankCells;
|
_ignoreBlankCells = ignoreBlankCells;
|
||||||
|
_fillDown = fillDown;
|
||||||
|
|
||||||
_combinedColumnName = null;
|
_combinedColumnName = null;
|
||||||
_prependColumnName = false;
|
_prependColumnName = false;
|
||||||
@ -134,6 +141,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
writer.key("startColumnName"); writer.value(_startColumnName);
|
writer.key("startColumnName"); writer.value(_startColumnName);
|
||||||
writer.key("columnCount"); writer.value(_columnCount);
|
writer.key("columnCount"); writer.value(_columnCount);
|
||||||
writer.key("ignoreBlankCells"); writer.value(_ignoreBlankCells);
|
writer.key("ignoreBlankCells"); writer.value(_ignoreBlankCells);
|
||||||
|
writer.key("fillDown"); writer.value(_fillDown);
|
||||||
if (_combinedColumnName != null) {
|
if (_combinedColumnName != null) {
|
||||||
writer.key("combinedColumnName"); writer.value(_combinedColumnName);
|
writer.key("combinedColumnName"); writer.value(_combinedColumnName);
|
||||||
writer.key("prependColumnName"); writer.value(_prependColumnName);
|
writer.key("prependColumnName"); writer.value(_prependColumnName);
|
||||||
@ -266,6 +274,7 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
for (int r = 0; r < oldRows.size(); r++) {
|
for (int r = 0; r < oldRows.size(); r++) {
|
||||||
Row oldRow = project.rows.get(r);
|
Row oldRow = project.rows.get(r);
|
||||||
Row firstNewRow = new Row(newColumns.size());
|
Row firstNewRow = new Row(newColumns.size());
|
||||||
|
int firstNewRowIndex = newRows.size();
|
||||||
|
|
||||||
newRows.add(firstNewRow);
|
newRows.add(firstNewRow);
|
||||||
|
|
||||||
@ -325,6 +334,21 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
|||||||
cell);
|
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(
|
return new HistoryEntry(
|
||||||
|
@ -253,7 +253,8 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
var config = {
|
var config = {
|
||||||
startColumnName: elmts.fromColumnSelect[0].value,
|
startColumnName: elmts.fromColumnSelect[0].value,
|
||||||
columnCount: elmts.toColumnSelect[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;
|
var mode = dialog.find('input[name="transpose-dialog-column-choices"]:checked')[0].value;
|
||||||
|
@ -54,6 +54,10 @@
|
|||||||
<td><input type="checkbox" bind="ignoreBlankCellsCheckbox" checked id="$transpose-dialog-ignore" /></td>
|
<td><input type="checkbox" bind="ignoreBlankCellsCheckbox" checked id="$transpose-dialog-ignore" /></td>
|
||||||
<td><label for="$transpose-dialog-ignore">Ignore blank cells</label></td>
|
<td><label for="$transpose-dialog-ignore">Ignore blank cells</label></td>
|
||||||
</tr>
|
</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>
|
</table></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table></div>
|
</table></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user