com.vaadin.ui.


Class Button

java.lang.Object
  com.vaadin.ui.AbstractComponent
      com.vaadin.ui.AbstractField
          com.vaadin.ui.Button

All Implemented Interfaces:

Buffered, BufferedValidatable, Property, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.ShortcutNotifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, Field, Serializable, EventListener

Direct Known Subclasses:

CheckBox, NativeButton

public class Button
extends AbstractField
implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier

A generic button component.

Since:

3.0

Version:

6.8.18

Author:

Vaadin Ltd.

See Also:

Serialized Form

Nested Class Summary
 class Button.ClickEvent
          Click event.
static interface Button.ClickListener
          Interface for listening for a Button.ClickEvent fired by a Component.
static class Button.ClickShortcut
          A ShortcutListener specifically made to define a keyboard shortcut that invokes a click on the given button.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Field
Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Field Summary
protected  Button.ClickShortcut clickShortcut
           
static String STYLE_LINK
          Deprecated. use BaseTheme.BUTTON_LINK instead.
 
Constructor Summary
Button()
          Creates a new push button.
Button(String caption)
          Creates a new push button.
Button(String caption, boolean initialState)
          Deprecated. use CheckBox instead of Button in "switchmode"
Button(String caption, Button.ClickListener listener)
          Creates a new push button with click listener.
Button(String caption, Object target, String methodName)
          Creates a new push button with a method listening button clicks.
Button(String caption, Property dataSource)
          Deprecated. use CheckBox instead of Button in "switchmode"
 
Method Summary
 void addListener(Button.ClickListener listener)
          Adds the button click listener.
 void addListener(FieldEvents.BlurListener listener)
          Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.
 void addListener(FieldEvents.FocusListener listener)
          Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.
 boolean booleanValue()
          Get the boolean value of the button state.
 void changeVariables(Object source, Map<String,Object> variables)
          Invoked when the value of a variable has changed.
 void click()
          Simulates a button click, notifying all server-side listeners.
protected  void fireClick()
          Fires a click event to all listeners without any event details.
protected  void fireClick(MouseEventDetails details)
          Fires a click event to all listeners.
 Class getType()
          The type of the button as a property.
 boolean isDisableOnClick()
          Determines if a button is automatically disabled when clicked.
 boolean isHtmlContentAllowed()
          Return HTML rendering setting
 boolean isSwitchMode()
          Deprecated. the CheckBox component should be used instead of Button in switch mode
 void paintContent(PaintTarget target)
          Paints the content of this component.
 void removeClickShortcut()
          Removes the keyboard shortcut previously set with setClickShortcut(int, int...).
 void removeListener(Button.ClickListener listener)
          Removes the button click listener.
 void removeListener(FieldEvents.BlurListener listener)
          Removes a BlurListener from the Component.
 void removeListener(FieldEvents.FocusListener listener)
          Removes a FocusListener from the Component.
 void setClickShortcut(int keyCode, int... modifiers)
          Makes it possible to invoke a click on this button by pressing the given ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKeys.
The shortcut is global (bound to the containing Window).
 void setDisableOnClick(boolean disableOnClick)
          Determines if a button is automatically disabled when clicked.
 void setHtmlContentAllowed(boolean htmlContentAllowed)
          Set whether the caption text is rendered as HTML or not.
 void setImmediate(boolean immediate)
          Sets immediate mode.
protected  void setInternalValue(Object newValue)
          Sets the internal field value.
 void setSwitchMode(boolean switchMode)
          Deprecated. the CheckBox component should be used instead of Button in switch mode
 
Methods inherited from class com.vaadin.ui.AbstractField
addListener, addListener, addShortcutListener, addValidator, attach, commit, constructField, detach, discard, fireReadOnlyStatusChange, fireValueChange, focus, getActionManager, getErrorMessage, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, getValue, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isReadThrough, isRequired, isValid, isValidationVisible, isWriteThrough, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeShortcutListener, removeValidator, setCurrentBufferedSourceException, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setReadThrough, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setValue, setWriteThrough, shouldHideErrors, toString, validate, valueChange
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, hasListeners, isEnabled, isImmediate, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setHeight, setHeightUnits, setIcon, setLocale, setParent, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, setWidth, setWidthUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Field
getDescription, setCaption, setDescription
 

Field Detail

STYLE_LINK

@Deprecated
public static final String STYLE_LINK

Deprecated. use BaseTheme.BUTTON_LINK instead.

Button style with no decorations. Looks like a link, acts like a button

See Also:
Constant Field Values

clickShortcut

protected Button.ClickShortcut clickShortcut
Constructor Detail

Button

public Button()

Creates a new push button. The value of the push button is false and it is immediate by default.

Button

public Button(String caption)

Creates a new push button. The value of the push button is false and it is immediate by default.

Parameters:
caption - the Button caption.

Button

public Button(String caption,
              Button.ClickListener listener)

Creates a new push button with click listener.

Parameters:
caption - the Button caption.
listener - the Button click listener.

Button

public Button(String caption,
              Object target,
              String methodName)

Creates a new push button with a method listening button clicks. Using this method is discouraged because it cannot be checked during compilation. Use Button(String, com.vaadin.ui.Button.ClickListener) instead. The method must have either no parameters, or only one parameter of Button.ClickEvent type.

Parameters:
caption - the Button caption.
target - the Object having the method for listening button clicks.
methodName - the name of the method in target object, that receives button click events.

Button

@Deprecated
public Button(String caption,
                         boolean initialState)

Deprecated. use CheckBox instead of Button in "switchmode"

Creates a new switch button with initial value.

Parameters:
state - the Initial state of the switch-button.
initialState -

Button

@Deprecated
public Button(String caption,
                         Property dataSource)

Deprecated. use CheckBox instead of Button in "switchmode"

Creates a new switch button that is connected to a boolean property.

Parameters:
state - the Initial state of the switch-button.
dataSource -

Method Detail

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException

Paints the content of this component.

Overrides:
paintContent in class AbstractField

Parameters:
event - the PaintEvent.
Throws:
IOException - if the writing failed due to input/output error.
PaintException - if the paint operation failed.

changeVariables

public void changeVariables(Object source,
                            Map<String,Object> variables)

Invoked when the value of a variable has changed. Button listeners are notified if the button is clicked.

Specified by:
changeVariables in interface VariableOwner
Overrides:
changeVariables in class AbstractField

Parameters:
source -
variables -

isSwitchMode

@Deprecated
public boolean isSwitchMode()

Deprecated. the CheckBox component should be used instead of Button in switch mode

Checks if it is switchMode.

Returns:
true if it is in Switch Mode, otherwise false.

setSwitchMode

@Deprecated
public void setSwitchMode(boolean switchMode)

Deprecated. the CheckBox component should be used instead of Button in switch mode

Sets the switchMode.

Parameters:
switchMode - The switchMode to set.

booleanValue

public boolean booleanValue()

Get the boolean value of the button state.

Returns:
True iff the button is pressed down or checked.

setImmediate

public void setImmediate(boolean immediate)

Sets immediate mode. Push buttons can not be set in non-immediate mode.

Overrides:
setImmediate in class AbstractComponent

Parameters:
immediate - the boolean value specifying if the component should be in the immediate mode after the call.
See Also:
AbstractComponent.setImmediate(boolean)

getType

public Class getType()

The type of the button as a property.

Specified by:
getType in interface Property
Specified by:
getType in class AbstractField

Returns:
type of the Property
See Also:
Property.getType()

addListener

public void addListener(Button.ClickListener listener)

Adds the button click listener.

Parameters:
listener - the Listener to be added.

removeListener

public void removeListener(Button.ClickListener listener)

Removes the button click listener.

Parameters:
listener - the Listener to be removed.

click

public void click()

Simulates a button click, notifying all server-side listeners. No action is taken is the button is disabled.

fireClick

protected void fireClick()

Fires a click event to all listeners without any event details. In subclasses, override fireClick(MouseEventDetails) instead of this method.

fireClick

protected void fireClick(MouseEventDetails details)

Fires a click event to all listeners.

Parameters:
details - MouseEventDetails from which keyboard modifiers and other information about the mouse click can be obtained. If the button was clicked by a keyboard event, some of the fields may be empty/undefined.

setInternalValue

protected void setInternalValue(Object newValue)

Description copied from class: AbstractField

Sets the internal field value. This is purely used by AbstractField to change the internal Field value. It does not trigger valuechange events. It can be overridden by the inheriting classes to update all dependent variables.

Overrides:
setInternalValue in class AbstractField

Parameters:
newValue - the new value to be set.

addListener

public void addListener(FieldEvents.BlurListener listener)

Description copied from interface: FieldEvents.BlurNotifier

Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.

Specified by:
addListener in interface FieldEvents.BlurNotifier

See Also:
FieldEvents.BlurListener

removeListener

public void removeListener(FieldEvents.BlurListener listener)

Description copied from interface: FieldEvents.BlurNotifier

Removes a BlurListener from the Component.

Specified by:
removeListener in interface FieldEvents.BlurNotifier

See Also:
FieldEvents.BlurListener

addListener

public void addListener(FieldEvents.FocusListener listener)

Description copied from interface: FieldEvents.FocusNotifier

Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.

Specified by:
addListener in interface FieldEvents.FocusNotifier

See Also:
FieldEvents.FocusListener

removeListener

public void removeListener(FieldEvents.FocusListener listener)

Description copied from interface: FieldEvents.FocusNotifier

Removes a FocusListener from the Component.

Specified by:
removeListener in interface FieldEvents.FocusNotifier

See Also:
FieldEvents.FocusListener

setClickShortcut

public void setClickShortcut(int keyCode,
                             int... modifiers)

Makes it possible to invoke a click on this button by pressing the given ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKeys.
The shortcut is global (bound to the containing Window).

Parameters:
keyCode - the keycode for invoking the shortcut
modifiers - the (optional) modifiers for invoking the shortcut, null for none

removeClickShortcut

public void removeClickShortcut()

Removes the keyboard shortcut previously set with setClickShortcut(int, int...).

isDisableOnClick

public boolean isDisableOnClick()

Determines if a button is automatically disabled when clicked. See setDisableOnClick(boolean) for details.

Returns:
true if the button is disabled when clicked, false otherwise

setDisableOnClick

public void setDisableOnClick(boolean disableOnClick)

Determines if a button is automatically disabled when clicked. If this is set to true the button will be automatically disabled when clicked, typically to prevent (accidental) extra clicks on a button.

Note that this is only used when the click comes from the user, not when calling click().

Also note that click shortcuts are not supported with this feature in Vaadin 6.x.

Parameters:
disableOnClick - true to disable button when it is clicked, false otherwise

setHtmlContentAllowed

public void setHtmlContentAllowed(boolean htmlContentAllowed)

Set whether the caption text is rendered as HTML or not. You might need to retheme button to allow higher content than the original text style. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text.

Parameters:
htmlContentAllowed - true if caption is rendered as HTML, false otherwise

isHtmlContentAllowed

public boolean isHtmlContentAllowed()

Return HTML rendering setting

Returns:
true if the caption text is to be rendered as HTML, false otherwise