Change-Id: Ie4ed85e56f0c23850eec56518a7493f5ed3257bdtags/7.4.0.beta1
@@ -105,4 +105,13 @@ public class CellReference<T> { | |||
public Object getValue() { | |||
return getColumn().getValue(getRow()); | |||
} | |||
/** | |||
* Gets the RowReference for this CellReference. | |||
* | |||
* @return the row reference | |||
*/ | |||
protected RowReference<T> getRowReference() { | |||
return rowReference; | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
/* | |||
* 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.client.widget.grid; | |||
import com.vaadin.client.widget.escalator.Cell; | |||
import com.vaadin.client.widgets.Grid; | |||
/** | |||
* A data class which contains information which identifies a cell being the | |||
* target of an event from {@link Grid}. | |||
* <p> | |||
* Since this class follows the <code>Flyweight</code>-pattern any instance of | |||
* this object is subject to change without the user knowing it and so should | |||
* not be stored anywhere outside of the method providing these instances. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class EventCellReference<T> extends CellReference<T> { | |||
private Grid<T> grid; | |||
public EventCellReference(Grid<T> grid) { | |||
super(new RowReference<T>(grid)); | |||
this.grid = grid; | |||
} | |||
/** | |||
* Sets the RowReference and CellReference to point to given Cell. | |||
* | |||
* @param targetCell | |||
* cell to point to | |||
*/ | |||
public void set(Cell targetCell) { | |||
int row = targetCell.getRow(); | |||
int column = targetCell.getColumn(); | |||
getRowReference().set(row, grid.getDataSource().getRow(row)); | |||
set(column, grid.getColumn(column)); | |||
} | |||
} |
@@ -16,6 +16,7 @@ | |||
package com.vaadin.client.widget.grid.events; | |||
import com.google.gwt.dom.client.BrowserEvents; | |||
import com.vaadin.client.widget.grid.CellReference; | |||
import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridClickHandler; | |||
import com.vaadin.client.widgets.Grid; | |||
import com.vaadin.client.widgets.Grid.AbstractGridMouseEvent; | |||
@@ -29,8 +30,8 @@ import com.vaadin.client.widgets.Grid.Section; | |||
*/ | |||
public class GridClickEvent extends AbstractGridMouseEvent<GridClickHandler> { | |||
public GridClickEvent(Grid<?> grid) { | |||
super(grid); | |||
public GridClickEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
super(grid, targetCell); | |||
} | |||
@Override |
@@ -17,6 +17,7 @@ package com.vaadin.client.widget.grid.events; | |||
import com.google.gwt.dom.client.BrowserEvents; | |||
import com.google.gwt.event.dom.client.KeyCodes; | |||
import com.vaadin.client.widget.grid.CellReference; | |||
import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyDownHandler; | |||
import com.vaadin.client.widgets.Grid; | |||
import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent; | |||
@@ -30,8 +31,8 @@ import com.vaadin.client.widgets.Grid.Section; | |||
*/ | |||
public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> { | |||
public GridKeyDownEvent(Grid<?> grid) { | |||
super(grid); | |||
public GridKeyDownEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
super(grid, targetCell); | |||
} | |||
@Override |
@@ -16,6 +16,7 @@ | |||
package com.vaadin.client.widget.grid.events; | |||
import com.google.gwt.dom.client.BrowserEvents; | |||
import com.vaadin.client.widget.grid.CellReference; | |||
import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyPressHandler; | |||
import com.vaadin.client.widgets.Grid; | |||
import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent; | |||
@@ -30,8 +31,8 @@ import com.vaadin.client.widgets.Grid.Section; | |||
public class GridKeyPressEvent extends | |||
AbstractGridKeyEvent<GridKeyPressHandler> { | |||
public GridKeyPressEvent(Grid<?> grid) { | |||
super(grid); | |||
public GridKeyPressEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
super(grid, targetCell); | |||
} | |||
@Override |
@@ -17,6 +17,7 @@ package com.vaadin.client.widget.grid.events; | |||
import com.google.gwt.dom.client.BrowserEvents; | |||
import com.google.gwt.event.dom.client.KeyCodes; | |||
import com.vaadin.client.widget.grid.CellReference; | |||
import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler; | |||
import com.vaadin.client.widgets.Grid; | |||
import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent; | |||
@@ -30,8 +31,8 @@ import com.vaadin.client.widgets.Grid.Section; | |||
*/ | |||
public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> { | |||
public GridKeyUpEvent(Grid<?> grid) { | |||
super(grid); | |||
public GridKeyUpEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
super(grid, targetCell); | |||
} | |||
@Override |
@@ -35,7 +35,7 @@ public class ClickSelectHandler<T> { | |||
@Override | |||
public void onClick(GridClickEvent event) { | |||
T row = grid.getDataSource().getRow(event.getTargetCell().getRow()); | |||
T row = (T) event.getTargetCell().getRow(); | |||
if (!grid.isSelected(row)) { | |||
grid.select(row); | |||
} |
@@ -17,7 +17,6 @@ package com.vaadin.client.widget.grid.selection; | |||
import com.google.gwt.event.dom.client.KeyCodes; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.vaadin.client.widget.escalator.Cell; | |||
import com.vaadin.client.widget.grid.DataAvailableEvent; | |||
import com.vaadin.client.widget.grid.DataAvailableHandler; | |||
import com.vaadin.client.widget.grid.events.BodyKeyDownHandler; | |||
@@ -53,8 +52,7 @@ public class SpaceSelectHandler<T> { | |||
event.getNativeEvent().preventDefault(); | |||
spaceDown = true; | |||
Cell focused = event.getFocusedCell(); | |||
final int rowIndex = focused.getRow(); | |||
final int rowIndex = event.getFocusedCell().getRowIndex(); | |||
if (scrollHandler != null) { | |||
scrollHandler.removeHandler(); |
@@ -81,6 +81,7 @@ import com.vaadin.client.widget.grid.DataAvailableHandler; | |||
import com.vaadin.client.widget.grid.EditorHandler; | |||
import com.vaadin.client.widget.grid.EditorHandler.EditorRequest; | |||
import com.vaadin.client.widget.grid.EditorHandler.EditorRequest.RequestCallback; | |||
import com.vaadin.client.widget.grid.EventCellReference; | |||
import com.vaadin.client.widget.grid.GridUtil; | |||
import com.vaadin.client.widget.grid.RendererCellReference; | |||
import com.vaadin.client.widget.grid.RowReference; | |||
@@ -1306,12 +1307,13 @@ public class Grid<T> extends ResizeComposite implements | |||
extends KeyEvent<HANDLER> { | |||
private Grid<?> grid; | |||
protected Cell focusedCell; | |||
private final Type<HANDLER> associatedType = new Type<HANDLER>( | |||
getBrowserEventType(), this); | |||
private final CellReference<?> targetCell; | |||
public AbstractGridKeyEvent(Grid<?> grid) { | |||
public AbstractGridKeyEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
this.grid = grid; | |||
this.targetCell = targetCell; | |||
} | |||
protected abstract String getBrowserEventType(); | |||
@@ -1330,8 +1332,8 @@ public class Grid<T> extends ResizeComposite implements | |||
* | |||
* @return focused cell | |||
*/ | |||
public Cell getFocusedCell() { | |||
return focusedCell; | |||
public CellReference<?> getFocusedCell() { | |||
return targetCell; | |||
} | |||
@Override | |||
@@ -1340,7 +1342,6 @@ public class Grid<T> extends ResizeComposite implements | |||
if (Element.is(target) | |||
&& !grid.isElementInChildWidget(Element.as(target))) { | |||
focusedCell = grid.cellFocusHandler.getFocusedCell(); | |||
Section section = Section.FOOTER; | |||
final RowContainer container = grid.cellFocusHandler.containerWithFocus; | |||
if (container == grid.escalator.getHeader()) { | |||
@@ -1365,12 +1366,13 @@ public class Grid<T> extends ResizeComposite implements | |||
extends MouseEvent<HANDLER> { | |||
private Grid<?> grid; | |||
protected Cell targetCell; | |||
private final CellReference<?> targetCell; | |||
private final Type<HANDLER> associatedType = new Type<HANDLER>( | |||
getBrowserEventType(), this); | |||
public AbstractGridMouseEvent(Grid<?> grid) { | |||
public AbstractGridMouseEvent(Grid<?> grid, CellReference<?> targetCell) { | |||
this.grid = grid; | |||
this.targetCell = targetCell; | |||
} | |||
protected abstract String getBrowserEventType(); | |||
@@ -1385,11 +1387,11 @@ public class Grid<T> extends ResizeComposite implements | |||
} | |||
/** | |||
* Gets the target cell for this event. | |||
* Gets the reference of target cell for this event. | |||
* | |||
* @return target cell | |||
*/ | |||
public Cell getTargetCell() { | |||
public CellReference<?> getTargetCell() { | |||
return targetCell; | |||
} | |||
@@ -1414,12 +1416,6 @@ public class Grid<T> extends ResizeComposite implements | |||
return; | |||
} | |||
targetCell = container.getCell(targetElement); | |||
if (targetCell == null) { | |||
// Is not a cell in given container. | |||
return; | |||
} | |||
Section section = Section.FOOTER; | |||
if (container == grid.escalator.getHeader()) { | |||
section = Section.HEADER; | |||
@@ -1440,10 +1436,11 @@ public class Grid<T> extends ResizeComposite implements | |||
private static final String CUSTOM_STYLE_PROPERTY_NAME = "customStyle"; | |||
private GridKeyDownEvent keyDown = new GridKeyDownEvent(this); | |||
private GridKeyUpEvent keyUp = new GridKeyUpEvent(this); | |||
private GridKeyPressEvent keyPress = new GridKeyPressEvent(this); | |||
private GridClickEvent clickEvent = new GridClickEvent(this); | |||
private EventCellReference<T> eventCell = new EventCellReference<T>(this); | |||
private GridKeyDownEvent keyDown = new GridKeyDownEvent(this, eventCell); | |||
private GridKeyUpEvent keyUp = new GridKeyUpEvent(this, eventCell); | |||
private GridKeyPressEvent keyPress = new GridKeyPressEvent(this, eventCell); | |||
private GridClickEvent clickEvent = new GridClickEvent(this, eventCell); | |||
private class CellFocusHandler { | |||
@@ -1920,14 +1917,15 @@ public class Grid<T> extends ResizeComposite implements | |||
private final class UserSorter { | |||
private final Timer timer; | |||
private Cell scheduledCell; | |||
private boolean scheduledMultisort; | |||
private Column<?, T> column; | |||
private UserSorter() { | |||
timer = new Timer() { | |||
@Override | |||
public void run() { | |||
UserSorter.this.sort(scheduledCell, scheduledMultisort); | |||
UserSorter.this.sort(column, scheduledMultisort); | |||
} | |||
}; | |||
} | |||
@@ -1945,9 +1943,14 @@ public class Grid<T> extends ResizeComposite implements | |||
* whether the sort command should act as a multi-sort stack | |||
* or not | |||
*/ | |||
public void sort(Cell cell, boolean multisort) { | |||
public void sort(Column<?, ?> column, boolean multisort) { | |||
if (!columns.contains(column)) { | |||
throw new IllegalArgumentException( | |||
"Given column is not a column in this grid. " | |||
+ column.toString()); | |||
} | |||
final Column<?, T> column = getColumn(cell.getColumn()); | |||
if (!column.isSortable()) { | |||
return; | |||
} | |||
@@ -1993,8 +1996,8 @@ public class Grid<T> extends ResizeComposite implements | |||
* @param delay | |||
* delay, in milliseconds | |||
*/ | |||
public void sortAfterDelay(int delay, Cell cell, boolean multisort) { | |||
scheduledCell = cell; | |||
public void sortAfterDelay(int delay, boolean multisort) { | |||
column = eventCell.getColumn(); | |||
scheduledMultisort = multisort; | |||
timer.schedule(delay); | |||
} | |||
@@ -3430,7 +3433,8 @@ public class Grid<T> extends ResizeComposite implements | |||
return; | |||
} | |||
sorter.sort(event.getFocusedCell(), event.isShiftKeyDown()); | |||
sorter.sort(event.getFocusedCell().getColumn(), | |||
event.isShiftKeyDown()); | |||
} | |||
}); | |||
@@ -4451,6 +4455,7 @@ public class Grid<T> extends ResizeComposite implements | |||
assert cell != null : "received " + eventType | |||
+ "-event with a null cell target"; | |||
eventCell.set(cell); | |||
// Editor can steal focus from Grid and is still handled | |||
if (handleEditorEvent(event, container, cell)) { | |||
@@ -4463,7 +4468,7 @@ public class Grid<T> extends ResizeComposite implements | |||
if (!isElementInChildWidget(e)) { | |||
// Sorting through header Click / KeyUp | |||
if (handleHeaderDefaultRowEvent(event, container, cell)) { | |||
if (handleHeaderDefaultRowEvent(event, container)) { | |||
return; | |||
} | |||
@@ -4471,7 +4476,7 @@ public class Grid<T> extends ResizeComposite implements | |||
return; | |||
} | |||
if (handleNavigationEvent(event, container, cell)) { | |||
if (handleNavigationEvent(event, container)) { | |||
return; | |||
} | |||
@@ -4530,8 +4535,8 @@ public class Grid<T> extends ResizeComposite implements | |||
private boolean handleRendererEvent(Event event, RowContainer container, | |||
Cell cell) { | |||
if (container == escalator.getBody() && cell != null) { | |||
Column<?, T> gridColumn = getColumn(cell.getColumn()); | |||
if (container == escalator.getBody()) { | |||
Column<?, T> gridColumn = eventCell.getColumn(); | |||
boolean enterKey = event.getType().equals(BrowserEvents.KEYDOWN) | |||
&& event.getKeyCode() == KeyCodes.KEY_ENTER; | |||
boolean doubleClick = event.getType() | |||
@@ -4564,8 +4569,7 @@ public class Grid<T> extends ResizeComposite implements | |||
return false; | |||
} | |||
private boolean handleNavigationEvent(Event event, RowContainer unused, | |||
Cell cell) { | |||
private boolean handleNavigationEvent(Event event, RowContainer unused) { | |||
if (!event.getType().equals(BrowserEvents.KEYDOWN)) { | |||
// Only handle key downs | |||
return false; | |||
@@ -4624,14 +4628,14 @@ public class Grid<T> extends ResizeComposite implements | |||
(RowReference<Object>) rowReference); | |||
private boolean handleHeaderDefaultRowEvent(Event event, | |||
RowContainer container, final Cell cell) { | |||
RowContainer container) { | |||
if (container != escalator.getHeader()) { | |||
return false; | |||
} | |||
if (!getHeader().getRow(cell.getRow()).isDefault()) { | |||
if (!getHeader().getRow(eventCell.getRowIndex()).isDefault()) { | |||
return false; | |||
} | |||
if (!getColumn(cell.getColumn()).isSortable()) { | |||
if (!eventCell.getColumn().isSortable()) { | |||
// Only handle sorting events if the column is sortable | |||
return false; | |||
} | |||
@@ -4647,7 +4651,7 @@ public class Grid<T> extends ResizeComposite implements | |||
rowEventTouchStartingPoint = new Point(touch.getClientX(), | |||
touch.getClientY()); | |||
sorter.sortAfterDelay(GridConstants.LONG_TAP_DELAY, cell, true); | |||
sorter.sortAfterDelay(GridConstants.LONG_TAP_DELAY, true); | |||
return true; | |||
@@ -4681,7 +4685,7 @@ public class Grid<T> extends ResizeComposite implements | |||
if (sorter.isDelayedSortScheduled()) { | |||
// Not a long tap yet, perform single sort | |||
sorter.cancelDelayedSort(); | |||
sorter.sort(cell, false); | |||
sorter.sort(eventCell.getColumn(), false); | |||
} | |||
return true; | |||
@@ -4697,7 +4701,7 @@ public class Grid<T> extends ResizeComposite implements | |||
} else if (BrowserEvents.CLICK.equals(event.getType())) { | |||
sorter.sort(cell, event.getShiftKey()); | |||
sorter.sort(eventCell.getColumn(), event.getShiftKey()); | |||
// Click events should go onward to cell focus logic | |||
return false; |
@@ -42,7 +42,6 @@ import com.vaadin.client.renderers.NumberRenderer; | |||
import com.vaadin.client.renderers.Renderer; | |||
import com.vaadin.client.renderers.TextRenderer; | |||
import com.vaadin.client.ui.VLabel; | |||
import com.vaadin.client.widget.escalator.Cell; | |||
import com.vaadin.client.widget.grid.CellReference; | |||
import com.vaadin.client.widget.grid.CellStyleGenerator; | |||
import com.vaadin.client.widget.grid.EditorHandler; | |||
@@ -1050,9 +1049,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyDown(GridKeyDownEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1061,9 +1060,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyDown(GridKeyDownEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1072,9 +1071,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyDown(GridKeyDownEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1084,9 +1083,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyUp(GridKeyUpEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1095,9 +1094,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyUp(GridKeyUpEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1106,9 +1105,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyUp(GridKeyUpEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1118,9 +1117,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyPress(GridKeyPressEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1129,9 +1128,9 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyPress(GridKeyPressEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
@@ -1140,16 +1139,16 @@ public class GridBasicClientFeaturesWidget extends | |||
@Override | |||
public void onKeyPress(GridKeyPressEvent event) { | |||
Cell focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), focused.getRow(), | |||
focused.getColumn()); | |||
CellReference<?> focused = event.getFocusedCell(); | |||
updateLabel(label, event.toDebugString(), | |||
focused.getRowIndex(), focused.getColumnIndex()); | |||
} | |||
}); | |||
} | |||
private void updateLabel(VLabel label, String output, int row, int col) { | |||
String coords = "(" + row + ", " + col + ")"; | |||
private void updateLabel(VLabel label, String output, int object, int column) { | |||
String coords = "(" + object + ", " + column + ")"; | |||
label.setText(coords + " " + output); | |||
} | |||
} |