From b06b1d68469e49e7784de342f0dcf9de64b35f5a Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Mon, 16 Mar 2015 11:45:22 +0200 Subject: Adds details generator swap support for Grid (#16644) Change-Id: I741970a7bcebd27d3aa28d608d767b4b4f063ae8 --- .../shared/ui/grid/ConnectorIndexChange.java | 143 -------------------- .../shared/ui/grid/DetailsConnectorChange.java | 147 +++++++++++++++++++++ .../com/vaadin/shared/ui/grid/GridClientRpc.java | 5 +- 3 files changed, 150 insertions(+), 145 deletions(-) delete mode 100644 shared/src/com/vaadin/shared/ui/grid/ConnectorIndexChange.java create mode 100644 shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java (limited to 'shared') diff --git a/shared/src/com/vaadin/shared/ui/grid/ConnectorIndexChange.java b/shared/src/com/vaadin/shared/ui/grid/ConnectorIndexChange.java deleted file mode 100644 index 16be92007e..0000000000 --- a/shared/src/com/vaadin/shared/ui/grid/ConnectorIndexChange.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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 com.vaadin.shared.Connector; - -/** - * A description of an indexing modification for a connector. This is used by - * Grid by internal bookkeeping updates. - * - * @since - * @author Vaadin Ltd - */ -public class ConnectorIndexChange implements Serializable { - - private Connector connector; - private Integer oldIndex; - private Integer newIndex; - - /** Create a new connector index change */ - public ConnectorIndexChange() { - } - - /** - * Convenience constructor for setting all the fields in one line. - *

- * 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 - */ - public ConnectorIndexChange(Connector connector, Integer oldIndex, - Integer newIndex) { - this.connector = connector; - this.oldIndex = oldIndex; - this.newIndex = newIndex; - - assert assertStateIsOk(); - } - - private boolean assertStateIsOk() { - assert (connector != null && newIndex != null) - || (connector == null && oldIndex != null && newIndex == null) : "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. - *

- * If null, the connector is recently added. This means that - * {@link #getConnector()} is expected not to return null. - * - * @return the old index for the connector - */ - public Integer getOldIndex() { - assert assertStateIsOk(); - return oldIndex; - } - - /** - * Gets the new index for the connector. - *

- * If null, the connector should be removed. This means that - * {@link #getConnector()} is expected to return null 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 null - */ - public Connector getConnector() { - assert assertStateIsOk(); - return connector; - } - - /** - * Sets the changed connector. - * - * @param connector - * the changed connector. May be null - */ - public void setConnector(Connector connector) { - this.connector = connector; - } - - /** - * Sets the old index - * - * @param oldIndex - * the old index. May be null 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 null if a connector is - * being removed - */ - public void setNewIndex(Integer newIndex) { - this.newIndex = newIndex; - } -} 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..40f4541fb1 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/grid/DetailsConnectorChange.java @@ -0,0 +1,147 @@ +/* + * 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 com.vaadin.shared.Connector; + +/** + * A description of an indexing modification for a connector. This is used by + * Grid by internal bookkeeping updates. + * + * @since + * @author Vaadin Ltd + */ +public class DetailsConnectorChange implements Serializable { + + private Connector connector; + private Integer oldIndex; + private Integer newIndex; + + /** Create a new connector index change */ + public DetailsConnectorChange() { + } + + /** + * Convenience constructor for setting all the fields in one line. + *

+ * 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 + */ + public DetailsConnectorChange(Connector connector, Integer oldIndex, + Integer newIndex) { + this.connector = connector; + this.oldIndex = oldIndex; + this.newIndex = newIndex; + + 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. + *

+ * If null, the connector is recently added. This means that + * {@link #getConnector()} is expected not to return null. + * + * @return the old index for the connector + */ + public Integer getOldIndex() { + assert assertStateIsOk(); + return oldIndex; + } + + /** + * Gets the new index for the connector. + *

+ * If null, the connector should be removed. This means that + * {@link #getConnector()} is expected to return null 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 null + */ + public Connector getConnector() { + assert assertStateIsOk(); + return connector; + } + + /** + * Sets the changed connector. + * + * @param connector + * the changed connector. May be null + */ + public void setConnector(Connector connector) { + this.connector = connector; + } + + /** + * Sets the old index + * + * @param oldIndex + * the old index. May be null 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 null if a connector is + * being removed + */ + public void setNewIndex(Integer newIndex) { + this.newIndex = newIndex; + } +} diff --git a/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java b/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java index 672c83ff53..98e7fac567 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridClientRpc.java @@ -65,9 +65,10 @@ public interface GridClientRpc extends ClientRpc { * @param connectorChanges * the indexing changes of details connectors * @param fetchId - * the id of the request for fetching the changes + * 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 connectorChanges, int fetchId); + Set connectorChanges, int fetchId); } -- cgit v1.2.3