protected void dispatch(HANDLER handler) {
EventTarget target = getNativeEvent().getEventTarget();
Grid<?> grid = getGrid();
- if (Element.is(target) && grid != null
- && !grid.isElementInChildWidget(Element.as(target))) {
-
+ if (Element.is(target) && grid != null) {
Section section = Section.FOOTER;
final RowContainer container = grid.cellFocusHandler.containerWithFocus;
if (container == grid.escalator.getHeader()) {
section = Section.BODY;
}
+ // Don't handle event of child widget unless the column has been
+ // explicitly permitted to do so
+ if (grid.isElementInChildWidget(Element.as(target))) {
+ Cell cell = container.getCell(target.cast());
+ if (cell != null) {
+ Column<?, ?> column = grid
+ .getVisibleColumn(cell.getColumn());
+ if (column == null || !column.isWidgetEventsAllowed()) {
+ return;
+ }
+ }
+ }
+
doDispatch(handler, section);
}
}
*/
protected boolean ignoreEventFromTarget(Grid<?> grid,
Element targetElement) {
- // Target is some widget inside of Grid
- return grid.isElementInChildWidget(targetElement);
+ boolean childWidget = grid.isElementInChildWidget(targetElement);
+ boolean handleWidgetEvent = false;
+
+ RowContainer container = grid.getEscalator()
+ .findRowContainer(targetElement);
+ if (container != null) {
+ Cell cell = container.getCell(targetElement);
+ if (cell != null) {
+ Column<?, ?> column = grid
+ .getVisibleColumn(cell.getColumn());
+ handleWidgetEvent = column != null
+ && column.isWidgetEventsAllowed();
+ }
+ }
+
+ return childWidget && !handleWidgetEvent;
}
protected abstract void doDispatch(HANDLER handler, Section section);
.toArray(new Column[reordered.size()]);
setColumnOrder(true, array);
transferCellFocusOnDrop();
- } // else no reordering
+ } // else
+ // no
+ // reordering
}
private void transferCellFocusOnDrop() {
private String hidingToggleCaption = null;
+ private boolean widgetEventsAllowed = false;
+
private double minimumWidthPx = GridConstants.DEFAULT_MIN_WIDTH;
private double maximumWidthPx = GridConstants.DEFAULT_MAX_WIDTH;
private int expandRatio = GridConstants.DEFAULT_EXPAND_RATIO;
cell.setText(headerCaption);
}
+ /**
+ * Returns whether Grid should handle events from Widgets in this
+ * Column.
+ *
+ * @return {@code true} to handle events from widgets; {@code false} to
+ * not
+ */
+ public boolean isWidgetEventsAllowed() {
+ return widgetEventsAllowed;
+ }
+
+ /**
+ * Sets whether Grid should handle events from Widgets in this Column.
+ *
+ * @param widgetEventsAllowed
+ * {@code true} to let grid handle events from widgets;
+ * {@code false} to not
+ */
+ public void setWidgetEventsAllowed(boolean widgetEventsAllowed) {
+ this.widgetEventsAllowed = widgetEventsAllowed;
+ }
+
}
protected class BodyUpdater implements EscalatorUpdater {
return (Renderer<?>) getState().renderer;
}
+ /**
+ * Sets whether Grid should handle events in this Column from Components
+ * and Widgets rendered by certain Renderers. By default the events are
+ * not handled.
+ * <p>
+ * <strong>Note:</strong> Enabling this feature will for example select
+ * a row when a component is clicked. For example in the case of a
+ * {@link ComboBox} or {@link TextField} it might be problematic as the
+ * component gets re-rendered and might lose focus.
+ *
+ * @param widgetEventsAllowed
+ * {@code true} to handle events; {@code false} to not
+ * @return this column
+ */
+ public Column<T, V> setWidgetEventsAllowed(
+ boolean widgetEventsAllowed) {
+ if (getState(false).widgetEventsAllowed != widgetEventsAllowed) {
+ getState().widgetEventsAllowed = widgetEventsAllowed;
+ }
+ return this;
+ }
+
+ /**
+ * Gets whether Grid is handling the events in this Column from
+ * Component and Widgets.
+ *
+ * @see #setWidgetEventsAllowed(boolean)
+ *
+ * @return {@code true} if handling events; {@code false} if not
+ */
+ public boolean isWidgetEventsAllowed() {
+ return getState(false).widgetEventsAllowed;
+ }
+
/**
* Gets the grid that this column belongs to.
*
* <p>
* You can add columns for nested properties with dot notation, eg.
* <code>"property.nestedProperty"</code>
-
*
+ *
* @param propertyName
* the property name of the new column, not <code>null</code>
* @param renderer
import java.util.stream.Stream;
import org.junit.Test;
+import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.By;
assertEquals("Other Components", grid.getHeaderCell(0, 1).getText());
}
+ @Test
+ public void testSelectRowByClickingLabel() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+ assertFalse("Row should not be initially selected",
+ grid.getRow(0).isSelected());
+
+ grid.getCell(0, 0).$(LabelElement.class).first().click(10, 10,
+ new Keys[0]);
+ assertTrue("Row should be selected", grid.getRow(0).isSelected());
+ }
+
private void assertRowExists(int i, String string) {
GridRowElement row = $(GridElement.class).first().getRow(i);
assertEquals("Label text did not match", string,