Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Maintenance release picks #259

Merged
merged 4 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/main/java/com/vaadin/flow/component/grid/Grid.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public static class Column<T> extends AbstractColumn<Column<T>> {

private Registration columnDataGeneratorRegistration;

private Renderer<T> renderer;

/**
* Constructs a new Column for use inside a Grid.
*
Expand All @@ -252,11 +254,13 @@ public static class Column<T> extends AbstractColumn<Column<T>> {
* @param columnId
* unique identifier of this column
* @param renderer
* the renderer to use in this column
* the renderer to use in this column, must not be {@code null}
*/
public Column(Grid<T> grid, String columnId, Renderer<T> renderer) {
super(grid);
Objects.requireNonNull(renderer);
this.columnInternalId = columnId;
this.renderer = renderer;

comparator = (a, b) -> 0;

Expand Down Expand Up @@ -285,6 +289,19 @@ protected String getInternalId() {
return columnInternalId;
}

/**
* Get the renderer used for this column.
*
* Note: Mutating the renderer after the Grid has been rendered
* on the client will not change the column, and can lead to
* undefined behavior.
*
* @return the renderer used for this column, should never be {@code null}
*/
public Renderer<T> getRenderer() {
return renderer;
}

/**
* Sets the width of this column as a CSS-string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ window.Vaadin.Flow.gridConnector = {
}
}

const sorterChangeListener = function(event) {
const sorterChangeListener = function() {
grid.$server.sortersChanged(grid._sorters.map(function(sorter) {
return {
path: sorter.path,
direction: sorter.direction
};
}));
}
grid.addEventListener('sorter-changed', sorterChangeListener);
grid._createPropertyObserver("_previousSorters", sorterChangeListener);

const itemsUpdated = function(items) {
if (!items || !Array.isArray(items)) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/vaadin/flow/component/grid/GridColumnTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.data.provider.SortDirection;
import com.vaadin.flow.data.renderer.IconRenderer;
import com.vaadin.flow.function.SerializableComparator;
import com.vaadin.flow.function.SerializableFunction;

public class GridColumnTest {

Grid<String> grid;
Column<String> firstColumn;
Column<String> secondColumn;
Column<String> thirdColumn;
Column<String> fourthColumn;

IconRenderer<String> renderer;

@Rule
public ExpectedException thrown = ExpectedException.none();
Expand All @@ -41,6 +48,8 @@ public void init() {
firstColumn = grid.addColumn(str -> str);
secondColumn = grid.addColumn(str -> str);
thirdColumn = grid.addColumn(str -> str);
renderer = new IconRenderer<String>(generator -> new Label(":D"));
fourthColumn = grid.addColumn(renderer);
}

@Test
Expand Down Expand Up @@ -164,6 +173,11 @@ public void addColumn_defaultComparator() {
-1, result);
}

@Test
public void testRenderer() {
assert renderer!= null;
Assert.assertEquals(renderer, fourthColumn.getRenderer());
}
private void expectNullPointerException(String message) {
thrown.expect(NullPointerException.class);
thrown.expectMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.vaadin.flow.component.grid.it;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
Expand All @@ -30,15 +29,6 @@
public class ButtonInGridIT extends AbstractComponentIT {

@Test
@Ignore
/**
* The test is disabled due #4268. The test is for grid#122 (which is
* actually an issue in the flow-component-renderer inside flow-data
* module).
*
* At the moment the bug is not fixed. So the test fails. Should be enabled
* back once the gird#122 is fixed.
*/
public void pressButtonUsingKeyboard() {
open();

Expand Down