aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/event/Action.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-08-13 18:34:33 +0300
committerArtur Signell <artur@vaadin.com>2012-08-13 19:18:33 +0300
commite85d933b25cc3c5cc85eb7eb4b13b950fd8e1569 (patch)
tree9ab6f13f7188cab44bbd979b1cf620f15328a03f /server/src/com/vaadin/event/Action.java
parent14dd4d0b28c76eb994b181a4570f3adec53342e6 (diff)
downloadvaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.tar.gz
vaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.zip
Moved server files to a server src folder (#9299)
Diffstat (limited to 'server/src/com/vaadin/event/Action.java')
-rw-r--r--server/src/com/vaadin/event/Action.java195
1 files changed, 195 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/Action.java b/server/src/com/vaadin/event/Action.java
new file mode 100644
index 0000000000..6c218c25dc
--- /dev/null
+++ b/server/src/com/vaadin/event/Action.java
@@ -0,0 +1,195 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.event;
+
+import java.io.Serializable;
+
+import com.vaadin.terminal.Resource;
+
+/**
+ * Implements the action framework. This class contains subinterfaces for action
+ * handling and listing, and for action handler registrations and
+ * unregistration.
+ *
+ * @author Vaadin Ltd.
+ * @version
+ * @VERSION@
+ * @since 3.0
+ */
+@SuppressWarnings("serial")
+public class Action implements Serializable {
+
+ /**
+ * Action title.
+ */
+ private String caption;
+
+ /**
+ * Action icon.
+ */
+ private Resource icon = null;
+
+ /**
+ * Constructs a new action with the given caption.
+ *
+ * @param caption
+ * the caption for the new action.
+ */
+ public Action(String caption) {
+ this.caption = caption;
+ }
+
+ /**
+ * Constructs a new action with the given caption string and icon.
+ *
+ * @param caption
+ * the caption for the new action.
+ * @param icon
+ * the icon for the new action.
+ */
+ public Action(String caption, Resource icon) {
+ this.caption = caption;
+ this.icon = icon;
+ }
+
+ /**
+ * Returns the action's caption.
+ *
+ * @return the action's caption as a <code>String</code>.
+ */
+ public String getCaption() {
+ return caption;
+ }
+
+ /**
+ * Returns the action's icon.
+ *
+ * @return the action's Icon.
+ */
+ public Resource getIcon() {
+ return icon;
+ }
+
+ /**
+ * An Action that implements this interface can be added to an
+ * Action.Notifier (or NotifierProxy) via the <code>addAction()</code>
+ * -method, which in many cases is easier than implementing the
+ * Action.Handler interface.<br/>
+ *
+ */
+ public interface Listener extends Serializable {
+ public void handleAction(Object sender, Object target);
+ }
+
+ /**
+ * Action.Containers implementing this support an easier way of adding
+ * single Actions than the more involved Action.Handler. The added actions
+ * must be Action.Listeners, thus handling the action themselves.
+ *
+ */
+ public interface Notifier extends Container {
+ public <T extends Action & Action.Listener> void addAction(T action);
+
+ public <T extends Action & Action.Listener> void removeAction(T action);
+ }
+
+ public interface ShortcutNotifier extends Serializable {
+ public void addShortcutListener(ShortcutListener shortcut);
+
+ public void removeShortcutListener(ShortcutListener shortcut);
+ }
+
+ /**
+ * Interface implemented by classes who wish to handle actions.
+ *
+ * @author Vaadin Ltd.
+ * @version
+ * @VERSION@
+ * @since 3.0
+ */
+ public interface Handler extends Serializable {
+
+ /**
+ * Gets the list of actions applicable to this handler.
+ *
+ * @param target
+ * the target handler to list actions for. For item
+ * containers this is the item id.
+ * @param sender
+ * the party that would be sending the actions. Most of this
+ * is the action container.
+ * @return the list of Action
+ */
+ public Action[] getActions(Object target, Object sender);
+
+ /**
+ * Handles an action for the given target. The handler method may just
+ * discard the action if it's not suitable.
+ *
+ * @param action
+ * the action to be handled.
+ * @param sender
+ * the sender of the action. This is most often the action
+ * container.
+ * @param target
+ * the target of the action. For item containers this is the
+ * item id.
+ */
+ public void handleAction(Action action, Object sender, Object target);
+ }
+
+ /**
+ * Interface implemented by all components where actions can be registered.
+ * This means that the components lets others to register as action handlers
+ * to it. When the component receives an action targeting its contents it
+ * should loop all action handlers registered to it and let them handle the
+ * action.
+ *
+ * @author Vaadin Ltd.
+ * @version
+ * @VERSION@
+ * @since 3.0
+ */
+ public interface Container extends Serializable {
+
+ /**
+ * Registers a new action handler for this container
+ *
+ * @param actionHandler
+ * the new handler to be added.
+ */
+ public void addActionHandler(Action.Handler actionHandler);
+
+ /**
+ * Removes a previously registered action handler for the contents of
+ * this container.
+ *
+ * @param actionHandler
+ * the handler to be removed.
+ */
+ public void removeActionHandler(Action.Handler actionHandler);
+ }
+
+ /**
+ * Sets the caption.
+ *
+ * @param caption
+ * the caption to set.
+ */
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ /**
+ * Sets the icon.
+ *
+ * @param icon
+ * the icon to set.
+ */
+ public void setIcon(Resource icon) {
+ this.icon = icon;
+ }
+
+}