summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2015-03-18 10:05:47 +0200
committerVaadin Code Review <review@vaadin.com>2015-03-19 07:33:33 +0000
commit2be1e43d7081f0bc2c5f905d6b007fe597934ae3 (patch)
treef89f209bc439e881078eb915d8d1acf27cc8a8b8 /server
parent4d5f6cf73f84bd0f68f05eb534699bddb898f9f1 (diff)
downloadvaadin-framework-2be1e43d7081f0bc2c5f905d6b007fe597934ae3.tar.gz
vaadin-framework-2be1e43d7081f0bc2c5f905d6b007fe597934ae3.zip
Adds server side column hiding API to Grid (#17023)
Change-Id: Ic00e873176f499dfc45976439e09d712932775da
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java159
1 files changed, 159 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 12722b2596..31a25d8f8f 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -167,6 +167,67 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
SortNotifier, SelectiveRenderer, ItemClickNotifier {
/**
+ * An event listener for column visibility change events in the Grid.
+ *
+ * @since
+ */
+ public interface ColumnVisibilityChangeListener extends Serializable {
+ /**
+ * Called when a column has become hidden or unhidden.
+ *
+ * @param event
+ */
+ void columnVisibilityChanged(ColumnVisibilityChangeEvent event);
+ }
+
+ /**
+ * An event that is fired when a column becomes hidden or unhidden.
+ *
+ * @since
+ */
+ public static class ColumnVisibilityChangeEvent extends Component.Event {
+
+ private final Column column;
+ private final boolean userOriginated;
+
+ /**
+ * Constructor for a column visibility change event.
+ *
+ * @param column
+ * the column that changed its visibility
+ * @param isUserOriginated
+ * <code>true</code> iff the event was triggered by an UI
+ * interaction
+ */
+ public ColumnVisibilityChangeEvent(Component source, Column column,
+ boolean isUserOriginated) {
+ super(source);
+ this.column = column;
+ userOriginated = isUserOriginated;
+ }
+
+ /**
+ * Gets the column that became hidden or unhidden.
+ *
+ * @return the column that became hidden or unhidden.
+ * @see Column#isHidden()
+ */
+ public Column getColumn() {
+ return column;
+ }
+
+ /**
+ * Returns <code>true</code> if the column reorder was done by the user,
+ * <code>false</code> if not and it was triggered by server side code.
+ *
+ * @return <code>true</code> if event is a result of user interaction
+ */
+ public boolean isUserOriginated() {
+ return userOriginated;
+ }
+ }
+
+ /**
* Custom field group that allows finding property types before an item has
* been bound.
*/
@@ -2715,6 +2776,66 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
public Field<?> getEditorField() {
return grid.getEditorField(getPropertyId());
}
+
+ /**
+ * Hides or shows the column. By default columns are visible before
+ * explicitly hiding them.
+ *
+ * @since
+ * @param hidden
+ * <code>true</code> to hide the column, <code>false</code>
+ * to show
+ */
+ public void setHidden(boolean hidden) {
+ if (hidden != getState().hidden) {
+ getState().hidden = hidden;
+ grid.markAsDirty();
+ grid.fireColumnVisibilityChangeEvent(this, false);
+ }
+ }
+
+ /**
+ * Is this column hidden. Default is {@code false}.
+ *
+ * @since
+ * @return <code>true</code> if the column is currently hidden,
+ * <code>false</code> otherwise
+ */
+ public boolean isHidden() {
+ return getState().hidden;
+ }
+
+ /**
+ * Set whether it is possible for the user to hide this column or not.
+ * Default is {@code false}.
+ * <p>
+ * <em>Note:</em> it is still possible to hide the column
+ * programmatically using {@link #setHidden(boolean)}
+ *
+ * @since
+ * @param hidable
+ * <code>true</code> iff the column may be hidable by the
+ * user via UI interaction
+ */
+ public void setHidable(boolean hidable) {
+ getState().hidable = hidable;
+ grid.markAsDirty();
+ }
+
+ /**
+ * Is it possible for the the user to hide this column. Default is
+ * {@code false}.
+ * <p>
+ * <em>Note:</em> the column can be programmatically hidden using
+ * {@link #setHidden(boolean)} regardless of the returned value.
+ *
+ * @since
+ * @return <code>true</code> if the user can hide the column,
+ * <code>false</code> if not
+ */
+ public boolean isHidable() {
+ return getState().hidable;
+ }
}
/**
@@ -2952,6 +3073,11 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
.findMethod(ColumnReorderListener.class, "columnReorder",
ColumnReorderEvent.class);
+ private static final Method COLUMN_VISIBILITY_METHOD = ReflectTools
+ .findMethod(ColumnVisibilityChangeListener.class,
+ "columnVisibilityChanged",
+ ColumnVisibilityChangeEvent.class);
+
/**
* Creates a new Grid with a new {@link IndexedContainer} as the data
* source.
@@ -5242,4 +5368,37 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
public void recalculateColumnWidths() {
getRpcProxy(GridClientRpc.class).recalculateColumnWidths();
}
+
+ /**
+ * Registers a new column visibility change listener
+ *
+ * @since
+ * @param listener
+ * the listener to register
+ */
+ public void addColumnVisibilityChangeListener(
+ ColumnVisibilityChangeListener listener) {
+ addListener(ColumnVisibilityChangeEvent.class, listener,
+ COLUMN_VISIBILITY_METHOD);
+ }
+
+ /**
+ * Removes a previously registered column visibility change listener
+ *
+ * @since
+ * @param listener
+ * the listener to remove
+ */
+ public void removeColumnVisibilityChangeListener(
+ ColumnVisibilityChangeListener listener) {
+ removeListener(ColumnVisibilityChangeEvent.class, listener,
+ COLUMN_VISIBILITY_METHOD);
+ }
+
+ private void fireColumnVisibilityChangeEvent(Column column,
+ boolean isUserOriginated) {
+ fireEvent(new ColumnVisibilityChangeEvent(this, column,
+ isUserOriginated));
+ }
+
}