Explorar el Código

Add GridContextClickEvent with item ids, properties and section (#16855)

Change-Id: I03091a3a7a22a921c127ed0b37fe792871ba5edd
tags/7.6.0.alpha7
Teemu Suo-Anttila hace 8 años
padre
commit
dd029323df

+ 1
- 0
WebContent/release-notes.html Ver fichero

@@ -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>

+ 1
- 0
client/src/com/vaadin/client/connectors/ClickableRendererConnector.java Ver fichero

@@ -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;

+ 25
- 0
client/src/com/vaadin/client/connectors/GridConnector.java Ver fichero

@@ -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.
*

+ 2
- 1
client/src/com/vaadin/client/renderers/ClickableRenderer.java Ver fichero

@@ -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

+ 1
- 1
client/src/com/vaadin/client/widget/grid/EventCellReference.java Ver fichero

@@ -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

+ 1
- 1
client/src/com/vaadin/client/widget/grid/events/GridClickEvent.java Ver fichero

@@ -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.

+ 1
- 1
client/src/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java Ver fichero

@@ -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.

+ 1
- 1
client/src/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java Ver fichero

@@ -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.

+ 1
- 1
client/src/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java Ver fichero

@@ -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.

+ 1
- 1
client/src/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java Ver fichero

@@ -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.

+ 1
- 7
client/src/com/vaadin/client/widgets/Grid.java Ver fichero

@@ -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;
@@ -217,13 +218,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.
*

+ 82
- 0
server/src/com/vaadin/ui/Grid.java Ver fichero

@@ -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;
@@ -385,6 +387,73 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
void commitError(CommitErrorEvent event);
}

/**
* 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
*/
@@ -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() {

+ 7
- 0
shared/src/com/vaadin/shared/ui/grid/GridConstants.java Ver fichero

@@ -26,6 +26,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.

+ 19
- 0
shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java Ver fichero

@@ -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
@@ -69,6 +70,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.
*

+ 61
- 0
uitest/src/com/vaadin/tests/contextclick/GridContextClick.java Ver fichero

@@ -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());
}
}

+ 82
- 0
uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java Ver fichero

@@ -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));
}

}

Cargando…
Cancelar
Guardar