Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ItemClickEvent.java 4.6KB

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