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.

Action.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.event;
  5. import java.io.Serializable;
  6. import com.vaadin.terminal.Resource;
  7. /**
  8. * Implements the action framework. This class contains subinterfaces for action
  9. * handling and listing, and for action handler registrations and
  10. * unregistration.
  11. *
  12. * @author Vaadin Ltd.
  13. * @since 3.0
  14. */
  15. @SuppressWarnings("serial")
  16. public class Action implements Serializable {
  17. /**
  18. * Action title.
  19. */
  20. private String caption;
  21. /**
  22. * Action icon.
  23. */
  24. private Resource icon = null;
  25. /**
  26. * Constructs a new action with the given caption.
  27. *
  28. * @param caption
  29. * the caption for the new action.
  30. */
  31. public Action(String caption) {
  32. this.caption = caption;
  33. }
  34. /**
  35. * Constructs a new action with the given caption string and icon.
  36. *
  37. * @param caption
  38. * the caption for the new action.
  39. * @param icon
  40. * the icon for the new action.
  41. */
  42. public Action(String caption, Resource icon) {
  43. this.caption = caption;
  44. this.icon = icon;
  45. }
  46. /**
  47. * Returns the action's caption.
  48. *
  49. * @return the action's caption as a <code>String</code>.
  50. */
  51. public String getCaption() {
  52. return caption;
  53. }
  54. /**
  55. * Returns the action's icon.
  56. *
  57. * @return the action's Icon.
  58. */
  59. public Resource getIcon() {
  60. return icon;
  61. }
  62. /**
  63. * An Action that implements this interface can be added to an
  64. * Action.Notifier (or NotifierProxy) via the <code>addAction()</code>
  65. * -method, which in many cases is easier than implementing the
  66. * Action.Handler interface.<br/>
  67. *
  68. */
  69. public interface Listener extends Serializable {
  70. public void handleAction(Object sender, Object target);
  71. }
  72. /**
  73. * Action.Containers implementing this support an easier way of adding
  74. * single Actions than the more involved Action.Handler. The added actions
  75. * must be Action.Listeners, thus handling the action themselves.
  76. *
  77. */
  78. public interface Notifier extends Container {
  79. public <T extends Action & Action.Listener> void addAction(T action);
  80. public <T extends Action & Action.Listener> void removeAction(T action);
  81. }
  82. public interface ShortcutNotifier extends Serializable {
  83. public void addShortcutListener(ShortcutListener shortcut);
  84. public void removeShortcutListener(ShortcutListener shortcut);
  85. }
  86. /**
  87. * Interface implemented by classes who wish to handle actions.
  88. *
  89. * @author Vaadin Ltd.
  90. * @version
  91. * @VERSION@
  92. * @since 3.0
  93. */
  94. public interface Handler extends Serializable {
  95. /**
  96. * Gets the list of actions applicable to this handler.
  97. *
  98. * @param target
  99. * the target handler to list actions for. For item
  100. * containers this is the item id.
  101. * @param sender
  102. * the party that would be sending the actions. Most of this
  103. * is the action container.
  104. * @return the list of Action
  105. */
  106. public Action[] getActions(Object target, Object sender);
  107. /**
  108. * Handles an action for the given target. The handler method may just
  109. * discard the action if it's not suitable.
  110. *
  111. * @param action
  112. * the action to be handled.
  113. * @param sender
  114. * the sender of the action. This is most often the action
  115. * container.
  116. * @param target
  117. * the target of the action. For item containers this is the
  118. * item id.
  119. */
  120. public void handleAction(Action action, Object sender, Object target);
  121. }
  122. /**
  123. * Interface implemented by all components where actions can be registered.
  124. * This means that the components lets others to register as action handlers
  125. * to it. When the component receives an action targeting its contents it
  126. * should loop all action handlers registered to it and let them handle the
  127. * action.
  128. *
  129. * @author Vaadin Ltd.
  130. * @version
  131. * @VERSION@
  132. * @since 3.0
  133. */
  134. public interface Container extends Serializable {
  135. /**
  136. * Registers a new action handler for this container
  137. *
  138. * @param actionHandler
  139. * the new handler to be added.
  140. */
  141. public void addActionHandler(Action.Handler actionHandler);
  142. /**
  143. * Removes a previously registered action handler for the contents of
  144. * this container.
  145. *
  146. * @param actionHandler
  147. * the handler to be removed.
  148. */
  149. public void removeActionHandler(Action.Handler actionHandler);
  150. }
  151. /**
  152. * Sets the caption.
  153. *
  154. * @param caption
  155. * the caption to set.
  156. */
  157. public void setCaption(String caption) {
  158. this.caption = caption;
  159. }
  160. /**
  161. * Sets the icon.
  162. *
  163. * @param icon
  164. * the icon to set.
  165. */
  166. public void setIcon(Resource icon) {
  167. this.icon = icon;
  168. }
  169. }