diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-10-05 17:46:28 +0300 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-10-09 12:33:21 +0000 |
commit | 2732b77278001c11fd5059fb89f19587302cb033 (patch) | |
tree | 2ecb166c2b0cbd1391f0f1bcd31cc58cdbec0a46 /client | |
parent | 9ee97bbf72551ba650e7ea910dddaae64f6c7ef0 (diff) | |
download | vaadin-framework-2732b77278001c11fd5059fb89f19587302cb033.tar.gz vaadin-framework-2732b77278001c11fd5059fb89f19587302cb033.zip |
Add Grid column resize event API (#16838)
Change-Id: I1cdecb54b3df45b16ddf2c7b06261198be086274
Diffstat (limited to 'client')
4 files changed, 145 insertions, 16 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 60a9aacb88..0a6ba1642e 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -62,6 +62,8 @@ import com.vaadin.client.widget.grid.events.BodyClickHandler; import com.vaadin.client.widget.grid.events.BodyDoubleClickHandler; import com.vaadin.client.widget.grid.events.ColumnReorderEvent; import com.vaadin.client.widget.grid.events.ColumnReorderHandler; +import com.vaadin.client.widget.grid.events.ColumnResizeEvent; +import com.vaadin.client.widget.grid.events.ColumnResizeHandler; import com.vaadin.client.widget.grid.events.ColumnVisibilityChangeEvent; import com.vaadin.client.widget.grid.events.ColumnVisibilityChangeHandler; import com.vaadin.client.widget.grid.events.GridClickEvent; @@ -193,14 +195,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements return null; } - @Override - protected void setWidth(double pixels, boolean userOriginated) { - super.setWidth(pixels, userOriginated); - if (userOriginated) { - getRpcProxy(GridServerRpc.class).columnResized(id, pixels); - } - } - private AbstractFieldConnector getEditorConnector() { return editorConnector; } @@ -479,6 +473,21 @@ public class GridConnector extends AbstractHasComponentsConnector implements } }; + private ColumnResizeHandler<JsonObject> columnResizeHandler = new ColumnResizeHandler<JsonObject>() { + + @Override + public void onColumnResize(ColumnResizeEvent<JsonObject> event) { + if (!columnsUpdatedFromState) { + Column<?, JsonObject> column = event.getColumn(); + if (column instanceof CustomGridColumn) { + getRpcProxy(GridServerRpc.class).columnResized( + ((CustomGridColumn) column).id, + column.getWidthActual()); + } + } + } + }; + private class CustomDetailsGenerator implements DetailsGenerator { private final Map<String, ComponentConnector> idToDetailsMap = new HashMap<String, ComponentConnector>(); @@ -750,6 +759,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements getWidget().addColumnReorderHandler(columnReorderHandler); getWidget().addColumnVisibilityChangeHandler( columnVisibilityChangeHandler); + getWidget().addColumnResizeHandler(columnResizeHandler); ConnectorFocusAndBlurHandler.addHandlers(this); diff --git a/client/src/com/vaadin/client/widget/grid/events/ColumnResizeEvent.java b/client/src/com/vaadin/client/widget/grid/events/ColumnResizeEvent.java new file mode 100644 index 0000000000..bb61ec021d --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/ColumnResizeEvent.java @@ -0,0 +1,67 @@ +/* + * 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.event.shared.GwtEvent; +import com.vaadin.client.widgets.Grid.Column; + +/** + * An event for notifying that the columns in the Grid have been resized. + * + * @param <T> + * The row type of the grid. The row type is the POJO type from where + * the data is retrieved into the column cells. + * @since + * @author Vaadin Ltd + */ +public class ColumnResizeEvent<T> extends GwtEvent<ColumnResizeHandler<T>> { + + /** + * Handler type. + */ + private final static Type<ColumnResizeHandler<?>> TYPE = new Type<ColumnResizeHandler<?>>(); + + private Column<?, T> column; + + /** + * @param column + */ + public ColumnResizeEvent(Column<?, T> column) { + this.column = column; + } + + public static final Type<ColumnResizeHandler<?>> getType() { + return TYPE; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public Type<ColumnResizeHandler<T>> getAssociatedType() { + return (Type) TYPE; + } + + @Override + protected void dispatch(ColumnResizeHandler<T> handler) { + handler.onColumnResize(this); + } + + /** + * @return the column + */ + public Column<?, T> getColumn() { + return column; + } +} diff --git a/client/src/com/vaadin/client/widget/grid/events/ColumnResizeHandler.java b/client/src/com/vaadin/client/widget/grid/events/ColumnResizeHandler.java new file mode 100644 index 0000000000..a1bbef4dab --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/events/ColumnResizeHandler.java @@ -0,0 +1,40 @@ +/* + * 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.event.shared.EventHandler; + +/** + * Handler for a Grid column resize event, called when the Grid's columns has + * been resized. + * + * @param <T> + * The row type of the grid. The row type is the POJO type from where + * the data is retrieved into the column cells. + * @since + * @author Vaadin Ltd + */ +public interface ColumnResizeHandler<T> extends EventHandler { + + /** + * A column resize event, fired by Grid when the columns of the Grid have + * been resized. + * + * @param event + * column resize event + */ + public void onColumnResize(ColumnResizeEvent<T> event); +} diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index db7b25720e..d31548eabd 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -124,6 +124,8 @@ import com.vaadin.client.widget.grid.events.BodyKeyPressHandler; import com.vaadin.client.widget.grid.events.BodyKeyUpHandler; import com.vaadin.client.widget.grid.events.ColumnReorderEvent; import com.vaadin.client.widget.grid.events.ColumnReorderHandler; +import com.vaadin.client.widget.grid.events.ColumnResizeEvent; +import com.vaadin.client.widget.grid.events.ColumnResizeHandler; import com.vaadin.client.widget.grid.events.ColumnVisibilityChangeEvent; import com.vaadin.client.widget.grid.events.ColumnVisibilityChangeHandler; import com.vaadin.client.widget.grid.events.FooterClickHandler; @@ -4761,17 +4763,13 @@ public class Grid<T> extends ResizeComposite implements * the width in pixels or negative for auto sizing */ public Column<C, T> setWidth(double pixels) { - setWidth(pixels, false); - return this; - } - - protected void setWidth(double pixels, boolean userOriginated) { if (!WidgetUtil.pixelValuesEqual(widthUser, pixels)) { widthUser = pixels; if (!isHidden()) { scheduleColumnWidthRecalculator(); } } + return this; } void doSetWidth(double pixels) { @@ -5578,7 +5576,7 @@ public class Grid<T> extends ResizeComposite implements @Override public void onUpdate(double deltaX, double deltaY) { - col.setWidth(initialWidth + deltaX, false); + col.setWidth(initialWidth + deltaX); } @Override @@ -5588,12 +5586,12 @@ public class Grid<T> extends ResizeComposite implements @Override public void onComplete() { - col.setWidth(col.getWidthActual(), true); + fireEvent(new ColumnResizeEvent<T>(col)); } @Override public void onCancel() { - col.setWidth(initialWidth, false); + col.setWidth(initialWidth); } }); dragger.addTo(td); @@ -7930,6 +7928,20 @@ public class Grid<T> extends ResizeComposite implements } /** + * Register a column resize handler to this Grid. The event for this handler + * is fired when the Grid's columns are resized. + * + * @since + * @param handler + * the handler for the event + * @return the registration for the event + */ + public HandlerRegistration addColumnResizeHandler( + ColumnResizeHandler<T> handler) { + return addHandler(handler, ColumnResizeEvent.getType()); + } + + /** * Apply sorting to data source. */ private void sort(boolean userOriginated) { |