summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-03-13 12:20:30 +0200
committerPekka Hyvönen <pekka@vaadin.com>2015-03-13 12:59:42 +0000
commit54d6480a3cbd6d721dc119a7f6c5c029b7dcefea (patch)
tree1fcce0d7cf05b4131a1104b8b5b48fa2fbf30757 /client/src
parentf091f9ff68e1d3b1c06c8e78b33cd07ccf480f9f (diff)
downloadvaadin-framework-54d6480a3cbd6d721dc119a7f6c5c029b7dcefea.tar.gz
vaadin-framework-54d6480a3cbd6d721dc119a7f6c5c029b7dcefea.zip
Client side event for grid's columns visibility change (#17023)
Change-Id: I1965ca6c298366d89b1940a992788d042cf7a4aa
Diffstat (limited to 'client/src')
-rw-r--r--client/src/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java3
-rw-r--r--client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java93
-rw-r--r--client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java39
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java18
4 files changed, 151 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java b/client/src/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java
index 4890ed063d..c72da0c48e 100644
--- a/client/src/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java
+++ b/client/src/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java
@@ -18,8 +18,7 @@ package com.vaadin.client.widget.grid.events;
import com.google.gwt.event.shared.GwtEvent;
/**
- * An event for notifying that the columns in the Grid's columns have been
- * reordered.
+ * An event for notifying that the columns in the Grid have been reordered.
*
* @param <T>
* The row type of the grid. The row type is the POJO type from where
diff --git a/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java b/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java
new file mode 100644
index 0000000000..10bfbfad68
--- /dev/null
+++ b/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java
@@ -0,0 +1,93 @@
+/*
+ * 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's have changed
+ * visibility.
+ *
+ * @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 ColumnVisibilityChangeEvent<T> extends
+ GwtEvent<ColumnVisibilityChangeHandler<T>> {
+
+ private final static Type<ColumnVisibilityChangeHandler<?>> TYPE = new Type<ColumnVisibilityChangeHandler<?>>();
+
+ public static final Type<ColumnVisibilityChangeHandler<?>> getType() {
+ return TYPE;
+ }
+
+ private final Column<?, T> column;
+
+ private final boolean userOriginated;
+
+ private final boolean hidden;
+
+ public ColumnVisibilityChangeEvent(Column<?, T> column, boolean hidden,
+ boolean userOriginated) {
+ this.column = column;
+ this.hidden = hidden;
+ this.userOriginated = userOriginated;
+ }
+
+ /**
+ * Returns the column where the visibility change occurred.
+ *
+ * @return the column where the visibility change occurred.
+ */
+ public Column<?, T> getColumn() {
+ return column;
+ }
+
+ /**
+ * Is the column hidden or visible.
+ *
+ * @return <code>true</code> if the column was hidden <code>false</code> if
+ * it was set visible
+ */
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ /**
+ * Is the visibility change triggered by user.
+ *
+ * @return <code>true</code> if the change was triggered by user,
+ * <code>false</code> if not
+ */
+ public boolean isUserOriginated() {
+ return userOriginated;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public com.google.gwt.event.shared.GwtEvent.Type<ColumnVisibilityChangeHandler<T>> getAssociatedType() {
+ return (Type) TYPE;
+ }
+
+ @Override
+ protected void dispatch(ColumnVisibilityChangeHandler<T> handler) {
+ handler.onVisibilityChange(this);
+ }
+
+}
diff --git a/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java b/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java
new file mode 100644
index 0000000000..10a7660954
--- /dev/null
+++ b/client/src/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java
@@ -0,0 +1,39 @@
+/*
+ * 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 visibility change event, called when the Grid's
+ * columns have changed visibility to hidden or visible.
+ *
+ * @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 ColumnVisibilityChangeHandler<T> extends EventHandler {
+
+ /**
+ * A column visibility change event, fired by Grid when a column in the Grid
+ * has changed visibility.
+ *
+ * @param event
+ * column visibility change event
+ */
+ public void onVisibilityChange(ColumnVisibilityChangeEvent<T> event);
+}
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index c7ec9cd062..7e08348da0 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -107,6 +107,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.ColumnVisibilityChangeEvent;
+import com.vaadin.client.widget.grid.events.ColumnVisibilityChangeHandler;
import com.vaadin.client.widget.grid.events.FooterClickHandler;
import com.vaadin.client.widget.grid.events.FooterDoubleClickHandler;
import com.vaadin.client.widget.grid.events.FooterKeyDownHandler;
@@ -3671,6 +3673,8 @@ public class Grid<T> extends ResizeComposite implements
grid.getVisibleColumns().indexOf(this), 1);
}
scheduleColumnWidthRecalculator();
+ this.grid.fireEvent(new ColumnVisibilityChangeEvent<T>(this,
+ hidden, false));
}
}
@@ -6418,6 +6422,20 @@ public class Grid<T> extends ResizeComposite implements
}
/**
+ * Register a column visibility change handler to this Grid. The event for
+ * this handler is fired when the Grid's columns change visibility.
+ *
+ * @since
+ * @param handler
+ * the handler for the event
+ * @return the registration for the event
+ */
+ public HandlerRegistration addColumnVisibilityChangeHandler(
+ ColumnVisibilityChangeHandler<T> handler) {
+ return addHandler(handler, ColumnVisibilityChangeEvent.getType());
+ }
+
+ /**
* Apply sorting to data source.
*/
private void sort(boolean userOriginated) {