Class AbstractCompositeComponentHandler<T,​S>

  • Type Parameters:
    T - the type of the data of this component handler
    S - 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 the CompositeComponentHandler 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 Detail

      • AbstractCompositeComponentHandler

        protected AbstractCompositeComponentHandler​(Class<T> dataType)
        Creates a new instance of AbstractCompositeComponentHandler and initializes it with the data type class.
        Parameters:
        dataType - the type of the data managed by this handler
    • Method Detail

      • addHandler

        public void addHandler​(String name,
                               ComponentHandler<S> handler)
        Adds the specified child ComponentHandler to this CompositeComponentHandler.
        Specified by:
        addHandler in interface CompositeComponentHandler<T,​S>
        Parameters:
        name - the name of the child handler
        handler - 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 interface ComponentHandler<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 interface ComponentHandler<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 interface ComponentHandler<T>
        Returns:
        the data type of this handler
      • isEnabled

        public boolean isEnabled()
        Returns a flag whether this ComponentHandler is enabled. This implementation returns true if and only if all child handlers are enabled.
        Specified by:
        isEnabled in interface ComponentHandler<T>
        Returns:
        a flag whether this ComponentHandler is enabled
      • setEnabled

        public void setEnabled​(boolean f)
        Changes the enabled state of this ComponentHandler. This implementation calls setEnabled() on all child handlers passing in the argument.
        Specified by:
        setEnabled in interface ComponentHandler<T>
        Parameters:
        f - the new enabled state
      • getChildHandlerCount

        public final int getChildHandlerCount()
        Returns the number of child ComponentHandlers that have been added to this CompositeComponentHandler.
        Returns:
        the number of child handlers
      • getChildHandlers

        protected List<ComponentHandler<S>> getChildHandlers()
        Returns a list with all child handlers managed by this CompositeComponentHandler. 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 this CompositeComponentHandler. 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