com.vaadin.ui.
Class AbstractComponent
java.lang.Object
com.vaadin.ui.AbstractComponent
All Implemented Interfaces:
MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Serializable, EventListener
Direct Known Subclasses:
AbstractComponentContainer, AbstractField, AbstractMedia, Embedded, Label, Link, MenuBar, Upload, UriFragmentUtility
- extends Object
- implements Component, MethodEventSource
public abstract class AbstractComponent
An abstract class that defines default implementation for the
Component
interface. Basic UI components that are not derived from an
external component can inherit this class to easily qualify as Vaadin
components. Most components in Vaadin do just that.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
static interface |
AbstractComponent.ComponentErrorEvent
|
static interface |
AbstractComponent.ComponentErrorHandler
|
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.terminal.Paintable |
---|
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener |
Field Summary |
---|
Fields inherited from interface com.vaadin.terminal.Sizeable |
---|
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS |
Constructor Summary | |
---|---|
AbstractComponent()
Constructs a new Component. |
Method Summary | |
---|---|
void |
addListener(Class<?> eventType,
Object target,
Method method)
Registers a new listener with the specified activation method to listen events generated by this component. |
void |
addListener(Class<?> eventType,
Object target,
String methodName)
Convenience method for registering a new listener with the specified activation method to listen events generated by this component. |
void |
addListener(Component.Listener listener)
Registers a new (generic) component event listener for the component. |
void |
addListener(Paintable.RepaintRequestListener listener)
Adds repaint request listener. |
protected void |
addListener(String eventIdentifier,
Class<?> eventType,
Object target,
Method method)
Registers a new listener with the specified activation method to listen events generated by this component. |
void |
addStyleName(String style)
Adds a style name to component. |
void |
attach()
Notifies the component that it is connected to an application. |
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are changed. |
void |
childRequestedRepaint(Collection<Paintable.RepaintRequestListener> alreadyNotified)
The child components of the component must call this method when they need repainting. |
void |
detach()
Notifies the component that it is detached from the application. |
protected void |
fireComponentErrorEvent()
Emits the component error event. |
protected void |
fireComponentEvent()
Emits the component event. |
protected void |
fireEvent(Component.Event event)
Sends the event to all listeners. |
protected void |
focus()
Sets the focus for this component if the component is Focusable . |
Application |
getApplication()
Gets the application object to which the component is attached. |
String |
getCaption()
Gets the caption of the component. |
ErrorMessage |
getComponentError()
Gets the component's error message. |
Object |
getData()
Gets the application specific data. |
String |
getDebugId()
Get's currently set debug identifier |
String |
getDescription()
Gets the component's description, used in tooltips and can be displayed directly in certain other components such as forms. |
AbstractComponent.ComponentErrorHandler |
getErrorHandler()
Gets the error handler for the component. |
ErrorMessage |
getErrorMessage()
Gets the error message for this component. |
float |
getHeight()
Gets the height of the object. |
int |
getHeightUnits()
Gets the height property units. |
Resource |
getIcon()
Gets the icon resource of the component. |
Collection<?> |
getListeners(Class<?> eventType)
Returns all listeners that are registered for the given event type or one of its subclasses. |
Locale |
getLocale()
Gets the locale of the component. |
Component |
getParent()
Gets the parent component of the component. |
String |
getStyle()
Deprecated. Use getStyleName() instead; renamed for consistency and to indicate that "style" should not be used to switch client side implementation, only to style the component. |
String |
getStyleName()
Gets all user-defined CSS style names of a component. |
float |
getWidth()
Gets the width of the object. |
int |
getWidthUnits()
Gets the width property units. |
Window |
getWindow()
Gets the parent window of the component. |
boolean |
handleError(AbstractComponent.ComponentErrorEvent error)
Handle the component error event. |
protected boolean |
hasListeners(Class<?> eventType)
Checks if the given AbstractComponent.ComponentErrorEvent type is listened for this component. |
boolean |
isEnabled()
Tests if the variable owner is enabled or not. |
boolean |
isImmediate()
Tests if the variable owner is in immediate mode or not. |
boolean |
isReadOnly()
Tests whether the component is in the read-only mode. |
boolean |
isVisible()
Tests the visibility property of the component. |
void |
paint(PaintTarget target)
Paints the Paintable into a UIDL stream. |
void |
paintContent(PaintTarget target)
Paints any needed component-specific things to the given UIDL stream. |
void |
removeListener(Class<?> eventType,
Object target)
Removes all registered listeners matching the given parameters. |
void |
removeListener(Class<?> eventType,
Object target,
Method method)
Removes one registered listener method. |
void |
removeListener(Class<?> eventType,
Object target,
String methodName)
Removes one registered listener method. |
void |
removeListener(Component.Listener listener)
Removes a previously registered component event listener from this component. |
void |
removeListener(Paintable.RepaintRequestListener listener)
Removes repaint request listener. |
protected void |
removeListener(String eventIdentifier,
Class<?> eventType,
Object target)
Removes all registered listeners matching the given parameters. |
void |
removeStyleName(String style)
Removes one or more style names from component. |
void |
requestRepaint()
Requests that the paintable should be repainted as soon as possible. |
void |
requestRepaintRequests()
Request sending of repaint events on any further visible changes. |
void |
setCaption(String caption)
Sets the component's caption String . |
void |
setComponentError(ErrorMessage componentError)
Sets the component's error message. |
void |
setData(Object data)
Sets the data object, that can be used for any application specific data. |
void |
setDebugId(String id)
Adds an unique id for component that get's transferred to terminal for testing purposes. |
void |
setDescription(String description)
Sets the component's description. |
void |
setEnabled(boolean enabled)
Enables or disables the component. |
void |
setErrorHandler(AbstractComponent.ComponentErrorHandler errorHandler)
Sets the error handler for the component. |
void |
setHeight(float height)
Deprecated. |
void |
setHeight(float height,
int unit)
Sets the height of the object. |
void |
setHeight(String height)
Sets the height of the component using String presentation. |
void |
setHeightUnits(int unit)
Deprecated. |
void |
setIcon(Resource icon)
Sets the component's icon. |
void |
setImmediate(boolean immediate)
Sets the component's immediate mode to the specified status. |
void |
setLocale(Locale locale)
Sets the locale of this component. |
void |
setParent(Component parent)
Sets the parent component of the component. |
void |
setReadOnly(boolean readOnly)
Sets the read-only mode of the component to the specified mode. |
void |
setSizeFull()
Sets the size to 100% x 100%. |
void |
setSizeUndefined()
Clears any size settings. |
void |
setStyle(String style)
Deprecated. Use setStyleName() instead; renamed for consistency and to indicate that "style" should not be used to switch client side implementation, only to style the component. |
void |
setStyleName(String style)
Sets one or more user-defined style names of the component, replacing any previous user-defined styles. |
void |
setVisible(boolean visible)
Sets the visibility of the component. |
void |
setWidth(float width)
Deprecated. |
void |
setWidth(float width,
int unit)
Sets the width of the object. |
void |
setWidth(String width)
Sets the width of the component using String presentation. |
void |
setWidthUnits(int unit)
Deprecated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
AbstractComponent
public AbstractComponent()
Constructs a new Component.
Method Detail |
---|
setDebugId
public void setDebugId(String id)
- Specified by:
setDebugId
in interfacePaintable
- Parameters:
id
- A short (< 20 chars) alphanumeric id
Description copied from interface: Paintable
Adds an unique id for component that get's transferred to terminal for testing purposes. Keeping identifiers unique throughout the Application instance is on programmers responsibility.
Note, that with the current terminal implementation the identifier cannot be changed while the component is visible. This means that the identifier should be set before the component is painted for the first time and kept the same while visible in the client.
getDebugId
public String getDebugId()
- Specified by:
getDebugId
in interfacePaintable
- Returns:
- current debug id, null if not set
Description copied from interface: Paintable
Get's currently set debug identifier
getStyle
@Deprecated
public String getStyle()
- Returns:
- the component's styleValue of property style.
Deprecated. Use getStyleName() instead; renamed for consistency and to indicate that "style" should not be used to switch client side implementation, only to style the component.
Gets style for component. Multiple styles are joined with spaces.
setStyle
@Deprecated
public void setStyle(String style)
- Parameters:
style
- the new style of the component.
Deprecated. Use setStyleName() instead; renamed for consistency and to indicate that "style" should not be used to switch client side implementation, only to style the component.
Sets and replaces all previous style names of the component. This method
will trigger a RepaintRequestEvent
.
getStyleName
public String getStyleName()
- Specified by:
getStyleName
in interfaceComponent
- Returns:
- the style name or a space-separated list of user-defined style names of the component
- See Also:
Component.setStyleName(String)
,Component.addStyleName(String)
,Component.removeStyleName(String)
Description copied from interface: Component
Gets all user-defined CSS style names of a component. If the component has multiple style names defined, the return string is a space-separated list of style names. Built-in style names defined in Vaadin or GWT are not returned.
The style names are returned only in the basic form in which they were added; each user-defined style name shows as two CSS style class names in the rendered HTML: one as it was given and one prefixed with the component-specific style name. Only the former is returned.
setStyleName
public void setStyleName(String style)
- Specified by:
setStyleName
in interfaceComponent
- Parameters:
style
- the new style or styles of the component as a space-separated list- See Also:
Component.getStyleName()
,Component.addStyleName(String)
,Component.removeStyleName(String)
Description copied from interface: Component
Sets one or more user-defined style names of the component, replacing any previous user-defined styles. Multiple styles can be specified as a space-separated list of style names. The style names must be valid CSS class names and should not conflict with any built-in style names in Vaadin or GWT.
Label label = new Label("This text has a lot of style");
label.setStyleName("myonestyle myotherstyle");
Each style name will occur in two versions: one as specified and one that
is prefixed with the style name of the component. For example, if you
have a Button
component and give it "mystyle
" style, the
component will have both "mystyle
" and "v-button-mystyle
"
styles. You could then style the component either with:
.myonestyle {background: blue;}
or
.v-button-myonestyle {background: blue;}
It is normally a good practice to use addStyleName()
rather than this setter, as different software
abstraction layers can then add their own styles without accidentally
removing those defined in other layers.
This method will trigger a
RepaintRequestEvent
.
addStyleName
public void addStyleName(String style)
- Specified by:
addStyleName
in interfaceComponent
- Parameters:
style
- the new style to be added to the component- See Also:
Component.getStyleName()
,Component.setStyleName(String)
,Component.removeStyleName(String)
Description copied from interface: Component
Adds a style name to component. The style name will be rendered as a HTML class name, which can be used in a CSS definition.
Label label = new Label("This text has style");
label.addStyleName("mystyle");
Each style name will occur in two versions: one as specified and one that
is prefixed wil the style name of the component. For example, if you have
a Button
component and give it "mystyle
" style, the
component will have both "mystyle
" and "v-button-mystyle
"
styles. You could then style the component either with:
.mystyle {font-style: italic;}
or
.v-button-mystyle {font-style: italic;}
This method will trigger a
RepaintRequestEvent
.
removeStyleName
public void removeStyleName(String style)
- Specified by:
removeStyleName
in interfaceComponent
- Parameters:
style
- the style name or style names to be removed- See Also:
Component.getStyleName()
,Component.setStyleName(String)
,Component.addStyleName(String)
Description copied from interface: Component
Removes one or more style names from component. Multiple styles can be specified as a space-separated list of style names.
The parameter must be a valid CSS style name. Only user-defined style
names added with addStyleName()
or
setStyleName()
can be removed; built-in
style names defined in Vaadin or GWT can not be removed.
RepaintRequestEvent
.
getCaption
public String getCaption()
- Specified by:
getCaption
in interfaceComponent
- Returns:
- the caption of the component or
null
if the caption is not set. - See Also:
Component.setCaption(String)
Description copied from interface: Component
Gets the caption of the component.
See Component.setCaption(String)
for a detailed description of the
caption.
setCaption
public void setCaption(String caption)
- Specified by:
setCaption
in interfaceComponent
- Parameters:
caption
- the new captionString
for the component.
Sets the component's caption String
. Caption is the visible
name of the component. This method will trigger a
RepaintRequestEvent
.
getLocale
public Locale getLocale()
- Returns:
- Locale of this component or
null
if the component and none of its parents has a locale set and the component is not yet attached to an application.
Description copied from interface: Component
Gets the locale of the component.
If a component does not have a locale set, the locale of its parent is
returned, and so on. Eventually, if no parent has locale set, the locale
of the application is returned. If the application does not have a locale
set, it is determined by Locale.getDefault()
.
As the component must be attached before its locale can be acquired, using this method in the internationalization of component captions, etc. is generally not feasible. For such use case, we recommend using an otherwise acquired reference to the application locale.
setLocale
public void setLocale(Locale locale)
- Parameters:
locale
- the locale to become this component's locale.
Sets the locale of this component.
// Component for which the locale is meaningful
InlineDateField date = new InlineDateField("Datum");
// German language specified with ISO 639-1 language
// code and ISO 3166-1 alpha-2 country code.
date.setLocale(new Locale("de", "DE"));
date.setResolution(DateField.RESOLUTION_DAY);
layout.addComponent(date);
getIcon
public Resource getIcon()
- Returns:
- the icon resource of the component or
null
if the component has no icon - See Also:
Component.setIcon(Resource)
Description copied from interface: Component
Gets the icon resource of the component.
See Component.setIcon(Resource)
for a detailed description of the icon.
setIcon
public void setIcon(Resource icon)
- Parameters:
icon
- the icon to be shown with the component's caption.- See Also:
Component.getIcon()
,Component.setCaption(String)
Sets the component's icon. This method will trigger a
RepaintRequestEvent
.
isEnabled
public boolean isEnabled()
- Specified by:
isEnabled
in interfaceVariableOwner
- Specified by:
isEnabled
in interfaceComponent
- Returns:
true
if the variable owner is enabled,false
if not- See Also:
VariableOwner.isEnabled()
Description copied from interface: VariableOwner
Tests if the variable owner is enabled or not. The terminal should not send any variable changes to disabled variable owners.
setEnabled
public void setEnabled(boolean enabled)
- Specified by:
setEnabled
in interfaceComponent
- Parameters:
enabled
- a boolean value specifying if the component should be enabled or not
Description copied from interface: Component
Enables or disables the component. The user can not interact disabled components, which are shown with a style that indicates the status, usually shaded in light gray color. Components are enabled by default. Children of a disabled component are automatically disabled; if a child component is explicitly set as disabled, changes in the disabled status of its parents do not change its status.
Button enabled = new Button("Enabled");
enabled.setEnabled(true); // The default
layout.addComponent(enabled);
Button disabled = new Button("Disabled");
disabled.setEnabled(false);
layout.addComponent(disabled);
This method will trigger a
RepaintRequestEvent
for the component and, if it is a
ComponentContainer
, for all its children recursively.
isImmediate
public boolean isImmediate()
- Specified by:
isImmediate
in interfaceVariableOwner
- Returns:
true
if the component is in immediate mode,false
if not.
Description copied from interface: VariableOwner
Tests if the variable owner is in immediate mode or not. Being in immediate mode means that all variable changes are required to be sent back from the terminal immediately when they occur.
Note: VariableOwner
does not include a set-
method for the immediateness property. This is because not all
VariableOwners wish to offer the functionality. Such VariableOwners are
never in the immediate mode, thus they always return false
in VariableOwner.isImmediate()
.
setImmediate
public void setImmediate(boolean immediate)
- Parameters:
immediate
- the boolean value specifying if the component should be in the immediate mode after the call.- See Also:
VariableOwner.isImmediate()
Sets the component's immediate mode to the specified status. This method
will trigger a RepaintRequestEvent
.
isVisible
public boolean isVisible()
- Returns:
true
if the component is visible in the user interface,false
if not- See Also:
Component.setVisible(boolean)
,Component.attach()
Description copied from interface: Component
Tests the visibility property of the component.
Visible components are drawn in the user interface, while invisible ones are not. The effect is not merely a cosmetic CSS change, but the entire HTML element will be empty. Making a component invisible through this property can alter the positioning of other components.
A component is visible only if all its parents are also visible. Notice that if a child component is explicitly set as invisible, changes in the visibility status of its parents do not change its status.
This method does not check whether the component is attached (see
Component.attach()
). The component and all its parents may be considered
"visible", but not necessarily attached to application. To test if
component will actually be drawn, check both its visibility and that
Component.getApplication()
does not return null
.
setVisible
public void setVisible(boolean visible)
- Specified by:
setVisible
in interfaceComponent
- Parameters:
visible
- the boolean value specifying if the component should be visible after the call or not.- See Also:
Component.isVisible()
Description copied from interface: Component
Sets the visibility of the component.
Visible components are drawn in the user interface, while invisible ones are not. The effect is not merely a cosmetic CSS change, but the entire HTML element will be empty.
TextField readonly = new TextField("Read-Only");
readonly.setValue("You can't see this!");
readonly.setVisible(false);
layout.addComponent(readonly);
A component is visible only if all of its parents are also visible. If a component is explicitly set to be invisible, changes in the visibility of its parents will not change the visibility of the component.
getDescription
public String getDescription()
- item1
- item2
- Returns:
- component's description
String
Gets the component's description, used in tooltips and can be displayed directly in certain other components such as forms. The description can be used to briefly describe the state of the component to the user. The description string may contain certain XML tags:
Tag | Description | Example |
<b> | bold | bold text |
<i> | italic | italic text |
<u> | underlined | underlined text |
<br> | linebreak | N/A |
<ul> <li>item1 <li>item1 </ul> |
item list |
|
These tags may be nested.
setDescription
public void setDescription(String description)
- Parameters:
description
- the new description string for the component.
Sets the component's description. See getDescription()
for more
information on what the description is. This method will trigger a
RepaintRequestEvent
.
The description is displayed as HTML/XHTML in tooltips or directly in
certain components so care should be taken to avoid creating the
possibility for HTML injection and possibly XSS vulnerabilities.
getParent
public Component getParent()
- Returns:
- the parent component
- See Also:
Component.setParent(Component)
Description copied from interface: Component
Gets the parent component of the component.
Components can be nested but a component can have only one parent. A
component that contains other components, that is, can be a parent,
should usually inherit the ComponentContainer
interface.
setParent
public void setParent(Component parent)
- Parameters:
parent
- the parent component
Description copied from interface: Component
Sets the parent component of the component.
This method automatically calls Component.attach()
if the parent becomes
attached to the application, regardless of whether it was attached
previously. Conversely, if the parent is null
and the component
is attached to the application, Component.detach()
is called for the
component.
This method is rarely called directly. The
ComponentContainer.addComponent(Component)
method is normally
used for adding components to a container and it will call this method
implicitly.
It is not possible to change the parent without first setting the parent
to null
.
getErrorMessage
public ErrorMessage getErrorMessage()
- Returns:
- ErrorMessage containing the description of the error state of the component or null, if the component contains no errors. Extending classes should override this method if they support other error message types such as validation errors or buffering errors. The returned error message contains information about all the errors.
Gets the error message for this component.
getComponentError
public ErrorMessage getComponentError()
- Returns:
- the component's error message.
Gets the component's error message.
setComponentError
public void setComponentError(ErrorMessage componentError)
- Parameters:
componentError
- the newErrorMessage
of the component.
Sets the component's error message. The message may contain certain XML tags, for more information see
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceComponent
- Returns:
true
if the component or any of its parents is in read-only mode,false
if not.- See Also:
Component.setReadOnly(boolean)
Description copied from interface: Component
Tests whether the component is in the read-only mode. The user can not
change the value of a read-only component. As only Field
components normally have a value that can be input or changed by the
user, this is mostly relevant only to field components, though not
restricted to them.
Notice that the read-only mode only affects whether the user can change the value of the component; it is possible to, for example, scroll a read-only table.
The method will return true
if the component or any of its
parents is in the read-only mode.
setReadOnly
public void setReadOnly(boolean readOnly)
- Specified by:
setReadOnly
in interfaceComponent
- Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
Description copied from interface: Component
Sets the read-only mode of the component to the specified mode. The user can not change the value of a read-only component.
As only Field
components normally have a value that can be input
or changed by the user, this is mostly relevant only to field components,
though not restricted to them.
Notice that the read-only mode only affects whether the user can change the value of the component; it is possible to, for example, scroll a read-only table.
This method will trigger a
RepaintRequestEvent
.
getWindow
public Window getWindow()
- Returns:
- the parent window of the component or
null
if it is not attached to a window or is itself a window
Description copied from interface: Component
Gets the parent window of the component.
If the component is not attached to a window through a component
containment hierarchy, null
is returned.
The window can be either an application-level window or a sub-window. If the component is itself a window, it returns a reference to itself, not to its containing window (of a sub-window).
attach
public void attach()
- See Also:
Component.getApplication()
Description copied from interface: Component
Notifies the component that it is connected to an application.
The caller of this method is Component.setParent(Component)
if the parent
is itself already attached to the application. If not, the parent will
call the Component.attach()
for all its children when it is attached to
the application. This method is always called before the component is
painted for the first time.
Reimplementing the attach()
method is useful for tasks that need
to get a reference to the parent, window, or application object with the
Component.getParent()
, Component.getWindow()
, and Component.getApplication()
methods. A component does not yet know these objects in the constructor,
so in such case, the methods will return null
. For example, the
following is invalid:
public class AttachExample extends CustomComponent {
public AttachExample() {
// ERROR: We can't access the application object yet.
ClassResource r = new ClassResource("smiley.jpg", getApplication());
Embedded image = new Embedded("Image:", r);
setCompositionRoot(image);
}
}
Adding a component to an application triggers calling the
Component.attach()
method for the component. Correspondingly, removing a
component from a container triggers calling the Component.detach()
method.
If the parent of an added component is already connected to the
application, the attach()
is called immediately from
Component.setParent(Component)
.
public class AttachExample extends CustomComponent {
public AttachExample() {
}
@Override
public void attach() {
super.attach(); // Must call.
// Now we know who ultimately owns us.
ClassResource r = new ClassResource("smiley.jpg", getApplication());
Embedded image = new Embedded("Image:", r);
setCompositionRoot(image);
}
}
The attachment logic is implemented in AbstractComponent
.
detach
public void detach()
Description copied from interface: Component
Notifies the component that it is detached from the application.
The Component.getApplication()
and Component.getWindow()
methods might
return null
after this method is called.
The caller of this method is Component.setParent(Component)
if the parent
is in the application. When the parent is detached from the application
it is its response to call Component.detach()
for all the children and to
detach itself from the terminal.
focus
protected void focus()
Sets the focus for this component if the component is Focusable
.
getApplication
public Application getApplication()
- Specified by:
getApplication
in interfaceComponent
- Returns:
- the parent application of the component or
null
. - See Also:
attach()
Gets the application object to which the component is attached.
The method will return null
if the component is not currently
attached to an application. This is often a problem in constructors of
regular components and in the initializers of custom composite
components. A standard workaround is to move the problematic
initialization to attach()
, as described in the documentation of
the method.
This method is not meant to be overridden. Due to CDI requirements we cannot declare it as final even though it should be final.
requestRepaintRequests
public void requestRepaintRequests()
- Specified by:
requestRepaintRequests
in interfacePaintable
Description copied from interface: Paintable
Request sending of repaint events on any further visible changes. Normally the paintable only send up to one repaint request for listeners after paint as the paintable as the paintable assumes that the listeners already know about the repaint need. This method resets the assumtion. Paint implicitly does the assumtion reset functionality implemented by this method.
This method is normally used only by the terminals to note paintables about implicit repaints (painting the component without actually invoking paint method).
paint
public void paint(PaintTarget target)
throws PaintException
- Parameters:
target
- the target UIDL stream where the component should paint itself to.- Throws:
PaintException
- if the paint operation failed.
Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.
It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.
Do not override this to paint your component. Override
paintContent(PaintTarget)
instead.
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Parameters:
target
- the target UIDL stream where the component should paint itself to- Throws:
PaintException
- if the paint operation failed.
Paints any needed component-specific things to the given UIDL stream. The
more general paint(PaintTarget)
method handles all general
attributes common to all components, and it calls this method to paint
any component-specific attributes to the UIDL stream.
requestRepaint
public void requestRepaint()
- Specified by:
requestRepaint
in interfacePaintable
Description copied from interface: Paintable
Requests that the paintable should be repainted as soon as possible.
childRequestedRepaint
public void childRequestedRepaint(Collection<Paintable.RepaintRequestListener> alreadyNotified)
- Specified by:
childRequestedRepaint
in interfaceComponent
- Parameters:
alreadyNotified
- the collection of repaint request listeners that have been already notified by the child. This component should not re-notify the listed listeners again. The container given as parameter must be modifiable as the component might modify it and pass it forward. Anull
parameter is interpreted as an empty collection.
Description copied from interface: Component
The child components of the component must call this method when they need repainting. The call must be made even in the case in which the children sent the repaint request themselves.
A repaint request is ignored if the component is invisible.
This method is called automatically by AbstractComponent
, which
also provides a default implementation of it. As this is a somewhat
internal feature, it is rarely necessary to reimplement this or call it
explicitly.
addListener
public void addListener(Paintable.RepaintRequestListener listener)
- Specified by:
addListener
in interfacePaintable
- Parameters:
listener
- the listener to be added.
Description copied from interface: Paintable
Adds repaint request listener. In order to assure that no repaint requests are missed, the new repaint listener should paint the paintable right after adding itself as listener.
removeListener
public void removeListener(Paintable.RepaintRequestListener listener)
- Specified by:
removeListener
in interfacePaintable
- Parameters:
listener
- the listener to be removed.
Description copied from interface: Paintable
Removes repaint request listener.
changeVariables
public void changeVariables(Object source,
Map<String,Object> variables)
- Specified by:
changeVariables
in interfaceVariableOwner
- Parameters:
source
- the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.
Description copied from interface: VariableOwner
Called when one or more variables handled by the implementing class are changed.
addListener
protected void addListener(String eventIdentifier,
Class<?> eventType,
Object target,
Method method)
- Parameters:
eventIdentifier
- the identifier of the event to listen foreventType
- the type of the listened event. Events of this type or its subclasses activate the listener.target
- the object instance who owns the activation method.method
- the activation method.- Since:
- 6.2
Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
This method additionally informs the event-api to route events with the given eventIdentifier to the components handleEvent function call.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
hasListeners
protected boolean hasListeners(Class<?> eventType)
- Parameters:
eventType
- the event type to be checked- Returns:
- true if a listener is registered for the given event type
Checks if the given AbstractComponent.ComponentErrorEvent
type is listened for this component.
removeListener
protected void removeListener(String eventIdentifier,
Class<?> eventType,
Object target)
- Parameters:
eventIdentifier
- the identifier of the event to stop listening foreventType
- the exact event type theobject
listens to.target
- the target object that has registered to listen to events of typeeventType
with one or more methods.- Since:
- 6.2
Removes all registered listeners matching the given parameters. Since
this method receives the event type and the listener object as
parameters, it will unregister all object
's methods that are
registered to listen to events of type eventType
generated
by this component.
This method additionally informs the event-api to stop routing events with the given eventIdentifier to the components handleEvent function call.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
addListener
public void addListener(Class<?> eventType,
Object target,
Method method)
- Specified by:
addListener
in interfaceMethodEventSource
- Parameters:
eventType
- the type of the listened event. Events of this type or its subclasses activate the listener.target
- the object instance who owns the activation method.method
- the activation method.
Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
addListener
public void addListener(Class<?> eventType,
Object target,
String methodName)
- Specified by:
addListener
in interfaceMethodEventSource
- Parameters:
eventType
- the type of the listened event. Events of this type or its subclasses activate the listener.target
- the object instance who owns the activation method.methodName
- the name of the activation method.
Convenience method for registering a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
This version of addListener
gets the name of the activation
method as a parameter. The actual method is reflected from
object
, and unless exactly one match is found,
java.lang.IllegalArgumentException
is thrown.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
Note: Using this method is discouraged because it cannot be checked
during compilation. Use addListener(Class, Object, Method)
or
addListener(com.vaadin.ui.Component.Listener)
instead.
removeListener
public void removeListener(Class<?> eventType,
Object target)
- Specified by:
removeListener
in interfaceMethodEventSource
- Parameters:
eventType
- the exact event type theobject
listens to.target
- the target object that has registered to listen to events of typeeventType
with one or more methods.
Removes all registered listeners matching the given parameters. Since
this method receives the event type and the listener object as
parameters, it will unregister all object
's methods that are
registered to listen to events of type eventType
generated
by this component.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
removeListener
public void removeListener(Class<?> eventType,
Object target,
Method method)
- Specified by:
removeListener
in interfaceMethodEventSource
- Parameters:
eventType
- the exact event type theobject
listens to.target
- target object that has registered to listen to events of typeeventType
with one or more methods.method
- the method owned bytarget
that's registered to listen to events of typeeventType
.
Removes one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
removeListener
public void removeListener(Class<?> eventType,
Object target,
String methodName)
- Specified by:
removeListener
in interfaceMethodEventSource
- Parameters:
eventType
- the exact event type theobject
listens to.target
- the target object that has registered to listen to events of typeeventType
with one or more methods.methodName
- the name of the method owned bytarget
that's registered to listen to events of typeeventType
.
Removes one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.
This version of removeListener
gets the name of the
activation method as a parameter. The actual method is reflected from
target
, and unless exactly one match is found,
java.lang.IllegalArgumentException
is thrown.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
getListeners
public Collection<?> getListeners(Class<?> eventType)
- Parameters:
eventType
- The type of event to return listeners for.- Returns:
- A collection with all registered listeners. Empty if no listeners are found.
Returns all listeners that are registered for the given event type or one of its subclasses.
fireEvent
protected void fireEvent(Component.Event event)
- Parameters:
event
- the Event to be sent to all listeners.
Sends the event to all listeners.
addListener
public void addListener(Component.Listener listener)
- Specified by:
addListener
in interfaceComponent
- Parameters:
listener
- the new Listener to be registered.- See Also:
Component.Event
,Component.removeListener(Listener)
Description copied from interface: Component
Registers a new (generic) component event listener for the component.
class Listening extends CustomComponent implements Listener {
// Stored for determining the source of an event
Button ok;
Label status; // For displaying info about the event
public Listening() {
VerticalLayout layout = new VerticalLayout();
// Some miscellaneous component
TextField name = new TextField("Say it all here");
name.addListener(this);
name.setImmediate(true);
layout.addComponent(name);
// Handle button clicks as generic events instead
// of Button.ClickEvent events
ok = new Button("OK");
ok.addListener(this);
layout.addComponent(ok);
// For displaying information about an event
status = new Label("");
layout.addComponent(status);
setCompositionRoot(layout);
}
public void componentEvent(Event event) {
// Act according to the source of the event
if (event.getSource() == ok)
getWindow().showNotification("Click!");
status.setValue("Event from " + event.getSource().getClass().getName()
+ ": " + event.getClass().getName());
}
}
Listening listening = new Listening();
layout.addComponent(listening);
removeListener
public void removeListener(Component.Listener listener)
- Specified by:
removeListener
in interfaceComponent
- Parameters:
listener
- the listener to be removed.- See Also:
Component.addListener(Listener)
Description copied from interface: Component
Removes a previously registered component event listener from this component.
fireComponentEvent
protected void fireComponentEvent()
Emits the component event. It is transmitted to all registered listeners interested in such events.
fireComponentErrorEvent
protected void fireComponentErrorEvent()
Emits the component error event. It is transmitted to all registered listeners interested in such events.
setData
public void setData(Object data)
- Parameters:
data
- the Application specific data.- Since:
- 3.1
Sets the data object, that can be used for any application specific data. The component does not use or modify this data.
getData
public Object getData()
- Returns:
- the Application specific data set with setData function.
- Since:
- 3.1
Gets the application specific data. See setData(Object)
.
getHeight
public float getHeight()
- Returns:
- height of the object in units specified by heightUnits property.
Description copied from interface: Sizeable
Gets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
getHeightUnits
public int getHeightUnits()
- Specified by:
getHeightUnits
in interfaceSizeable
- Returns:
- units used in height property.
Description copied from interface: Sizeable
Gets the height property units.
getWidth
public float getWidth()
- Returns:
- width of the object in units specified by widthUnits property.
Description copied from interface: Sizeable
Gets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
getWidthUnits
public int getWidthUnits()
- Specified by:
getWidthUnits
in interfaceSizeable
- Returns:
- units used in width property.
Description copied from interface: Sizeable
Gets the width property units.
setHeight
@Deprecated
public void setHeight(float height)
- Parameters:
height
- the height of the object in units specified by heightUnits property.
Deprecated.
Description copied from interface: Sizeable
Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
setHeightUnits
@Deprecated
public void setHeightUnits(int unit)
- Specified by:
setHeightUnits
in interfaceSizeable
- Parameters:
unit
- the units used in height property.
Deprecated.
Description copied from interface: Sizeable
Sets the height property units.
setHeight
public void setHeight(float height,
int unit)
- Parameters:
height
- the height of the object.unit
- the unit used for the width. Possible values includeSizeable.UNITS_PIXELS
,Sizeable.UNITS_POINTS
,Sizeable.UNITS_PICAS
,Sizeable.UNITS_EM
,Sizeable.UNITS_EX
,Sizeable.UNITS_MM
,Sizeable.UNITS_CM
,Sizeable.UNITS_INCH
,Sizeable.UNITS_PERCENTAGE
.
Description copied from interface: Sizeable
Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
setSizeFull
public void setSizeFull()
- Specified by:
setSizeFull
in interfaceSizeable
Description copied from interface: Sizeable
Sets the size to 100% x 100%.
setSizeUndefined
public void setSizeUndefined()
- Specified by:
setSizeUndefined
in interfaceSizeable
Description copied from interface: Sizeable
Clears any size settings.
setWidth
@Deprecated
public void setWidth(float width)
- Parameters:
width
- the width of the object in units specified by widthUnits property.
Deprecated.
Description copied from interface: Sizeable
Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
setWidthUnits
@Deprecated
public void setWidthUnits(int unit)
- Specified by:
setWidthUnits
in interfaceSizeable
- Parameters:
unit
- the units used in width property.
Deprecated.
Description copied from interface: Sizeable
Sets the width property units.
setWidth
public void setWidth(float width,
int unit)
- Parameters:
width
- the width of the object.unit
- the unit used for the width. Possible values includeSizeable.UNITS_PIXELS
,Sizeable.UNITS_POINTS
,Sizeable.UNITS_PICAS
,Sizeable.UNITS_EM
,Sizeable.UNITS_EX
,Sizeable.UNITS_MM
,Sizeable.UNITS_CM
,Sizeable.UNITS_INCH
,Sizeable.UNITS_PERCENTAGE
.
Description copied from interface: Sizeable
Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
setWidth
public void setWidth(String width)
- Parameters:
width
- in CSS style string representation, null or empty string to reset
Description copied from interface: Sizeable
Sets the width of the component using String presentation. String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size. The empty string ("") or null will unset the width and set the units to pixels. See CSS specification for more details.
setHeight
public void setHeight(String height)
- Parameters:
height
- in CSS style string representation
Description copied from interface: Sizeable
Sets the height of the component using String presentation. String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size. The empty string ("") or null will unset the height and set the units to pixels. See CSS specification for more details.
getErrorHandler
public AbstractComponent.ComponentErrorHandler getErrorHandler()
- Returns:
Gets the error handler for the component. The error handler is dispatched whenever there is an error processing the data coming from the client.
setErrorHandler
public void setErrorHandler(AbstractComponent.ComponentErrorHandler errorHandler)
- Parameters:
errorHandler
- AbstractField specific error handler
Sets the error handler for the component. The error handler is dispatched whenever there is an error processing the data coming from the client. If the error handler is not set, the application error handler is used to handle the exception.
handleError
public boolean handleError(AbstractComponent.ComponentErrorEvent error)
- Parameters:
error
- Error event to handle- Returns:
- True if the error has been handled False, otherwise. If the error haven't been handled by this component, it will be handled in the application error handler.
Handle the component error event.