summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui/AbstractField.java
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2010-03-23 08:31:20 +0000
committerMarc Englund <marc.englund@itmill.com>2010-03-23 08:31:20 +0000
commitcc6fa776179274fb514b76cbfabddcac8d8469b9 (patch)
treed292b2b65805931accdc588170560af173e53cbf /src/com/vaadin/ui/AbstractField.java
parent12a9faf7aa438715805d08d3a42b63b0f18965a5 (diff)
downloadvaadin-framework-cc6fa776179274fb514b76cbfabddcac8d8469b9.tar.gz
vaadin-framework-cc6fa776179274fb514b76cbfabddcac8d8469b9.zip
Easier keyboard shortcuts for #875 - includes shorthand notation for ShortcutAction, Form is now handler in addition to Panel, AbstractField.addAction() delegates handling to containing Window. Javadoc and examples TBD
svn changeset:12026/svn branch:6.3
Diffstat (limited to 'src/com/vaadin/ui/AbstractField.java')
-rw-r--r--src/com/vaadin/ui/AbstractField.java73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index c3d5066600..413916f298 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -19,6 +19,9 @@ import com.vaadin.data.Property;
import com.vaadin.data.Validatable;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.event.Action;
+import com.vaadin.event.ActionManager;
+import com.vaadin.event.ShortcutListener;
import com.vaadin.terminal.CompositeErrorMessage;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.PaintException;
@@ -52,7 +55,7 @@ import com.vaadin.terminal.PaintTarget;
*/
@SuppressWarnings("serial")
public abstract class AbstractField extends AbstractComponent implements Field,
- Property.ReadOnlyStatusChangeNotifier {
+ Property.ReadOnlyStatusChangeNotifier, Action.NotifierProxy {
/* Private members */
@@ -124,6 +127,12 @@ public abstract class AbstractField extends AbstractComponent implements Field,
*/
private boolean validationVisible = true;
+ /**
+ * Keeps track of the Actions added to this component; the actual
+ * handling/notifying is delegated, usually to the containing window.
+ */
+ protected ActionManager actionManager;
+
/* Component basics */
/*
@@ -1046,6 +1055,21 @@ public abstract class AbstractField extends AbstractComponent implements Field,
if (delayedFocus) {
focus();
}
+ if (actionManager != null && !(this instanceof Action.Container)) {
+ // Only for non Action.Containers because those want to paint
+ // actions themselves - e.g Form
+ actionManager.setViewer(getWindow());
+ }
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ if (actionManager != null && !(this instanceof Action.Container)) {
+ // Only for non Action.Containers because those want to paint
+ // actions themselves - e.g Form
+ actionManager.setViewer((Window) null);
+ }
}
/**
@@ -1161,4 +1185,51 @@ public abstract class AbstractField extends AbstractComponent implements Field,
requestRepaint();
}
+ /*
+ * Actions
+ */
+
+ protected ActionManager getActionManager() {
+ if (actionManager == null) {
+ actionManager = new ActionManager();
+ if (getWindow() != null) {
+ actionManager.setViewer(getWindow());
+ }
+ }
+ return actionManager;
+ }
+
+ public <T extends Action & Action.Listener> boolean addAction(T action) {
+ return getActionManager().addAction(action);
+ }
+
+ public <T extends Action & Action.Listener> boolean removeAction(T action) {
+ if (actionManager == null) {
+ return actionManager.removeAction(action);
+ }
+ return false;
+ }
+
+ public static class FocusShortcut extends ShortcutListener {
+ protected Focusable focusable;
+
+ public FocusShortcut(Focusable focusable, String shorthandCaption) {
+ super(shorthandCaption);
+ this.focusable = focusable;
+ }
+
+ public FocusShortcut(Focusable focusable, int keyCode, int... modifiers) {
+ super(null, keyCode, modifiers);
+ this.focusable = focusable;
+ }
+
+ public FocusShortcut(Focusable focusable, int keyCode) {
+ this(focusable, keyCode, null);
+ }
+
+ @Override
+ public void handleAction(Object sender, Object target) {
+ this.focusable.focus();
+ }
+ }
} \ No newline at end of file