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.

ItemClickEvent.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright 2000-2016 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.v7.event;
  17. import java.io.Serializable;
  18. import java.lang.reflect.Method;
  19. import com.vaadin.event.MouseEvents.ClickEvent;
  20. import com.vaadin.shared.MouseEventDetails;
  21. import com.vaadin.ui.Component;
  22. import com.vaadin.v7.data.Container;
  23. import com.vaadin.v7.data.Item;
  24. import com.vaadin.v7.data.Property;
  25. /**
  26. *
  27. * Click event fired by a {@link Component} implementing {@link Container}
  28. * interface. ItemClickEvents happens on an {@link Item} rendered somehow on
  29. * terminal. Event may also contain a specific {@link Property} on which the
  30. * click event happened.
  31. *
  32. * @since 5.3
  33. *
  34. * @deprecated As of 8.0, see component-specific click events.
  35. */
  36. @SuppressWarnings("serial")
  37. @Deprecated
  38. public class ItemClickEvent extends ClickEvent implements Serializable {
  39. private Item item;
  40. private Object itemId;
  41. private Object propertyId;
  42. public ItemClickEvent(Component source, Item item, Object itemId,
  43. Object propertyId, MouseEventDetails details) {
  44. super(source, details);
  45. this.item = item;
  46. this.itemId = itemId;
  47. this.propertyId = propertyId;
  48. }
  49. /**
  50. * Gets the item on which the click event occurred.
  51. *
  52. * @return item which was clicked
  53. */
  54. public Item getItem() {
  55. return item;
  56. }
  57. /**
  58. * Gets a possible identifier in source for clicked Item
  59. *
  60. * @return
  61. */
  62. public Object getItemId() {
  63. return itemId;
  64. }
  65. /**
  66. * Returns property on which click event occurred. Returns null if source
  67. * cannot be resolved at property level. For example if clicked a cell in
  68. * table, the "column id" is returned.
  69. *
  70. * @return a property id of clicked property or null if click didn't occur
  71. * on any distinct property.
  72. */
  73. public Object getPropertyId() {
  74. return propertyId;
  75. }
  76. public static final Method ITEM_CLICK_METHOD;
  77. static {
  78. try {
  79. ITEM_CLICK_METHOD = ItemClickListener.class.getDeclaredMethod(
  80. "itemClick", new Class[] { ItemClickEvent.class });
  81. } catch (final NoSuchMethodException e) {
  82. // This should never happen
  83. throw new RuntimeException();
  84. }
  85. }
  86. @Deprecated
  87. public interface ItemClickListener extends Serializable {
  88. public void itemClick(ItemClickEvent event);
  89. }
  90. /**
  91. * The interface for adding and removing <code>ItemClickEvent</code>
  92. * listeners. By implementing this interface a class explicitly announces
  93. * that it will generate an <code>ItemClickEvent</code> when one of its
  94. * items is clicked.
  95. * <p>
  96. * Note: The general Java convention is not to explicitly declare that a
  97. * class generates events, but to directly define the
  98. * <code>addListener</code> and <code>removeListener</code> methods. That
  99. * way the caller of these methods has no real way of finding out if the
  100. * class really will send the events, or if it just defines the methods to
  101. * be able to implement an interface.
  102. * </p>
  103. *
  104. * @since 6.5
  105. * @see ItemClickListener
  106. * @see ItemClickEvent
  107. */
  108. @Deprecated
  109. public interface ItemClickNotifier extends Serializable {
  110. /**
  111. * Register a listener to handle {@link ItemClickEvent}s.
  112. *
  113. * @param listener
  114. * ItemClickListener to be registered
  115. */
  116. public void addItemClickListener(ItemClickListener listener);
  117. /**
  118. * @deprecated As of 7.0, replaced by
  119. * {@link #addItemClickListener(ItemClickListener)}
  120. **/
  121. @Deprecated
  122. public void addListener(ItemClickListener listener);
  123. /**
  124. * Removes an ItemClickListener.
  125. *
  126. * @param listener
  127. * ItemClickListener to be removed
  128. */
  129. public void removeItemClickListener(ItemClickListener listener);
  130. /**
  131. * @deprecated As of 7.0, replaced by
  132. * {@link #removeItemClickListener(ItemClickListener)}
  133. **/
  134. @Deprecated
  135. public void removeListener(ItemClickListener listener);
  136. }
  137. }