Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.event;
  5. import com.itmill.toolkit.terminal.Resource;
  6. /**
  7. * Implements the action framework. This class contains subinterfaces for action
  8. * handling and listing, and for action handler registrations and
  9. * unregistration.
  10. *
  11. * @author IT Mill Ltd.
  12. * @version
  13. * @VERSION@
  14. * @since 3.0
  15. */
  16. public class Action {
  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. * Interface implemented by classes who wish to handle actions.
  64. *
  65. * @author IT Mill Ltd.
  66. * @version
  67. * @VERSION@
  68. * @since 3.0
  69. */
  70. public interface Handler {
  71. /**
  72. * Gets the list of actions applicable to this handler.
  73. *
  74. * @param target
  75. * the target handler to list actions for. For item
  76. * containers this is the item id.
  77. * @param sender
  78. * the party that would be sending the actions. Most of
  79. * this is the action container.
  80. * @return the list of Action
  81. */
  82. public Action[] getActions(Object target, Object sender);
  83. /**
  84. * Handles an action for the given target. The handler method may just
  85. * discard the action if it's not suitable.
  86. *
  87. * @param action
  88. * the action to be handled.
  89. * @param sender
  90. * the sender of the action. This is most often the
  91. * action container.
  92. * @param target
  93. * the target of the action. For item containers this is
  94. * the item id.
  95. */
  96. public void handleAction(Action action, Object sender, Object target);
  97. }
  98. /**
  99. * Interface implemented by all components where actions can be registered.
  100. * This means that the components lets others to register as action handlers
  101. * to it. When the component receives an action targeting its contents it
  102. * should loop all action handlers registered to it and let them handle the
  103. * action.
  104. *
  105. * @author IT Mill Ltd.
  106. * @version
  107. * @VERSION@
  108. * @since 3.0
  109. */
  110. public interface Container {
  111. /**
  112. * Registers a new action handler for this container
  113. *
  114. * @param actionHandler
  115. * the new handler to be added.
  116. */
  117. public void addActionHandler(Action.Handler actionHandler);
  118. /**
  119. * Removes a previously registered action handler for the contents of
  120. * this container.
  121. *
  122. * @param actionHandler
  123. * the handler to be removed.
  124. */
  125. public void removeActionHandler(Action.Handler actionHandler);
  126. }
  127. /**
  128. * Sets the caption.
  129. *
  130. * @param caption
  131. * the caption to set.
  132. */
  133. public void setCaption(String caption) {
  134. this.caption = caption;
  135. }
  136. /**
  137. * Sets the icon.
  138. *
  139. * @param icon
  140. * the icon to set.
  141. */
  142. public void setIcon(Resource icon) {
  143. this.icon = icon;
  144. }
  145. }