org.vostok.vaadin.addon.button.spin
Class SpinButton

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractComponentContainer
              extended by com.vaadin.ui.AbstractLayout
                  extended by com.vaadin.ui.CssLayout
                      extended by org.vostok.vaadin.addon.button.spin.SpinButton
All Implemented Interfaces:
com.vaadin.data.Property, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer, com.vaadin.data.Validatable, com.vaadin.event.ContextClickEvent.ContextClickNotifier, com.vaadin.event.LayoutEvents.LayoutClickNotifier, com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Sizeable, com.vaadin.shared.Connector, com.vaadin.ui.Button.ClickListener, com.vaadin.ui.Component, com.vaadin.ui.ComponentContainer, com.vaadin.ui.HasComponents, com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier, com.vaadin.ui.Layout, java.io.Serializable, java.lang.Iterable<com.vaadin.ui.Component>

public class SpinButton
extends com.vaadin.ui.CssLayout
implements com.vaadin.data.Property, com.vaadin.data.Property.Viewer, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.ui.Button.ClickListener, com.vaadin.data.Validatable

SpinButton is a multi purpose component, designed to display and browse over data with next/previous buttons.
SpinButton uses a data model, therefore values aren't necessarily fixed neither linear and can be done at request. There's a set of default models but you can easily create your. Output can be rendered into an TextField (default) or in provided component (component type container)

SpinButton also provides 5 layouts and already pack with 3 (simple) data models : number, date, list.

Extend com.vaadin.data.Validatable since 1.1
Since version 1.1, value inside a spin button can be manually edited

setWidth, setHeigh issues :
Because of the structure of the widget, setWidth, setHeight are known to cause problem. Recommanded solution is to use style instead, directly on the texteField, as described on the 4th sample.
See sample at http://vaadin.vostoksystem.eu

Version:
1.1
Author:
levreau.jerome@vostoksystem.eu
See Also:
Serialized Form

Nested Class Summary
static interface SpinButton.Editable<T>
          This interface must be set to a madel in order to allow user to enter new values.
static interface SpinButton.EditionListener
          Listen for edition change.
static class SpinButton.Layout
          SpinButton rendering
static interface SpinButton.Model<T>
          Model defines how values must be displayed and managed.
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyException, com.vaadin.data.Property.ReadOnlyStatusChangeEvent, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.Transactional<T>, com.vaadin.data.Property.ValueChangeEvent, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout
com.vaadin.ui.Layout.AlignmentHandler, com.vaadin.ui.Layout.MarginHandler, com.vaadin.ui.Layout.SpacingHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier, com.vaadin.ui.HasComponents.ComponentAttachEvent, com.vaadin.ui.HasComponents.ComponentAttachListener, com.vaadin.ui.HasComponents.ComponentDetachEvent, com.vaadin.ui.HasComponents.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
com.vaadin.server.Sizeable.Unit
 
Field Summary
static java.lang.String BASECSS
           
static java.lang.String EDITORCSS
           
static java.lang.String ICONONLYCSS
           
protected static int STATE_CANCEL_EDIT
           
protected static int STATE_COMMIT_EDIT
           
protected static int STATE_EDIT
           
protected static int STATE_NOEDIT
           
protected static int STATE_STANDBY
           
protected static int STATE_START_EDIT
           
 
Fields inherited from class com.vaadin.ui.CssLayout
components
 
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
 
Fields inherited from interface com.vaadin.ui.Button.ClickListener
BUTTON_CLICK_METHOD
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
SpinButton()
          backward compatibility, never use
SpinButton(com.vaadin.ui.Component... children)
          backward compatibility, never use
SpinButton(SpinButton.Model model)
          Creates a new spinbutton with model model. default layout to Layout.BOX default button will be i18nButton increase/decrease
SpinButton(SpinButton.Model model, SpinButton.Layout layout)
          Creates a new spinbutton with model model. and pack with layout layout
SpinButton(SpinButton.Model model, SpinButton.Layout layout, com.vaadin.ui.Button minus, com.vaadin.ui.Button plus)
          Create a new spin button.
 
Method Summary
 void addEditionListener(SpinButton.EditionListener listener)
          add an ew listener for user input (if model allows)
 void addListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void addListener(SpinButton.EditionListener listener)
          add an ew listener for user input (if model allows)
 void addValidator(com.vaadin.data.Validator validator)
           
 void addValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void buttonClick(com.vaadin.ui.Button.ClickEvent event)
           
 SpinButton.Editable getEditable()
          return editable instance (model). convenience method to acces getconverter/serConverter
 com.vaadin.data.Property getPropertyDataSource()
           
 java.lang.Object getRawValue()
          return raw value from model
 java.lang.Class getType()
           
 java.util.Collection<com.vaadin.data.Validator> getValidators()
          
 java.lang.Object getValue()
           
 boolean isEditable()
          return true if this spinButton accept edition.
 boolean isInEdit()
          return true if this spinButton is actually waiting for user input.
 boolean isInvalidAllowed()
          
 boolean isValid()
          
 void removeAllValidators()
           
 void removeListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void removeListener(SpinButton.EditionListener listener)
           
 void removeValidator(com.vaadin.data.Validator validator)
           
 void removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
           
 void removeValueChangeListener(SpinButton.EditionListener listener)
           
 void setButtonIconOnly(boolean value)
          Convenience method to hide caption from button. default to true.
 void setEditable(boolean value)
          Enable user edition of value.
 void setInvalidAllowed(boolean invalidValueAllowed)
          
 void setPropertyDataSource(com.vaadin.data.Property newDataSource)
          set datasource for component.
 void setValue(java.lang.Object newValue)
          note newValue == getValue() is not garanties.
 void switchEdition(boolean value)
          force this Spinbutton in edition mode and give focus to the TextField.
 void validate()
          
 void validate(java.lang.Object value)
           
 
Methods inherited from class com.vaadin.ui.CssLayout
addComponent, addComponent, addComponentAsFirst, addLayoutClickListener, addListener, beforeClientResponse, getComponent, getComponentCount, getComponentIndex, getCss, getState, iterator, readDesign, removeComponent, removeLayoutClickListener, removeListener, replaceComponent, writeDesign
 
Methods inherited from class com.vaadin.ui.AbstractLayout
readMargin, writeMargin
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addComponentAttachListener, addComponentDetachListener, addComponents, addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, getComponentIterator, moveComponentsFrom, removeAllComponents, removeComponentAttachListener, removeComponentDetachListener, removeListener, removeListener, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getState, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidthUndefined
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Property
isReadOnly, setReadOnly
 
Methods inherited from interface com.vaadin.ui.ComponentContainer
addComponents, addListener, addListener, getComponentIterator, moveComponentsFrom, removeAllComponents, removeListener, removeListener
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
 
Methods inherited from interface com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier
addComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListener
 

Field Detail

STATE_NOEDIT

protected static final int STATE_NOEDIT
See Also:
Constant Field Values

STATE_STANDBY

protected static final int STATE_STANDBY
See Also:
Constant Field Values

STATE_EDIT

protected static final int STATE_EDIT
See Also:
Constant Field Values

STATE_START_EDIT

protected static final int STATE_START_EDIT
See Also:
Constant Field Values

STATE_COMMIT_EDIT

protected static final int STATE_COMMIT_EDIT
See Also:
Constant Field Values

STATE_CANCEL_EDIT

protected static final int STATE_CANCEL_EDIT
See Also:
Constant Field Values

BASECSS

public static final java.lang.String BASECSS
See Also:
Constant Field Values

ICONONLYCSS

public static final java.lang.String ICONONLYCSS
See Also:
Constant Field Values

EDITORCSS

public static final java.lang.String EDITORCSS
See Also:
Constant Field Values
Constructor Detail

SpinButton

public SpinButton()
backward compatibility, never use

Throws:
java.lang.NullPointerException - always

SpinButton

public SpinButton(com.vaadin.ui.Component... children)
backward compatibility, never use

Parameters:
children - not used
Throws:
java.lang.NullPointerException - always

SpinButton

public SpinButton(SpinButton.Model model)
Creates a new spinbutton with model model. default layout to Layout.BOX default button will be i18nButton increase/decrease

Parameters:
model - data model to use

SpinButton

public SpinButton(SpinButton.Model model,
                  SpinButton.Layout layout)
Creates a new spinbutton with model model. and pack with layout layout

Parameters:
model - data model to use
layout - layout to use. can be null

SpinButton

public SpinButton(SpinButton.Model model,
                  SpinButton.Layout layout,
                  com.vaadin.ui.Button minus,
                  com.vaadin.ui.Button plus)
Create a new spin button.
Note model instance for each spinButton are independant ( spinA.getModel() != spinB.getModel() )

Parameters:
model - Model for values. mandatory
layout - layout to use. A css rule will also be added in the form of v-spinbutton-[the layout]. Can be null
plus - custon button bot the plus/increase button. can Be null.
minus - custom button for the minus/decrease button. Can br null.
Method Detail

buttonClick

public void buttonClick(com.vaadin.ui.Button.ClickEvent event)
Specified by:
buttonClick in interface com.vaadin.ui.Button.ClickListener

setPropertyDataSource

public void setPropertyDataSource(com.vaadin.data.Property newDataSource)
set datasource for component.
This method will call setValue and trigger any ValueChangeListener.
In order to avoid unwanted callback listener, you must call this method BEFORE addValueChangeListener.

Specified by:
setPropertyDataSource in interface com.vaadin.data.Property.Viewer
Parameters:
newDataSource - new Property for component, or null to reset it

getPropertyDataSource

public com.vaadin.data.Property getPropertyDataSource()
Specified by:
getPropertyDataSource in interface com.vaadin.data.Property.Viewer

addValueChangeListener

public void addValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
addValueChangeListener in interface com.vaadin.data.Property.ValueChangeNotifier

addListener

public void addListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
addListener in interface com.vaadin.data.Property.ValueChangeNotifier

removeValueChangeListener

public void removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
removeValueChangeListener in interface com.vaadin.data.Property.ValueChangeNotifier

removeListener

public void removeListener(com.vaadin.data.Property.ValueChangeListener listener)
Specified by:
removeListener in interface com.vaadin.data.Property.ValueChangeNotifier

getValue

public java.lang.Object getValue()
Specified by:
getValue in interface com.vaadin.data.Property

getRawValue

public java.lang.Object getRawValue()
return raw value from model

Returns:
raw value from model
Since:
1.1

setValue

public void setValue(java.lang.Object newValue)
              throws com.vaadin.data.Property.ReadOnlyException
note newValue == getValue() is not garanties.

Specified by:
setValue in interface com.vaadin.data.Property
Parameters:
newValue -
Throws:
com.vaadin.data.Property.ReadOnlyException

getType

public java.lang.Class getType()
Specified by:
getType in interface com.vaadin.data.Property

setButtonIconOnly

public void setButtonIconOnly(boolean value)
Convenience method to hide caption from button. default to true.

Parameters:
value - true to hide caption (default)

isEditable

public boolean isEditable()
return true if this spinButton accept edition.
Model must implement Editable, has valid validate method and allow edition (default false)

Returns:
Since:
1.1

getEditable

public SpinButton.Editable getEditable()
                                throws java.lang.UnsupportedOperationException
return editable instance (model). convenience method to acces getconverter/serConverter

Returns:
Editable
Throws:
java.lang.UnsupportedOperationException - if model does not support edition

setEditable

public void setEditable(boolean value)
Enable user edition of value.
Note model must implement Editable interface.
note this.isEditable() might not be equal to value

Parameters:
value - true to enable value

isInEdit

public boolean isInEdit()
return true if this spinButton is actually waiting for user input.

Returns:
true if waiting for user input
Since:
1.1

switchEdition

public void switchEdition(boolean value)
force this Spinbutton in edition mode and give focus to the TextField.
If rending commponent is not and TextField a convenience one will be provided.

Parameters:
value - true to switch component in edition mode. If not posible, does nothing.

addEditionListener

public void addEditionListener(SpinButton.EditionListener listener)
add an ew listener for user input (if model allows)

Parameters:
listener -
Since:
1.1

addListener

public void addListener(SpinButton.EditionListener listener)
add an ew listener for user input (if model allows)

Parameters:
listener -
Since:
1.1

removeValueChangeListener

public void removeValueChangeListener(SpinButton.EditionListener listener)
Parameters:
listener -
Since:
1.1

removeListener

public void removeListener(SpinButton.EditionListener listener)
Parameters:
listener -
Since:
1.1

addValidator

public void addValidator(com.vaadin.data.Validator validator)
Specified by:
addValidator in interface com.vaadin.data.Validatable
Parameters:
validator -
Since:
1.1

removeValidator

public void removeValidator(com.vaadin.data.Validator validator)
Specified by:
removeValidator in interface com.vaadin.data.Validatable
Parameters:
validator -
Since:
1.1

removeAllValidators

public void removeAllValidators()
Specified by:
removeAllValidators in interface com.vaadin.data.Validatable
Since:
1.1

getValidators

public java.util.Collection<com.vaadin.data.Validator> getValidators()

Specified by:
getValidators in interface com.vaadin.data.Validatable

isValid

public boolean isValid()

Specified by:
isValid in interface com.vaadin.data.Validatable
Since:
1.1

validate

public void validate()
              throws com.vaadin.data.Validator.InvalidValueException

Specified by:
validate in interface com.vaadin.data.Validatable
Throws:
com.vaadin.data.Validator.InvalidValueException
Since:
1.1

validate

public void validate(java.lang.Object value)
              throws com.vaadin.data.Validator.InvalidValueException
Parameters:
value -
Throws:
com.vaadin.data.Validator.InvalidValueException
Since:
1.1

isInvalidAllowed

public boolean isInvalidAllowed()

Specified by:
isInvalidAllowed in interface com.vaadin.data.Validatable
Returns:
Since:
1.1

setInvalidAllowed

public void setInvalidAllowed(boolean invalidValueAllowed)
                       throws java.lang.UnsupportedOperationException

Specified by:
setInvalidAllowed in interface com.vaadin.data.Validatable
Throws:
java.lang.UnsupportedOperationException
Since:
1.1