Class ComponentGroup
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.components.ComponentGroup
-
public class ComponentGroup extends Object
This class represents a group of components.
The form builder library supports adding components to logical groups. Logical in this context means that these groups do not have a direct representation on the generated GUI. They exist only during the builder process and can be used to reference components. Examples include constructing radio groups or composite component handlers.
A
ComponentGroup
instance does not contain the components themselves, but rather their names. For obtaining the corresponding components access to aComponentBuilderData
object is required.- Version:
- $Id: ComponentGroup.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description ComponentGroup()
Creates a new instance ofComponentGroup
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComponent(String name)
Adds a component to this group.static ComponentGroup
createGroup(org.apache.commons.jelly.JellyContext context, String name)
Creates a newComponentGroup
instance and stores it in the specified context.void
enableGroup(ComponentBuilderData data, boolean enabled)
Changes the enabled state of thisComponentGroup
.static ComponentGroup
fromBeanContext(BeanContext context, String groupName)
Obtains theComponentGroup
with the specified name from the givenBeanContext
.static ComponentGroup
fromContext(org.apache.commons.jelly.JellyContext context, String name)
Fetches the group with the given name from the specified jelly context.Map<String,ComponentHandler<?>>
getComponentHandlers(ComponentBuilderData data)
Returns a map with theComponentHandler
objects of the components this group refers to.Set<String>
getComponentNames()
Returns a set with the names of all components contained in this group.Map<String,Object>
getComponents(ComponentBuilderData data)
Returns a map with all components this group refers to.static boolean
groupExists(org.apache.commons.jelly.JellyContext context, String name)
Tests whether a group with the specified name exists in the given jelly context.static boolean
groupExistsInBeanContext(BeanContext context, String groupName)
Tests whether a group with the specified name exists in the givenBeanContext
.static void
storeGroup(org.apache.commons.jelly.JellyContext context, String name, ComponentGroup group)
Stores a component group in the jelly context under a given name.
-
-
-
Method Detail
-
getComponentNames
public Set<String> getComponentNames()
Returns a set with the names of all components contained in this group. The order of elements in the set corresponds to the order in which the components have been added to this group.- Returns:
- a set with the names of all contained components
-
addComponent
public void addComponent(String name)
Adds a component to this group.- Parameters:
name
- the name of the component to add
-
getComponents
public Map<String,Object> getComponents(ComponentBuilderData data) throws FormBuilderException
Returns a map with all components this group refers to. This method looks up all component names in the specifiedComponentBuilderData
object. The resulting map contains the names of the components as keys and the corresponding component objects as values. If a component name cannot be resolved, aFormBuilderException
exception is thrown.- Parameters:
data
- theComponentBuilderData
object (must not be null)- Returns:
- a map with all components that belong to this group
- Throws:
FormBuilderException
- if a component cannot be resolvedIllegalArgumentException
- if theComponentBuilderData
object is null
-
getComponentHandlers
public Map<String,ComponentHandler<?>> getComponentHandlers(ComponentBuilderData data) throws FormBuilderException
Returns a map with theComponentHandler
objects of the components this group refers to. This method works likegetComponents(ComponentBuilderData)
, but the resulting map contains theComponentHandler
s rather than the components themselves.- Parameters:
data
- theComponentBuilderData
object (must not be null)- Returns:
- a map with all component handlers that belong to this group
- Throws:
FormBuilderException
- if a component cannot be resolvedIllegalArgumentException
- if theComponentBuilderData
object is null
-
enableGroup
public void enableGroup(ComponentBuilderData data, boolean enabled) throws FormBuilderException
Changes the enabled state of thisComponentGroup
. This method obtains theComponentHandler
objects for all components that belong to this group. Then it calls thesetEnabled()
method on all these handlers.- Parameters:
data
- theComponentBuilderData
object (must not be null)enabled
- the new enabled flag- Throws:
FormBuilderException
- if a component cannot be resolvedIllegalArgumentException
- if theComponentBuilderData
object is null- See Also:
getComponentHandlers(ComponentBuilderData)
-
fromContext
public static ComponentGroup fromContext(org.apache.commons.jelly.JellyContext context, String name) throws NoSuchElementException
Fetches the group with the given name from the specified jelly context. If the group does not exist, an exception will be thrown.- Parameters:
context
- the jelly context (must not be nullname
- the name of the desired group- Returns:
- the group with this name
- Throws:
IllegalArgumentException
- if the context is nullNoSuchElementException
- if there is no such group
-
groupExists
public static boolean groupExists(org.apache.commons.jelly.JellyContext context, String name)
Tests whether a group with the specified name exists in the given jelly context. Note thatComponentGroup
objects are not stored under their name in the context, but a specific prefix is used. So always this method has to be used to check the existence of a group rather than testing the context directly.- Parameters:
context
- the jelly contextname
- the name of the group- Returns:
- true if there is such a group, false otherwise
- Throws:
IllegalArgumentException
- if the context is null
-
storeGroup
public static void storeGroup(org.apache.commons.jelly.JellyContext context, String name, ComponentGroup group)
Stores a component group in the jelly context under a given name.- Parameters:
context
- the contextname
- the group's namegroup
- the group to store (if null , the group will be removed if it exists)
-
createGroup
public static ComponentGroup createGroup(org.apache.commons.jelly.JellyContext context, String name) throws FormBuilderException
Creates a newComponentGroup
instance and stores it in the specified context. This is a convenience method which performs the following steps:- It checks whether already a group with the specified name exists in the context. If this is the case, an exception is thrown.
- Otherwise a new
ComponentGroup
instance is created. - The new instance is stored in the context under the specified name.
- The newly created instance is returned.
- Parameters:
context
- the Jelly context (must not be nullname
- the name of the newComponentGroup
(must not be null)- Returns:
- the newly created
ComponentGroup
instance - Throws:
FormBuilderException
- if a group with this name already existsIllegalArgumentException
- if the group name or the context is null
-
fromBeanContext
public static ComponentGroup fromBeanContext(BeanContext context, String groupName)
Obtains theComponentGroup
with the specified name from the givenBeanContext
. This method is similar tofromContext(JellyContext, String)
, but theComponentGroup
is resolved from aBeanContext
object. This can be useful if the group is to be obtained after a builder operation. In this case, the Jelly context may not be available directly, but it can be accessed through theBeanContext
returned by the builder.- Parameters:
context
- theBeanContext
groupName
- the name of the group to be obtained- Returns:
- the corresponding
ComponentGroup
instance - Throws:
IllegalArgumentException
- if theBeanContext
is nullInjectionException
- if the group cannot be resolved
-
groupExistsInBeanContext
public static boolean groupExistsInBeanContext(BeanContext context, String groupName)
Tests whether a group with the specified name exists in the givenBeanContext
. Works likegroupExists(JellyContext, String)
, but checks the givenBeanContext
.- Parameters:
context
- theBeanContext
groupName
- the name of the group in question- Returns:
- a flag whether this
ComponentGroup
can be found in thisBeanContext
- Throws:
IllegalArgumentException
- if theBeanContext
is null
-
-