com.arsdigita.bebop
Class CompoundComponent

java.lang.Object
  extended bycom.arsdigita.bebop.Completable
      extended bycom.arsdigita.bebop.CompoundComponent
All Implemented Interfaces:
Component, Lockable
Direct Known Subclasses:
DimensionBar, PartySearchSelect, PartySearchSelect.Search, PrivilegedComponentSelector

public class CompoundComponent
extends Completable
implements Component

Provides a convenient method of creating components that are an aggregation of other components and that should have the public interface of a component (rather than that of a container, form, and so on). The methods of the Component interface are delegated to a Container object, which is a SimpleContainer by default. The methods of the Container interface are present with protected access. This allows subclasses of CompoundComponent to alter the structure of the component while preserving the simple Component interface to users of the class.

Users of this class should subclass CompoundComponent and add components in the subclass' constructor, remembering to first call super() or super( Container ). Note that the super( Container ) method will use the passed Container in place of the SimpleContainer to hold the added components.

Author:
Oliver Stewart

Field Summary
 
Fields inherited from class com.arsdigita.bebop.Completable
versionId
 
Fields inherited from interface com.arsdigita.bebop.Component
BEBOP_XML_NS, CLASS, ID, ON_CLICK, STYLE, versionId
 
Constructor Summary
CompoundComponent()
          Creates a new compound component.
CompoundComponent(Container container)
          Creates a new compound component, using the specified container to hold added components.
 
Method Summary
protected  void add(Component c)
          Adds a component to the container.
protected  void add(Component c, int constraints)
          Adds a component with the specified layout constraints to the container.
 Iterator children()
          Returns an iterator over the children of this component.
protected  boolean contains(Object o)
          Returns true if this list contains the specified element.
 void generateXML(PageState state, Element parent)
          Adds a DOM subtree representing this component under the given parent node.
protected  Component get(int index)
          Gets the component at the specified position.
 String getClassAttr()
          Gets the class attribute.
protected  Container getContainer()
          Return the Container used to hold added components.
 String getIdAttr()
          Gets the id attribute.
 String getKey()
          Retrieves the programmer-supplied key.
 String getStyleAttr()
          Gets the style attribute.
protected  int indexOf(Component c)
           
protected  boolean isEmpty()
          Returns true if the container contains no components.
 boolean isLocked()
          Return whether an object is locked and thus immutable, or can still be modified.
 boolean isVisible(PageState state)
          Determines whether the component is visible in the request represented by state.
 void lock()
          Lock an object.
 void register(Form f, FormModel m)
          Registers form parameters with the form model for this form.
 void register(Page p)
          Registers state parameters for the page with its model.
 void respond(PageState state)
          Responds to the request.
 void setClassAttr(String theClass)
          Sets the class attribute.
 void setIdAttr(String id)
          Sets the id attribute.
 Component setKey(String key)
          Supplies a key for making parameter names unique.
 void setStyleAttr(String style)
          Sets the style attribute.
 void setVisible(PageState state, boolean v)
          Changes the visibility of the component.
protected  int size()
          Returns the number of elements in the container.
 
Methods inherited from class com.arsdigita.bebop.Completable
addCompletionListener, fireCompletionEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundComponent

public CompoundComponent()
Creates a new compound component.


CompoundComponent

public CompoundComponent(Container container)
Creates a new compound component, using the specified container to hold added components.

Parameters:
container - container to hold added components
Method Detail

getContainer

protected Container getContainer()
Return the Container used to hold added components.

Returns:
Container object used to hold components

add

protected void add(Component c)
Adds a component to the container.

Parameters:
c - the component to add
See Also:
Container.add( Component )

add

protected void add(Component c,
                   int constraints)
Adds a component with the specified layout constraints to the container.

Parameters:
c - the component to add to the container
constraints - layout constraints (a bitwise OR of static ints in the particular layout)
See Also:
Container.add( Component, int )

contains

protected boolean contains(Object o)
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).

This method returns trueonly if the object has been directly added to the container. If the container contains another container that contains this object, this method returns false.

Parameters:
o - element whose presence in the container is to be tested
Returns:
true if the container contains the specified object directly; false otherwise.
See Also:
Container.contains( Object )

get

protected Component get(int index)
Gets the component at the specified position. Each call to the add method increments the index. Since the user has no control over the index of added components (other than counting each call to the add method), this method should be used in conjunction with indexOf.

Parameters:
index - the index of the item to be retrieved from this container
Returns:
the component at the specified position in this container.

indexOf

protected int indexOf(Component c)
Parameters:
c - the component to search for
Returns:
the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
See Also:
Container.indexOf( Component )

isEmpty

protected boolean isEmpty()
Returns true if the container contains no components.

Returns:
true if the container contains no components; false otherwise.
See Also:
Container.isEmpty()

size

protected int size()
Returns the number of elements in the container. This method does not recursively count the components indirectly contained in the container.

Returns:
the number of components directly in this container.
See Also:
Container.size()

children

public Iterator children()
Description copied from interface: Component
Returns an iterator over the children of this component. If the component has no children, returns an empty (not null) iterator.

Specified by:
children in interface Component
Returns:
an iterator over the children of this component.
See Also:
Component.children()

generateXML

public void generateXML(PageState state,
                        Element parent)
Description copied from interface: Component

Adds a DOM subtree representing this component under the given parent node. Uses the request values stored in state.

Specified by:
generateXML in interface Component
Parameters:
state - represents the current request
parent - the node under which the DOM subtree should be added
See Also:
Component.generateXML( PageState, Element )

getClassAttr

public String getClassAttr()
Description copied from interface: Component
Gets the class attribute.

Specified by:
getClassAttr in interface Component
Returns:
the class attribute.
See Also:
Component.getClassAttr()

getIdAttr

public String getIdAttr()
Description copied from interface: Component
Gets the id attribute.

Specified by:
getIdAttr in interface Component
Returns:
the id attribute.
See Also:
Component.getIdAttr()

getKey

public String getKey()
Description copied from interface: Component
Retrieves the programmer-supplied key. Normally, there is no such key and the method returns null.

Specified by:
getKey in interface Component
Returns:
the programmer-supplied key.
See Also:
Component.getKey()

getStyleAttr

public String getStyleAttr()
Description copied from interface: Component
Gets the style attribute.

Specified by:
getStyleAttr in interface Component
Returns:
the style attribute.
See Also:
Component.getStyleAttr()

isVisible

public boolean isVisible(PageState state)
Description copied from interface: Component
Determines whether the component is visible in the request represented by state.

Specified by:
isVisible in interface Component
Parameters:
state - represents the current request
Returns:
true if the component is visible in the request; false otherwise.
See Also:
Component.isVisible( PageState )

register

public void register(Form f,
                     FormModel m)
Description copied from interface: Component
Registers form parameters with the form model for this form. This method is only important for form sections and widgets (components that have a connection to an HTML form). Other components can implement it as a no-op.

Specified by:
register in interface Component
See Also:
Component.register( Form, FormModel )

register

public void register(Page p)
Description copied from interface: Component
Registers state parameters for the page with its model. A simple component with a state parameter param would do the following in the body of this method:
   p.addComponent(this);
   p.addComponentStateParam(this, param);
 
You should override this method to set the default visibility of your component:
 public void register(Page p) {
     super.register(p);
     p.setVisibleDefault(childNotInitiallyShown,false);
     p.setVisibleDefault(anotherChild, false);
 }
 
Always call super.register when you override register. Otherwise your component may malfunction and produce errors like "Widget ... isn't associated with any Form"

Specified by:
register in interface Component
See Also:
Component.register( Page )

respond

public void respond(PageState state)
             throws javax.servlet.ServletException
Description copied from interface: Component

Responds to the request. This method is only called if the request was made from a link or form that the component put on the page in the PageState.stateAsURL() previous request.

No output should be generated on the HTTP response. The component can store intermediate results in the state by calling setAttribute.

This method is called before any output is printed to the HTTP response so that the component can forward to a different page and thereby commit the response.

Specified by:
respond in interface Component
Parameters:
state - represents the current request
Throws:
javax.servlet.ServletException
See Also:
Component.respond( PageState )

setClassAttr

public void setClassAttr(String theClass)
Description copied from interface: Component
Sets the class attribute.

Specified by:
setClassAttr in interface Component
Parameters:
theClass - a valid XML name
See Also:
Component.setClassAttr( String )

setIdAttr

public void setIdAttr(String id)
Description copied from interface: Component
Sets the id attribute. id should be an XML name that is unique within the Page in which this component is contained. The value of id is copied literally to the output and not used for internal processing.

Specified by:
setIdAttr in interface Component
Parameters:
id - a valid XML identifier
See Also:
Component.setIdAttr( String )

setKey

public Component setKey(String key)
Description copied from interface: Component
Supplies a key for making parameter names unique. To be used instead of the component's index (see Component Prefix). To avoid collision with indexOf, it should (1) be a legal fragment of a cgi parameter, (2) differ from "g", and (3) not start with a digit.

Specified by:
setKey in interface Component
See Also:
Component.setKey( String )

setStyleAttr

public void setStyleAttr(String style)
Description copied from interface: Component
Sets the style attribute. style should be a valid CSS style, because its value will be copied verbatim to the output and appear as a style attribute in the top level XML or HTML output element.

Specified by:
setStyleAttr in interface Component
Parameters:
style - a valid CSS style description for use in the style attribute of an HTML tag
See Also:
Component.setStyleAttr( String )

setVisible

public void setVisible(PageState state,
                       boolean v)
Description copied from interface: Component
Changes the visibility of the component. The component will keep the visibility that is set with this method in subsequent requests to this page.

Specified by:
setVisible in interface Component
Parameters:
state - represents the current request
v - true if the component should be visible
See Also:
Component.setVisible( PageState, boolean )

lock

public void lock()
Description copied from interface: Lockable
Lock an object. Locked objects are to be considered immutable. Any attempt to modify them, e.g., through a setXXX method should lead to an exception.

Most lockable Bebop classes throw an IllegalStateException if an attempt is made to modify a locked instance.

Specified by:
lock in interface Lockable
See Also:
Lockable.lock()

isLocked

public boolean isLocked()
Description copied from interface: Lockable
Return whether an object is locked and thus immutable, or can still be modified.

Specified by:
isLocked in interface Lockable
See Also:
Lockable.isLocked()


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC