com.vaadin.ui
Class CustomField<T>

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractField<T>
              extended by com.vaadin.ui.CustomField<T>
Type Parameters:
T - field value type
All Implemented Interfaces:
Buffered, BufferedValidatable, Property<T>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.ShortcutNotifier, MethodEventSource, ClientConnector, RpcTarget, Sizeable, com.vaadin.shared.Connector, Component, Component.Focusable, ComponentContainer, Field<T>, HasComponents, java.io.Serializable, java.lang.Iterable<Component>

public abstract class CustomField<T>
extends AbstractField<T>
implements ComponentContainer

A Field whose UI content can be constructed by the user, enabling the creation of e.g. form fields by composing Vaadin components. Customization of both the visual presentation and the logic of the field is possible. Subclasses must implement AbstractField.getType() and initContent(). Most custom fields can simply compose a user interface that calls the methods AbstractField.setInternalValue(Object) and AbstractField.getInternalValue() when necessary. It is also possible to override AbstractField.validate(), AbstractField.setInternalValue(Object), AbstractField.commit(), AbstractField.setPropertyDataSource(Property), AbstractField.isEmpty() and other logic of the field. Methods overriding AbstractField.setInternalValue(Object) should also call the corresponding superclass method.

Since:
7.0
See Also:
Serialized Form

Nested Class Summary
 
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.ComponentContainer
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
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.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Field Summary
 
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
CustomField()
          Constructs a new custom field.
 
Method Summary
 void addComponent(Component c)
          Adds the component into this container.
 void addComponentAttachListener(ComponentContainer.ComponentAttachListener listener)
          Listens the component attach events.
 void addComponentDetachListener(ComponentContainer.ComponentDetachListener listener)
          Listens the component detach events.
 void addListener(ComponentContainer.ComponentAttachListener listener)
          Deprecated. Since 7.0, replaced by addComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)
 void addListener(ComponentContainer.ComponentDetachListener listener)
          Deprecated. Since 7.0, replaced by addComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)
 void attach()
          Constructs the content and notifies it that the CustomField is attached to a window.
protected  void fireComponentAttachEvent(Component component)
          Fires the component attached event.
 int getComponentCount()
          Gets the number of children this ComponentContainer has.
 java.util.Iterator<Component> getComponentIterator()
          Gets an iterator to the collection of contained components.
protected  Component getContent()
          Returns the content (UI) of the custom component.
protected abstract  Component initContent()
          Create the content component or layout for the field.
 boolean isComponentVisible(Component childComponent)
          Checks if the child component is visible.
 java.util.Iterator<Component> iterator()
           
 void moveComponentsFrom(ComponentContainer source)
          Moves all components from an another container into this container.
 void removeAllComponents()
          Removes all components from this container.
 void removeComponent(Component c)
          Removes the component from this container.
 void removeComponentAttachListener(ComponentContainer.ComponentAttachListener listener)
          Stops the listening component attach events.
 void removeComponentDetachListener(ComponentContainer.ComponentDetachListener listener)
          Stops the listening component detach events.
 void removeListener(ComponentContainer.ComponentAttachListener listener)
          Deprecated. Since 7.0, replaced by removeComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)
 void removeListener(ComponentContainer.ComponentDetachListener listener)
          Deprecated. Since 7.0, replaced by removeComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)
 void replaceComponent(Component oldComponent, Component newComponent)
          Replaces the component in the container with another one without changing position.
 void setHeight(float height, Sizeable.Unit unit)
          Sets the height of the object.
 void setWidth(float height, Sizeable.Unit unit)
          Sets the width of the object.
 
Methods inherited from class com.vaadin.ui.AbstractField
addListener, addListener, addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, beforeClientResponse, commit, detach, discard, fireReadOnlyStatusChange, fireValueChange, focus, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getErrorMessage, getInternalValue, getPropertyDataSource, getRequiredError, getState, getTabIndex, getType, getValidators, getValue, isBuffered, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isRequired, isValid, isValidationVisible, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInternalValue, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setValue, shouldHideErrors, toString, validate, validate, valueChange
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, fireEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getHeight, getHeightUnits, getIcon, getId, getListeners, getLocale, getParent, getStyleName, getWidth, getWidthUnits, handleError, hasListeners, isConnectorEnabled, isEnabled, isImmediate, isVisible, removeListener, removeListener, removeListener, removeListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setIcon, setId, setImmediate, setLocale, setParent, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addExtension, addMethodInvocationToQueue, createState, encodeState, getAllChildrenIterable, getConnectorId, getExtensions, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, getCaption, getIcon, getId, getLocale, getParent, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
beforeClientResponse, detach, encodeState, getExtensions, getStateType, handleConnectorRequest, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setParent
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.RpcTarget
getRpcManager
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setSizeFull, setSizeUndefined, setWidth
 
Methods inherited from interface com.vaadin.event.Action.ShortcutNotifier
addShortcutListener, removeShortcutListener
 

Constructor Detail

CustomField

public CustomField()
Constructs a new custom field.

The component is implemented by wrapping the methods of the composition root component given as parameter. The composition root must be set before the component can be used.

Method Detail

attach

public void attach()
Constructs the content and notifies it that the CustomField is attached to a window.

Specified by:
attach in interface ClientConnector
Specified by:
attach in interface Component
Overrides:
attach in class AbstractField<T>
See Also:
Component.attach()

getContent

protected Component getContent()
Returns the content (UI) of the custom component.

Returns:
Component

initContent

protected abstract Component initContent()
Create the content component or layout for the field. Subclasses of CustomField should implement this method. Note that this method is called when the CustomField is attached to a layout or when getContent() is called explicitly for the first time. It is only called once for a CustomField.

Returns:
Component representing the UI of the CustomField

setHeight

public void setHeight(float height,
                      Sizeable.Unit unit)
Description copied from interface: Sizeable
Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).

Specified by:
setHeight in interface Sizeable
Overrides:
setHeight in class AbstractComponent
Parameters:
height - the height of the object.
unit - the unit used for the width.

setWidth

public void setWidth(float height,
                     Sizeable.Unit unit)
Description copied from interface: Sizeable
Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).

Specified by:
setWidth in interface Sizeable
Overrides:
setWidth in class AbstractComponent
Parameters:
height - the width of the object.
unit - the unit used for the width.

getComponentIterator

public java.util.Iterator<Component> getComponentIterator()
Description copied from interface: HasComponents
Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.

Specified by:
getComponentIterator in interface HasComponents
Returns:
the component iterator.

iterator

public java.util.Iterator<Component> iterator()
Specified by:
iterator in interface java.lang.Iterable<Component>

getComponentCount

public int getComponentCount()
Description copied from interface: ComponentContainer
Gets the number of children this ComponentContainer has. This must be symmetric with what HasComponents.getComponentIterator() returns.

Specified by:
getComponentCount in interface ComponentContainer
Returns:
The number of child components this container has.

fireComponentAttachEvent

protected void fireComponentAttachEvent(Component component)
Fires the component attached event. This should be called by the addComponent methods after the component have been added to this container.

Parameters:
component - the component that has been added to this container.

addComponent

public void addComponent(Component c)
Description copied from interface: ComponentContainer
Adds the component into this container.

Specified by:
addComponent in interface ComponentContainer
Parameters:
c - the component to be added.

removeComponent

public void removeComponent(Component c)
Description copied from interface: ComponentContainer
Removes the component from this container.

Specified by:
removeComponent in interface ComponentContainer
Parameters:
c - the component to be removed.

removeAllComponents

public void removeAllComponents()
Description copied from interface: ComponentContainer
Removes all components from this container.

Specified by:
removeAllComponents in interface ComponentContainer

replaceComponent

public void replaceComponent(Component oldComponent,
                             Component newComponent)
Description copied from interface: ComponentContainer
Replaces the component in the container with another one without changing position.

This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.

Specified by:
replaceComponent in interface ComponentContainer
Parameters:
oldComponent - the old component that will be replaced.
newComponent - the new component to be replaced.

moveComponentsFrom

public void moveComponentsFrom(ComponentContainer source)
Description copied from interface: ComponentContainer
Moves all components from an another container into this container. The components are removed from source.

Specified by:
moveComponentsFrom in interface ComponentContainer
Parameters:
source - the container which contains the components that are to be moved to this container.

addComponentAttachListener

public void addComponentAttachListener(ComponentContainer.ComponentAttachListener listener)
Description copied from interface: ComponentContainer
Listens the component attach events.

Specified by:
addComponentAttachListener in interface ComponentContainer
Parameters:
listener - the listener to add.

addListener

@Deprecated
public void addListener(ComponentContainer.ComponentAttachListener listener)
Deprecated. Since 7.0, replaced by addComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)

Specified by:
addListener in interface ComponentContainer

removeComponentAttachListener

public void removeComponentAttachListener(ComponentContainer.ComponentAttachListener listener)
Description copied from interface: ComponentContainer
Stops the listening component attach events.

Specified by:
removeComponentAttachListener in interface ComponentContainer
Parameters:
listener - the listener to removed.

removeListener

@Deprecated
public void removeListener(ComponentContainer.ComponentAttachListener listener)
Deprecated. Since 7.0, replaced by removeComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)

Specified by:
removeListener in interface ComponentContainer

addComponentDetachListener

public void addComponentDetachListener(ComponentContainer.ComponentDetachListener listener)
Description copied from interface: ComponentContainer
Listens the component detach events.

Specified by:
addComponentDetachListener in interface ComponentContainer

addListener

@Deprecated
public void addListener(ComponentContainer.ComponentDetachListener listener)
Deprecated. Since 7.0, replaced by addComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)

Specified by:
addListener in interface ComponentContainer

removeComponentDetachListener

public void removeComponentDetachListener(ComponentContainer.ComponentDetachListener listener)
Description copied from interface: ComponentContainer
Stops the listening component detach events.

Specified by:
removeComponentDetachListener in interface ComponentContainer

removeListener

@Deprecated
public void removeListener(ComponentContainer.ComponentDetachListener listener)
Deprecated. Since 7.0, replaced by removeComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)

Specified by:
removeListener in interface ComponentContainer

isComponentVisible

public boolean isComponentVisible(Component childComponent)
Description copied from interface: HasComponents
Checks if the child component is visible. This method allows hiding a child component from updates and communication to and from the client. This is useful for components that show only a limited number of its children at any given time and want to allow updates only for the children that are visible (e.g. TabSheet has one tab open at a time).

Note that this will prevent updates from reaching the child even though the child itself is set to visible. Also if a child is set to invisible this will not force it to be visible.

Specified by:
isComponentVisible in interface HasComponents
Parameters:
childComponent - The child component to check
Returns:
true if the child component is visible to the user, false otherwise


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.