summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-04-30 13:40:45 +0300
committerPekka Hyvönen <pekka@vaadin.com>2015-04-30 13:40:52 +0300
commitef9fb276a93d1a7967ef0e6405dee56c8aa2a148 (patch)
tree622280f6e6e2904fef61c3483fe36e14ab6b924d /shared
parenta9bc160aee00b93340ac3f047505e032d4a696b0 (diff)
parentbbf30fff168fd4a9552d23c8341e27aa1821884b (diff)
downloadvaadin-framework-ef9fb276a93d1a7967ef0e6405dee56c8aa2a148.tar.gz
vaadin-framework-ef9fb276a93d1a7967ef0e6405dee56c8aa2a148.zip
Merge branch 'grid-7.5'
Change-Id: Ifa976fa4be1258fd35999de17775da70afedb2a8
Diffstat (limited to 'shared')
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java190
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java19
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridColumnState.java9
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java44
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridState.java14
5 files changed, 275 insertions, 1 deletions
diff --git a/shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java b/shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java
new file mode 100644
index 0000000000..8b64d22423
--- /dev/null
+++ b/shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java
@@ -0,0 +1,190 @@
+/*
+ * 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.shared.ui.grid;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import com.vaadin.shared.Connector;
+
+/**
+ * A description of an indexing modification for a connector. This is used by
+ * Grid for internal bookkeeping updates.
+ *
+ * @since 7.5.0
+ * @author Vaadin Ltd
+ */
+public class DetailsConnectorChange implements Serializable {
+
+ public static final Comparator<DetailsConnectorChange> REMOVED_FIRST_COMPARATOR = new Comparator<DetailsConnectorChange>() {
+ @Override
+ public int compare(DetailsConnectorChange a, DetailsConnectorChange b) {
+ boolean deleteA = a.getNewIndex() == null;
+ boolean deleteB = b.getNewIndex() == null;
+ if (deleteA && !deleteB) {
+ return -1;
+ } else if (!deleteA && deleteB) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ };
+
+ private Connector connector;
+ private Integer oldIndex;
+ private Integer newIndex;
+ private boolean shouldStillBeVisible;
+
+ /** Create a new connector index change */
+ public DetailsConnectorChange() {
+ }
+
+ /**
+ * Convenience constructor for setting all the fields in one line.
+ * <p>
+ * Calling this constructor will also assert that the state of the pojo is
+ * consistent by internal assumptions.
+ *
+ * @param connector
+ * the changed connector
+ * @param oldIndex
+ * the old index
+ * @param newIndex
+ * the new index
+ * @param shouldStillBeVisible
+ * details should be visible regardless of {@code connector}
+ */
+ public DetailsConnectorChange(Connector connector, Integer oldIndex,
+ Integer newIndex, boolean shouldStillBeVisible) {
+ this.connector = connector;
+ this.oldIndex = oldIndex;
+ this.newIndex = newIndex;
+ this.shouldStillBeVisible = shouldStillBeVisible;
+
+ assert assertStateIsOk();
+ }
+
+ private boolean assertStateIsOk() {
+ boolean connectorAndNewIndexIsNotNull = connector != null
+ && newIndex != null;
+ boolean connectorAndNewIndexIsNullThenOldIndexIsSet = connector == null
+ && newIndex == null && oldIndex != null;
+
+ assert (connectorAndNewIndexIsNotNull || connectorAndNewIndexIsNullThenOldIndexIsSet) : "connector: "
+ + nullityString(connector)
+ + ", oldIndex: "
+ + nullityString(oldIndex)
+ + ", newIndex: "
+ + nullityString(newIndex);
+ return true;
+ }
+
+ private static String nullityString(Object object) {
+ return object == null ? "null" : "non-null";
+ }
+
+ /**
+ * Gets the old index for the connector.
+ * <p>
+ * If <code>null</code>, the connector is recently added. This means that
+ * {@link #getConnector()} is expected not to return <code>null</code>.
+ *
+ * @return the old index for the connector
+ */
+ public Integer getOldIndex() {
+ assert assertStateIsOk();
+ return oldIndex;
+ }
+
+ /**
+ * Gets the new index for the connector.
+ * <p>
+ * If <code>null</code>, the connector should be removed. This means that
+ * {@link #getConnector()} is expected to return <code>null</code> as well.
+ *
+ * @return the new index for the connector
+ */
+ public Integer getNewIndex() {
+ assert assertStateIsOk();
+ return newIndex;
+ }
+
+ /**
+ * Gets the changed connector.
+ *
+ * @return the changed connector. Might be <code>null</code>
+ */
+ public Connector getConnector() {
+ assert assertStateIsOk();
+ return connector;
+ }
+
+ /**
+ * Sets the changed connector.
+ *
+ * @param connector
+ * the changed connector. May be <code>null</code>
+ */
+ public void setConnector(Connector connector) {
+ this.connector = connector;
+ }
+
+ /**
+ * Sets the old index
+ *
+ * @param oldIndex
+ * the old index. May be <code>null</code> if a new connector is
+ * being inserted
+ */
+ public void setOldIndex(Integer oldIndex) {
+ this.oldIndex = oldIndex;
+ }
+
+ /**
+ * Sets the new index
+ *
+ * @param newIndex
+ * the new index. May be <code>null</code> if a connector is
+ * being removed
+ */
+ public void setNewIndex(Integer newIndex) {
+ this.newIndex = newIndex;
+ }
+
+ /**
+ * Checks whether whether the details should remain open, even if connector
+ * might be <code>null</code>.
+ *
+ * @return <code>true</code> iff the details should remain open, even if
+ * connector might be <code>null</code>
+ */
+ public boolean isShouldStillBeVisible() {
+ return shouldStillBeVisible;
+ }
+
+ /**
+ * Sets whether the details should remain open, even if connector might be
+ * <code>null</code>.
+ *
+ * @param shouldStillBeVisible
+ * <code>true</code> iff the details should remain open, even if
+ * connector might be <code>null</code>
+ */
+ public void setShouldStillBeVisible(boolean shouldStillBeVisible) {
+ this.shouldStillBeVisible = shouldStillBeVisible;
+ }
+}
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java b/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java
index 4ba081b5df..3c6d993482 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java
@@ -15,6 +15,8 @@
*/
package com.vaadin.shared.ui.grid;
+import java.util.Set;
+
import com.vaadin.shared.communication.ClientRpc;
/**
@@ -26,7 +28,8 @@ import com.vaadin.shared.communication.ClientRpc;
public interface GridClientRpc extends ClientRpc {
/**
- * Command client Grid to scroll to a specific data row.
+ * Command client Grid to scroll to a specific data row and its (optional)
+ * details.
*
* @param row
* zero-based row index. If the row index is below zero or above
@@ -55,4 +58,18 @@ public interface GridClientRpc extends ClientRpc {
*/
public void recalculateColumnWidths();
+ /**
+ * Informs the GridConnector on how the indexing of details connectors has
+ * changed.
+ *
+ * @since 7.5.0
+ * @param connectorChanges
+ * the indexing changes of details connectors
+ * @param fetchId
+ * the id of the request for fetching the changes. A negative
+ * number indicates a push (not requested by the client side)
+ */
+ public void setDetailsConnectorChanges(
+ Set<DetailsConnectorChange> connectorChanges, int fetchId);
+
}
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
index 4c5b2c3a02..5aa9ea9b65 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
@@ -76,4 +76,13 @@ public class GridColumnState implements Serializable {
* minWidth is less than the calculated width, minWidth will win.
*/
public double minWidth = GridConstants.DEFAULT_MIN_WIDTH;
+
+ /** Is the column currently hidden. */
+ public boolean hidden = false;
+
+ /** Can the column be hidden by the UI. */
+ public boolean hidable = false;
+
+ /** The caption for the column hiding toggle. */
+ public String hidingToggleCaption;
}
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java b/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java
index c90a016383..dca55c11c4 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridServerRpc.java
@@ -47,4 +47,48 @@ public interface GridServerRpc extends ServerRpc {
* mouse event details
*/
void itemClick(String rowKey, String columnId, MouseEventDetails details);
+
+ /**
+ * Informs the server that the columns of the Grid have been reordered.
+ *
+ * @since 7.5.0
+ * @param newColumnOrder
+ * a list of column ids in the new order
+ * @param oldColumnOrder
+ * a list of column ids in order before the change
+ */
+ void columnsReordered(List<String> newColumnOrder,
+ List<String> oldColumnOrder);
+
+ /**
+ * This is a trigger for Grid to send whatever has changed regarding the
+ * details components.
+ * <p>
+ * The components can't be sent eagerly, since they are generated as a side
+ * effect in
+ * {@link com.vaadin.data.RpcDataProviderExtension#beforeClientResponse(boolean)}
+ * , and that is too late to change the hierarchy. So we need this
+ * round-trip to work around that limitation.
+ *
+ * @since 7.5.0
+ * @param fetchId
+ * an unique identifier for the request
+ * @see com.vaadin.ui.Grid#setDetailsVisible(Object, boolean)
+ */
+ void sendDetailsComponents(int fetchId);
+
+ /**
+ * Informs the server that the column's visibility has been changed.
+ *
+ * @since 7.5.0
+ * @param id
+ * the id of the column
+ * @param hidden
+ * <code>true</code> if hidden, <code>false</code> if unhidden
+ * @param userOriginated
+ * <code>true</code> if triggered by user, <code>false</code> if
+ * by code
+ */
+ void columnVisibilityChanged(String id, boolean hidden,
+ boolean userOriginated);
}
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridState.java b/shared/src/com/vaadin/shared/ui/grid/GridState.java
index 7018df1413..e039f70988 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridState.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridState.java
@@ -103,6 +103,16 @@ public class GridState extends AbstractComponentState {
public static final String JSONKEY_CELLSTYLES = "cs";
/**
+ * The key that tells whether details are visible for the row
+ *
+ * @see com.vaadin.ui.Grid#setDetailsGenerator(com.vaadin.ui.Grid.DetailsGenerator)
+ * @see com.vaadin.ui.Grid#setDetailsVisible(Object, boolean)
+ * @see com.vaadin.shared.data.DataProviderRpc#setRowData(int,
+ * elemental.json.JsonArray)
+ * */
+ public static final String JSONKEY_DETAILS_VISIBLE = "dv";
+
+ /**
* Columns in grid.
*/
public List<GridColumnState> columns = new ArrayList<GridColumnState>();
@@ -156,4 +166,8 @@ public class GridState extends AbstractComponentState {
/** The caption for the cancel button in the editor */
@DelegateToWidget
public String editorCancelCaption = GridConstants.DEFAULT_CANCEL_CAPTION;
+
+ /** Whether the columns can be reordered */
+ @DelegateToWidget
+ public boolean columnReorderingAllowed;
}