diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-03-15 14:00:50 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-03-15 14:00:50 +0200 |
commit | c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f (patch) | |
tree | 9adcbf965914c9ad9c5d84a79cecdbc6117a1234 /client | |
parent | 0fe0e727784b311e2b76f3b5a06d3a823d2006f4 (diff) | |
download | vaadin-framework-c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f.tar.gz vaadin-framework-c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f.zip |
Allow changing renderers after column creation (#8841)
Closes #8250
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java | 6 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/treegrid/TreeGridConnector.java | 47 |
2 files changed, 34 insertions, 19 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java index d619b50b5d..149ef4c1f9 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java @@ -73,7 +73,6 @@ public class ColumnConnector extends AbstractExtensionConnector { return null; } }; - column.setRenderer(getRendererConnector().getRenderer()); getParent().addColumn(column, getState().internalId); } @@ -92,6 +91,11 @@ public class ColumnConnector extends AbstractExtensionConnector { column.setSortable(getState().sortable); } + @OnStateChange("renderer") + void updateRenderer() { + column.setRenderer(getRendererConnector().getRenderer()); + } + @OnStateChange("hidingToggleCaption") void updateHidingToggleCaption() { column.setHidingToggleCaption(getState().hidingToggleCaption); diff --git a/client/src/main/java/com/vaadin/client/connectors/treegrid/TreeGridConnector.java b/client/src/main/java/com/vaadin/client/connectors/treegrid/TreeGridConnector.java index 7f11683bbe..0cccb6cd6f 100644 --- a/client/src/main/java/com/vaadin/client/connectors/treegrid/TreeGridConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/treegrid/TreeGridConnector.java @@ -18,12 +18,13 @@ package com.vaadin.client.connectors.treegrid; import java.util.Collection; import java.util.logging.Logger; +import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.BrowserEvents; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.user.client.Event; import com.google.web.bindery.event.shared.HandlerRegistration; -import com.vaadin.client.communication.StateChangeEvent; +import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.connectors.grid.GridConnector; import com.vaadin.client.renderers.ClickableRenderer; import com.vaadin.client.renderers.HierarchyRenderer; @@ -43,7 +44,7 @@ import elemental.json.JsonObject; /** * A connector class for the TreeGrid component. - * + * * @author Vaadin Ltd * @since 8.1 */ @@ -67,13 +68,18 @@ public class TreeGridConnector extends GridConnector { return (TreeGridState) super.getState(); } - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - if (stateChangeEvent.hasPropertyChanged("hierarchyColumnId") - || stateChangeEvent.hasPropertyChanged("columns")) { - + /** + * This method has been scheduled finally to avoid possible race conditions + * between state change handling for the Grid and its columns. The renderer + * of the column is set in a state change handler, and might not be + * available when this method is executed. + * <p> + * TODO: This might need some clean up if we decide to allow setting a new + * renderer for hierarchy columns. + */ + @OnStateChange("hierarchyColumnId") + void updateHierarchyColumn() { + Scheduler.get().scheduleFinally(() -> { // Id of old hierarchy column String oldHierarchyColumnId = this.hierarchyColumnId; @@ -111,7 +117,7 @@ public class TreeGridConnector extends GridConnector { Logger.getLogger(TreeGridConnector.class.getName()).warning( "Couldn't find column: " + newHierarchyColumnId); } - } + }); } private HierarchyRenderer getHierarchyRenderer() { @@ -159,18 +165,21 @@ public class TreeGridConnector extends GridConnector { } private native void replaceCellFocusEventHandler(Grid<?> grid, - GridEventHandler<?> eventHandler)/*-{ + GridEventHandler<?> eventHandler) + /*-{ var browserEventHandlers = grid.@com.vaadin.client.widgets.Grid::browserEventHandlers; - + // FocusEventHandler is initially 5th in the list of browser event handlers browserEventHandlers.@java.util.List::set(*)(5, eventHandler); }-*/; - private native void replaceClickEvent(Grid<?> grid, GridClickEvent event)/*-{ + private native void replaceClickEvent(Grid<?> grid, GridClickEvent event) + /*-{ grid.@com.vaadin.client.widgets.Grid::clickEvent = event; }-*/; - private native EventCellReference<?> getEventCell(Grid<?> grid)/*-{ + private native EventCellReference<?> getEventCell(Grid<?> grid) + /*-{ return grid.@com.vaadin.client.widgets.Grid::eventCell; }-*/; @@ -213,13 +222,15 @@ public class TreeGridConnector extends GridConnector { } } - private native Collection<String> getNavigationEvents(Grid<?> grid)/*-{ - return grid.@com.vaadin.client.widgets.Grid::cellFocusHandler - .@com.vaadin.client.widgets.Grid.CellFocusHandler::getNavigationEvents()(); + private native Collection<String> getNavigationEvents(Grid<?> grid) + /*-{ + return grid.@com.vaadin.client.widgets.Grid::cellFocusHandler + .@com.vaadin.client.widgets.Grid.CellFocusHandler::getNavigationEvents()(); }-*/; private native void handleNavigationEvent(Grid<?> grid, - Grid.GridEvent<JsonObject> event)/*-{ + Grid.GridEvent<JsonObject> event) + /*-{ grid.@com.vaadin.client.widgets.Grid::cellFocusHandler .@com.vaadin.client.widgets.Grid.CellFocusHandler::handleNavigationEvent(*)( event.@com.vaadin.client.widgets.Grid.GridEvent::getDomEvent()(), |