123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /*
- * 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.
- * <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
- */
- 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.
- * <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;
- }
- }
|