diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-10-20 13:28:48 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-10-29 08:52:47 +0000 |
commit | 07c9de85cc0681cb6f09712120f5f494a096fabd (patch) | |
tree | 7bd5825b5405b162e8ffa5d18f5f2d05d5c3856a | |
parent | c69192915ece08cdd9403a663ff7266674efce8f (diff) | |
download | vaadin-framework-07c9de85cc0681cb6f09712120f5f494a096fabd.tar.gz vaadin-framework-07c9de85cc0681cb6f09712120f5f494a096fabd.zip |
Renames "active cell" to "cell focus" or "focused cell" (#13334)
It was quite confusing to have so many meanings of "active".
Active row still means "the visible rows". And onActivate still means
enter or click on a cell.
Change-Id: Ib3e5d50adab619410974796a03c13240db35e29c
20 files changed, 406 insertions, 384 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Escalator.java b/client/src/com/vaadin/client/ui/grid/Escalator.java index c054331c00..2ca90fe802 100644 --- a/client/src/com/vaadin/client/ui/grid/Escalator.java +++ b/client/src/com/vaadin/client/ui/grid/Escalator.java @@ -3403,11 +3403,11 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker * its parents are) removed from the document. Therefore, we sort * everything around that row instead. */ - final TableRowElement activeRow = getEscalatorRowWithFocus(); + final TableRowElement focusedRow = getEscalatorRowWithFocus(); - if (activeRow != null) { - assert activeRow.getParentElement() == root : "Trying to sort around a row that doesn't exist in body"; - assert visualRowOrder.contains(activeRow) : "Trying to sort around a row that doesn't exist in visualRowOrder."; + if (focusedRow != null) { + assert focusedRow.getParentElement() == root : "Trying to sort around a row that doesn't exist in body"; + assert visualRowOrder.contains(focusedRow) : "Trying to sort around a row that doesn't exist in visualRowOrder."; } /* @@ -3433,19 +3433,19 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker * everything underneath that row. Otherwise, all rows are placed as * first child. */ - boolean insertFirst = (activeRow == null); + boolean insertFirst = (focusedRow == null); final ListIterator<TableRowElement> i = visualRowOrder .listIterator(visualRowOrder.size()); while (i.hasPrevious()) { TableRowElement tr = i.previous(); - if (tr == activeRow) { + if (tr == focusedRow) { insertFirst = true; } else if (insertFirst) { root.insertFirst(tr); } else { - root.insertAfter(tr, activeRow); + root.insertAfter(tr, focusedRow); } } @@ -3459,12 +3459,12 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker * <code>null</code> if focus is outside of a body row. */ private TableRowElement getEscalatorRowWithFocus() { - TableRowElement activeRow = null; + TableRowElement rowContainingFocus = null; - final Element activeElement = Util.getFocusedElement(); + final Element focusedElement = Util.getFocusedElement(); - if (root.isOrHasChild(activeElement)) { - Element e = activeElement; + if (root.isOrHasChild(focusedElement)) { + Element e = focusedElement; while (e != null && e != root) { /* @@ -3472,13 +3472,13 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker * cell... We'll take the deepest one. */ if (TableRowElement.is(e)) { - activeRow = TableRowElement.as(e); + rowContainingFocus = TableRowElement.as(e); } e = e.getParentElement(); } } - return activeRow; + return rowContainingFocus; } @Override diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index dcb34fd8cc..6e752bc989 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -135,7 +135,7 @@ public class Grid<T> extends ResizeComposite implements } private Grid<?> grid; - protected Cell activeCell; + protected Cell focusedCell; private final Type<HANDLER> associatedType = new Type<HANDLER>( getBrowserEventType(), this); @@ -155,12 +155,12 @@ public class Grid<T> extends ResizeComposite implements } /** - * Gets the active cell for this event. + * Gets the focused cell for this event. * - * @return active cell + * @return focused cell */ - public Cell getActiveCell() { - return activeCell; + public Cell getFocusedCell() { + return focusedCell; } @Override @@ -169,9 +169,9 @@ public class Grid<T> extends ResizeComposite implements if (Element.is(target) && Util.findWidget(Element.as(target), null) == grid) { - activeCell = grid.activeCellHandler.getActiveCell(); + focusedCell = grid.cellFocusHandler.getFocusedCell(); GridSection section = GridSection.FOOTER; - final RowContainer container = grid.activeCellHandler.container; + final RowContainer container = grid.cellFocusHandler.containerWithFocus; if (container == grid.escalator.getHeader()) { section = GridSection.HEADER; } else if (container == grid.escalator.getBody()) { @@ -194,130 +194,129 @@ public class Grid<T> extends ResizeComposite implements private GridKeyUpEvent keyUp = new GridKeyUpEvent(this); private GridKeyPressEvent keyPress = new GridKeyPressEvent(this); - private class ActiveCellHandler { + private class CellFocusHandler { - private RowContainer container = escalator.getBody(); - private int activeRow = 0; - private Range activeCellRange = Range.withLength(0, 1); - private int lastActiveBodyRow = 0; - private int lastActiveHeaderRow = 0; - private int lastActiveFooterRow = 0; - private TableCellElement cellWithActiveStyle = null; - private TableRowElement rowWithActiveStyle = null; + private RowContainer containerWithFocus = escalator.getBody(); + private int rowWithFocus = 0; + private Range cellFocusRange = Range.withLength(0, 1); + private int lastFocusedBodyRow = 0; + private int lastFocusedHeaderRow = 0; + private int lastFocusedFooterRow = 0; + private TableCellElement cellWithFocusStyle = null; + private TableRowElement rowWithFocusStyle = null; - public ActiveCellHandler() { + public CellFocusHandler() { sinkEvents(getNavigationEvents()); } - private Cell getActiveCell() { - return new Cell(activeRow, activeCellRange.getStart(), - cellWithActiveStyle); + private Cell getFocusedCell() { + return new Cell(rowWithFocus, cellFocusRange.getStart(), + cellWithFocusStyle); } /** * Sets style names for given cell when needed. */ - public void updateActiveCellStyle(FlyweightCell cell, + public void updateFocusedCellStyle(FlyweightCell cell, RowContainer cellContainer) { int cellRow = cell.getRow(); int cellColumn = cell.getColumn(); int colSpan = cell.getColSpan(); - boolean columnActive = Range.withLength(cellColumn, colSpan) - .intersects(activeCellRange); + boolean columnHasFocus = Range.withLength(cellColumn, colSpan) + .intersects(cellFocusRange); - if (cellContainer == container) { + if (cellContainer == containerWithFocus) { // Cell is in the current container - if (cellRow == activeRow && columnActive) { - if (cellWithActiveStyle != cell.getElement()) { - // Cell is correct but it does not have active style - if (cellWithActiveStyle != null) { - // Remove old active style - setStyleName(cellWithActiveStyle, - cellActiveStyleName, false); + if (cellRow == rowWithFocus && columnHasFocus) { + if (cellWithFocusStyle != cell.getElement()) { + // Cell is correct but it does not have focused style + if (cellWithFocusStyle != null) { + // Remove old focus style + setStyleName(cellWithFocusStyle, + cellFocusStyleName, false); } - cellWithActiveStyle = cell.getElement(); + cellWithFocusStyle = cell.getElement(); - // Add active style to correct cell. - setStyleName(cellWithActiveStyle, cellActiveStyleName, + // Add focus style to correct cell. + setStyleName(cellWithFocusStyle, cellFocusStyleName, true); } - } else if (cellWithActiveStyle == cell.getElement()) { + } else if (cellWithFocusStyle == cell.getElement()) { // Due to escalator reusing cells, a new cell has the same - // element but is not the active cell. - setStyleName(cellWithActiveStyle, cellActiveStyleName, - false); - cellWithActiveStyle = null; + // element but is not the focused cell. + setStyleName(cellWithFocusStyle, cellFocusStyleName, false); + cellWithFocusStyle = null; } } if (cellContainer == escalator.getHeader() || cellContainer == escalator.getFooter()) { // Correct header and footer column also needs highlighting - setStyleName(cell.getElement(), headerFooterActiveStyleName, - columnActive); + setStyleName(cell.getElement(), headerFooterFocusStyleName, + columnHasFocus); } } /** - * Sets active row style name for given row if needed. + * Sets focus style for the given row if needed. * * @param row * a row object */ - public void updateActiveRowStyle(Row row) { - if (activeRow == row.getRow() && container == escalator.getBody()) { - if (row.getElement() != rowWithActiveStyle) { - // Row should have active style but does not have it. - if (rowWithActiveStyle != null) { - setStyleName(rowWithActiveStyle, rowActiveStyleName, + public void updateFocusedRowStyle(Row row) { + if (rowWithFocus == row.getRow() + && containerWithFocus == escalator.getBody()) { + if (row.getElement() != rowWithFocusStyle) { + // Row should have focus style but does not have it. + if (rowWithFocusStyle != null) { + setStyleName(rowWithFocusStyle, rowFocusStyleName, false); } - rowWithActiveStyle = row.getElement(); - setStyleName(rowWithActiveStyle, rowActiveStyleName, true); + rowWithFocusStyle = row.getElement(); + setStyleName(rowWithFocusStyle, rowFocusStyleName, true); } - } else if (rowWithActiveStyle == row.getElement() - || (container != escalator.getBody() && rowWithActiveStyle != null)) { - // Remove active style. - setStyleName(rowWithActiveStyle, rowActiveStyleName, false); - rowWithActiveStyle = null; + } else if (rowWithFocusStyle == row.getElement() + || (containerWithFocus != escalator.getBody() && rowWithFocusStyle != null)) { + // Remove focus style. + setStyleName(rowWithFocusStyle, rowFocusStyleName, false); + rowWithFocusStyle = null; } } /** - * Sets currently active cell to a cell in given container with given - * indices. + * Sets the currently focused. * * @param row - * new active row + * the index of the row having focus * @param column - * new active column + * the index of the column having focus * @param container - * new container + * the row container having focus */ - private void setActiveCell(int row, int column, RowContainer container) { - if (row == activeRow && activeCellRange.contains(column) - && container == this.container) { - refreshRow(activeRow); + private void setCellFocus(int row, int column, RowContainer container) { + if (row == rowWithFocus && cellFocusRange.contains(column) + && container == this.containerWithFocus) { + refreshRow(rowWithFocus); return; } - int oldRow = activeRow; - activeRow = row; - Range oldRange = activeCellRange; + int oldRow = rowWithFocus; + rowWithFocus = row; + Range oldRange = cellFocusRange; if (container == escalator.getBody()) { - scrollToRow(activeRow); - activeCellRange = Range.withLength(column, 1); + scrollToRow(rowWithFocus); + cellFocusRange = Range.withLength(column, 1); } else { int i = 0; - Element cell = container.getRowElement(activeRow) + Element cell = container.getRowElement(rowWithFocus) .getFirstChildElement(); do { int colSpan = cell .getPropertyInt(FlyweightCell.COLSPAN_ATTR); Range cellRange = Range.withLength(i, colSpan); if (cellRange.contains(column)) { - activeCellRange = cellRange; + cellFocusRange = cellRange; break; } cell = cell.getNextSiblingElement(); @@ -330,26 +329,26 @@ public class Grid<T> extends ResizeComposite implements escalator.scrollToColumn(column, ScrollDestination.ANY, 10); } - if (this.container == container) { - if (oldRange.equals(activeCellRange) && oldRow != activeRow) { + if (this.containerWithFocus == container) { + if (oldRange.equals(cellFocusRange) && oldRow != rowWithFocus) { refreshRow(oldRow); } else { refreshHeader(); refreshFooter(); } } else { - RowContainer oldContainer = this.container; - this.container = container; + RowContainer oldContainer = this.containerWithFocus; + this.containerWithFocus = container; if (oldContainer == escalator.getBody()) { - lastActiveBodyRow = oldRow; + lastFocusedBodyRow = oldRow; } else if (oldContainer == escalator.getHeader()) { - lastActiveHeaderRow = oldRow; + lastFocusedHeaderRow = oldRow; } else { - lastActiveFooterRow = oldRow; + lastFocusedFooterRow = oldRow; } - if (!oldRange.equals(activeCellRange)) { + if (!oldRange.equals(cellFocusRange)) { refreshHeader(); refreshFooter(); if (oldContainer == escalator.getBody()) { @@ -359,23 +358,26 @@ public class Grid<T> extends ResizeComposite implements oldContainer.refreshRows(oldRow, 1); } } - refreshRow(activeRow); + refreshRow(rowWithFocus); } /** - * Sets currently active cell used for keyboard navigation. Note that - * active cell is not JavaScript {@code document.activeElement}. + * Sets focus on a cell. + * + * <p> + * <em>Note</em>: cell focus is not the same as JavaScript's + * {@code document.activeElement}. * * @param cell * a cell object */ - public void setActiveCell(Cell cell) { - setActiveCell(cell.getRow(), cell.getColumn(), + public void setCellFocus(Cell cell) { + setCellFocus(cell.getRow(), cell.getColumn(), escalator.findRowContainer(cell.getElement())); } /** - * Gets list of events that can be used for active cell navigation. + * Gets list of events that can be used for cell focusing. * * @return list of navigation related event types */ @@ -384,17 +386,17 @@ public class Grid<T> extends ResizeComposite implements } /** - * Handle events that can change the currently active cell. + * Handle events that can move the cell focus. */ public void handleNavigationEvent(Event event, Cell cell) { if (event.getType().equals(BrowserEvents.CLICK)) { - setActiveCell(cell); + setCellFocus(cell); // Grid should have focus when clicked. getElement().focus(); } else if (event.getType().equals(BrowserEvents.KEYDOWN)) { - int newRow = activeRow; - RowContainer newContainer = container; - int newColumn = activeCellRange.getStart(); + int newRow = rowWithFocus; + RowContainer newContainer = containerWithFocus; + int newColumn = cellFocusRange.getStart(); switch (event.getKeyCode()) { case KeyCodes.KEY_DOWN: @@ -404,10 +406,10 @@ public class Grid<T> extends ResizeComposite implements --newRow; break; case KeyCodes.KEY_RIGHT: - if (activeCellRange.getEnd() >= getVisibleColumns().size()) { + if (cellFocusRange.getEnd() >= getVisibleColumns().size()) { return; } - newColumn = activeCellRange.getEnd(); + newColumn = cellFocusRange.getEnd(); break; case KeyCodes.KEY_LEFT: if (newColumn == 0) { @@ -417,12 +419,12 @@ public class Grid<T> extends ResizeComposite implements break; case KeyCodes.KEY_TAB: if (event.getShiftKey()) { - newContainer = getPreviousContainer(container); + newContainer = getPreviousContainer(containerWithFocus); } else { - newContainer = getNextContainer(container); + newContainer = getNextContainer(containerWithFocus); } - if (newContainer == container) { + if (newContainer == containerWithFocus) { return; } break; @@ -430,29 +432,29 @@ public class Grid<T> extends ResizeComposite implements return; } - if (newContainer != container) { + if (newContainer != containerWithFocus) { if (newContainer == escalator.getBody()) { - newRow = lastActiveBodyRow; + newRow = lastFocusedBodyRow; } else if (newContainer == escalator.getHeader()) { - newRow = lastActiveHeaderRow; + newRow = lastFocusedHeaderRow; } else { - newRow = lastActiveFooterRow; + newRow = lastFocusedFooterRow; } } else if (newRow < 0) { newContainer = getPreviousContainer(newContainer); - if (newContainer == container) { + if (newContainer == containerWithFocus) { newRow = 0; } else if (newContainer == escalator.getBody()) { newRow = getLastVisibleRowIndex(); } else { newRow = newContainer.getRowCount() - 1; } - } else if (newRow >= container.getRowCount()) { + } else if (newRow >= containerWithFocus.getRowCount()) { newContainer = getNextContainer(newContainer); - if (newContainer == container) { - newRow = container.getRowCount() - 1; + if (newContainer == containerWithFocus) { + newRow = containerWithFocus.getRowCount() - 1; } else if (newContainer == escalator.getBody()) { newRow = getFirstVisibleRowIndex(); } else { @@ -461,15 +463,17 @@ public class Grid<T> extends ResizeComposite implements } if (newContainer.getRowCount() == 0) { - // There are no rows in the container. Can't change the - // active cell. + /* + * There are no rows in the container. Can't change the + * focused cell. + */ return; } event.preventDefault(); event.stopPropagation(); - setActiveCell(newRow, newColumn, newContainer); + setCellFocus(newRow, newColumn, newContainer); } } @@ -505,64 +509,67 @@ public class Grid<T> extends ResizeComposite implements } private void refreshRow(int row) { - container.refreshRows(row, 1); + containerWithFocus.refreshRows(row, 1); } /** - * Offset active cell range by given integer. + * Offsets the focused cell's range. * * @param offset - * offset for fixing active cell range + * offset for fixing focused cell's range */ public void offsetRangeBy(int offset) { - activeCellRange = activeCellRange.offsetBy(offset); + cellFocusRange = cellFocusRange.offsetBy(offset); } /** - * Informs ActiveCellHandler that certain range of rows has been added - * to the Grid body. ActiveCellHandler will fix indices accordingly. + * Informs {@link CellFocusHandler} that certain range of rows has been + * added to the Grid body. {@link CellFocusHandler} will fix indices + * accordingly. * * @param added * a range of added rows */ public void rowsAddedToBody(Range added) { - boolean bodyIsCurrentlyActive = (container == escalator.getBody()); - boolean insertionIsAboveActiveCell = (added.getStart() <= activeRow); - if (bodyIsCurrentlyActive && insertionIsAboveActiveCell) { - setActiveCell(activeRow + added.length(), - activeCellRange.getStart(), container); + boolean bodyHasFocus = (containerWithFocus == escalator.getBody()); + boolean insertionIsAboveFocusedCell = (added.getStart() <= rowWithFocus); + if (bodyHasFocus && insertionIsAboveFocusedCell) { + setCellFocus(rowWithFocus + added.length(), + cellFocusRange.getStart(), containerWithFocus); } } /** - * Informs ActiveCellHandler that certain range of rows has been removed - * from the Grid body. ActiveCellHandler will fix indices accordingly. + * Informs {@link CellFocusHandler} that certain range of rows has been + * removed from the Grid body. {@link CellFocusHandler} will fix indices + * accordingly. * * @param removed * a range of removed rows */ public void rowsRemovedFromBody(Range removed) { - int activeColumn = activeCellRange.getStart(); - if (container != escalator.getBody()) { + int focusedColumn = cellFocusRange.getStart(); + if (containerWithFocus != escalator.getBody()) { return; - } else if (!removed.contains(activeRow)) { - if (removed.getStart() > activeRow) { + } else if (!removed.contains(rowWithFocus)) { + if (removed.getStart() > rowWithFocus) { return; } - setActiveCell(activeRow - removed.length(), activeColumn, - container); + setCellFocus(rowWithFocus - removed.length(), focusedColumn, + containerWithFocus); } else { - if (container.getRowCount() > removed.getEnd()) { - setActiveCell(removed.getStart(), activeColumn, container); + if (containerWithFocus.getRowCount() > removed.getEnd()) { + setCellFocus(removed.getStart(), focusedColumn, + containerWithFocus); } else if (removed.getStart() > 0) { - setActiveCell(removed.getStart() - 1, activeColumn, - container); + setCellFocus(removed.getStart() - 1, focusedColumn, + containerWithFocus); } else { if (escalator.getHeader().getRowCount() > 0) { - setActiveCell(lastActiveHeaderRow, activeColumn, + setCellFocus(lastFocusedHeaderRow, focusedColumn, escalator.getHeader()); } else if (escalator.getFooter().getRowCount() > 0) { - setActiveCell(lastActiveFooterRow, activeColumn, + setCellFocus(lastFocusedFooterRow, focusedColumn, escalator.getFooter()); } } @@ -753,16 +760,16 @@ public class Grid<T> extends ResizeComposite implements private String rowHasDataStyleName; private String rowSelectedStyleName; - private String cellActiveStyleName; - private String rowActiveStyleName; - private String headerFooterActiveStyleName; + private String cellFocusStyleName; + private String rowFocusStyleName; + private String headerFooterFocusStyleName; /** * Current selection model. */ private SelectionModel<T> selectionModel; - protected final ActiveCellHandler activeCellHandler; + protected final CellFocusHandler cellFocusHandler; private final UserSorter sorter = new UserSorter(); @@ -1244,7 +1251,7 @@ public class Grid<T> extends ResizeComposite implements setStyleName(rowElement, rowSelectedStyleName, false); } - activeCellHandler.updateActiveRowStyle(row); + cellFocusHandler.updateFocusedRowStyle(row); for (FlyweightCell cell : cellsToUpdate) { GridColumn<?, T> column = getColumnFromVisibleIndex(cell @@ -1253,7 +1260,7 @@ public class Grid<T> extends ResizeComposite implements assert column != null : "Column was not found from cell (" + cell.getColumn() + "," + cell.getRow() + ")"; - activeCellHandler.updateActiveCellStyle(cell, + cellFocusHandler.updateFocusedCellStyle(cell, escalator.getBody()); Renderer renderer = column.getRenderer(); @@ -1361,7 +1368,7 @@ public class Grid<T> extends ResizeComposite implements break; } - activeCellHandler.updateActiveCellStyle(cell, container); + cellFocusHandler.updateFocusedCellStyle(cell, container); } } @@ -1485,7 +1492,7 @@ public class Grid<T> extends ResizeComposite implements public Grid() { initWidget(escalator); getElement().setTabIndex(0); - activeCellHandler = new ActiveCellHandler(); + cellFocusHandler = new CellFocusHandler(); setStylePrimaryName("v-grid"); @@ -1547,7 +1554,7 @@ public class Grid<T> extends ResizeComposite implements return; } - sorter.sort(event.getActiveCell(), event.isShiftKeyDown()); + sorter.sort(event.getFocusedCell(), event.isShiftKeyDown()); } }); @@ -1567,9 +1574,14 @@ public class Grid<T> extends ResizeComposite implements rowHasDataStyleName = getStylePrimaryName() + "-row-has-data"; rowSelectedStyleName = getStylePrimaryName() + "-row-selected"; - cellActiveStyleName = getStylePrimaryName() + "-cell-active"; - headerFooterActiveStyleName = getStylePrimaryName() + "-header-active"; - rowActiveStyleName = getStylePrimaryName() + "-row-active"; + + /* + * TODO rename CSS "active" to "focused" once Valo theme has been + * merged. + */ + cellFocusStyleName = getStylePrimaryName() + "-cell-active"; + headerFooterFocusStyleName = getStylePrimaryName() + "-header-active"; + rowFocusStyleName = getStylePrimaryName() + "-row-active"; if (isAttached()) { refreshHeader(); @@ -1968,14 +1980,14 @@ public class Grid<T> extends ResizeComposite implements public void dataRemoved(int firstIndex, int numberOfItems) { escalator.getBody().removeRows(firstIndex, numberOfItems); Range removed = Range.withLength(firstIndex, numberOfItems); - activeCellHandler.rowsRemovedFromBody(removed); + cellFocusHandler.rowsRemovedFromBody(removed); } @Override public void dataAdded(int firstIndex, int numberOfItems) { escalator.getBody().insertRows(firstIndex, numberOfItems); Range added = Range.withLength(firstIndex, numberOfItems); - activeCellHandler.rowsAddedToBody(added); + cellFocusHandler.rowsAddedToBody(added); } @Override @@ -2302,11 +2314,9 @@ public class Grid<T> extends ResizeComposite implements if (container == null) { // TODO: Add a check to catch mouse click outside of table but // inside of grid - cell = activeCellHandler.getActiveCell(); - container = activeCellHandler.container; - } - - else { + cell = cellFocusHandler.getFocusedCell(); + container = cellFocusHandler.containerWithFocus; + } else { cell = container.getCell(e); if (event.getType().equals(BrowserEvents.MOUSEDOWN)) { cellOnPrevMouseDown = cell; @@ -2347,7 +2357,7 @@ public class Grid<T> extends ResizeComposite implements return; } - if (handleActiveCellEvent(event, container, cell)) { + if (handleCellFocusEvent(event, container, cell)) { return; } } @@ -2372,7 +2382,7 @@ public class Grid<T> extends ResizeComposite implements } } else if (event.getTypeInt() == Event.ONKEYDOWN && event.getKeyCode() == EditorRow.KEYCODE_SHOW) { - editorRow.editRow(activeCellHandler.activeRow); + editorRow.editRow(cellFocusHandler.rowWithFocus); return true; } } @@ -2408,11 +2418,11 @@ public class Grid<T> extends ResizeComposite implements return false; } - private boolean handleActiveCellEvent(Event event, RowContainer container, + private boolean handleCellFocusEvent(Event event, RowContainer container, Cell cell) { - Collection<String> navigation = activeCellHandler.getNavigationEvents(); + Collection<String> navigation = cellFocusHandler.getNavigationEvents(); if (navigation.contains(event.getType())) { - activeCellHandler.handleNavigationEvent(event, cell); + cellFocusHandler.handleNavigationEvent(event, cell); } return false; } @@ -2546,7 +2556,7 @@ public class Grid<T> extends ResizeComposite implements sorter.sort(cell, event.getShiftKey()); - // Click events should go onward to active cell logic + // Click events should go onward to cell focus logic return false; } else { return false; @@ -2652,13 +2662,13 @@ public class Grid<T> extends ResizeComposite implements if (this.selectColumnRenderer != null) { removeColumnSkipSelectionColumnCheck(selectionColumn); - activeCellHandler.offsetRangeBy(-1); + cellFocusHandler.offsetRangeBy(-1); } this.selectColumnRenderer = selectColumnRenderer; if (selectColumnRenderer != null) { - activeCellHandler.offsetRangeBy(1); + cellFocusHandler.offsetRangeBy(1); selectionColumn = new SelectionColumn(selectColumnRenderer); // FIXME: this needs to be done elsewhere, requires design... @@ -2935,8 +2945,8 @@ public class Grid<T> extends ResizeComposite implements /** * Register a BodyKeyDownHandler to this Grid. The event for this handler is - * fired when a KeyDown event occurs while active cell is in the Body of - * this Grid. + * fired when a KeyDown event occurs while cell focus is in the Body of this + * Grid. * * @param handler * the key handler to register @@ -2948,7 +2958,7 @@ public class Grid<T> extends ResizeComposite implements /** * Register a BodyKeyUpHandler to this Grid. The event for this handler is - * fired when a KeyUp event occurs while active cell is in the Body of this + * fired when a KeyUp event occurs while cell focus is in the Body of this * Grid. * * @param handler @@ -2961,7 +2971,7 @@ public class Grid<T> extends ResizeComposite implements /** * Register a BodyKeyPressHandler to this Grid. The event for this handler - * is fired when a KeyPress event occurs while active cell is in the Body of + * is fired when a KeyPress event occurs while cell focus is in the Body of * this Grid. * * @param handler @@ -2975,8 +2985,8 @@ public class Grid<T> extends ResizeComposite implements /** * Register a HeaderKeyDownHandler to this Grid. The event for this handler - * is fired when a KeyDown event occurs while active cell is in the Header - * of this Grid. + * is fired when a KeyDown event occurs while cell focus is in the Header of + * this Grid. * * @param handler * the key handler to register @@ -2989,8 +2999,8 @@ public class Grid<T> extends ResizeComposite implements /** * Register a HeaderKeyUpHandler to this Grid. The event for this handler is - * fired when a KeyUp event occurs while active cell is in the Header of - * this Grid. + * fired when a KeyUp event occurs while cell focus is in the Header of this + * Grid. * * @param handler * the key handler to register @@ -3002,7 +3012,7 @@ public class Grid<T> extends ResizeComposite implements /** * Register a HeaderKeyPressHandler to this Grid. The event for this handler - * is fired when a KeyPress event occurs while active cell is in the Header + * is fired when a KeyPress event occurs while cell focus is in the Header * of this Grid. * * @param handler @@ -3016,8 +3026,8 @@ public class Grid<T> extends ResizeComposite implements /** * Register a FooterKeyDownHandler to this Grid. The event for this handler - * is fired when a KeyDown event occurs while active cell is in the Footer - * of this Grid. + * is fired when a KeyDown event occurs while cell focus is in the Footer of + * this Grid. * * @param handler * the key handler to register @@ -3030,8 +3040,8 @@ public class Grid<T> extends ResizeComposite implements /** * Register a FooterKeyUpHandler to this Grid. The event for this handler is - * fired when a KeyUp event occurs while active cell is in the Footer of - * this Grid. + * fired when a KeyUp event occurs while cell focus is in the Footer of this + * Grid. * * @param handler * the key handler to register @@ -3043,7 +3053,7 @@ public class Grid<T> extends ResizeComposite implements /** * Register a FooterKeyPressHandler to this Grid. The event for this handler - * is fired when a KeyPress event occurs while active cell is in the Footer + * is fired when a KeyPress event occurs while cell focus is in the Footer * of this Grid. * * @param handler diff --git a/client/src/com/vaadin/client/ui/grid/events/BodyKeyDownHandler.java b/client/src/com/vaadin/client/ui/grid/events/BodyKeyDownHandler.java index 2ec81174b9..6df8160194 100644 --- a/client/src/com/vaadin/client/ui/grid/events/BodyKeyDownHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/BodyKeyDownHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyDownHandler; /** - * Handler for {@link GridKeyDownEvent}s that happen when active cell is in the - * body of the Grid. + * Handler for {@link GridKeyDownEvent}s that happen when the focused cell is in + * the body of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/BodyKeyPressHandler.java b/client/src/com/vaadin/client/ui/grid/events/BodyKeyPressHandler.java index f328a11ab8..347dc0c842 100644 --- a/client/src/com/vaadin/client/ui/grid/events/BodyKeyPressHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/BodyKeyPressHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyPressHandler; /** - * Handler for {@link GridKeyPressEvent}s that happen when active cell is in the - * body of the Grid. + * Handler for {@link GridKeyPressEvent}s that happen when the focused cell is + * in the body of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/BodyKeyUpHandler.java b/client/src/com/vaadin/client/ui/grid/events/BodyKeyUpHandler.java index f5cab67946..fe8ee1f4cc 100644 --- a/client/src/com/vaadin/client/ui/grid/events/BodyKeyUpHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/BodyKeyUpHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler; /** - * Handler for {@link GridKeyUpEvent}s that happen when active cell is in the - * body of the Grid. + * Handler for {@link GridKeyUpEvent}s that happen when the focused cell is in + * the body of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/FooterKeyDownHandler.java b/client/src/com/vaadin/client/ui/grid/events/FooterKeyDownHandler.java index e84da350dd..8c71e9d0f7 100644 --- a/client/src/com/vaadin/client/ui/grid/events/FooterKeyDownHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/FooterKeyDownHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyDownHandler; /** - * Handler for {@link GridKeyDownEvent}s that happen when active cell is in the - * footer of the Grid. + * Handler for {@link GridKeyDownEvent}s that happen when the focused cell is in + * the footer of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/FooterKeyPressHandler.java b/client/src/com/vaadin/client/ui/grid/events/FooterKeyPressHandler.java index 617e25f190..75780c7049 100644 --- a/client/src/com/vaadin/client/ui/grid/events/FooterKeyPressHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/FooterKeyPressHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyPressHandler; /** - * Handler for {@link GridKeyPressEvent}s that happen when active cell is in the - * footer of the Grid. + * Handler for {@link GridKeyPressEvent}s that happen when the focused cell is + * in the footer of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/FooterKeyUpHandler.java b/client/src/com/vaadin/client/ui/grid/events/FooterKeyUpHandler.java index 4dd3dc7f01..436c23ed48 100644 --- a/client/src/com/vaadin/client/ui/grid/events/FooterKeyUpHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/FooterKeyUpHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler; /** - * Handler for {@link GridKeyUpEvent}s that happen when active cell is in the - * footer of the Grid. + * Handler for {@link GridKeyUpEvent}s that happen when the focused cell is in + * the footer of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyDownHandler.java b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyDownHandler.java index a19bfad6bf..df074c7cd7 100644 --- a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyDownHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyDownHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyDownHandler; /** - * Handler for {@link GridKeyDownEvent}s that happen when active cell is in the - * header of the Grid. + * Handler for {@link GridKeyDownEvent}s that happen when the focused cell is in + * the header of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyPressHandler.java b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyPressHandler.java index 1188dc9b3e..d34102a7a4 100644 --- a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyPressHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyPressHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyPressHandler; /** - * Handler for {@link GridKeyPressEvent}s that happen when active cell is in the - * header of the Grid. + * Handler for {@link GridKeyPressEvent}s that happen when the focused cell is + * in the header of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyUpHandler.java b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyUpHandler.java index 3a8bc3e78a..ac459189b6 100644 --- a/client/src/com/vaadin/client/ui/grid/events/HeaderKeyUpHandler.java +++ b/client/src/com/vaadin/client/ui/grid/events/HeaderKeyUpHandler.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.grid.events; import com.vaadin.client.ui.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler; /** - * Handler for {@link GridKeyUpEvent}s that happen when active cell is in the - * header of the Grid. + * Handler for {@link GridKeyUpEvent}s that happen when the focused cell is in + * the header of the Grid. * * @since * @author Vaadin Ltd diff --git a/client/src/com/vaadin/client/ui/grid/renderers/ComplexRenderer.java b/client/src/com/vaadin/client/ui/grid/renderers/ComplexRenderer.java index 07c04da223..e6a2293b25 100644 --- a/client/src/com/vaadin/client/ui/grid/renderers/ComplexRenderer.java +++ b/client/src/com/vaadin/client/ui/grid/renderers/ComplexRenderer.java @@ -131,8 +131,8 @@ public abstract class ComplexRenderer<T> implements Renderer<T> { } /** - * Called when the cell is "activated" by pressing <code>enter</code>, - * double clicking or performing a double tap on the cell. + * Called when the cell is activated by pressing <code>enter</code>, double + * clicking or performing a double tap on the cell. * * @param cell * the activated cell diff --git a/client/src/com/vaadin/client/ui/grid/selection/MultiSelectionRenderer.java b/client/src/com/vaadin/client/ui/grid/selection/MultiSelectionRenderer.java index 38668c8627..8cffd6042b 100644 --- a/client/src/com/vaadin/client/ui/grid/selection/MultiSelectionRenderer.java +++ b/client/src/com/vaadin/client/ui/grid/selection/MultiSelectionRenderer.java @@ -552,8 +552,8 @@ public class MultiSelectionRenderer<T> extends ComplexRenderer<Boolean> { } spaceDown = true; - Cell active = event.getActiveCell(); - final int rowIndex = active.getRow(); + Cell focused = event.getFocusedCell(); + final int rowIndex = focused.getRow(); if (scrollHandler != null) { scrollHandler.removeHandler(); diff --git a/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java b/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java index dad9399466..ca3d4f9dd0 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java @@ -50,7 +50,7 @@ public class GridColspansTest extends MultiBrowserTest { } @Test - public void testActiveHeaderColumnsWithNavigation() throws IOException { + public void testFocusedHeaderColumnsWithNavigation() throws IOException { openTestURL(); GridElement grid = $(GridElement.class).first(); @@ -59,12 +59,12 @@ public class GridColspansTest extends MultiBrowserTest { compareScreen("beforeNavigation"); for (int i = 1; i <= 6; ++i) { - assertEquals(true, grid.getFooterCell(1, 1).isActiveHeader()); - assertEquals(i < 3, grid.getFooterCell(0, 1).isActiveHeader()); - assertEquals(i >= 3, grid.getFooterCell(0, 3).isActiveHeader()); - assertEquals(true, grid.getHeaderCell(0, 1).isActiveHeader()); - assertEquals(i < 3, grid.getHeaderCell(1, 1).isActiveHeader()); - assertEquals(i >= 3, grid.getHeaderCell(1, 3).isActiveHeader()); + assertEquals(true, grid.getFooterCell(1, 1).isFocusedHeader()); + assertEquals(i < 3, grid.getFooterCell(0, 1).isFocusedHeader()); + assertEquals(i >= 3, grid.getFooterCell(0, 3).isFocusedHeader()); + assertEquals(true, grid.getHeaderCell(0, 1).isFocusedHeader()); + assertEquals(i < 3, grid.getHeaderCell(1, 1).isFocusedHeader()); + assertEquals(i >= 3, grid.getHeaderCell(1, 3).isFocusedHeader()); new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform(); } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridElement.java b/uitest/src/com/vaadin/tests/components/grid/GridElement.java index 27c552340a..3eb868fe2f 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridElement.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridElement.java @@ -38,16 +38,18 @@ public class GridElement extends AbstractComponentElement { public static class GridCellElement extends AbstractElement { - private String ACTIVE_CLASS_NAME = "-cell-active"; - private String ACTIVE_HEADER_CLASS_NAME = "-header-active"; + // TODO static final? + // TODO rename "active" to "focused" once Valo CSS is merged + private String FOCUSED_CELL_CLASS_NAME = "-cell-active"; + private String FOCUSED_HEADER_CLASS_NAME = "-header-active"; private String FROZEN_CLASS_NAME = "frozen"; - public boolean isActive() { - return getAttribute("class").contains(ACTIVE_CLASS_NAME); + public boolean isFocused() { + return getAttribute("class").contains(FOCUSED_CELL_CLASS_NAME); } - public boolean isActiveHeader() { - return getAttribute("class").contains(ACTIVE_HEADER_CLASS_NAME); + public boolean isFocusedHeader() { + return getAttribute("class").contains(FOCUSED_HEADER_CLASS_NAME); } public boolean isFrozen() { @@ -57,11 +59,13 @@ public class GridElement extends AbstractComponentElement { public static class GridRowElement extends AbstractElement { - private String ACTIVE_CLASS_NAME = "-row-active"; + // TODO static final? + // TODO rename "active" to "focused" once Valo CSS is merged + private String FOCUSED_CLASS_NAME = "-row-active"; private String SELECTED_CLASS_NAME = "-row-selected"; - public boolean isActive() { - return getAttribute("class").contains(ACTIVE_CLASS_NAME); + public boolean isFocused() { + return getAttribute("class").contains(FOCUSED_CLASS_NAME); } @Override diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java index 67e974bd0a..ef9e082ee6 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java @@ -74,6 +74,8 @@ public class GridStylingTest extends GridStaticSectionTest { assertTrue(classNames.contains(stylename + "-cell")); if (row == 0 && col == 0) { + // TODO: rename "active" to "focused" once Valo CSS is + // merged assertTrue(classNames, classNames.contains(stylename + "-header-active")); } @@ -96,6 +98,10 @@ public class GridStylingTest extends GridStaticSectionTest { assertTrue(classNames.contains(stylename + "-cell")); if (row == 0 && col == 0) { + /* + * TODO: rename "active" to "focused" once Valo CSS is + * merged + */ assertTrue(classNames.contains(stylename + "-cell-active")); } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridActiveCellAdjustmentTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridActiveCellAdjustmentTest.java deleted file mode 100644 index 4fef839d2b..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridActiveCellAdjustmentTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.GridElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridActiveCellAdjustmentTest extends GridBasicFeaturesTest { - - @Test - public void testActiveCellWithAddAndRemoveRows() { - openTestURL(); - GridElement grid = getGridElement(); - - grid.getCell(0, 0).click(); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Active cell was not moved when adding a row", - grid.getCell(1, 0).isActive()); - - selectMenuPath("Component", "Body rows", "Add 18 rows"); - assertTrue("Active cell was not moved when adding multiple rows", grid - .getCell(19, 0).isActive()); - - for (int i = 18; i <= 0; --i) { - selectMenuPath("Component", "Body rows", "Remove first row"); - assertTrue("Active cell was not moved when removing a row", grid - .getCell(i, 0).isActive()); - } - } - -} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java new file mode 100644 index 0000000000..e8a9a96177 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid.basicfeatures.server; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.components.grid.GridElement; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest { + + @Test + public void testCellFocusWithAddAndRemoveRows() { + openTestURL(); + GridElement grid = getGridElement(); + + grid.getCell(0, 0).click(); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Cell focus was not moved when adding a row", + grid.getCell(1, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add 18 rows"); + assertTrue("Cell focus was not moved when adding multiple rows", grid + .getCell(19, 0).isFocused()); + + for (int i = 18; i <= 0; --i) { + selectMenuPath("Component", "Body rows", "Remove first row"); + assertTrue("Cell focus was not moved when removing a row", grid + .getCell(i, 0).isFocused()); + } + } + + @Test + public void testCellFocusOffsetWhileInDifferentSection() { + openTestURL(); + getGridElement().getCell(0, 0).click(); + new Actions(getDriver()).sendKeys(Keys.UP).perform(); + assertTrue("Header 0,0 should've become focused", getGridElement() + .getHeaderCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Header 0,0 should've remained focused", getGridElement() + .getHeaderCell(0, 0).isFocused()); + } + + @Test + public void testCellFocusOffsetWhileInSameSectionAndInsertedAbove() { + openTestURL(); + assertTrue("Body 0,0 should've gotten focus", + getGridElement().getCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Body 1,0 should've gotten focus", + getGridElement().getCell(1, 0).isFocused()); + } + + @Test + public void testCellFocusOffsetWhileInSameSectionAndInsertedBelow() { + openTestURL(); + assertTrue("Body 0,0 should've gotten focus", + getGridElement().getCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add second row"); + assertTrue("Body 0,0 should've remained focused", getGridElement() + .getCell(0, 0).isFocused()); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java index e219a8dba3..6f25211b76 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java @@ -30,31 +30,31 @@ import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { @Test - public void testCellActiveOnClick() { + public void testCellFocusOnClick() { openTestURL(); GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0) - .isActive()); + assertTrue("Body cell 0, 0 is not focused on init.", grid.getCell(0, 0) + .isFocused()); grid.getCell(5, 2).click(); - assertFalse("Body cell 0, 0 was still active after clicking", grid - .getCell(0, 0).isActive()); - assertTrue("Body cell 5, 2 is not active after clicking", - grid.getCell(5, 2).isActive()); + assertFalse("Body cell 0, 0 was still focused after clicking", grid + .getCell(0, 0).isFocused()); + assertTrue("Body cell 5, 2 is not focused after clicking", grid + .getCell(5, 2).isFocused()); } @Test - public void testCellNotActiveWhenRendererHandlesEvent() { + public void testCellNotFocusedWhenRendererHandlesEvent() { openTestURL(); GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0) - .isActive()); + assertTrue("Body cell 0, 0 is not focused on init.", grid.getCell(0, 0) + .isFocused()); grid.getHeaderCell(0, 3).click(); - assertFalse("Body cell 0, 0 is active after click on header.", grid - .getCell(0, 0).isActive()); - assertTrue("Header cell 0, 3 is not active after click on header.", - grid.getHeaderCell(0, 3).isActive()); + assertFalse("Body cell 0, 0 is focused after click on header.", grid + .getCell(0, 0).isFocused()); + assertTrue("Header cell 0, 3 is not focused after click on header.", + grid.getHeaderCell(0, 3).isFocused()); } @Test @@ -65,24 +65,24 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { grid.getCell(0, 0).click(); new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - assertTrue("Body cell 1, 0 is not active after keyboard navigation.", - grid.getCell(1, 0).isActive()); + assertTrue("Body cell 1, 0 is not focused after keyboard navigation.", + grid.getCell(1, 0).isFocused()); new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform(); - assertTrue("Body cell 1, 1 is not active after keyboard navigation.", - grid.getCell(1, 1).isActive()); + assertTrue("Body cell 1, 1 is not focused after keyboard navigation.", + grid.getCell(1, 1).isFocused()); int i; for (i = 1; i < 40; ++i) { new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); } - assertFalse("Grid has not scrolled with active cell", + assertFalse("Grid has not scrolled with cell focus", isElementPresent(By.xpath("//td[text() = '(0, 0)']"))); - assertTrue("Active cell is not visible", + assertTrue("Cell focus is not visible", isElementPresent(By.xpath("//td[text() = '(" + i + ", 0)']"))); - assertTrue("Body cell " + i + ", 1 is not active", grid.getCell(i, 1) - .isActive()); + assertTrue("Body cell " + i + ", 1 is not focused", grid.getCell(i, 1) + .isFocused()); } @Test @@ -95,11 +95,11 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { .perform(); grid.scrollToRow(280); - assertTrue("Header cell is not active.", grid.getHeaderCell(0, 7) - .isActive()); + assertTrue("Header cell is not focused.", grid.getHeaderCell(0, 7) + .isFocused()); new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - assertTrue("Body cell 280, 7 is not active", grid.getCell(280, 7) - .isActive()); + assertTrue("Body cell 280, 7 is not focused", grid.getCell(280, 7) + .isFocused()); } @Test @@ -112,11 +112,11 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { grid.scrollToRow(300); grid.getFooterCell(0, 2).click(); - assertTrue("Footer cell is not active.", grid.getFooterCell(0, 2) - .isActive()); + assertTrue("Footer cell does not have focus.", grid.getFooterCell(0, 2) + .isFocused()); new Actions(getDriver()).sendKeys(Keys.ARROW_UP).perform(); - assertTrue("Body cell 300, 2 is not active", grid.getCell(300, 2) - .isActive()); + assertTrue("Body cell 300, 2 does not have focus.", grid + .getCell(300, 2).isFocused()); } @Test @@ -126,22 +126,22 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { GridElement grid = getGridElement(); grid.getCell(10, 2).click(); - assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2) - .isActive()); + assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2) + .isFocused()); new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) .keyUp(Keys.SHIFT).perform(); - assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2) - .isActive()); + assertTrue("Header cell 0, 2 does not have focus", + grid.getHeaderCell(0, 2).isFocused()); new Actions(getDriver()).sendKeys(Keys.TAB).perform(); - assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2) - .isActive()); + assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2) + .isFocused()); // Navigate out of the Grid and try to navigate with arrow keys. new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) .sendKeys(Keys.TAB).keyUp(Keys.SHIFT).sendKeys(Keys.ARROW_DOWN) .perform(); - assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2) - .isActive()); + assertTrue("Header cell 0, 2 does not have focus", + grid.getHeaderCell(0, 2).isFocused()); } @Test @@ -153,21 +153,21 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { GridElement grid = getGridElement(); grid.getCell(10, 2).click(); - assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2) - .isActive()); + assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2) + .isFocused()); new Actions(getDriver()).sendKeys(Keys.TAB).perform(); - assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2) - .isActive()); + assertTrue("Footer cell 0, 2 does not have focus", + grid.getFooterCell(0, 2).isFocused()); new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) .keyUp(Keys.SHIFT).perform(); - assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2) - .isActive()); + assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2) + .isFocused()); // Navigate out of the Grid and try to navigate with arrow keys. new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB) .sendKeys(Keys.ARROW_UP).perform(); - assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2) - .isActive()); + assertTrue("Footer cell 0, 2 does not have focus", + grid.getFooterCell(0, 2).isFocused()); } @Test @@ -202,8 +202,8 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { assertTrue("Row 30 did not become visible", isElementPresent(By.xpath("//td[text() = '(30, 2)']"))); - assertTrue("Original active cell is no longer active", getGridElement() - .getCell(5, 2).isActive()); + assertTrue("Originally focused cell is no longer focused", + getGridElement().getCell(5, 2).isFocused()); getGridElement().getCell(50, 2).click(); @@ -215,42 +215,7 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { assertTrue("Row 21 did not become visible", isElementPresent(By.xpath("//td[text() = '(21, 2)']"))); - assertTrue("Original active cell is no longer active", getGridElement() - .getCell(50, 2).isActive()); - } - - @Test - public void testActiveCellOffsetWhileInDifferentSection() { - openTestURL(); - getGridElement().getCell(0, 0).click(); - new Actions(getDriver()).sendKeys(Keys.UP).perform(); - assertTrue("Header 0,0 should've become active", getGridElement() - .getHeaderCell(0, 0).isActive()); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Header 0,0 should've remained active", getGridElement() - .getHeaderCell(0, 0).isActive()); - } - - @Test - public void testActiveCellOffsetWhileInSameSectionAndInsertedAbove() { - openTestURL(); - assertTrue("Body 0,0 should've been", getGridElement().getCell(0, 0) - .isActive()); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Body 1,0 should've become active", getGridElement() - .getCell(1, 0).isActive()); - } - - @Test - public void testActiveCellOffsetWhileInSameSectionAndInsertedBelow() { - openTestURL(); - assertTrue("Body 0,0 should've been active", - getGridElement().getCell(0, 0).isActive()); - - selectMenuPath("Component", "Body rows", "Add second row"); - assertTrue("Body 0,0 should've remained active", getGridElement() - .getCell(0, 0).isActive()); + assertTrue("Originally focused cell is no longer focused", + getGridElement().getCell(50, 2).isFocused()); } } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java index 59f2d7fd17..197f684f07 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java @@ -894,9 +894,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyDown(GridKeyDownEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -905,9 +905,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyDown(GridKeyDownEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -916,9 +916,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyDown(GridKeyDownEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -928,9 +928,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyUp(GridKeyUpEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -939,9 +939,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyUp(GridKeyUpEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -950,9 +950,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyUp(GridKeyUpEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -962,9 +962,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyPress(GridKeyPressEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -973,9 +973,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyPress(GridKeyPressEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); @@ -984,9 +984,9 @@ public class GridBasicClientFeaturesWidget extends @Override public void onKeyPress(GridKeyPressEvent event) { - Cell active = event.getActiveCell(); - updateLabel(label, event.toDebugString(), active.getRow(), - active.getColumn()); + Cell focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRow(), + focused.getColumn()); } }); |