You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DetailsConnectorChange.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.shared.ui.grid;
  17. import java.io.Serializable;
  18. import com.vaadin.shared.Connector;
  19. /**
  20. * A description of an indexing modification for a connector. This is used by
  21. * Grid by internal bookkeeping updates.
  22. *
  23. * @since
  24. * @author Vaadin Ltd
  25. */
  26. public class DetailsConnectorChange implements Serializable {
  27. private Connector connector;
  28. private Integer oldIndex;
  29. private Integer newIndex;
  30. /** Create a new connector index change */
  31. public DetailsConnectorChange() {
  32. }
  33. /**
  34. * Convenience constructor for setting all the fields in one line.
  35. * <p>
  36. * Calling this constructor will also assert that the state of the pojo is
  37. * consistent by internal assumptions.
  38. *
  39. * @param connector
  40. * the changed connector
  41. * @param oldIndex
  42. * the old index
  43. * @param newIndex
  44. * the new index
  45. */
  46. public DetailsConnectorChange(Connector connector, Integer oldIndex,
  47. Integer newIndex) {
  48. this.connector = connector;
  49. this.oldIndex = oldIndex;
  50. this.newIndex = newIndex;
  51. assert assertStateIsOk();
  52. }
  53. private boolean assertStateIsOk() {
  54. boolean connectorAndNewIndexIsNotNull = connector != null
  55. && newIndex != null;
  56. boolean connectorAndNewIndexIsNullThenOldIndexIsSet = connector == null
  57. && newIndex == null && oldIndex != null;
  58. assert (connectorAndNewIndexIsNotNull || connectorAndNewIndexIsNullThenOldIndexIsSet) : "connector: "
  59. + nullityString(connector)
  60. + ", oldIndex: "
  61. + nullityString(oldIndex)
  62. + ", newIndex: "
  63. + nullityString(newIndex);
  64. return true;
  65. }
  66. private static String nullityString(Object object) {
  67. return object == null ? "null" : "non-null";
  68. }
  69. /**
  70. * Gets the old index for the connector.
  71. * <p>
  72. * If <code>null</code>, the connector is recently added. This means that
  73. * {@link #getConnector()} is expected not to return <code>null</code>.
  74. *
  75. * @return the old index for the connector
  76. */
  77. public Integer getOldIndex() {
  78. assert assertStateIsOk();
  79. return oldIndex;
  80. }
  81. /**
  82. * Gets the new index for the connector.
  83. * <p>
  84. * If <code>null</code>, the connector should be removed. This means that
  85. * {@link #getConnector()} is expected to return <code>null</code> as well.
  86. *
  87. * @return the new index for the connector
  88. */
  89. public Integer getNewIndex() {
  90. assert assertStateIsOk();
  91. return newIndex;
  92. }
  93. /**
  94. * Gets the changed connector.
  95. *
  96. * @return the changed connector. Might be <code>null</code>
  97. */
  98. public Connector getConnector() {
  99. assert assertStateIsOk();
  100. return connector;
  101. }
  102. /**
  103. * Sets the changed connector.
  104. *
  105. * @param connector
  106. * the changed connector. May be <code>null</code>
  107. */
  108. public void setConnector(Connector connector) {
  109. this.connector = connector;
  110. }
  111. /**
  112. * Sets the old index
  113. *
  114. * @param oldIndex
  115. * the old index. May be <code>null</code> if a new connector is
  116. * being inserted
  117. */
  118. public void setOldIndex(Integer oldIndex) {
  119. this.oldIndex = oldIndex;
  120. }
  121. /**
  122. * Sets the new index
  123. *
  124. * @param newIndex
  125. * the new index. May be <code>null</code> if a connector is
  126. * being removed
  127. */
  128. public void setNewIndex(Integer newIndex) {
  129. this.newIndex = newIndex;
  130. }
  131. }