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
CompositeComponentHandlerinterface.This base class already provides functionality for managing a list of child
ComponentHandlerobjects. It also has base implementations for most of the methods defined by theCompositeComponentHandlerinterface. 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 protectedAbstractCompositeComponentHandler(Class<T> dataType)Creates a new instance ofAbstractCompositeComponentHandlerand initializes it with the data type class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(String name, ComponentHandler<S> handler)Adds the specified childComponentHandlerto thisCompositeComponentHandler.protected ComponentHandler<S>getChildHandler(String name)Returns the child handler with the specified name.intgetChildHandlerCount()Returns the number of childComponentHandlers that have been added to thisCompositeComponentHandler.protected intgetChildHandlerIndex(String name)Returns the index for the child handler with the given name.protected StringgetChildHandlerNameAt(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.ObjectgetComponent()Returns the component this handler is associated with.ObjectgetOuterComponent()Returns the outer component this handler is associated with.Class<?>getType()Returns the data type of this component handler.booleanisEnabled()Returns a flag whether thisComponentHandleris enabled.voidsetEnabled(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 childComponentHandlerto thisCompositeComponentHandler.- Specified by:
addHandlerin 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:
getComponentin 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:
getOuterComponentin 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:
getTypein interfaceComponentHandler<T>- Returns:
- the data type of this handler
-
isEnabled
public boolean isEnabled()
Returns a flag whether thisComponentHandleris enabled. This implementation returns true if and only if all child handlers are enabled.- Specified by:
isEnabledin interfaceComponentHandler<T>- Returns:
- a flag whether this
ComponentHandleris 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:
setEnabledin interfaceComponentHandler<T>- Parameters:
f- the new enabled state
-
getChildHandlerCount
public final int getChildHandlerCount()
Returns the number of childComponentHandlers 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
ComponentHandleror 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
ComponentHandleror null
-
-