Class AbstractCompositeComponentHandler<T,S>
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.components.AbstractCompositeComponentHandler<T,S>
-
- Type Parameters:
T
- the type of the data of this component handlerS
- the type of the child handlers
- All Implemented Interfaces:
CompositeComponentHandler<T,S>
,ComponentHandler<T>
- Direct Known Subclasses:
AbstractRadioButtonHandler
public abstract class AbstractCompositeComponentHandler<T,S> extends Object implements CompositeComponentHandler<T,S>
An abstract base class for concrete implementations of the
CompositeComponentHandler
interface.This base class already provides functionality for managing a list of child
ComponentHandler
objects. It also has base implementations for most of the methods defined by theCompositeComponentHandler
interface. Concrete sub classes mainly have to implement the methods for accessing the data of this handler. Here the idea is that the data of the child component handlers must be converted into an object that is the data of this composite handler. For the base implementations of the other interface methods refer to the method documentation.Implementation note: This class is not thread-safe.
- Version:
- $Id: AbstractCompositeComponentHandler.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCompositeComponentHandler(Class<T> dataType)
Creates a new instance ofAbstractCompositeComponentHandler
and initializes it with the data type class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHandler(String name, ComponentHandler<S> handler)
Adds the specified childComponentHandler
to thisCompositeComponentHandler
.protected ComponentHandler<S>
getChildHandler(String name)
Returns the child handler with the specified name.int
getChildHandlerCount()
Returns the number of childComponentHandler
s that have been added to thisCompositeComponentHandler
.protected int
getChildHandlerIndex(String name)
Returns the index for the child handler with the given name.protected String
getChildHandlerNameAt(int index)
Returns the name of the child handler at the specified index.protected Set<String>
getChildHandlerNames()
Returns a set with the names of the child handlers that have been added to this handler.protected List<ComponentHandler<S>>
getChildHandlers()
Returns a list with all child handlers managed by thisCompositeComponentHandler
.Object
getComponent()
Returns the component this handler is associated with.Object
getOuterComponent()
Returns the outer component this handler is associated with.Class<?>
getType()
Returns the data type of this component handler.boolean
isEnabled()
Returns a flag whether thisComponentHandler
is enabled.void
setEnabled(boolean f)
Changes the enabled state of thisComponentHandler
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.jguiraffe.gui.forms.ComponentHandler
getData, setData
-
-
-
-
Method Detail
-
addHandler
public void addHandler(String name, ComponentHandler<S> handler)
Adds the specified childComponentHandler
to thisCompositeComponentHandler
.- Specified by:
addHandler
in interfaceCompositeComponentHandler<T,S>
- Parameters:
name
- the name of the child handlerhandler
- the child handler to be added (must not be null)- Throws:
IllegalArgumentException
- if the handler is null or a child handler with this name already exists
-
getComponent
public Object getComponent()
Returns the component this handler is associated with. This base implementation always returns null because there is no underlying component.- Specified by:
getComponent
in interfaceComponentHandler<T>
- Returns:
- the associated component
-
getOuterComponent
public Object getOuterComponent()
Returns the outer component this handler is associated with. This base implementation always returns null because this handler is not associated with a concrete component.- Specified by:
getOuterComponent
in interfaceComponentHandler<T>
- Returns:
- the outer component
-
getType
public Class<?> getType()
Returns the data type of this component handler. This base implementation returns the class that was passed to the constructor.- Specified by:
getType
in interfaceComponentHandler<T>
- Returns:
- the data type of this handler
-
isEnabled
public boolean isEnabled()
Returns a flag whether thisComponentHandler
is enabled. This implementation returns true if and only if all child handlers are enabled.- Specified by:
isEnabled
in interfaceComponentHandler<T>
- Returns:
- a flag whether this
ComponentHandler
is enabled
-
setEnabled
public void setEnabled(boolean f)
Changes the enabled state of thisComponentHandler
. This implementation callssetEnabled()
on all child handlers passing in the argument.- Specified by:
setEnabled
in interfaceComponentHandler<T>
- Parameters:
f
- the new enabled state
-
getChildHandlerCount
public final int getChildHandlerCount()
Returns the number of childComponentHandler
s that have been added to thisCompositeComponentHandler
.- Returns:
- the number of child handlers
-
getChildHandlers
protected List<ComponentHandler<S>> getChildHandlers()
Returns a list with all child handlers managed by thisCompositeComponentHandler
. Derived classes can call this method to access the child handlers. Note: the list must not be modified.- Returns:
- a list with all child handlers
-
getChildHandlerNames
protected Set<String> getChildHandlerNames()
Returns a set with the names of the child handlers that have been added to this handler. The order of the names in this set corresponds to the order in which the child handlers have been added. Note: the set must not be modified.- Returns:
- a set with the names of the child handlers
-
getChildHandler
protected ComponentHandler<S> getChildHandler(String name)
Returns the child handler with the specified name. If the handler cannot be found, null is returned.- Parameters:
name
- the name of the child handler in question- Returns:
- the corresponding child
ComponentHandler
or null
-
getChildHandlerIndex
protected int getChildHandlerIndex(String name)
Returns the index for the child handler with the given name. Indices are 0-based. If the name cannot be resolved, this method returns -1.- Parameters:
name
- the name of the child handler in question- Returns:
- the index of this child handler
-
getChildHandlerNameAt
protected String getChildHandlerNameAt(int index)
Returns the name of the child handler at the specified index. The index can run from 0 to the number of child handlers minus 1. The handlers are indexed in the order they have been added to thisCompositeComponentHandler
. If the index passed in is invalid, this method returns null.- Parameters:
index
- the index of the desired child handler- Returns:
- the corresponding child
ComponentHandler
or null
-
-