diff options
16 files changed, 287 insertions, 14 deletions
diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index 4bda750780..d1cb44e16d 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -121,6 +121,7 @@ GridConnector, GridState, GridServerRpc and GridClientRpc</li> <li>StringToEnumConverter now explicitly supports Enum types with custom toString() implementations. This may affect applications that relied on the undefined behavior in previous versions.</li> + <li>The Section enumeration from client-side of the Grid has been moved to GridConstants</li> </ul> <h3 id="knownissues">Known Issues and Limitations</h3> <ul> diff --git a/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java b/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java index 87f88c5106..9d16a57a17 100644 --- a/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java +++ b/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java @@ -17,6 +17,7 @@ package com.vaadin.client.connectors; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.MouseEventDetailsBuilder; +import com.vaadin.client.renderers.ClickableRenderer; import com.vaadin.client.renderers.ClickableRenderer.RendererClickEvent; import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; import com.vaadin.shared.ui.grid.renderers.RendererClickRpc; diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index bffef05f89..9e57b17714 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -32,6 +32,7 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.dom.client.ContextMenuEvent; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Timer; @@ -54,6 +55,7 @@ import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.CellStyleGenerator; import com.vaadin.client.widget.grid.DetailsGenerator; import com.vaadin.client.widget.grid.EditorHandler; +import com.vaadin.client.widget.grid.EventCellReference; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; import com.vaadin.client.widget.grid.events.BodyClickHandler; @@ -77,6 +79,7 @@ import com.vaadin.client.widgets.Grid.FooterCell; import com.vaadin.client.widgets.Grid.FooterRow; import com.vaadin.client.widgets.Grid.HeaderCell; import com.vaadin.client.widgets.Grid.HeaderRow; +import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.data.sort.SortDirection; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.grid.EditorClientRpc; @@ -84,6 +87,7 @@ 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.GridConstants.Section; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridStaticSectionState; @@ -1188,6 +1192,27 @@ public class GridConnector extends AbstractHasComponentsConnector implements return super.getTooltipInfo(element); } + @Override + protected void sendContextClickEvent(ContextMenuEvent event) { + EventCellReference<JsonObject> eventCell = getWidget().getEventCell(); + + Section section = eventCell.getSection(); + String rowKey = null; + if (eventCell.isBody()) { + rowKey = getRowKey(eventCell.getRow()); + } + + String columnId = getColumnId(eventCell.getColumn()); + MouseEventDetails details = MouseEventDetailsBuilder + .buildMouseEventDetails(event.getNativeEvent()); + + getRpcProxy(GridServerRpc.class).contextClick(eventCell.getRowIndex(), + rowKey, columnId, section, details); + + event.preventDefault(); + event.stopPropagation(); + } + /** * Creates a concatenation of all columns errors for Editor. * diff --git a/client/src/com/vaadin/client/renderers/ClickableRenderer.java b/client/src/com/vaadin/client/renderers/ClickableRenderer.java index 83059f8f01..caffc521d1 100644 --- a/client/src/com/vaadin/client/renderers/ClickableRenderer.java +++ b/client/src/com/vaadin/client/renderers/ClickableRenderer.java @@ -24,6 +24,7 @@ import com.google.gwt.event.dom.client.DomEvent; import com.google.gwt.event.dom.client.MouseEvent; import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.WidgetUtil; @@ -33,7 +34,7 @@ import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.EventCellReference; import com.vaadin.client.widgets.Escalator; import com.vaadin.client.widgets.Grid; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * An abstract superclass for renderers that render clickable widgets. Click diff --git a/client/src/com/vaadin/client/widget/grid/EventCellReference.java b/client/src/com/vaadin/client/widget/grid/EventCellReference.java index 854d91920b..3066e5c1db 100644 --- a/client/src/com/vaadin/client/widget/grid/EventCellReference.java +++ b/client/src/com/vaadin/client/widget/grid/EventCellReference.java @@ -19,7 +19,7 @@ import com.google.gwt.dom.client.TableCellElement; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widgets.Grid; import com.vaadin.client.widgets.Grid.Column; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * A data class which contains information which identifies a cell being the diff --git a/client/src/com/vaadin/client/widget/grid/events/GridClickEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridClickEvent.java index ade878abc6..33a4c923b7 100644 --- a/client/src/com/vaadin/client/widget/grid/events/GridClickEvent.java +++ b/client/src/com/vaadin/client/widget/grid/events/GridClickEvent.java @@ -20,7 +20,7 @@ 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; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Represents native mouse click event in Grid. diff --git a/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java index d67b8df17a..64a1a88b42 100644 --- a/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java +++ b/client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java @@ -20,7 +20,7 @@ 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; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Represents native mouse double click event in Grid. diff --git a/client/src/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java index 2ca7448849..9849137982 100644 --- a/client/src/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java +++ b/client/src/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java @@ -21,7 +21,7 @@ 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; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Represents native key down event in Grid. diff --git a/client/src/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java index 7171814262..35a3af0c2e 100644 --- a/client/src/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java +++ b/client/src/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java @@ -20,7 +20,7 @@ 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; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Represents native key press event in Grid. diff --git a/client/src/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java b/client/src/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java index 2b761a7039..d273835233 100644 --- a/client/src/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java +++ b/client/src/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java @@ -21,7 +21,7 @@ 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; -import com.vaadin.client.widgets.Grid.Section; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Represents native key up event in Grid. diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index f7bbcf8872..0a027349aa 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -165,6 +165,7 @@ import com.vaadin.client.widgets.Grid.StaticSection.StaticCell; import com.vaadin.client.widgets.Grid.StaticSection.StaticRow; import com.vaadin.shared.data.sort.SortDirection; import com.vaadin.shared.ui.grid.GridConstants; +import com.vaadin.shared.ui.grid.GridConstants.Section; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.shared.ui.grid.Range; @@ -218,13 +219,6 @@ public class Grid<T> extends ResizeComposite implements private static final String SELECT_ALL_CHECKBOX_CLASSNAME = "-select-all-checkbox"; /** - * Enum describing different sections of Grid. - */ - public enum Section { - HEADER, BODY, FOOTER - } - - /** * Abstract base class for Grid header and footer sections. * * @since 7.5.0 diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 469f85d947..f0e7b664e0 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -68,6 +68,7 @@ import com.vaadin.data.sort.SortOrder; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.ConverterUtil; +import com.vaadin.event.ContextClickEvent; import com.vaadin.event.ItemClickEvent; import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.event.ItemClickEvent.ItemClickNotifier; @@ -92,6 +93,7 @@ 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.GridConstants.Section; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridStaticCellType; @@ -386,6 +388,73 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** + * ContextClickEvent for the Grid Component. + * + * @since + */ + public static class GridContextClickEvent extends ContextClickEvent { + + private final Object itemId; + private final int rowIndex; + private final Object propertyId; + private final Section section; + + public GridContextClickEvent(Grid source, + MouseEventDetails mouseEventDetails, Section section, + int rowIndex, Object itemId, Object propertyId) { + super(source, mouseEventDetails); + this.itemId = itemId; + this.propertyId = propertyId; + this.section = section; + this.rowIndex = rowIndex; + } + + /** + * Returns the item id of context clicked row. + * + * @return item id of clicked row; <code>null</code> if header or footer + */ + public Object getItemId() { + return itemId; + } + + /** + * Returns property id of clicked column. + * + * @return property id + */ + public Object getPropertyId() { + return propertyId; + } + + /** + * Return the clicked section of Grid. + * + * @return section of grid + */ + public Section getSection() { + return section; + } + + /** + * Returns the clicked row index relative to Grid section. In the body + * of the Grid the index is the item index in the Container. Header and + * Footer rows for index can be fetched with + * {@link Grid#getHeaderRow(int)} and {@link Grid#getFooterRow(int)}. + * + * @return row index in section + */ + public int getRowIndex() { + return rowIndex; + } + + @Override + public Grid getComponent() { + return (Grid) super.getComponent(); + } + } + + /** * An event which is fired when saving the editor fails */ public static class CommitErrorEvent extends Component.Event { @@ -4239,6 +4308,19 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, fireEvent(new EditorCloseEvent(Grid.this, getKeyMapper().get( rowKey))); } + + @Override + public void contextClick(int rowIndex, String rowKey, + String columnId, Section section, MouseEventDetails details) { + Object itemId = null; + if (rowKey != null) { + itemId = getKeyMapper().get(rowKey); + } + + fireEvent(new GridContextClickEvent(Grid.this, details, + section, rowIndex, itemId, + getPropertyIdByColumnId(columnId))); + } }); registerRpc(new EditorServerRpc() { diff --git a/shared/src/com/vaadin/shared/ui/grid/GridConstants.java b/shared/src/com/vaadin/shared/ui/grid/GridConstants.java index 5b2ac96975..ba4a677b5f 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridConstants.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridConstants.java @@ -27,6 +27,13 @@ import java.io.Serializable; public final class GridConstants implements Serializable { /** + * Enum describing different sections of Grid. + */ + public enum Section { + HEADER, BODY, FOOTER + } + + /** * Default padding in pixels when scrolling programmatically, without an * explicitly defined padding value. */ diff --git a/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java b/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java index 8d64794b41..83abc5263e 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java @@ -20,6 +20,7 @@ import java.util.List; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.shared.ui.grid.GridConstants.Section; /** * Client-to-server RPC interface for the Grid component @@ -70,6 +71,24 @@ public interface GridServerRpc extends ServerRpc { void itemClick(String rowKey, String columnId, MouseEventDetails details); /** + * Informs the server that a context click has happened inside of Grid. + * + * @since + * @param rowIndex + * index of clicked row in Grid section + * @param rowKey + * a key identifying the clicked item + * @param columnId + * column id identifying the clicked property + * @param section + * grid section (header, footer, body) + * @param details + * mouse event details + */ + void contextClick(int rowIndex, String rowKey, String columnId, + Section section, MouseEventDetails details); + + /** * Informs the server that the columns of the Grid have been reordered. * * @since 7.5.0 diff --git a/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java b/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java new file mode 100644 index 0000000000..a942a2ab0f --- /dev/null +++ b/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java @@ -0,0 +1,61 @@ +/* + * 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.contextclick; + +import com.vaadin.data.Item; +import com.vaadin.shared.ui.grid.GridConstants.Section; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.GridContextClickEvent; + +public class GridContextClick extends + AbstractContextClickUI<Grid, GridContextClickEvent> { + + @Override + protected Grid createTestComponent() { + Grid grid = new Grid(PersonContainer.createWithTestData()); + grid.setFooterVisible(true); + grid.appendFooterRow(); + + grid.setColumnOrder("address", "email", "firstName", "lastName", + "phoneNumber", "address.streetAddress", "address.postalCode", + "address.city"); + + grid.setSizeFull(); + + return grid; + } + + @Override + protected void handleContextClickEvent(GridContextClickEvent event) { + String value = ""; + Object propertyId = event.getPropertyId(); + if (event.getItemId() != null) { + Item item = event.getComponent().getContainerDataSource() + .getItem(event.getItemId()); + value += item.getItemProperty("firstName").getValue(); + value += " " + item.getItemProperty("lastName").getValue(); + } else if (event.getSection() == Section.HEADER) { + value = event.getComponent().getHeaderRow(event.getRowIndex()) + .getCell(propertyId).getText(); + } else if (event.getSection() == Section.FOOTER) { + value = event.getComponent().getFooterRow(event.getRowIndex()) + .getCell(propertyId).getText(); + } + log("ContextClickEvent value: " + value + ", propertyId: " + propertyId + + ", section: " + event.getSection()); + } +} diff --git a/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java b/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java new file mode 100644 index 0000000000..c4a67f5fc8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java @@ -0,0 +1,82 @@ +/* + * 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.contextclick; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; + +public class GridContextClickTest extends AbstractContextClickTest { + @Test + public void testBodyContextClickWithTypedListener() { + openTestURL(); + + addOrRemoveTypedListener(); + + contextClick($(GridElement.class).first().getCell(0, 0)); + + assertEquals( + "1. ContextClickEvent value: Lisa Schneider, propertyId: address, section: BODY", + getLogRow(0)); + + contextClick($(GridElement.class).first().getCell(0, 3)); + + assertEquals( + "2. ContextClickEvent value: Lisa Schneider, propertyId: lastName, section: BODY", + getLogRow(0)); + } + + @Test + public void testHeaderContextClickWithTypedListener() { + openTestURL(); + + addOrRemoveTypedListener(); + + contextClick($(GridElement.class).first().getHeaderCell(0, 0)); + + assertEquals( + "1. ContextClickEvent value: Address, propertyId: address, section: HEADER", + getLogRow(0)); + + contextClick($(GridElement.class).first().getHeaderCell(0, 3)); + + assertEquals( + "2. ContextClickEvent value: Last Name, propertyId: lastName, section: HEADER", + getLogRow(0)); + } + + @Test + public void testFooterContextClickWithTypedListener() { + openTestURL(); + + addOrRemoveTypedListener(); + + contextClick($(GridElement.class).first().getFooterCell(0, 0)); + + assertEquals( + "1. ContextClickEvent value: , propertyId: address, section: FOOTER", + getLogRow(0)); + + contextClick($(GridElement.class).first().getFooterCell(0, 3)); + + assertEquals( + "2. ContextClickEvent value: , propertyId: lastName, section: FOOTER", + getLogRow(0)); + } + +} |