com.sencha.gxt.widget.core.client.form
Class Field<T>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.sencha.gxt.widget.core.client.Component
              extended by com.sencha.gxt.widget.core.client.cell.CellComponent<T>
                  extended by com.sencha.gxt.widget.core.client.form.Field<T>
Type Parameters:
T - the field's data type
All Implemented Interfaces:
Editor<T>, HasEditorDelegate<T>, HasEditorErrors<T>, LeafValueEditor<T>, ValueAwareEditor<T>, HasAttachHandlers, HasResizeHandlers, HasValueChangeHandlers<T>, HasHandlers, EventListener, TakesValue<T>, HasEnabled, HasName, HasValue<T>, HasVisibility, IsWidget, HasKeyProvider<T>, BeforeHideEvent.HasBeforeHideHandlers, BeforeShowContextMenuEvent.HasBeforeShowContextMenuHandler, BeforeShowEvent.HasBeforeShowHandlers, BlurEvent.HasBlurHandlers, DisableEvent.HasDisableHandlers, EnableEvent.HasEnableHandlers, FocusEvent.HasFocusHandlers, HideEvent.HasHideHandlers, InvalidEvent.HasInvalidHandlers, MoveEvent.HasMoveHandlers, ShowContextMenuEvent.HasShowContextMenuHandler, ShowEvent.HasShowHandlers, ValidEvent.HasValidHandlers, IsField<T>, HasFocusSupport, HasItemId
Direct Known Subclasses:
CheckBox, Slider, ValueBaseField

public abstract class Field<T>
extends CellComponent<T>
implements IsField<T>, HasValue<T>, HasValueChangeHandlers<T>, HasName, InvalidEvent.HasInvalidHandlers, ValidEvent.HasValidHandlers, LeafValueEditor<T>, HasEditorErrors<T>, HasEditorDelegate<T>, ValueAwareEditor<T>

Base class for all cell based fields. Adapts these fields for use as widgets, adding validation features, and the ability to interact with the GWT Editor framework.

The Field instance implements several Editor interfaces to participate in the full editing lifecycle.

All errors are displayed through a ErrorHandler instance, whether they arrive from the Cell's parsing, the Field's validation, or from validation errors given to an editor driver. Events are also dispatched when the validity of the field changes.


Nested Class Summary
static interface Field.FieldStyles
           
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Method Summary
 HandlerRegistration addInvalidHandler(InvalidEvent.InvalidHandler handler)
          Adds a InvalidEvent.InvalidHandler handler for InvalidEvent events.
 void addValidator(Validator<T> validator)
           
 HandlerRegistration addValidHandler(ValidEvent.ValidHandler handler)
          Adds a ValidEvent handler for ValidEvent events.
 HandlerRegistration addValueChangeHandler(ValueChangeHandler<T> handler)
           
 void clear()
          Clears the value from the field.
 void clearInvalid()
          Clear any invalid styles / messages for this field.
 void finishEditing()
           
 void flush()
           
 void forceInvalid(java.lang.String msg)
          Forces the field to be invalid using the given error message.
 FieldCell<T> getCell()
          Get the Cell wrapped by this widget.
 ErrorHandler getErrorSupport()
          Returns the field's error support instance.
 java.lang.String getName()
          Gets the field's name.
 boolean getValidateOnBlur()
          Returns true if the value is validate on blur.
 int getValidationDelay()
          Returns the field's validation delay in milliseconds.
 java.util.List<Validator<T>> getValidators()
          Returns the field's validators.
 boolean isAutoValidate()
          Returns true if the field value is validated on each key press.
 boolean isEditing()
           
 boolean isReadOnly()
          Returns the read only state.
 boolean isValid()
          Returns whether or not the field value is currently valid.
 boolean isValid(boolean preventMark)
          Returns whether or not the field value is currently valid.
 void markInvalid(java.lang.String msg)
          Marks this field as invalid.
 void onBrowserEvent(Event event)
           
 void onPropertyChange(java.lang.String... paths)
           
 void removeValidator(Validator<T> validator)
          Removes the validator.
 void reset()
          Resets the current field value to the originally loaded value and clears any validation messages.
 void setAutoValidate(boolean autoValidate)
          Sets whether the value is validated on each key press (defaults to false).
 void setDelegate(EditorDelegate<T> delegate)
           
 void setErrorSupport(ErrorHandler error)
          Sets the field's error support instance.
 void setName(java.lang.String name)
           
 void setOriginalValue(T value)
           
 void setReadOnly(boolean readOnly)
          Sets the field's read only state.
 void setValidateOnBlur(boolean validateOnBlur)
          Sets whether the field should validate when it loses focus (defaults to true).
 void setValidationDelay(int validationDelay)
          Sets length of time in milliseconds after user input begins until validation is initiated (defaults to 250).
 void setValue(T value, boolean fireEvents, boolean redraw)
          Sets this object's value and optionally redraw the widget.
 void showErrors(java.util.List<EditorError> errors)
           
 boolean validate()
          Validates the field value.
 boolean validate(boolean preventMark)
          Validates the field value.
 
Methods inherited from class com.sencha.gxt.widget.core.client.cell.CellComponent
getElement, getKeyProvider, getValue, redraw, setValue, setValue
 
Methods inherited from class com.sencha.gxt.widget.core.client.Component
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleOnOver, clearSizeCache, disable, disableEvents, enable, enableEvents, fireEvent, focus, getData, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getShadow, getStateId, getToolTip, hide, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isRendered, isStateful, isVisible, isVisible, mask, mask, removeToolTip, setAllowTextSelection, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setPagePosition, setPixelSize, setPosition, setShadow, setSize, setStateful, setStateId, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.user.client.ui.IsWidget
asWidget
 
Methods inherited from interface com.google.gwt.user.client.TakesValue
getValue, setValue
 
Methods inherited from interface com.google.gwt.user.client.ui.HasValue
getValue, setValue, setValue
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.editor.client.ValueAwareEditor
setValue
 

Method Detail

addInvalidHandler

public HandlerRegistration addInvalidHandler(InvalidEvent.InvalidHandler handler)
Description copied from interface: InvalidEvent.HasInvalidHandlers
Adds a InvalidEvent.InvalidHandler handler for InvalidEvent events.

Specified by:
addInvalidHandler in interface InvalidEvent.HasInvalidHandlers
Parameters:
handler - the handler
Returns:
the registration for the event

addValidator

public void addValidator(Validator<T> validator)

addValidHandler

public HandlerRegistration addValidHandler(ValidEvent.ValidHandler handler)
Description copied from interface: ValidEvent.HasValidHandlers
Adds a ValidEvent handler for ValidEvent events.

Specified by:
addValidHandler in interface ValidEvent.HasValidHandlers
Parameters:
handler - the handler
Returns:
the registration for the event

addValueChangeHandler

public HandlerRegistration addValueChangeHandler(ValueChangeHandler<T> handler)
Specified by:
addValueChangeHandler in interface HasValueChangeHandlers<T>
Overrides:
addValueChangeHandler in class CellComponent<T>

clear

public void clear()
Clears the value from the field.

Specified by:
clear in interface IsField<T>

clearInvalid

public void clearInvalid()
Clear any invalid styles / messages for this field.

Specified by:
clearInvalid in interface IsField<T>

finishEditing

public void finishEditing()

flush

public void flush()
Specified by:
flush in interface ValueAwareEditor<T>

forceInvalid

public void forceInvalid(java.lang.String msg)
Forces the field to be invalid using the given error message. When using this feature, clearInvalid() must be called to clear the error. Also, no other validation logic will execute.

Parameters:
msg - the error text

getCell

public FieldCell<T> getCell()
Description copied from class: CellComponent
Get the Cell wrapped by this widget.

Overrides:
getCell in class CellComponent<T>
Returns:
the Cell being wrapped

getErrorSupport

public ErrorHandler getErrorSupport()
Returns the field's error support instance.

Returns:
the error support

getName

public java.lang.String getName()
Gets the field's name.

Specified by:
getName in interface HasName
Returns:
the field's new name

getValidateOnBlur

public boolean getValidateOnBlur()
Returns true if the value is validate on blur.

Returns:
the validate on blur state

getValidationDelay

public int getValidationDelay()
Returns the field's validation delay in milliseconds.

Returns:
the delay in milliseconds

getValidators

public java.util.List<Validator<T>> getValidators()
Returns the field's validators.

Returns:
the validators

isAutoValidate

public boolean isAutoValidate()
Returns true if the field value is validated on each key press.

Returns:
the auto validate state

isEditing

public boolean isEditing()

isReadOnly

public boolean isReadOnly()
Returns the read only state.

Returns:
true if read only, otherwise false

isValid

public boolean isValid()
Returns whether or not the field value is currently valid.

Returns:
true if valid

isValid

public boolean isValid(boolean preventMark)
Description copied from interface: IsField
Returns whether or not the field value is currently valid.

Specified by:
isValid in interface IsField<T>
Parameters:
preventMark - true for silent validation (no invalid event and field is not marked invalid)
Returns:
true if the value is valid, otherwise false

markInvalid

public void markInvalid(java.lang.String msg)
Marks this field as invalid. Validation will still run if called again, and the error message will be changed or cleared based on validation. To set a error message that will not be cleared until manually cleared see forceInvalid(String)

Parameters:
msg - the validation message

onBrowserEvent

public void onBrowserEvent(Event event)
Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class CellComponent<T>

onPropertyChange

public void onPropertyChange(java.lang.String... paths)
Specified by:
onPropertyChange in interface ValueAwareEditor<T>

removeValidator

public void removeValidator(Validator<T> validator)
Removes the validator.

Parameters:
validator - the validator to remove

reset

public void reset()
Description copied from interface: IsField
Resets the current field value to the originally loaded value and clears any validation messages.

Specified by:
reset in interface IsField<T>

setAutoValidate

public void setAutoValidate(boolean autoValidate)
Sets whether the value is validated on each key press (defaults to false).

Parameters:
autoValidate - true to validate on each key press

setDelegate

public void setDelegate(EditorDelegate<T> delegate)
Specified by:
setDelegate in interface HasEditorDelegate<T>

setErrorSupport

public void setErrorSupport(ErrorHandler error)
Sets the field's error support instance.

See the following concrete implementations:

Parameters:
error - the error support

setName

public void setName(java.lang.String name)
Specified by:
setName in interface HasName

setOriginalValue

public void setOriginalValue(T value)

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the field's read only state.

Parameters:
readOnly - the read only state

setValidateOnBlur

public void setValidateOnBlur(boolean validateOnBlur)
Sets whether the field should validate when it loses focus (defaults to true).

Parameters:
validateOnBlur - true to validate on blur, otherwise false

setValidationDelay

public void setValidationDelay(int validationDelay)
Sets length of time in milliseconds after user input begins until validation is initiated (defaults to 250).

Parameters:
validationDelay - the delay in milliseconds

setValue

public void setValue(T value,
                     boolean fireEvents,
                     boolean redraw)
Description copied from class: CellComponent
Sets this object's value and optionally redraw the widget. Fires ValueChangeEvent when fireEvents is true and the new value does not equal the existing value. Redraws the widget when redraw is true and the new value does not equal the existing value.

Overrides:
setValue in class CellComponent<T>
Parameters:
value - the object's new value
fireEvents - fire events if true and value is new
redraw - redraw the widget if true and value is new

showErrors

public void showErrors(java.util.List<EditorError> errors)
Specified by:
showErrors in interface HasEditorErrors<T>

validate

public boolean validate()
Validates the field value.

Returns:
true if valid, otherwise false

validate

public boolean validate(boolean preventMark)
Validates the field value.

Specified by:
validate in interface IsField<T>
Parameters:
preventMark - true to not mark the field valid and fire invalid event when invalid
Returns:
true if valid, otherwise false


Copyright © 2012. All Rights Reserved.