aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2011-11-22 11:10:03 +0200
committerArtur Signell <artur@vaadin.com>2011-11-22 13:18:37 +0200
commit9a36668a93e3eec4607d76ba837bca729565b04e (patch)
treef78e0e42fe4bf8574b45edf2bd8dd6e486e485fe /src
parentd62453474921c5d323bd7b506c03016e574e0bfb (diff)
downloadvaadin-framework-9a36668a93e3eec4607d76ba837bca729565b04e.tar.gz
vaadin-framework-9a36668a93e3eec4607d76ba837bca729565b04e.zip
#7964 CheckBox now extends AbstractField directly.
ClickListener is no longer available for a CheckBox. Fixed tests accordingly
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java6
-rw-r--r--src/com/vaadin/ui/CheckBox.java137
2 files changed, 74 insertions, 69 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
index 2318a1ab69..3f5973d804 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
@@ -26,6 +26,8 @@ import com.vaadin.terminal.gwt.client.VTooltip;
public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
Paintable, Field, FocusHandler, BlurHandler {
+ public static final String VARIABLE_STATE = "state";
+
public static final String CLASSNAME = "v-checkbox";
String id;
@@ -55,7 +57,7 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
event.getNativeEvent(), getElement());
client.updateVariable(id, "mousedetails", details.serialize(),
false);
- client.updateVariable(id, "state", getValue(), immediate);
+ client.updateVariable(id, VARIABLE_STATE, getValue(), immediate);
}
});
@@ -119,7 +121,7 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
// Set text
setText(uidl.getStringAttribute("caption"));
- setValue(uidl.getBooleanVariable("state"));
+ setValue(uidl.getBooleanVariable(VARIABLE_STATE));
immediate = uidl.getBooleanAttribute("immediate");
}
diff --git a/src/com/vaadin/ui/CheckBox.java b/src/com/vaadin/ui/CheckBox.java
index b9ae236cb0..9435caf587 100644
--- a/src/com/vaadin/ui/CheckBox.java
+++ b/src/com/vaadin/ui/CheckBox.java
@@ -4,110 +4,113 @@
package com.vaadin.ui;
-import java.lang.reflect.Method;
+import java.util.Map;
import com.vaadin.data.Property;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.ui.VCheckBox;
@ClientWidget(com.vaadin.terminal.gwt.client.ui.VCheckBox.class)
-public class CheckBox extends Button {
+public class CheckBox extends AbstractField {
/**
- * Creates a new switch button.
+ * Creates a new checkbox.
*/
public CheckBox() {
- setSwitchMode(true);
}
/**
- * Creates a new switch button with a caption and a set initial state.
+ * Creates a new checkbox with a set caption.
*
* @param caption
- * the caption of the switch button
- * @param initialState
- * the initial state of the switch button
+ * the Checkbox caption.
*/
- @SuppressWarnings("deprecation")
- public CheckBox(String caption, boolean initialState) {
- super(caption, initialState);
- }
-
- /**
- * Creates a new switch button with a caption and a click listener.
- *
- * @param caption
- * the caption of the switch button
- * @param listener
- * the click listener
- */
- public CheckBox(String caption, ClickListener listener) {
- super(caption, listener);
- setSwitchMode(true);
+ public CheckBox(String caption) {
+ this();
+ setCaption(caption);
}
/**
- * Convenience method for creating a new switch button with a method
- * listening button clicks. Using this method is discouraged because it
- * cannot be checked during compilation. Use
- * {@link #addListener(Class, Object, Method)} or
- * {@link #addListener(com.vaadin.ui.Component.Listener)} instead. The
- * method must have either no parameters, or only one parameter of
- * Button.ClickEvent type.
+ * Creates a new checkbox with a caption and a set initial state.
*
* @param caption
- * the Button caption.
- * @param target
- * the Object having the method for listening button clicks.
- * @param methodName
- * the name of the method in target object, that receives button
- * click events.
+ * the caption of the checkbox
+ * @param initialState
+ * the initial state of the checkbox
*/
- public CheckBox(String caption, Object target, String methodName) {
- super(caption, target, methodName);
- setSwitchMode(true);
+ public CheckBox(String caption, boolean initialState) {
+ this(caption);
+ setValue(initialState);
}
/**
- * Creates a new switch button that is connected to a boolean property.
+ * Creates a new checkbox that is connected to a boolean property.
*
* @param state
* the Initial state of the switch-button.
* @param dataSource
*/
- @SuppressWarnings("deprecation")
public CheckBox(String caption, Property dataSource) {
- super(caption, dataSource);
- setSwitchMode(true);
+ this(caption);
+ setPropertyDataSource(dataSource);
}
- /**
- * Creates a new push button with a set caption.
- *
- * The value of the push button is always false and they are immediate by
- * default.
- *
- * @param caption
- * the Button caption.
- */
+ @Override
+ public Class<?> getType() {
+ return Boolean.class;
+ }
- @SuppressWarnings("deprecation")
- public CheckBox(String caption) {
- super(caption, false);
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ super.paintContent(target);
+
+ target.addVariable(this, VCheckBox.VARIABLE_STATE, (Boolean) getValue());
}
- @Deprecated
@Override
- public void setSwitchMode(boolean switchMode)
- throws UnsupportedOperationException {
- if (this.switchMode && !switchMode) {
- throw new UnsupportedOperationException(
- "CheckBox is always in switch mode (consider using a Button)");
+ public void changeVariables(Object source, Map<String, Object> variables) {
+ super.changeVariables(source, variables);
+
+ if (!isReadOnly() && variables.containsKey(VCheckBox.VARIABLE_STATE)) {
+ // Gets the new and old states
+ final Boolean newValue = (Boolean) variables
+ .get(VCheckBox.VARIABLE_STATE);
+ final Boolean oldValue = (Boolean) getValue();
+
+ // The event is only sent if the switch state is changed
+ if (newValue != null && !newValue.equals(oldValue)) {
+ setValue(newValue);
+ }
+ }
+
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ fireEvent(new FocusEvent(this));
+ }
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ fireEvent(new BlurEvent(this));
}
- super.setSwitchMode(true);
}
- @Override
- public void setDisableOnClick(boolean disableOnClick) {
- throw new UnsupportedOperationException(
- "CheckBox does not support disable on click");
+ public void addListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ public void removeListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
+ public void addListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ public void removeListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+
+ }
}