Browse Source

Rename variables to indicate whether they use DOM index or Grid index (#8275)

tags/7.7.7
Artur 7 years ago
parent
commit
066c1ca542

+ 2
- 2
client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java View File

public int getRowIndex(); public int getRowIndex();


/** /**
* Returns the index of the column being focused.
* Returns the DOM index of the column being focused.
* *
* @return the column index
* @return the column index (excluding hidden columns)
*/ */
public int getColumnIndex(); public int getColumnIndex();



+ 53
- 49
client/src/main/java/com/vaadin/client/widgets/Grid.java View File



private Grid<T> grid; private Grid<T> grid;
private final int rowIndex; private final int rowIndex;
private final int columnIndex;
private final int columnIndexDOM;
private RequestCallback<T> callback; private RequestCallback<T> callback;
private boolean completed = false; private boolean completed = false;


public EditorRequestImpl(Grid<T> grid, int rowIndex, int columnIndex,
public EditorRequestImpl(Grid<T> grid, int rowIndex, int columnIndexDOM,
RequestCallback<T> callback) { RequestCallback<T> callback) {
this.grid = grid; this.grid = grid;
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.columnIndex = columnIndex;
this.columnIndexDOM = columnIndexDOM;
this.callback = callback; this.callback = callback;
} }




@Override @Override
public int getColumnIndex() { public int getColumnIndex() {
return columnIndex;
return columnIndexDOM;
} }


@Override @Override
} }


/** /**
* Returns the column index the editor was opened at. If the editor is
* not open, returns -1.
* Returns the DOM column index (excluding hidden columns) the editor
* was opened at. If the editor is not open, returns -1.
* *
* @return the column index or -1 if editor is not open * @return the column index or -1 if editor is not open
*/ */
public int getFocusedColumnIndex() { public int getFocusedColumnIndex() {
return getEditor().focusedColumnIndex;
return getEditor().focusedColumnIndexDOM;
} }
} }


if (focusedElement == grid.getElement() if (focusedElement == grid.getElement()
|| focusedElement == Document.get().getBody() || focusedElement == Document.get().getBody()
|| count > 2) { || count > 2) {
focusColumn(focusedColumnIndex);
focusColumn(focusedColumnIndexDOM);
} else { } else {
++count; ++count;
Scheduler.get().scheduleDeferred(this); Scheduler.get().scheduleDeferred(this);
private boolean enabled = false; private boolean enabled = false;
private State state = State.INACTIVE; private State state = State.INACTIVE;
private int rowIndex = -1; private int rowIndex = -1;
private int focusedColumnIndex = -1;
private int focusedColumnIndexDOM = -1;
private String styleName = null; private String styleName = null;


private HandlerRegistration hScrollHandler; private HandlerRegistration hScrollHandler;
bindTimeout.cancel(); bindTimeout.cancel();


rowIndex = request.getRowIndex(); rowIndex = request.getRowIndex();
focusedColumnIndex = request.getColumnIndex();
if (focusedColumnIndex >= 0) {
focusedColumnIndexDOM = request.getColumnIndex();
if (focusedColumnIndexDOM >= 0) {
// Update internal focus of Grid // Update internal focus of Grid
grid.focusCell(rowIndex, focusedColumnIndex);
grid.focusCell(rowIndex, focusedColumnIndexDOM);
} }


showOverlay(); showOverlay();
* *
* @param rowIndex * @param rowIndex
* the index of the row to be edited * the index of the row to be edited
* @param columnIndex
* the column index of the editor widget that should be
* initially focused or -1 to not set focus
* @param columnIndexDOM
* the column index (excluding hidden columns) of the editor
* widget that should be initially focused or -1 to not set
* focus
* *
* @throws IllegalStateException * @throws IllegalStateException
* if this editor is not enabled * if this editor is not enabled
* *
* @since 7.5 * @since 7.5
*/ */
public void editRow(final int rowIndex, final int columnIndex) {
public void editRow(final int rowIndex, final int columnIndexDOM) {
if (!enabled) { if (!enabled) {
throw new IllegalStateException( throw new IllegalStateException(
"Cannot edit row: editor is not enabled"); "Cannot edit row: editor is not enabled");
return; return;
} }
} }
if (columnIndex >= grid.getVisibleColumns().size()) {
if (columnIndexDOM >= grid.getVisibleColumns().size()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Edited column index " + columnIndex
"Edited column index " + columnIndexDOM
+ " was bigger than visible column count."); + " was bigger than visible column count.");
} }


if (this.rowIndex == rowIndex if (this.rowIndex == rowIndex
&& focusedColumnIndex == columnIndex) {
&& focusedColumnIndexDOM == columnIndexDOM) {
// NO-OP // NO-OP
return; return;
} }


if (this.rowIndex == rowIndex) { if (this.rowIndex == rowIndex) {
if (focusedColumnIndex != columnIndex) {
if (columnIndex >= grid.getFrozenColumnCount()) {
if (focusedColumnIndexDOM != columnIndexDOM) {
if (columnIndexDOM >= grid.getFrozenColumnCount()) {
// Scroll to new focused column. // Scroll to new focused column.
grid.getEscalator().scrollToColumn(columnIndex,
grid.getEscalator().scrollToColumn(columnIndexDOM,
ScrollDestination.ANY, 0); ScrollDestination.ANY, 0);
} }


focusedColumnIndex = columnIndex;
focusedColumnIndexDOM = columnIndexDOM;
} }


updateHorizontalScrollPosition(); updateHorizontalScrollPosition();


// Update Grid internal focus and focus widget if possible // Update Grid internal focus and focus widget if possible
if (focusedColumnIndex >= 0) {
grid.focusCell(rowIndex, focusedColumnIndex);
focusColumn(focusedColumnIndex);
if (focusedColumnIndexDOM >= 0) {
grid.focusCell(rowIndex, focusedColumnIndexDOM);
focusColumn(focusedColumnIndexDOM);
} }


// No need to request anything from the editor handler. // No need to request anything from the editor handler.


final Escalator escalator = grid.getEscalator(); final Escalator escalator = grid.getEscalator();
if (escalator.getVisibleRowRange().contains(rowIndex)) { if (escalator.getVisibleRowRange().contains(rowIndex)) {
show(rowIndex, columnIndex);
show(rowIndex, columnIndexDOM);
} else { } else {
vScrollHandler = grid.addScrollHandler(new ScrollHandler() { vScrollHandler = grid.addScrollHandler(new ScrollHandler() {
@Override @Override
public void onScroll(ScrollEvent event) { public void onScroll(ScrollEvent event) {
if (escalator.getVisibleRowRange().contains(rowIndex)) { if (escalator.getVisibleRowRange().contains(rowIndex)) {
show(rowIndex, columnIndex);
show(rowIndex, columnIndexDOM);
vScrollHandler.removeHandler(); vScrollHandler.removeHandler();
} }
} }
"Cannot cancel edit: editor is not in edit mode"); "Cannot cancel edit: editor is not in edit mode");
} }
handler.cancel(new EditorRequestImpl<T>(grid, rowIndex, handler.cancel(new EditorRequestImpl<T>(grid, rowIndex,
focusedColumnIndex, null));
focusedColumnIndexDOM, null));
doCancel(); doCancel();
} }


hideOverlay(); hideOverlay();
state = State.INACTIVE; state = State.INACTIVE;
rowIndex = -1; rowIndex = -1;
focusedColumnIndex = -1;
focusedColumnIndexDOM = -1;
grid.getEscalator().setScrollLocked(Direction.VERTICAL, false); grid.getEscalator().setScrollLocked(Direction.VERTICAL, false);
updateSelectionCheckboxesAsNeeded(true); updateSelectionCheckboxesAsNeeded(true);
} }
setButtonsEnabled(false); setButtonsEnabled(false);
saveTimeout.schedule(SAVE_TIMEOUT_MS); saveTimeout.schedule(SAVE_TIMEOUT_MS);
EditorRequest<T> request = new EditorRequestImpl<T>(grid, rowIndex, EditorRequest<T> request = new EditorRequestImpl<T>(grid, rowIndex,
focusedColumnIndex, saveRequestCallback);
focusedColumnIndexDOM, saveRequestCallback);
handler.save(request); handler.save(request);
updateSelectionCheckboxesAsNeeded(true); updateSelectionCheckboxesAsNeeded(true);
} }
grid.attachWidget(editor, cell); grid.attachWidget(editor, cell);
} }


if (i == focusedColumnIndex) {
if (i == focusedColumnIndexDOM) {
if (BrowserInfo.get().isIE8()) { if (BrowserInfo.get().isIE8()) {
Scheduler.get().scheduleDeferred(fieldFocusCommand); Scheduler.get().scheduleDeferred(fieldFocusCommand);
} else { } else {
focusColumn(focusedColumnIndex);
focusColumn(focusedColumnIndexDOM);
} }
} }
} else { } else {
Unit.PX); Unit.PX);
} }


private void focusColumn(int colIndex) {
if (colIndex < 0 || colIndex >= grid.getVisibleColumns().size()) {
private void focusColumn(int columnIndexDOM) {
if (columnIndexDOM < 0
|| columnIndexDOM >= grid.getVisibleColumns().size()) {
// NO-OP // NO-OP
return; return;
} }


Widget editor = getWidget(grid.getVisibleColumn(colIndex));
Widget editor = getWidget(grid.getVisibleColumn(columnIndexDOM));
if (editor instanceof Focusable) { if (editor instanceof Focusable) {
((Focusable) editor).focus(); ((Focusable) editor).focus();
} else if (editor instanceof com.google.gwt.user.client.ui.Focusable) { } else if (editor instanceof com.google.gwt.user.client.ui.Focusable) {
* *
* @param rowIndex * @param rowIndex
* index of row to focus * index of row to focus
* @param columnIndex
* index of cell to focus
* @param columnIndexDOM
* index (excluding hidden columns) of cell to focus
*/ */
void focusCell(int rowIndex, int columnIndex) {
void focusCell(int rowIndex, int columnIndexDOM) {
final Range rowRange = Range.between(0, dataSource.size()); final Range rowRange = Range.between(0, dataSource.size());
final Range columnRange = Range.between(0, getVisibleColumns().size()); final Range columnRange = Range.between(0, getVisibleColumns().size());


assert rowRange.contains( assert rowRange.contains(
rowIndex) : "Illegal row index. Should be in range " + rowRange; rowIndex) : "Illegal row index. Should be in range " + rowRange;
assert columnRange.contains( assert columnRange.contains(
columnIndex) : "Illegal column index. Should be in range "
columnIndexDOM) : "Illegal column index. Should be in range "
+ columnRange; + columnRange;


if (rowRange.contains(rowIndex) && columnRange.contains(columnIndex)) {
cellFocusHandler.setCellFocus(rowIndex, columnIndex,
if (rowRange.contains(rowIndex)
&& columnRange.contains(columnIndexDOM)) {
cellFocusHandler.setCellFocus(rowIndex, columnIndexDOM,
escalator.getBody()); escalator.getBody());
WidgetUtil.focus(getElement()); WidgetUtil.focus(getElement());
} }
assert column.isHidden(); assert column.isHidden();
// Hidden columns are not included in Escalator // Hidden columns are not included in Escalator
} else { } else {
getEscalator().getColumnConfiguration().removeColumns(visibleColumnIndex,
1);
getEscalator().getColumnConfiguration()
.removeColumns(visibleColumnIndex, 1);
} }


updateFrozenColumns(); updateFrozenColumns();
return columns.get(index); return columns.get(index);
} }


private Column<?, T> getVisibleColumn(int index)
private Column<?, T> getVisibleColumn(int columnIndexDOM)
throws IllegalArgumentException { throws IllegalArgumentException {
List<Column<?, T>> visibleColumns = getVisibleColumns(); List<Column<?, T>> visibleColumns = getVisibleColumns();
if (index < 0 || index >= visibleColumns.size()) {
if (columnIndexDOM < 0 || columnIndexDOM >= visibleColumns.size()) {
throw new IllegalStateException("Column not found."); throw new IllegalStateException("Column not found.");
} }
return visibleColumns.get(index);
return visibleColumns.get(columnIndexDOM);
} }


/** /**
} }


Widget widget; Widget widget;
if (editor.focusedColumnIndex < 0) {
if (editor.focusedColumnIndexDOM < 0) {
widget = null; widget = null;
} else { } else {
widget = editor.getWidget(getColumn(editor.focusedColumnIndex));
widget = editor
.getWidget(getColumn(editor.focusedColumnIndexDOM));
} }


EditorDomEvent<T> editorEvent = new EditorDomEvent<T>( EditorDomEvent<T> editorEvent = new EditorDomEvent<T>(

Loading…
Cancel
Save