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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.event;
  5. import java.io.Serializable;
  6. import java.lang.reflect.Method;
  7. import com.vaadin.data.Container;
  8. import com.vaadin.data.Item;
  9. import com.vaadin.data.Property;
  10. import com.vaadin.event.MouseEvents.ClickEvent;
  11. import com.vaadin.terminal.gwt.client.MouseEventDetails;
  12. import com.vaadin.ui.Component;
  13. /**
  14. *
  15. * Click event fired by a {@link Component} implementing
  16. * {@link com.vaadin.data.Container} interface. ItemClickEvents happens on an
  17. * {@link Item} rendered somehow on terminal. Event may also contain a specific
  18. * {@link Property} on which the click event happened.
  19. *
  20. * @since 5.3
  21. *
  22. */
  23. @SuppressWarnings("serial")
  24. public class ItemClickEvent extends ClickEvent implements Serializable {
  25. private Item item;
  26. private Object itemId;
  27. private Object propertyId;
  28. public ItemClickEvent(Component source, Item item, Object itemId,
  29. Object propertyId, MouseEventDetails details) {
  30. super(source, details);
  31. this.item = item;
  32. this.itemId = itemId;
  33. this.propertyId = propertyId;
  34. }
  35. /**
  36. * Gets the item on which the click event occurred.
  37. *
  38. * @return item which was clicked
  39. */
  40. public Item getItem() {
  41. return item;
  42. }
  43. /**
  44. * Gets a possible identifier in source for clicked Item
  45. *
  46. * @return
  47. */
  48. public Object getItemId() {
  49. return itemId;
  50. }
  51. /**
  52. * Returns property on which click event occurred. Returns null if source
  53. * cannot be resolved at property leve. For example if clicked a cell in
  54. * table, the "column id" is returned.
  55. *
  56. * @return a property id of clicked property or null if click didn't occur
  57. * on any distinct property.
  58. */
  59. public Object getPropertyId() {
  60. return propertyId;
  61. }
  62. public static final Method ITEM_CLICK_METHOD;
  63. static {
  64. try {
  65. ITEM_CLICK_METHOD = ItemClickListener.class.getDeclaredMethod(
  66. "itemClick", new Class[] { ItemClickEvent.class });
  67. } catch (final java.lang.NoSuchMethodException e) {
  68. // This should never happen
  69. throw new java.lang.RuntimeException();
  70. }
  71. }
  72. public interface ItemClickListener extends Serializable {
  73. public void itemClick(ItemClickEvent event);
  74. }
  75. /**
  76. * Components implementing
  77. *
  78. * @link {@link Container} interface may support emitting
  79. * {@link ItemClickEvent}s.
  80. */
  81. public interface ItemClickSource extends Serializable {
  82. /**
  83. * Register listener to handle ItemClickEvents.
  84. *
  85. * Note! Click listeners are rather terminal dependent features.
  86. *
  87. * This feature is EXPERIMENTAL
  88. *
  89. * @param listener
  90. * ItemClickListener to be registered
  91. */
  92. public void addListener(ItemClickListener listener);
  93. /**
  94. * Removes ItemClickListener.
  95. *
  96. * @param listener
  97. */
  98. public void removeListener(ItemClickListener listener);
  99. }
  100. }