summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/GridEventHandler.java34
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Grid.java452
2 files changed, 286 insertions, 200 deletions
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/GridEventHandler.java b/client/src/main/java/com/vaadin/client/widget/grid/GridEventHandler.java
new file mode 100644
index 0000000000..181c8e78da
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/widget/grid/GridEventHandler.java
@@ -0,0 +1,34 @@
+/*
+ * 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.widgets.Grid.GridEvent;
+
+/**
+ * A handler for events emitted by elements in Grid.
+ *
+ * @param <T>
+ * the grid row type
+ */
+public interface GridEventHandler<T> {
+ /**
+ * Attempts to handle the given grid event.
+ *
+ * @param event
+ * the event that occurred
+ */
+ public void onEvent(GridEvent<T> event);
+} \ No newline at end of file
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index 6e7f92f8d7..889216e673 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -77,7 +77,6 @@ import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
-
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.DeferredWorker;
import com.vaadin.client.Focusable;
@@ -119,6 +118,7 @@ import com.vaadin.client.widget.grid.DetailsGenerator;
import com.vaadin.client.widget.grid.EditorHandler;
import com.vaadin.client.widget.grid.EditorHandler.EditorRequest;
import com.vaadin.client.widget.grid.EventCellReference;
+import com.vaadin.client.widget.grid.GridEventHandler;
import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator;
import com.vaadin.client.widget.grid.RendererCellReference;
import com.vaadin.client.widget.grid.RowReference;
@@ -1186,6 +1186,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
public static class GridEvent<T> {
private Event event;
private EventCellReference<T> cell;
+ private boolean handled = false;
protected GridEvent(Event event, EventCellReference<T> cell) {
this.event = event;
@@ -1218,6 +1219,25 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
public Grid<T> getGrid() {
return cell.getGrid();
}
+
+ /**
+ * Check whether this event has already been marked as handled.
+ *
+ * @return whether this event has already been marked as handled
+ */
+ public boolean isHandled() {
+ return handled;
+ }
+
+ /**
+ * Set the status of this event. Setting to {@code true} effectively
+ * marks this event as having already been handled.
+ *
+ * @param handled
+ */
+ public void setHandled(boolean handled) {
+ this.handled = handled;
+ }
}
/**
@@ -1451,7 +1471,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
};
/** A set of all the columns that display an error flag. */
- private final Set<Column<?, T>> columnErrors = new HashSet<Grid.Column<?, T>>();
+ private final Set<Column<?, T>> columnErrors = new HashSet<Column<?, T>>();
private boolean buffered = true;
/** Original position of editor */
@@ -2420,27 +2440,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
}
- /**
- * A handler for DOM events emitted by elements in Grid.
- *
- * @param <T>
- * the grid row type
- */
- public interface BrowserEventHandler<T> {
- /**
- * Attempts to handle the given DOM event. Returns whether the event was
- * handled and subsequent handlers should not be run.
- *
- * @param event
- * the event that occurred
- * @param cell
- * the cell where the event occurred
- * @return true if subsequent handlers should not be run, false
- * otherwise
- */
- public boolean onEvent(Event event, EventCellReference<T> cell);
- }
-
private static final String CUSTOM_STYLE_PROPERTY_NAME = "customStyle";
/**
@@ -2534,8 +2533,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
setStyleName(rowWithFocusStyle, rowFocusStyleName, true);
}
} else if (rowWithFocusStyle == row.getElement()
- || (containerWithFocus != escalator.getBody()
- && rowWithFocusStyle != null)) {
+ || containerWithFocus != escalator.getBody()
+ && rowWithFocusStyle != null) {
// Remove focus style.
setStyleName(rowWithFocusStyle, rowFocusStyleName, false);
rowWithFocusStyle = null;
@@ -2832,9 +2831,9 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* a range of added rows
*/
public void rowsAddedToBody(Range added) {
- boolean bodyHasFocus = (containerWithFocus == escalator.getBody());
- boolean insertionIsAboveFocusedCell = (added
- .getStart() <= rowWithFocus);
+ boolean bodyHasFocus = containerWithFocus == escalator.getBody();
+ boolean insertionIsAboveFocusedCell = added
+ .getStart() <= rowWithFocus;
if (bodyHasFocus && insertionIsAboveFocusedCell) {
rowWithFocus += added.length();
rowWithFocus = Math.min(rowWithFocus,
@@ -3351,8 +3350,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
setColumnSizes(columnSizes);
for (Column<?, T> column : nonFixedColumns) {
- final int expandRatio = (defaultExpandRatios ? 1
- : column.getExpandRatio());
+ final int expandRatio = defaultExpandRatios ? 1
+ : column.getExpandRatio();
final double maxWidth = getMaxWidth(column);
final double newWidth = Math.min(maxWidth,
column.getWidthActual());
@@ -3485,8 +3484,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
boolean hasAutoWidth = column.getWidth() < 0;
if (hasAutoWidth && currentWidth < minWidth) {
columnSizes.put(columnIndex, minWidth);
- pixelsToRemoveFromOtherColumns += (minWidth
- - currentWidth);
+ pixelsToRemoveFromOtherColumns += minWidth
+ - currentWidth;
minWidthsCausedReflows = true;
/*
@@ -3905,7 +3904,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
.getFirstChildElement();
double height = WidgetUtil
.getRequiredHeightBoundingClientRectDouble(firstHeaderCell)
- - (WidgetUtil.measureVerticalBorder(getElement()) / 2);
+ - WidgetUtil.measureVerticalBorder(getElement()) / 2;
openCloseButton.setHeight(height + "px");
}
@@ -3964,7 +3963,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private final class ColumnHider {
/** Map from columns to their hiding toggles, component might change */
- private HashMap<Column<?, T>, MenuItem> columnToHidingToggleMap = new HashMap<Grid.Column<?, T>, MenuItem>();
+ private HashMap<Column<?, T>, MenuItem> columnToHidingToggleMap = new HashMap<Column<?, T>, MenuItem>();
/**
* When column is being hidden with a toggle, do not refresh toggles for
@@ -3981,7 +3980,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
toggle.setStyleName("hidden", column.isHidden());
} else if (columnToHidingToggleMap.containsKey(column)) {
sidebar.menuBar
- .removeItem((columnToHidingToggleMap.remove(column)));
+ .removeItem(columnToHidingToggleMap.remove(column));
}
updateTogglesOrder();
}
@@ -4384,8 +4383,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
final int colspan = header.getRow(eventCell.getRowIndex())
.getCell(eventCell.getColumn()).getColspan();
if (latestColumnDropIndex != draggedColumnIndex
- && latestColumnDropIndex != (draggedColumnIndex
- + colspan)) {
+ && latestColumnDropIndex != draggedColumnIndex + colspan) {
List<Column<?, T>> columns = getColumns();
List<Column<?, T>> reordered = new ArrayList<Column<?, T>>();
if (draggedColumnIndex < latestColumnDropIndex) {
@@ -4574,7 +4572,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
}
- if (leftBound == (rightBound - 1)) {
+ if (leftBound == rightBound - 1) {
return;
}
@@ -4603,6 +4601,15 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
};
+ private final List<GridEventHandler<T>> browserEventHandlers = new ArrayList<GridEventHandler<T>>();
+
+ private CellStyleGenerator<T> cellStyleGenerator;
+ private RowStyleGenerator<T> rowStyleGenerator;
+ private RowReference<T> rowReference = new RowReference<T>(this);
+ private CellReference<T> cellReference = new CellReference<T>(rowReference);
+ private RendererCellReference rendererCellReference = new RendererCellReference(
+ (RowReference<Object>) rowReference);
+
/**
* Enumeration for easy setting of selection mode.
*/
@@ -5496,7 +5503,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
setStyleName(rowElement, rowHasDataStyleName, hasData);
}
- boolean isEvenIndex = (row.getRow() % 2 == 0);
+ boolean isEvenIndex = row.getRow() % 2 == 0;
setStyleName(rowElement, rowStripeStyleName, !isEvenIndex);
rowReference.set(rowIndex, rowData, rowElement);
@@ -5734,15 +5741,20 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
&& staticRow instanceof HeaderRow
&& ((HeaderRow) staticRow).isDefault()) {
- final DivElement resizeElement = Document.get().createDivElement();
- resizeElement.addClassName(getStylePrimaryName() + "-column-resize-simple-indicator");
+ final DivElement resizeElement = Document.get()
+ .createDivElement();
+ resizeElement.addClassName(getStylePrimaryName()
+ + "-column-resize-simple-indicator");
final int column = cell.getColumn();
- final DragHandle dragger = new DragHandle(getStylePrimaryName() + "-column-resize-handle");
+ final DragHandle dragger = new DragHandle(
+ getStylePrimaryName() + "-column-resize-handle");
dragger.addTo(td);
- // Common functionality for drag handle callback implementations
- abstract class AbstractDHCallback implements DragHandleCallback {
+ // Common functionality for drag handle callback
+ // implementations
+ abstract class AbstractDHCallback
+ implements DragHandleCallback {
protected Column<?, T> col = getVisibleColumn(column);
protected double initialWidth = 0;
protected double minCellWidth;
@@ -5752,7 +5764,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
initialWidth = col.getWidthActual();
width = initialWidth;
- minCellWidth = escalator.getMinCellWidth(getVisibleColumns().indexOf(col));
+ minCellWidth = escalator.getMinCellWidth(
+ getVisibleColumns().indexOf(col));
for (Column<?, T> c : getVisibleColumns()) {
if (selectionColumn == c) {
// Don't modify selection column.
@@ -5765,15 +5778,18 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
}
- WidgetUtil.setTextSelectionEnabled(getElement(), false);
+ WidgetUtil.setTextSelectionEnabled(getElement(),
+ false);
}
protected void dragEnded() {
- WidgetUtil.setTextSelectionEnabled(getElement(), true);
+ WidgetUtil.setTextSelectionEnabled(getElement(),
+ true);
}
}
final DragHandleCallback simpleResizeMode = new AbstractDHCallback() {
+ @Override
protected void dragEnded() {
super.dragEnded();
dragger.getElement().removeChild(resizeElement);
@@ -5783,14 +5799,24 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
public void onStart() {
dragStarted();
dragger.getElement().appendChild(resizeElement);
- resizeElement.getStyle().setLeft((dragger.getElement().getOffsetWidth() - resizeElement.getOffsetWidth()) * .5, Unit.PX);
- resizeElement.getStyle().setHeight(col.grid.getOffsetHeight(), Unit.PX);
+ resizeElement.getStyle()
+ .setLeft((dragger.getElement()
+ .getOffsetWidth()
+ - resizeElement.getOffsetWidth())
+ * .5, Unit.PX);
+ resizeElement.getStyle().setHeight(
+ col.grid.getOffsetHeight(), Unit.PX);
}
@Override
public void onUpdate(double deltaX, double deltaY) {
- width = Math.max(minCellWidth, initialWidth + deltaX);
- resizeElement.getStyle().setLeft((dragger.getElement().getOffsetWidth() - resizeElement.getOffsetWidth()) * .5 + (width - initialWidth), Unit.PX);
+ width = Math.max(minCellWidth,
+ initialWidth + deltaX);
+ resizeElement.getStyle().setLeft(
+ (dragger.getElement().getOffsetWidth()
+ - resizeElement.getOffsetWidth())
+ * .5 + (width - initialWidth),
+ Unit.PX);
}
@Override
@@ -5815,7 +5841,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
@Override
public void onUpdate(double deltaX, double deltaY) {
- width = Math.max(minCellWidth, initialWidth + deltaX);
+ width = Math.max(minCellWidth,
+ initialWidth + deltaX);
col.setWidth(width);
}
@@ -5833,7 +5860,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
};
- // DragHandle gets assigned a 'master callback' that delegates
+ // DragHandle gets assigned a 'master callback' that
+ // delegates
// functionality to the correct case-specific implementation
dragger.setCallback(new DragHandleCallback() {
@@ -5841,15 +5869,16 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
@Override
public void onStart() {
- switch(getColumnResizeMode()) {
- case SIMPLE:
- currentCallback = simpleResizeMode;
- break;
- case ANIMATED:
- currentCallback = animatedResizeMode;
- break;
- default:
- throw new UnsupportedOperationException("Support for current column resize mode is not yet implemented");
+ switch (getColumnResizeMode()) {
+ case SIMPLE:
+ currentCallback = simpleResizeMode;
+ break;
+ case ANIMATED:
+ currentCallback = animatedResizeMode;
+ break;
+ default:
+ throw new UnsupportedOperationException(
+ "Support for current column resize mode is not yet implemented");
}
currentCallback.onStart();
@@ -5857,7 +5886,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
@Override
public void onUpdate(double deltaX, double deltaY) {
- currentCallback.onUpdate(deltaX,deltaY);
+ currentCallback.onUpdate(deltaX, deltaY);
}
@Override
@@ -6094,6 +6123,19 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
});
+ browserEventHandlers.addAll(Arrays.asList(
+ // Opening, closing and navigating in the editor
+ new EditorEventHandler(),
+ // Keyboard and click handlers, Escalator events
+ new SuperEventHandler(),
+ // Column reordering via header drag&drop
+ new HeaderCellDragStartHandler(),
+ // Column sorting via header click
+ new HeaderDefaultRowEventHandler(),
+ // Invoking event-aware renderers
+ new RendererEventHandler(),
+ // Moving cell focus by keyboard or mouse
+ new CellFocusEventHandler()));
}
@Override
@@ -6128,10 +6170,11 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private ColumnResizeMode columnResizeMode = ColumnResizeMode.ANIMATED;
/**
- * Sets the column resize mode to use. The default mode is {@link ColumnResizeMode.ANIMATED}.
+ * Sets the column resize mode to use. The default mode is
+ * {@link ColumnResizeMode.ANIMATED}.
*
- * @param mode a ColumnResizeMode value
- *
+ * @param mode
+ * a ColumnResizeMode value
* @since 7.7.5
*/
public void setColumnResizeMode(ColumnResizeMode mode) {
@@ -6139,7 +6182,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
- * Returns the current column resize mode. The default mode is {@link ColumnResizeMode.ANIMATED}.
+ * Returns the current column resize mode. The default mode is
+ * {@link ColumnResizeMode.ANIMATED}.
*
* @return a ColumnResizeMode value
*
@@ -7331,35 +7375,9 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
+ "-event with a null cell target";
eventCell.set(cell, getSectionFromContainer(container));
- // Editor can steal focus from Grid and is still handled
- if (editorEventHandler.onEvent(event, eventCell)) {
- return;
- }
-
- // Fire GridKeyEvents and GridClickEvents. Pass the event to escalator.
- if (superEventHandler.onEvent(event, eventCell)) {
- return;
- }
-
- if (childWidgetEventHandler.onEvent(event, eventCell)) {
- return;
- }
-
- if (headerCellDragStartHandler.onEvent(event, eventCell)) {
- return;
- }
-
- // Sorting through header Click / KeyUp
- if (headerDefaultRowEventHandler.onEvent(event, eventCell)) {
- return;
- }
-
- if (rendererEventHandler.onEvent(event, eventCell)) {
- return;
- }
-
- if (cellFocusEventHandler.onEvent(event, eventCell)) {
- return;
+ GridEvent<T> gridEvent = new GridEvent<T>(event, eventCell);
+ for (GridEventHandler<T> handler : browserEventHandlers) {
+ handler.onEvent(gridEvent);
}
}
@@ -7412,12 +7430,12 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
return w != null;
}
- private BrowserEventHandler<T> editorEventHandler = new BrowserEventHandler<T>() {
+ private class EditorEventHandler implements GridEventHandler<T> {
@Override
- public boolean onEvent(Event event, EventCellReference<T> eventCell) {
+ public void onEvent(GridEvent<T> event) {
if (!isEditorEnabled()) {
- return false;
+ return;
}
Widget widget;
@@ -7427,162 +7445,184 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
widget = editor.getWidget(getColumn(editor.focusedColumnIndex));
}
- EditorDomEvent<T> editorEvent = new EditorDomEvent<T>(event, eventCell, widget);
+ EditorDomEvent<T> editorEvent = new EditorDomEvent<T>(
+ event.getDomEvent(), event.getCell(), widget);
- return getEditor().getEventHandler().handleEvent(editorEvent);
+ event.setHandled(
+ getEditor().getEventHandler().handleEvent(editorEvent));
}
};
- private BrowserEventHandler<T> superEventHandler = new BrowserEventHandler<T>() {
+ private class SuperEventHandler implements GridEventHandler<T> {
@Override
- public boolean onEvent(Event event, EventCellReference<T> cell) {
- Grid.super.onBrowserEvent(event);
- return false;
+ public void onEvent(GridEvent<T> event) {
+ if (event.isHandled()) {
+ return;
+ }
+ Grid.super.onBrowserEvent(event.getDomEvent());
}
};
- private BrowserEventHandler<T> childWidgetEventHandler = new BrowserEventHandler<T>() {
+ private abstract class AbstractGridEventHandler
+ implements GridEventHandler<T> {
@Override
- public boolean onEvent(Event e, EventCellReference<T> cell) {
- return isElementInChildWidget(Element.as(e.getEventTarget()));
+ public void onEvent(GridEvent<T> event) {
+ if (event.isHandled()) {
+ return;
+ }
+ event.setHandled(isElementInChildWidget(
+ Element.as(event.getDomEvent().getEventTarget())));
}
};
- private BrowserEventHandler<T> rendererEventHandler = new BrowserEventHandler<T>() {
+ private class RendererEventHandler extends AbstractGridEventHandler {
@Override
- public boolean onEvent(Event e, EventCellReference<T> cell) {
-
- if (!cell.isBody()) {
- return false;
+ public void onEvent(GridEvent<T> event) {
+ super.onEvent(event);
+ if (event.isHandled()) {
+ return;
+ }
+ if (!event.getCell().isBody()) {
+ return;
}
- Column<?, T> gridColumn = cell.getColumn();
- boolean enterKey = e.getType().equals(BrowserEvents.KEYDOWN)
- && e.getKeyCode() == KeyCodes.KEY_ENTER;
- boolean doubleClick = e.getType()
+ Column<?, T> gridColumn = event.getCell().getColumn();
+ boolean enterKey = event.getDomEvent().getType()
+ .equals(BrowserEvents.KEYDOWN)
+ && event.getDomEvent().getKeyCode() == KeyCodes.KEY_ENTER;
+ boolean doubleClick = event.getDomEvent().getType()
.equals(BrowserEvents.DBLCLICK);
if (gridColumn.getRenderer() instanceof ComplexRenderer) {
ComplexRenderer<?> cplxRenderer = (ComplexRenderer<?>) gridColumn
.getRenderer();
- if (cplxRenderer.getConsumedEvents().contains(e
- .getType())) {
- if (cplxRenderer.onBrowserEvent(cell, e)) {
- return true;
+ if (cplxRenderer.getConsumedEvents()
+ .contains(event.getDomEvent().getType())) {
+ if (cplxRenderer.onBrowserEvent(event.getCell(),
+ event.getDomEvent())) {
+ event.setHandled(true);
}
}
// Calls onActivate if KeyDown and Enter or double click
if ((enterKey || doubleClick)
- && cplxRenderer.onActivate(cell)) {
- return true;
+ && cplxRenderer.onActivate(event.getCell())) {
+ event.setHandled(true);
}
}
- return false;
}
};
- private BrowserEventHandler<T> cellFocusEventHandler = new BrowserEventHandler<T>() {
+ private class CellFocusEventHandler extends AbstractGridEventHandler {
@Override
- public boolean onEvent(Event e, EventCellReference<T> cell) {
+ public void onEvent(GridEvent<T> event) {
+ super.onEvent(event);
+ if (event.isHandled()) {
+ return;
+ }
+
Collection<String> navigation = cellFocusHandler
.getNavigationEvents();
- if (navigation.contains(e.getType())) {
- cellFocusHandler.handleNavigationEvent(e, cell);
+ if (navigation.contains(event.getDomEvent().getType())) {
+ cellFocusHandler.handleNavigationEvent(event.getDomEvent(),
+ event.getCell());
}
- return false;
}
};
- private BrowserEventHandler<T> headerCellDragStartHandler = new BrowserEventHandler<T>() {
+ private class HeaderCellDragStartHandler extends AbstractGridEventHandler {
@Override
- public boolean onEvent(Event e, EventCellReference<T> cell) {
+ public void onEvent(GridEvent<T> event) {
+ super.onEvent(event);
+ if (event.isHandled()) {
+ return;
+ }
if (!isColumnReorderingAllowed()) {
- return false;
+ return;
}
- if (!cell.isHeader()) {
- return false;
+ if (!event.getCell().isHeader()) {
+ return;
}
- if (cell.getColumnIndex() < escalator.getColumnConfiguration()
- .getFrozenColumnCount()) {
- return false;
+ if (event.getCell().getColumnIndex() < escalator
+ .getColumnConfiguration().getFrozenColumnCount()) {
+ return;
}
- if (e.getTypeInt() == Event.ONMOUSEDOWN
- && e.getButton() == NativeEvent.BUTTON_LEFT
- || e.getTypeInt() == Event.ONTOUCHSTART) {
- dndHandler.onDragStartOnDraggableElement(e,
+ if (event.getDomEvent().getTypeInt() == Event.ONMOUSEDOWN
+ && event.getDomEvent()
+ .getButton() == NativeEvent.BUTTON_LEFT
+ || event.getDomEvent().getTypeInt() == Event.ONTOUCHSTART) {
+ dndHandler.onDragStartOnDraggableElement(event.getDomEvent(),
headerCellDndCallback);
- e.preventDefault();
- e.stopPropagation();
- return true;
+ event.getDomEvent().preventDefault();
+ event.getDomEvent().stopPropagation();
+ event.setHandled(true);
}
- return false;
}
};
- private CellStyleGenerator<T> cellStyleGenerator;
- private RowStyleGenerator<T> rowStyleGenerator;
- private RowReference<T> rowReference = new RowReference<T>(this);
- private CellReference<T> cellReference = new CellReference<T>(rowReference);
- private RendererCellReference rendererCellReference = new RendererCellReference(
- (RowReference<Object>) rowReference);
-
- private BrowserEventHandler<T> headerDefaultRowEventHandler = new BrowserEventHandler<T>() {
+ private class HeaderDefaultRowEventHandler
+ extends AbstractGridEventHandler {
private Point rowEventTouchStartingPoint;
@Override
- public boolean onEvent(Event event, EventCellReference<T> cell) {
- if (!cell.isHeader()) {
- return false;
+ public void onEvent(GridEvent<T> event) {
+ super.onEvent(event);
+ if (event.isHandled()) {
+ return;
}
- if (!getHeader().getRow(cell.getRowIndex()).isDefault()) {
- return false;
+ if (!event.getCell().isHeader()) {
+ return;
}
- if (!cell.getColumn().isSortable()) {
+ if (!getHeader().getRow(event.getCell().getRowIndex())
+ .isDefault()) {
+ return;
+ }
+ if (!event.getCell().getColumn().isSortable()) {
// Only handle sorting events if the column is sortable
- return false;
+ return;
}
- if (BrowserEvents.MOUSEDOWN.equals(event.getType())
- && event.getShiftKey()) {
+ if (BrowserEvents.MOUSEDOWN.equals(event.getDomEvent().getType())
+ && event.getDomEvent().getShiftKey()) {
// Don't select text when shift clicking on a header.
- event.preventDefault();
+ event.getDomEvent().preventDefault();
}
- if (BrowserEvents.TOUCHSTART.equals(event.getType())) {
- if (event.getTouches().length() > 1) {
- return false;
+ if (BrowserEvents.TOUCHSTART
+ .equals(event.getDomEvent().getType())) {
+ if (event.getDomEvent().getTouches().length() > 1) {
+ return;
}
- event.preventDefault();
+ event.getDomEvent().preventDefault();
- Touch touch = event.getChangedTouches().get(0);
+ Touch touch = event.getDomEvent().getChangedTouches().get(0);
rowEventTouchStartingPoint = new Point(touch.getClientX(),
touch.getClientY());
sorter.sortAfterDelay(GridConstants.LONG_TAP_DELAY, true);
- return true;
-
- } else if (BrowserEvents.TOUCHMOVE.equals(event.getType())) {
- if (event.getTouches().length() > 1) {
- return false;
+ event.setHandled(true);
+ } else if (BrowserEvents.TOUCHMOVE
+ .equals(event.getDomEvent().getType())) {
+ if (event.getDomEvent().getTouches().length() > 1) {
+ return;
}
- event.preventDefault();
+ event.getDomEvent().preventDefault();
- Touch touch = event.getChangedTouches().get(0);
- double diffX = Math.abs(
- touch.getClientX() - rowEventTouchStartingPoint.getX());
- double diffY = Math.abs(
- touch.getClientY() - rowEventTouchStartingPoint.getY());
+ Touch touch = event.getDomEvent().getChangedTouches().get(0);
+ double diffX = Math.abs(
+ touch.getClientX() - rowEventTouchStartingPoint.getX());
+ double diffY = Math.abs(
+ touch.getClientY() - rowEventTouchStartingPoint.getY());
// Cancel long tap if finger strays too far from
// starting point
@@ -7591,38 +7631,34 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
sorter.cancelDelayedSort();
}
- return true;
-
- } else if (BrowserEvents.TOUCHEND.equals(event.getType())) {
- if (event.getTouches().length() > 1) {
- return false;
+ event.setHandled(true);
+ } else if (BrowserEvents.TOUCHEND
+ .equals(event.getDomEvent().getType())) {
+ if (event.getDomEvent().getTouches().length() > 1) {
+ return;
}
if (sorter.isDelayedSortScheduled()) {
// Not a long tap yet, perform single sort
sorter.cancelDelayedSort();
- sorter.sort(cell.getColumn(), false);
+ sorter.sort(event.getCell().getColumn(), false);
}
- return true;
-
- } else if (BrowserEvents.TOUCHCANCEL.equals(event.getType())) {
- if (event.getTouches().length() > 1) {
- return false;
+ event.setHandled(true);
+ } else if (BrowserEvents.TOUCHCANCEL
+ .equals(event.getDomEvent().getType())) {
+ if (event.getDomEvent().getTouches().length() > 1) {
+ return;
}
sorter.cancelDelayedSort();
- return true;
-
- } else if (BrowserEvents.CLICK.equals(event.getType())) {
+ event.setHandled(true);
+ } else if (BrowserEvents.CLICK
+ .equals(event.getDomEvent().getType())) {
- sorter.sort(cell.getColumn(), event.getShiftKey());
-
- // Click events should go onward to cell focus logic
- return false;
- } else {
- return false;
+ sorter.sort(event.getCell().getColumn(),
+ event.getDomEvent().getShiftKey());
}
}
};
@@ -7901,7 +7937,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
*/
public boolean deselectAll() {
if (selectionModel instanceof SelectionModel.Single<?>) {
- Single<T> single = ((SelectionModel.Single<T>) selectionModel);
+ Single<T> single = (SelectionModel.Single<T>) selectionModel;
if (single.getSelectedRow() != null) {
return single.deselect(single.getSelectedRow());
} else {
@@ -8351,6 +8387,22 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
+ * Adds a low-level DOM event handler to this Grid. The handler is inserted
+ * into the given position in the list of handlers. The handlers are invoked
+ * in order. If the
+ * {@link GridEventHandler#onEvent(Event, EventCellReference) onEvent}
+ * method of a handler returns true, subsequent handlers are not invoked.
+ *
+ * @param index
+ * the index to insert the handler to
+ * @param handler
+ * the handler to add
+ */
+ public void addBrowserEventHandler(int index, GridEventHandler<T> handler) {
+ browserEventHandlers.add(index, handler);
+ }
+
+ /**
* Apply sorting to data source.
*/
private void sort(boolean userOriginated) {