com.itmill.toolkit.ui
Class CustomComponent

java.lang.Object
  extended by com.itmill.toolkit.terminal.Identifiable
      extended by com.itmill.toolkit.ui.CustomComponent
All Implemented Interfaces:
Paintable, VariableOwner, Component, EventListener

public class CustomComponent
extends Identifiable
implements Component

Custom component provides simple implementation of Component interface for creation of new UI components by composition of existing components.

The component is used by inheriting the CustomComponent class and setting composite root inside the Custom component. The composite root itself can contain more components, but their interfaces are hidden from the users.

Since:
3.0
Version:
4.1.4
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
Constructor Summary
CustomComponent()
          Constructs a new custom component.
CustomComponent(Component compositionRoot)
          Constructs a new custom component.
 
Method Summary
 void addListener(Component.Listener listener)
          Custom component does not implement any component events by default.
 void addListener(Paintable.RepaintRequestListener listener)
          Adds repaint request listener.
 void attach()
          Notifies the component that it is connected to an application.
 void changeVariables(Object source, Map variables)
          Called when one or more variables handled by the implementing class are changed.
 void childRequestedRepaint(Collection alreadyNotified)
          The children must call this method when they need repainting.
 void dependsOn(VariableOwner depended)
          Makes this VariableOwner depend on the given VariableOwner.
 void detach()
          Notifies the component that it is detached from the application.
 Application getApplication()
          Gets the component's parent application
 String getCaption()
          The caption of the custom component is by default the caption of the root component, or null if the root is not set.
 String getComponentType()
          Gets the component type.
protected  Component getCompositionRoot()
          Returns the composition root.
 Set getDirectDependencies()
          Gets the variable change listeners this VariableOwner directly depends on.
 Resource getIcon()
          The icon of the custom component is by default the icon of the root component, or null if the root is not set.
 Locale getLocale()
          The icon of the custom component is by default the locale of the parent or null if the parent is not set.
 Component getParent()
          Gets the visual parent of the component.
 String getStyle()
          Custom component does not implement custom styles by default and this function returns null.
 Window getWindow()
          Gets the component's parent window.
 boolean isEnabled()
          Custom component is allways enabled by default.
 boolean isImmediate()
          Custom component is by default in the non-immediate mode.
 boolean isReadOnly()
          The custom components are not readonly by default.
 boolean isVisible()
          Tests if the component is visible or not.
 void paint(PaintTarget target)
           Paints the paintable into a UIDL stream.
 void removeDirectDependency(VariableOwner depended)
          Removes the given component from this component's dependency list.
 void removeListener(Component.Listener listener)
          Custom component does not implement any component events by default.
 void removeListener(Paintable.RepaintRequestListener listener)
          Removes repaint request listener.
 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 setComponentType(String componentType)
          Sets the component type.
protected  void setCompositionRoot(Component compositionRoot)
          Sets the compositions root.
 void setEnabled(boolean enabled)
          The custom component is allways enabled by default.
 void setParent(Component parent)
          Sets the component's parent component.
 void setReadOnly(boolean readOnly)
          Sets the component's to read-only mode to the specified state.
 void setStyle(String style)
          Sets the look-and-feel style of the component.
 void setVisible(boolean visible)
          Sets the components visibility status.
 
Methods inherited from class com.itmill.toolkit.terminal.Identifiable
getDebugId, getUIID, setDebugId, setUIID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomComponent

public CustomComponent()
Constructs a new custom component.

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.


CustomComponent

public CustomComponent(Component compositionRoot)
Constructs a new custom component.

The component is implemented by wrapping the methods of the composition root component given as parameter. The composition root must not be null and can not be changed after the composition.

Parameters:
compositionRoot - the root of the composition component tree.
Method Detail

getCompositionRoot

protected final Component getCompositionRoot()
Returns the composition root.

Returns:
the Component Composition root.

setCompositionRoot

protected final void setCompositionRoot(Component compositionRoot)
Sets the compositions root.

The composition root must be set to non-null value before the component can be used. The composition root can only be set once.

Parameters:
compositionRoot - the root of the composition component tree.

attach

public void attach()
Notifies the component that it is connected to an application.

Specified by:
attach in interface Component
See Also:
Component.attach()

detach

public void detach()
Notifies the component that it is detached from the application.

Specified by:
detach in interface Component
See Also:
Component.detach()

getApplication

public Application getApplication()
Gets the component's parent application

Specified by:
getApplication in interface Component
Returns:
the parent application of the component or null.
See Also:
Component.getApplication()

getCaption

public String getCaption()
The caption of the custom component is by default the caption of the root component, or null if the root is not set.

Specified by:
getCaption in interface Component
Returns:
the component's caption String.
See Also:
Component.getCaption()

getIcon

public Resource getIcon()
The icon of the custom component is by default the icon of the root component, or null if the root is not set.

Specified by:
getIcon in interface Component
Returns:
the component's icon or null if it not defined.
See Also:
Component.getIcon()

getLocale

public Locale getLocale()
The icon of the custom component is by default the locale of the parent or null if the parent is not set.

Specified by:
getLocale in interface Component
Returns:
This component's locale. If this component does not have a locale, the locale of its parent is returned. Eventually locale of application is returned. If application does not have its own locale the locale is determined by Locale.getDefautlt. Returns null if the component does not have its own locale and has not yet been added to a containment hierarchy such that the locale can be determined from the containing parent.
See Also:
Component.getLocale()

getParent

public Component getParent()
Gets the visual parent of the component.

Specified by:
getParent in interface Component
Returns:
the parent component.
See Also:
Component.getParent()

getStyle

public String getStyle()
Custom component does not implement custom styles by default and this function returns null.

Specified by:
getStyle in interface Component
Returns:
the component's styleValue of property style.
See Also:
Component.getStyle()

getWindow

public Window getWindow()
Gets the component's parent window.

Specified by:
getWindow in interface Component
Returns:
the parent window of the component or null.
See Also:
Component.getWindow()

isEnabled

public boolean isEnabled()
Custom component is allways enabled by default.

Specified by:
isEnabled in interface VariableOwner
Specified by:
isEnabled in interface Component
Returns:
true if the variable owner is enabled, false if not
See Also:
Component.isEnabled()

isImmediate

public boolean isImmediate()
Custom component is by default in the non-immediate mode. The immediateness of the custom component is defined by the components it is composed of.

Specified by:
isImmediate in interface VariableOwner
Returns:
true if the component is in immediate mode, false if not.
See Also:
VariableOwner.isImmediate()

isReadOnly

public boolean isReadOnly()
The custom components are not readonly by default.

Specified by:
isReadOnly in interface Component
Returns:
true if the component is in read-only mode, false if not.
See Also:
Component.isReadOnly()

isVisible

public boolean isVisible()
Tests if the component is visible or not.

Specified by:
isVisible in interface Component
Returns:
true if the component is visible in the UI, false if not
See Also:
Component.isVisible()

requestRepaint

public void requestRepaint()
Description copied from interface: Paintable
Requests that the paintable should be repainted as soon as possible.

Specified by:
requestRepaint in interface Paintable

childRequestedRepaint

public void childRequestedRepaint(Collection alreadyNotified)
Description copied from interface: Component
The children must call this method when they need repainting. The call must be made event in the case the children sent the repaint request themselves.

Specified by:
childRequestedRepaint in interface Component
Parameters:
alreadyNotified - the collection of repaint request listeners that have been already notified by the child. This component should not renotify the listed listeners again. The container given as parameter must be modifiable as the component might modify it and pass it forwards. Null parameter is interpreted as empty collection.

addListener

public void addListener(Paintable.RepaintRequestListener listener)
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.

Specified by:
addListener in interface Paintable
Parameters:
listener - the listener to be added.

removeListener

public void removeListener(Paintable.RepaintRequestListener listener)
Description copied from interface: Paintable
Removes repaint request listener.

Specified by:
removeListener in interface Paintable
Parameters:
listener - the listener to be removed.

setEnabled

public void setEnabled(boolean enabled)
The custom component is allways enabled by default.

Specified by:
setEnabled in interface Component
Parameters:
enabled - the boolean value specifying if the component should be enabled after the call or not

setParent

public void setParent(Component parent)
Sets the component's parent component.

Specified by:
setParent in interface Component
Parameters:
parent - the new parent component.
See Also:
Component.setParent(com.itmill.toolkit.ui.Component)

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the component's to read-only mode to the specified state.

Specified by:
setReadOnly in interface Component
Parameters:
readOnly - the boolean value specifying if the component should be in read-only mode after the call or not.
See Also:
Component.setReadOnly(boolean)

setStyle

public void setStyle(String style)
Sets the look-and-feel style of the component.

Specified by:
setStyle in interface Component
Parameters:
style - the new style of the component.
See Also:
Component.setStyle(java.lang.String)

setVisible

public void setVisible(boolean visible)
Sets the components visibility status.

Specified by:
setVisible in interface Component
Parameters:
visible - the Boolean value specifying if the component should be visible after the call or not.
See Also:
Component.setVisible(boolean)

requestRepaintRequests

public void requestRepaintRequests()
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).

Specified by:
requestRepaintRequests in interface Paintable

paint

public void paint(PaintTarget target)
           throws PaintException
Description copied from interface: Paintable

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.

Specified by:
paint in interface Paintable
Parameters:
target - the target UIDL stream where the component should paint itself to.
Throws:
PaintException - if the paint operation failed.

changeVariables

public void changeVariables(Object source,
                            Map variables)
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
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.
See Also:
VariableOwner.changeVariables(java.lang.Object, java.util.Map)

dependsOn

public void dependsOn(VariableOwner depended)
Makes this VariableOwner depend on the given VariableOwner.

Specified by:
dependsOn in interface VariableOwner
Parameters:
depended - the VariableOwner component who this component depends on.
See Also:
VariableOwner.dependsOn(com.itmill.toolkit.terminal.VariableOwner)

getDirectDependencies

public Set getDirectDependencies()
Gets the variable change listeners this VariableOwner directly depends on.

Specified by:
getDirectDependencies in interface VariableOwner
Returns:
Set of VariableOwners this component directly depend on, null if this component does not depend on anybody.
See Also:
VariableOwner.getDirectDependencies()

removeDirectDependency

public void removeDirectDependency(VariableOwner depended)
Removes the given component from this component's dependency list.

Specified by:
removeDirectDependency in interface VariableOwner
Parameters:
depended - the component to be removed from this component's dependency list.
See Also:
VariableOwner.removeDirectDependency(com.itmill.toolkit.terminal.VariableOwner)

addListener

public void addListener(Component.Listener listener)
Custom component does not implement any component events by default.

Specified by:
addListener in interface Component
Parameters:
listener - the listener to add.

removeListener

public void removeListener(Component.Listener listener)
Custom component does not implement any component events by default.

Specified by:
removeListener in interface Component
Parameters:
listener - the listener to remove.

getComponentType

public String getComponentType()
Gets the component type. The component type is textual type of the component. This is included in the UIDL as component tag attribute. If the component type is null (default), the component tag is not included in the UIDL at all.

Returns:
the component type.

setComponentType

public void setComponentType(String componentType)
Sets the component type. The component type is textual type of the component. This is included in the UIDL as component tag attribute. If the component type is null (default), the component tag is not included in the UIDL at all.

Parameters:
componentType - the componentType to set.


Copyright © 2000-2008 IT Mill Ltd. All Rights Reserved.