Made facets' expressions editable.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@527 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-04-24 01:19:13 +00:00
parent b8adb42c4e
commit 0778b324de
8 changed files with 73 additions and 7 deletions

View File

@ -40,7 +40,7 @@ public class PreviewExpressionCommand extends Command {
Project project = getProject(request); Project project = getProject(request);
int cellIndex = Integer.parseInt(request.getParameter("cellIndex")); int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
String columnName = project.columnModel.getColumnByCellIndex(cellIndex).getName(); String columnName = cellIndex < 0 ? "" : project.columnModel.getColumnByCellIndex(cellIndex).getName();
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
String rowIndicesString = request.getParameter("rowIndices"); String rowIndicesString = request.getParameter("rowIndices");

View File

@ -71,7 +71,7 @@ public class Row implements HasFields, Jsonizable {
} }
public Cell getCell(int cellIndex) { public Cell getCell(int cellIndex) {
if (cellIndex < cells.size()) { if (cellIndex >= 0 && cellIndex < cells.size()) {
return cells.get(cellIndex); return cells.get(cellIndex);
} else { } else {
return null; return null;
@ -79,7 +79,7 @@ public class Row implements HasFields, Jsonizable {
} }
public Object getCellValue(int cellIndex) { public Object getCellValue(int cellIndex) {
if (cellIndex < cells.size()) { if (cellIndex >= 0 && cellIndex < cells.size()) {
Cell cell = cells.get(cellIndex); Cell cell = cells.get(cellIndex);
if (cell != null) { if (cell != null) {
return cell.value; return cell.value;

View File

@ -98,7 +98,7 @@ ExpressionPreviewDialog.Widget = function(
if (colon > 0) { if (colon > 0) {
var l = expression.substring(0, colon); var l = expression.substring(0, colon);
if (l == "gel" || l == "jython" || l == "clojure") { if (l == "gel" || l == "jython" || l == "clojure") {
expression = expression.substring(colon + 1); this.expression = expression.substring(colon + 1);
language = l; language = l;
} }
} }

View File

@ -135,7 +135,7 @@ ListFacet.prototype._initializeUI = function() {
this._elmts = DOM.bind(this._div); this._elmts = DOM.bind(this._div);
this._elmts.titleSpan.text(this._config.name); this._elmts.titleSpan.text(this._config.name);
this._elmts.expressionDiv.text(this._config.expression); this._elmts.expressionDiv.text(this._config.expression).click(function() { self._editExpression(); });
this._elmts.removeButton.click(function() { self._remove(); }); this._elmts.removeButton.click(function() { self._remove(); });
this._elmts.resetButton.click(function() { self._reset(); }); this._elmts.resetButton.click(function() { self._reset(); });
@ -491,3 +491,29 @@ ListFacet.prototype._remove = function() {
ListFacet.prototype._updateRest = function() { ListFacet.prototype._updateRest = function() {
Gridworks.update({ engineChanged: true }); Gridworks.update({ engineChanged: true });
}; };
ListFacet.prototype._editExpression = function() {
var self = this;
var title = (this._config.columnName) ?
("Edit Facet's Expression based on Column " + this._config.columnName) :
"Edit Facet's Expression"
var column = Gridworks.columnNameToColumn(this._config.columnName);
var o = DataTableView.sampleVisibleRows(column);
new ExpressionPreviewDialog(
title,
column ? column.cellIndex : -1,
o.rowIndices,
o.values,
this._config.expression,
function(expr) {
if (expr != self._config.expression) {
self._config.expression = expr;
self._elmts.expressionDiv.text(self._config.expression);
self.reset();
self._updateRest();
}
}
);
};

View File

@ -115,7 +115,7 @@ RangeFacet.prototype._initializeUI = function() {
this._elmts = DOM.bind(this._div); this._elmts = DOM.bind(this._div);
this._elmts.facetTitle.text(this._config.name); this._elmts.facetTitle.text(this._config.name);
this._elmts.expressionDiv.text(this._config.expression); this._elmts.expressionDiv.text(this._config.expression).click(function() { self._editExpression(); });
this._elmts.resetButton.click(function() { this._elmts.resetButton.click(function() {
self.reset(); self.reset();
@ -330,3 +330,32 @@ RangeFacet.prototype._remove = function() {
RangeFacet.prototype._updateRest = function() { RangeFacet.prototype._updateRest = function() {
Gridworks.update({ engineChanged: true }); Gridworks.update({ engineChanged: true });
}; };
RangeFacet.prototype._editExpression = function() {
var self = this;
var title = (this._config.columnName) ?
("Edit Facet's Expression based on Column " + this._config.columnName) :
"Edit Facet's Expression"
var column = Gridworks.columnNameToColumn(this._config.columnName);
var o = DataTableView.sampleVisibleRows(column);
new ExpressionPreviewDialog(
title,
column ? column.cellIndex : -1,
o.rowIndices,
o.values,
this._config.expression,
function(expr) {
if (expr != self._config.expression) {
self._config.expression = expr;
self._elmts.expressionDiv.text(self._config.expression);
self.reset();
self._from = null;
self._to = null;
self._updateRest();
}
}
);
};

View File

@ -295,6 +295,16 @@ Gridworks.cellIndexToColumn = function(cellIndex) {
} }
return null; return null;
}; };
Gridworks.columnNameToColumn = function(columnName) {
var columns = theProject.columnModel.columns;
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
if (column.name == columnName) {
return column;
}
}
return null;
};
Gridworks.preparePool = function(pool) { Gridworks.preparePool = function(pool) {
for (var id in pool.recons) { for (var id in pool.recons) {

View File

@ -419,7 +419,7 @@ DataTableView.sampleVisibleRows = function(column) {
rowIndices.push(row.i); rowIndices.push(row.i);
var v = null; var v = null;
if (column.cellIndex < row.cells.length) { if (column && column.cellIndex < row.cells.length) {
var cell = row.cells[column.cellIndex]; var cell = row.cells[column.cellIndex];
if (cell !== null) { if (cell !== null) {
v = cell.v; v = cell.v;

View File

@ -60,6 +60,7 @@ li.facet-container {
font-family: monospace; font-family: monospace;
font-size: 11px; font-size: 11px;
background: #eee; background: #eee;
cursor: pointer;
} }
.facet-status { .facet-status {