diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-01-09 14:55:13 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-14 10:25:13 +0000 |
commit | 35372dc1d3ede9d2005ac8bda5d5a7e4f3aba98d (patch) | |
tree | 9a387eeef20e858d9d586c7c02141f6273277945 /client | |
parent | dcfebeb46143d8e9c21424c572c48d2217c80477 (diff) | |
download | vaadin-framework-35372dc1d3ede9d2005ac8bda5d5a7e4f3aba98d.tar.gz vaadin-framework-35372dc1d3ede9d2005ac8bda5d5a7e4f3aba98d.zip |
Add ItemClickEvents to Grid (#15449)
Change-Id: I743f4de9fd11c5d81b11a3b8f2e0957293c5587c
Diffstat (limited to 'client')
7 files changed, 235 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index a2e63fc397..98562a871e 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -29,9 +29,11 @@ import java.util.logging.Logger; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorHierarchyChangeEvent; +import com.vaadin.client.MouseEventDetailsBuilder; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.connectors.RpcDataSourceConnector.RpcDataSource; @@ -45,6 +47,10 @@ import com.vaadin.client.widget.grid.CellStyleGenerator; import com.vaadin.client.widget.grid.EditorHandler; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; +import com.vaadin.client.widget.grid.events.BodyClickHandler; +import com.vaadin.client.widget.grid.events.BodyDoubleClickHandler; +import com.vaadin.client.widget.grid.events.GridClickEvent; +import com.vaadin.client.widget.grid.events.GridDoubleClickEvent; import com.vaadin.client.widget.grid.events.SelectAllEvent; import com.vaadin.client.widget.grid.events.SelectAllHandler; import com.vaadin.client.widget.grid.selection.AbstractRowHandleSelectionModel; @@ -68,6 +74,7 @@ import com.vaadin.shared.ui.grid.EditorClientRpc; import com.vaadin.shared.ui.grid.EditorServerRpc; import com.vaadin.shared.ui.grid.GridClientRpc; import com.vaadin.shared.ui.grid.GridColumnState; +import com.vaadin.shared.ui.grid.GridConstants; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridState.SharedSelectionMode; @@ -304,6 +311,35 @@ public class GridConnector extends AbstractHasComponentsConnector implements } } + private class ItemClickHandler implements BodyClickHandler, + BodyDoubleClickHandler { + + @Override + public void onClick(GridClickEvent event) { + if (hasEventListener(GridConstants.ITEM_CLICK_EVENT_ID)) { + fireItemClick(event.getTargetCell(), event.getNativeEvent()); + } + } + + @Override + public void onDoubleClick(GridDoubleClickEvent event) { + if (hasEventListener(GridConstants.ITEM_CLICK_EVENT_ID)) { + fireItemClick(event.getTargetCell(), event.getNativeEvent()); + } + } + + private void fireItemClick(CellReference<?> cell, NativeEvent mouseEvent) { + String rowKey = getRowKey((JsonObject) cell.getRow()); + String columnId = getColumnId(cell.getColumn()); + getRpcProxy(GridServerRpc.class) + .itemClick( + rowKey, + columnId, + MouseEventDetailsBuilder + .buildMouseEventDetails(mouseEvent)); + } + } + /** * Maps a generated column id to a grid column instance */ @@ -347,6 +383,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements } }; + private ItemClickHandler itemClickHandler = new ItemClickHandler(); + @Override @SuppressWarnings("unchecked") public Grid<JsonObject> getWidget() { @@ -397,6 +435,10 @@ public class GridConnector extends AbstractHasComponentsConnector implements getWidget().addSelectionHandler(internalSelectionChangeHandler); + /* Item click events */ + getWidget().addBodyClickHandler(itemClickHandler); + getWidget().addBodyDoubleClickHandler(itemClickHandler); + getWidget().addSortHandler(new SortHandler<JsonObject>() { @Override public void sort(SortEvent<JsonObject> event) { @@ -881,7 +923,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { } - public String getColumnId(Grid.Column<?, JsonObject> column) { + public String getColumnId(Grid.Column<?, ?> column) { if (column instanceof CustomGridColumn) { return ((CustomGridColumn) column).id; } diff --git a/client/src/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java b/client/src/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java index f72dcc37d2..15e22a6d57 100644 --- a/client/src/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java +++ b/client/src/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java @@ -31,4 +31,9 @@ public abstract interface AbstractGridMouseEventHandler extends EventHandler { public void onClick(GridClickEvent event); } + public abstract interface GridDoubleClickHandler extends + AbstractGridMouseEventHandler { + public void onDoubleClick(GridDoubleClickEvent event); + } + }
\ No newline at end of file diff --git a/client/src/com/vaadin/client/widget/grid/events/BodyDoubleClickHandler.java b/client/src/com/vaadin/client/widget/grid/events/BodyDoubleClickHandler.java new file mode 100644 index 0000000000..a7be5bad24 --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/BodyDoubleClickHandler.java @@ -0,0 +1,29 @@ +/* + * 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.events; + +import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridDoubleClickHandler; + +/** + * Handler for {@link GridDoubleClickEvent}s that happen in the body of the + * Grid. + * + * @since + * @author Vaadin Ltd + */ +public interface BodyDoubleClickHandler extends GridDoubleClickHandler { + +} diff --git a/client/src/com/vaadin/client/widget/grid/events/FooterDoubleClickHandler.java b/client/src/com/vaadin/client/widget/grid/events/FooterDoubleClickHandler.java new file mode 100644 index 0000000000..3bb9c9ee72 --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/FooterDoubleClickHandler.java @@ -0,0 +1,29 @@ +/* + * 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.events; + +import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridDoubleClickHandler; + +/** + * Handler for {@link GridDoubleClickEvent}s that happen in the footer of the + * Grid. + * + * @since + * @author Vaadin Ltd + */ +public interface FooterDoubleClickHandler extends GridDoubleClickHandler { + +} diff --git a/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java new file mode 100644 index 0000000000..20e432aa85 --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java @@ -0,0 +1,52 @@ +/* + * 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.events; + +import com.google.gwt.dom.client.BrowserEvents; +import com.vaadin.client.widget.grid.CellReference; +import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridDoubleClickHandler; +import com.vaadin.client.widgets.Grid; +import com.vaadin.client.widgets.Grid.AbstractGridMouseEvent; +import com.vaadin.client.widgets.Grid.Section; + +/** + * Represents native mouse double click event in Grid. + * + * @since + * @author Vaadin Ltd + */ +public class GridDoubleClickEvent extends + AbstractGridMouseEvent<GridDoubleClickHandler> { + + public GridDoubleClickEvent(Grid<?> grid, CellReference<?> targetCell) { + super(grid, targetCell); + } + + @Override + protected String getBrowserEventType() { + return BrowserEvents.DBLCLICK; + } + + @Override + protected void doDispatch(GridDoubleClickHandler handler, Section section) { + if ((section == Section.BODY && handler instanceof BodyDoubleClickHandler) + || (section == Section.HEADER && handler instanceof HeaderDoubleClickHandler) + || (section == Section.FOOTER && handler instanceof FooterDoubleClickHandler)) { + handler.onDoubleClick(this); + } + } + +} diff --git a/client/src/com/vaadin/client/widget/grid/events/HeaderDoubleClickHandler.java b/client/src/com/vaadin/client/widget/grid/events/HeaderDoubleClickHandler.java new file mode 100644 index 0000000000..7ebb0c17f8 --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/HeaderDoubleClickHandler.java @@ -0,0 +1,29 @@ +/* + * 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.events; + +import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridDoubleClickHandler; + +/** + * Handler for {@link GridDoubleClickEvent}s that happen in the header of the + * Grid. + * + * @since + * @author Vaadin Ltd + */ +public interface HeaderDoubleClickHandler extends GridDoubleClickHandler { + +} diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index d401b4da78..18115b2a3b 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -89,18 +89,22 @@ import com.vaadin.client.widget.grid.RowStyleGenerator; import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler; import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler; import com.vaadin.client.widget.grid.events.BodyClickHandler; +import com.vaadin.client.widget.grid.events.BodyDoubleClickHandler; import com.vaadin.client.widget.grid.events.BodyKeyDownHandler; import com.vaadin.client.widget.grid.events.BodyKeyPressHandler; import com.vaadin.client.widget.grid.events.BodyKeyUpHandler; import com.vaadin.client.widget.grid.events.FooterClickHandler; +import com.vaadin.client.widget.grid.events.FooterDoubleClickHandler; import com.vaadin.client.widget.grid.events.FooterKeyDownHandler; import com.vaadin.client.widget.grid.events.FooterKeyPressHandler; import com.vaadin.client.widget.grid.events.FooterKeyUpHandler; import com.vaadin.client.widget.grid.events.GridClickEvent; +import com.vaadin.client.widget.grid.events.GridDoubleClickEvent; import com.vaadin.client.widget.grid.events.GridKeyDownEvent; import com.vaadin.client.widget.grid.events.GridKeyPressEvent; import com.vaadin.client.widget.grid.events.GridKeyUpEvent; import com.vaadin.client.widget.grid.events.HeaderClickHandler; +import com.vaadin.client.widget.grid.events.HeaderDoubleClickHandler; import com.vaadin.client.widget.grid.events.HeaderKeyDownHandler; import com.vaadin.client.widget.grid.events.HeaderKeyPressHandler; import com.vaadin.client.widget.grid.events.HeaderKeyUpHandler; @@ -1450,6 +1454,8 @@ public class Grid<T> extends ResizeComposite implements private GridKeyUpEvent keyUp = new GridKeyUpEvent(this, eventCell); private GridKeyPressEvent keyPress = new GridKeyPressEvent(this, eventCell); private GridClickEvent clickEvent = new GridClickEvent(this, eventCell); + private GridDoubleClickEvent doubleClickEvent = new GridDoubleClickEvent( + this, eventCell); private class CellFocusHandler { @@ -5358,6 +5364,48 @@ public class Grid<T> extends ResizeComposite implements } /** + * Register a BodyDoubleClickHandler to this Grid. The event for this + * handler is fired when a double click event occurs in the Body of this + * Grid. + * + * @param handler + * the double click handler to register + * @return the registration for the event + */ + public HandlerRegistration addBodyDoubleClickHandler( + BodyDoubleClickHandler handler) { + return addHandler(handler, doubleClickEvent.getAssociatedType()); + } + + /** + * Register a HeaderDoubleClickHandler to this Grid. The event for this + * handler is fired when a double click event occurs in the Header of this + * Grid. + * + * @param handler + * the double click handler to register + * @return the registration for the event + */ + public HandlerRegistration addHeaderDoubleClickHandler( + HeaderDoubleClickHandler handler) { + return addHandler(handler, doubleClickEvent.getAssociatedType()); + } + + /** + * Register a FooterDoubleClickHandler to this Grid. The event for this + * handler is fired when a double click event occurs in the Footer of this + * Grid. + * + * @param handler + * the double click handler to register + * @return the registration for the event + */ + public HandlerRegistration addFooterDoubleClickHandler( + FooterDoubleClickHandler handler) { + return addHandler(handler, doubleClickEvent.getAssociatedType()); + } + + /** * Apply sorting to data source. */ private void sort(boolean userOriginated) { |