summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-02-19 17:03:00 +0200
committerPekka Hyvönen <pekka@vaadin.com>2015-02-19 17:03:00 +0200
commitad7bcdc7d22cedf30d76dd6d1ba7a1c9bcabdd53 (patch)
treeee480c8c0e0c56b2fcf7b1e3657f42b78ef4ceeb /server
parent9b2f51ca9ff48ad9484b8ee67770ab1a58352b35 (diff)
downloadvaadin-framework-ad7bcdc7d22cedf30d76dd6d1ba7a1c9bcabdd53.tar.gz
vaadin-framework-ad7bcdc7d22cedf30d76dd6d1ba7a1c9bcabdd53.zip
Fire server-side event when column order changes. (#16643)
Event fired for both UI and programmatic changes. Change-Id: I043e7407ee11547cb3b6639dc14c26ff036a9d82
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java86
1 files changed, 85 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 72a772713f..df64ee85ed 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -337,6 +337,58 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
}
/**
+ * An event listener for column reorder events in the Grid.
+ *
+ * @since
+ */
+ public interface ColumnReorderListener extends Serializable {
+ /**
+ * Called when the columns of the grid have been reordered.
+ *
+ * @param event
+ * An event providing more information
+ */
+ void columnReorder(ColumnReorderEvent event);
+ }
+
+ /**
+ * An event that is fired when the columns are reordered.
+ *
+ * @since
+ */
+ public static class ColumnReorderEvent extends Component.Event {
+
+ /**
+ * Is the column reorder related to this event initiated by the user
+ */
+ private final boolean userOriginated;
+
+ /**
+ *
+ * @param source
+ * the grid where the event originated from
+ * @param userOriginated
+ * <code>true</code> if event is a result of user
+ * interaction, <code>false</code> if from API call
+ */
+ public ColumnReorderEvent(Grid source, boolean userOriginated) {
+ super(source);
+ this.userOriginated = userOriginated;
+ }
+
+ /**
+ * 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;
+ }
+
+ }
+
+ /**
* Default error handler for the editor
*
*/
@@ -2896,6 +2948,10 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
private static final Method SORT_ORDER_CHANGE_METHOD = ReflectTools
.findMethod(SortListener.class, "sort", SortEvent.class);
+ private static final Method COLUMN_REORDER_METHOD = ReflectTools
+ .findMethod(ColumnReorderListener.class, "columnReorder",
+ ColumnReorderEvent.class);
+
/**
* Creates a new Grid with a new {@link IndexedContainer} as the data
* source.
@@ -3120,7 +3176,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
connectorTracker);
diffState.put(diffStateKey, encodeResult.getEncodedValue());
- // TODO fire column reorder event
+ fireColumnReorderEvent(true);
} else {
// make sure the client is reverted to the order that the
// server thinks it is
@@ -3632,6 +3688,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
columnOrder.addAll(stateColumnOrder);
}
getState().columnOrder = columnOrder;
+ fireColumnReorderEvent(false);
}
/**
@@ -4098,6 +4155,33 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
removeListener(SelectionEvent.class, listener, SELECTION_CHANGE_METHOD);
}
+ private void fireColumnReorderEvent(boolean userOriginated) {
+ fireEvent(new ColumnReorderEvent(this, userOriginated));
+ }
+
+ /**
+ * Registers a new column reorder listener.
+ *
+ * @since
+ * @param listener
+ * the listener to register
+ */
+ public void addColumnReorderListener(ColumnReorderListener listener) {
+ addListener(ColumnReorderEvent.class, listener, COLUMN_REORDER_METHOD);
+ }
+
+ /**
+ * Removes a previously registered column reorder listener.
+ *
+ * @since
+ * @param listener
+ * the listener to remove
+ */
+ public void removeColumnReorderListener(ColumnReorderListener listener) {
+ removeListener(ColumnReorderEvent.class, listener,
+ COLUMN_REORDER_METHOD);
+ }
+
/**
* Gets the
* {@link com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper