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

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