EchoPoint
1.0

echopoint.util
Class ComponentKit

java.lang.Object
  extended byechopoint.util.ComponentKit

public class ComponentKit
extends java.lang.Object

A utility to class to help with Component manipulation

Author:
Brad Baker

Nested Class Summary
static interface ComponentKit.ComponentTraversalCallBack
          ComponentOperationCallBack is an interface used during the traverseComponent() method.
 
Method Summary
static nextapp.echo.Component[] getComponentPath(nextapp.echo.Component parent, nextapp.echo.Component child)
          This method will return an array of Components that indicates the path from parent to child.
static nextapp.echo.Component getComponentRoot(nextapp.echo.Component child)
          Returns the highest Component parent starting from child.
static java.lang.Object getIdentifier(nextapp.echo.Component component, java.lang.String attrName)
           
static boolean remove(nextapp.echo.Component parent, nextapp.echo.Component child)
          This method will remove a child component from anywhere in the component hierarchy from parent downwards.
static void setEnabled(nextapp.echo.Component component, boolean enabled)
          This method makes the component, and all its children, enabled or disabled.
static void setIdentifier(nextapp.echo.Component component, java.lang.String attrName, java.lang.Object attrValue)
           
static boolean setProperty(nextapp.echo.Component component, java.lang.String propertyName, java.lang.Object propertyValue)
          This method will use reflection to set a property on a given component, and all of its children.
static boolean setProperty(nextapp.echo.Component component, java.lang.String propertyName, java.lang.Object propertyValue, java.lang.Class filterClass)
          This method will use reflection to set a property on a given component, and all of its children.
static void setVisible(nextapp.echo.Component component, boolean visible)
          This method makes the component, and all its children, visible or invisible.
static void traverseComponent(nextapp.echo.Component startComponent, ComponentKit.ComponentTraversalCallBack traverseCallBack)
          This method will traverse the current component and all its children, in a depth first manner, and call the ComponentTraversalCallBack object for each component found.
static void traverseInstance(nextapp.echo.EchoInstance instance, ComponentKit.ComponentTraversalCallBack traverseCallBack)
          This method will traverse the EchoInstance and all its child components, in a depth first manner, and call the ComponentTraversalCallBack object for each component found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

remove

public static boolean remove(nextapp.echo.Component parent,
                             nextapp.echo.Component child)
This method will remove a child component from anywhere in the component hierarchy from parent downwards.

Parameters:
parent - - an ancestor of child
child - - the component to remove
Returns:
true if the component was actually removed, or false if the parent is not an ancestor of child.

getComponentPath

public static nextapp.echo.Component[] getComponentPath(nextapp.echo.Component parent,
                                                        nextapp.echo.Component child)
This method will return an array of Components that indicates the path from parent to child. The parent Component (ie the root of the path) is the first element in the array, while the child will be the last. If the parent is not an ancestor of the child, then a zero length array will be returned.

Parameters:
parent - the parent component to be searched
child - - the child component to find.
Returns:
an array of Components between parent and child or a zero length array if there is no path.

getComponentRoot

public static nextapp.echo.Component getComponentRoot(nextapp.echo.Component child)
Returns the highest Component parent starting from child. This is in fact ths parent that has no parent.

Parameters:
child - - the component to start searching at
Returns:
- the higest parent Component

setVisible

public static void setVisible(nextapp.echo.Component component,
                              boolean visible)
This method makes the component, and all its children, visible or invisible.

Parameters:
component - - the component inquestion
visible - - true to make all components visible or false to make them invisible

setEnabled

public static void setEnabled(nextapp.echo.Component component,
                              boolean enabled)
This method makes the component, and all its children, enabled or disabled.

Parameters:
component - - the component inquestion
enabled - - true to make all components enabled or false to make them disabled

setIdentifier

public static void setIdentifier(nextapp.echo.Component component,
                                 java.lang.String attrName,
                                 java.lang.Object attrValue)
See Also:
IdKit.setAttribute(Component, String, Object)

getIdentifier

public static java.lang.Object getIdentifier(nextapp.echo.Component component,
                                             java.lang.String attrName)
See Also:
IdKit.getAttribute(Component, String)

traverseComponent

public static void traverseComponent(nextapp.echo.Component startComponent,
                                     ComponentKit.ComponentTraversalCallBack traverseCallBack)
This method will traverse the current component and all its children, in a depth first manner, and call the ComponentTraversalCallBack object for each component found.

Parameters:
startComponent - - the component to start at.
traverseCallBack - - the ComponentTraversalCallBack to call when a component is found

traverseInstance

public static void traverseInstance(nextapp.echo.EchoInstance instance,
                                    ComponentKit.ComponentTraversalCallBack traverseCallBack)
This method will traverse the EchoInstance and all its child components, in a depth first manner, and call the ComponentTraversalCallBack object for each component found.

Parameters:
instance - - the EchoInstance to traverse.
traverseCallBack - - the ComponentTraversalCallBack to call when a component is found

setProperty

public static boolean setProperty(nextapp.echo.Component component,
                                  java.lang.String propertyName,
                                  java.lang.Object propertyValue)
This method will use reflection to set a property on a given component, and all of its children. For example you could set the component's font via :

 		ComponentKit.setProperty(myComponent, "font", new Font(Font.VERDANA,Font.BOLD,8));
 

This method uses JavaBean rules for setting properties, that is it will look for a method called setXxx that takes one parameter, where Xxx is the setter method of the property to be set. Failing that it will look for setXXX and finally just XXX.

This method guarantees not to throw any exceptions, but rather return false if it cannot set the properties on an eligble object.

Parameters:
component - - the component in question
propertyName - - then name of the property to set
propertyValue - - the new value
Returns:
true if the property could be set.

setProperty

public static boolean setProperty(nextapp.echo.Component component,
                                  java.lang.String propertyName,
                                  java.lang.Object propertyValue,
                                  java.lang.Class filterClass)
This method will use reflection to set a property on a given component, and all of its children. For exmaple you could set the component's font via :

 		ComponentKit.setProperty(myComponent, "font", new Font(Font.VERDANA,Font.BOLD,8), RadionButton.class);
 

This method uses JavaBean rules for setting properties, that is it will look for a method called setXxx that takes one parameter, where Xxx is the setter method of the property to be set. Failing that it will look for setXXX and finally just XXX.

If a non null filterClass is provided then it will only set properties on components that are assignable from the filterClass. If the filterClass is null, then all components will be matched.

This method guarantees not to throw any exceptions, but rather return false if it cannot set the properties on an eligble object.

Parameters:
component - - the component in question
propertyName - - then name of the property to set
propertyValue - - the new value
filterClass - - only sets components derived from the filter class or matches all components if its null.
Returns:
true if the property could be set.

EchoPoint
1.0