public abstract class BaseComponent extends Object implements IElementIdentifier
| Modifier and Type | Class and Description |
|---|---|
static class |
BaseComponent.SubComponent
Reference to a subcomponent.
|
log| Modifier | Constructor and Description |
|---|---|
protected |
BaseComponent()
Create a component.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
_attach(Page page)
Attach this component and its children to their owning page.
|
protected void |
_initProps(Map<String,Object> props)
Initialize properties to be passed to widget factory.
|
void |
addChild(BaseComponent child)
Adds a child to the end of the child list.
|
void |
addChild(BaseComponent child,
BaseComponent before)
Adds a child to the child list immediately before the reference child.
|
void |
addChild(BaseComponent child,
int index)
Adds a child to the child list at the specified position.
|
void |
addChildren(Collection<? extends BaseComponent> children)
Adds a list of children.
|
void |
addEventForward(Class<? extends Event> eventClass,
BaseComponent target)
Adds an event forward.
|
void |
addEventForward(Class<? extends Event> eventClass,
BaseComponent target,
String forwardType)
Adds an event forward.
|
void |
addEventForward(String eventType,
BaseComponent target)
Adds an event forward.
|
void |
addEventForward(String eventType,
BaseComponent target,
String forwardType)
Adds an event forward.
|
void |
addEventListener(Class<? extends Event> eventClass,
IEventListener eventListener)
Adds an event listener.
|
void |
addEventListener(Class<? extends Event> eventClass,
IEventListener eventListener,
boolean syncToClient)
Adds an event listener.
|
void |
addEventListener(String eventType,
IEventListener eventListener)
Adds an event listener.
|
void |
addEventListener(String eventType,
IEventListener eventListener,
boolean syncToClient)
Adds an event listener.
|
protected void |
afterAddChild(BaseComponent child)
Called after a new child is added.
|
protected void |
afterRemoveChild(BaseComponent child)
Called after a child is removed.
|
protected void |
afterSetParent(BaseComponent oldParent)
Called after a new parent is set.
|
protected boolean |
areEqual(Object obj1,
Object obj2)
Returns true if two objects are equal, allowing for null values.
|
protected void |
beforeAddChild(BaseComponent child)
Called before a new child is added.
|
protected void |
beforeRemoveChild(BaseComponent child)
Called before a child is removed.
|
protected void |
beforeSetParent(BaseComponent newParent)
Called before a new parent is set.
|
void |
bind(String propertyName,
IBinding binding)
Convenience method for programmatically adding a binding.
|
void |
bringToFront()
Override to cause a UI component to be brought to the forefront of the UI.
|
protected <T> T |
defaultify(T value,
T deflt)
Returns the input value if it is not null, or the default value otherwise.
|
void |
destroy()
Destroys this component.
|
void |
destroyChildren()
Destroy all children under this
|
void |
detach()
Removes, but does not destroy, this component from its parent.
|
void |
finalize()
Destroy a component and all its children upon finalization.
|
Map<String,BaseComponent> |
findAllNamed()
Returns a map of all named components in this namespace.
|
Object |
findAttribute(String name)
Finds the named attribute, returning its value.
|
BaseComponent |
findByName(String name)
Looks up a component by its name within the namespace occupied by this component.
|
<T extends BaseComponent> |
findByName(String name,
Class<T> type)
Looks up a component of the specified type by its name within the namespace occupied by this
component.
|
BaseComponent |
findChildByData(Object data)
Find the first child containing the specified data object.
|
BaseComponent |
findChildByLabel(String label)
Find the first child whose label matches the specified value.
|
void |
fireEvent(Event event)
Send an event to this component's registered event listeners.
|
void |
fireEvent(String eventType)
Send an event to this component's registered event listeners.
|
void |
fireEventToClient(String eventType,
IElementIdentifier target,
Object data)
Send an event to the client.
|
void |
fireEventToClient(String eventType,
Object data)
Send an event to the client.
|
<T extends BaseComponent> |
getAncestor(Class<T> type)
Return first ancestor that is of the requested type.
|
<T> T |
getAncestor(Class<T> type,
boolean includeSelf)
Return first ancestor that is of the requested type.
|
Object |
getAttribute(String name)
Returns the value of the named attribute.
|
<T> T |
getAttribute(String name,
Class<T> type)
Returns the value of the named attribute, converted to the specified type.
|
<T> T |
getAttribute(String name,
T dflt)
Returns the value of the named attribute, cast to the specified type.
|
Map<String,Object> |
getAttributes()
Returns the attribute map for this component.
|
<T extends BaseComponent> |
getChild(Class<T> type)
Return the first child of the requested type.
|
BaseComponent |
getChildAt(int index)
Returns the child at the specified index.
|
int |
getChildCount()
Returns the number of children.
|
int |
getChildCount(Class<? extends BaseComponent> type)
Returns the count of children of a specified type.
|
List<BaseComponent> |
getChildren()
Returns an immutable list of existing children.
|
<T extends BaseComponent> |
getChildren(Class<T> type)
Returns an iterable of children of the specified type.
|
protected String |
getContent()
Returns the text content associated with this component, if any.
|
Object |
getController()
Returns a reference to the last controller wired to this component.
|
List<Object> |
getControllers()
Returns an immutable list of controllers wired to this component.
|
Object |
getData()
Returns the data object associated with the component.
|
<T> T |
getData(Class<T> type)
Returns the data object associated with the component if it is of the specified type;
otherwise returns null.
|
ComponentDefinition |
getDefinition()
Return the component's definition.
|
BaseComponent |
getFirstChild()
Returns the first child of this component.
|
String |
getId()
Returns the unique id of the client widget corresponding to this component.
|
int |
getIndex()
Returns the index of this child within its parent.
|
BaseComponent |
getLastChild()
Returns the last child of this component.
|
String |
getName()
Returns the name associated with this instance.
|
BaseComponent |
getNamespace()
Returns the namespace to which this component belongs.
|
BaseComponent |
getNextSibling()
Return the next sibling for this component.
|
Page |
getPage()
Returns the page to which this component belongs.
|
BaseComponent |
getParent()
Returns this component's parent, if any.
|
BaseComponent |
getPreviousSibling()
Return the previous sibling for this component.
|
BaseComponent |
getRoot()
Return the root component of this component's hierarchy.
|
boolean |
hasAttribute(String name)
Returns true if the named attribute exists.
|
boolean |
hasEventListener(Class<? extends Event> eventClass)
Returns true if this component has any listeners registered for the specified event type.
|
boolean |
hasEventListener(String eventType)
Returns true if this component has any listeners registered for the specified event type.
|
void |
invoke(IElementIdentifier id,
String function,
IResponseCallback<?> callback,
Object... args)
Invoke a widget or sub-widget function on the client.
|
void |
invoke(IElementIdentifier id,
String function,
Object... args)
Invoke a widget or sub-widget function on the client.
|
void |
invoke(String function,
IResponseCallback<?> callback,
Object... args)
Invoke a widget function on the client.
|
void |
invoke(String function,
Object... args)
Invoke a widget function on the client.
|
void |
invokeIfAttached(String function,
Object... args)
Invoke a widget function on the client only if attached to a page.
|
boolean |
isAncestor(BaseComponent comp)
Returns true if this component is the same as or an ancestor of the specified component.
|
boolean |
isContainer()
Returns true if this component may contain children.
|
protected boolean |
isContentSynced()
Returns true if the content property is to be synced to the client.
|
boolean |
isDead()
Returns true if the component is dead (meaning its corresponding widget has been destroyed).
|
boolean |
isNamespace()
Returns true if this component is a namespace boundary.
|
boolean |
isRendered()
Returns true if the component has been rendered on the browser.
|
void |
notifyAncestors(Event event,
boolean includeThis)
Send an event to all the ancestors of this component.
|
void |
notifyDescendants(Event event,
boolean includeThis)
Send an event to all the descendants of this component using a depth-first traversal.
|
protected String |
nullify(String value)
Converts empty string to null.
|
protected void |
onAttach(Page page)
Called when this component is first attached to a page.
|
protected void |
onDestroy()
Override to perform any special cleanup operations when this component is destroyed.
|
protected void |
onDestroyTracked(BaseComponent comp)
Invoked when a tracked component is destroyed.
|
protected boolean |
propertyChange(String propertyName,
Object oldValue,
Object newValue,
boolean syncToClient)
Handle changes to published properties.
|
Object |
removeAttribute(String name)
Removes the named attribute if it exists.
|
void |
removeChild(BaseComponent child)
Removes a child from this parent.
|
void |
removeEventForward(Class<? extends Event> eventClass,
BaseComponent target)
Removes an event forward, if one exists.
|
void |
removeEventForward(Class<? extends Event> eventClass,
BaseComponent target,
String forwardType)
Removes an event forward, if one exists.
|
void |
removeEventForward(String eventType,
BaseComponent target)
Removes an event forward, if one exists.
|
void |
removeEventForward(String eventType,
BaseComponent target,
String forwardType)
Removes an event forward, if one exists.
|
void |
removeEventListener(Class<? extends Event> eventClass,
IEventListener eventListener)
Removes an event listener.
|
void |
removeEventListener(Class<? extends Event> eventClass,
IEventListener eventListener,
boolean syncToClient)
Removes an event listener.
|
void |
removeEventListener(String eventType,
IEventListener eventListener)
Removes an event listener.
|
void |
removeEventListener(String eventType,
IEventListener eventListener,
boolean syncToClient)
Removes an event listener.
|
Object |
setAttribute(String name,
Object value)
Sets the value of a named attribute.
|
protected void |
setContent(String content)
Sets the text content associated with this component.
|
protected void |
setContentSynced(boolean contentSynced)
Set to true if the content property is to be synced to the client.
|
void |
setData(Object data)
Sets the data object to be associated with the component.
|
void |
setIndex(int index)
Moves this child to the specified index within its parent.
|
void |
setName(String name)
Sets the name associated with this instance.
|
void |
setParent(BaseComponent parent)
Sets the component's parent.
|
BaseComponent.SubComponent |
sub(String subId)
Returns a subcomponent identifier.
|
void |
swapChildren(int index1,
int index2)
Swap the position of two children.
|
protected void |
swapTrackedComponents(BaseComponent track,
BaseComponent untrack)
Swap tracking from one component to another.
|
protected void |
sync(String state,
Object value)
Synchronize a state value to the client.
|
String |
toString()
Returns basic information about this component for display purposes.
|
protected void |
trackComponent(BaseComponent comp)
Monitors a component for destroy events, invoking #onTrackedDestroy when detected.
|
protected String |
trimify(String value)
Trims whitespace from a string and nullifies it.
|
protected void |
untrackComponent(BaseComponent comp)
Removes tracking for a component.
|
protected void |
validate()
Validates that this component is not dead.
|
protected static void |
validate(BaseComponent comp)
Validates that a component still exists (i.e., is not dead).
|
protected void |
validateChild(BaseComponent child)
Validates that the specified component may be added as a child.
|
protected void |
validateIsChild(BaseComponent child)
Validates that the specified component is currently a child of this component.
|
protected void |
validatePage(Page page)
Validates that the specified page can be an owner of this component.
|
protected void |
validateParent(BaseComponent parent)
Validates that a component would a valid parent for this component.
|
void |
wireController(Object controller)
Wires a controller's annotated components and event handlers, in that order, using this
component to resolve name references.
|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waittransformForClientprotected BaseComponent()
protected static void validate(BaseComponent comp)
comp - Component to validate.ComponentException - Thrown upon validation failure.public ComponentDefinition getDefinition()
@Component.PropertyGetter(value="name", description="The name associated with this component instance (must be unique within the enclosing namespace).") public String getName()
@Component.PropertySetter(value="name", description="The name associated with this component instance (must be unique within the enclosing namespace).") public void setName(String name)
name - The component's name.@Component.PropertyGetter(value="id", description="The unique id of the client widget corresponding to this component.") public String getId()
getId in interface IElementIdentifierIElementIdentifier.getId()public void detach()
public void destroy()
public void finalize()
throws Throwable
finalize in class ObjectThrowableObject.finalize()public void destroyChildren()
protected void onDestroy()
public boolean isDead()
public boolean isRendered()
protected void validate()
ComponentException - Thrown if validation fails.public BaseComponent getParent()
protected void validateParent(BaseComponent parent)
parent - Component to validate.ComponentException - Thrown if the new parent is not a valid parent for this
component.public void setParent(BaseComponent parent)
parent - The new parent.ComponentException - Thrown if the new parent is not a valid parent for this
component.public Map<String,Object> getAttributes()
public Object getAttribute(String name)
name - The attribute name.public <T> T getAttribute(String name, T dflt)
T - The attribute value's expected type.name - The attribute name.dflt - The default attribute value. This will be returned under one of the following
conditions:
public <T> T getAttribute(String name, Class<T> type)
T - The return type.name - The attribute name.type - The return type for the attribute value.public Object findAttribute(String name)
name - The attribute name.@Component.PropertySetter(value="attr:") public Object setAttribute(String name, Object value)
name - The attribute name.value - The new value.public Object removeAttribute(String name)
name - The attribute name.public boolean hasAttribute(String name)
name - The attribute name.protected void validateIsChild(BaseComponent child)
child - The component to check.ComponentException - Thrown if the component fails validation.protected void validateChild(BaseComponent child)
child - The component to check.ComponentException - Thrown if the component fails validation.public void addChild(BaseComponent child)
child - Child to add.public void addChild(BaseComponent child, int index)
child - Child to add.index - The position in the child list where the new child will be inserted.public void addChild(BaseComponent child, BaseComponent before)
child - Child to add.before - The reference child.public void addChildren(Collection<? extends BaseComponent> children)
children - List of children to add.public void removeChild(BaseComponent child)
child - Child to remove.public void swapChildren(int index1,
int index2)
index1 - Index of the first child.index2 - Index of the second child.protected void beforeSetParent(BaseComponent newParent)
newParent - The new parent.protected void afterSetParent(BaseComponent oldParent)
oldParent - The old parent.protected void beforeAddChild(BaseComponent child)
child - The new child.protected void afterAddChild(BaseComponent child)
child - The new child.protected void beforeRemoveChild(BaseComponent child)
child - The child to be removed.protected void afterRemoveChild(BaseComponent child)
child - The removed child.public List<BaseComponent> getChildren()
public <T extends BaseComponent> Iterable<T> getChildren(Class<T> type)
T - The desired type.type - The desired type.public int getChildCount()
public int getChildCount(Class<? extends BaseComponent> type)
type - The desired type.public boolean isContainer()
public <T extends BaseComponent> T getChild(Class<T> type)
T - The type of child sought.type - The type of child sought.public BaseComponent getChildAt(int index)
index - The index of the child sought.public BaseComponent getFirstChild()
public BaseComponent getLastChild()
public BaseComponent getRoot()
public <T extends BaseComponent> T getAncestor(Class<T> type)
T - The type of ancestor sought.type - The type of ancestor sought.public <T> T getAncestor(Class<T> type, boolean includeSelf)
T - Expected return type.type - The type of ancestor sought.includeSelf - If true, include this component in the search.public boolean isAncestor(BaseComponent comp)
comp - Component to test.public int getIndex()
public void setIndex(int index)
index - New index for this child.public BaseComponent getNextSibling()
public BaseComponent getPreviousSibling()
public BaseComponent getNamespace()
@Component.PropertyGetter(value="namespace", bindable=false, description="When true, this component acts as a namespace boundary.") public boolean isNamespace()
public Page getPage()
protected void onAttach(Page page)
page - The attached page.protected void validatePage(Page page)
page - The page to be tested.ComponentException - If fails validation.protected void _attach(Page page)
page - Page to receive this component.protected void _initProps(Map<String,Object> props)
props - Properties for widget factory.protected void sync(String state, Object value)
state - The state name.value - The state value.public void invoke(String function, Object... args)
function - The name of the function.args - Arguments for the function.public void invoke(String function, IResponseCallback<?> callback, Object... args)
function - The name of the function.callback - Optional callback for invocation result.args - Arguments for the function.public void invokeIfAttached(String function, Object... args)
function - The name of the function.args - Arguments for the function.public void invoke(IElementIdentifier id, String function, IResponseCallback<?> callback, Object... args)
id - The id of the widget or sub-widget.function - The name of the function.callback - Optional callback for invocation result.args - Arguments for the function.public void invoke(IElementIdentifier id, String function, Object... args)
id - The id of the widget or sub-widget.function - The name of the function.args - Arguments for the function.public BaseComponent findByName(String name)
name - Component name or "/"-delimited path. "^" in path means parent namespace.public Map<String,BaseComponent> findAllNamed()
public <T extends BaseComponent> T findByName(String name, Class<T> type)
T - The expected return type.name - Component name or path.type - Expected return type.public BaseComponent findChildByData(Object data)
data - The data object to find.public BaseComponent findChildByLabel(String label)
label - The label to find.public BaseComponent.SubComponent sub(String subId)
subId - The sub identifier.public void addEventForward(String eventType, BaseComponent target)
eventType - The event type to forward.target - The target for the forwarded event.public void addEventForward(String eventType, BaseComponent target, String forwardType)
eventType - The event type to forward.target - The target for the forwarded event.forwardType - The type of the forwarded event. If null, the original event type is used.public void addEventForward(Class<? extends Event> eventClass, BaseComponent target)
eventClass - The event type to forward.target - The target for the forwarded event.public void addEventForward(Class<? extends Event> eventClass, BaseComponent target, String forwardType)
eventClass - The event type to forward.target - The target for the forwarded event.forwardType - The type of the forwarded event. If null, the original event type is used.public void removeEventForward(String eventType, BaseComponent target)
eventType - The source event type.target - The forwarded event target.public void removeEventForward(String eventType, BaseComponent target, String forwardType)
eventType - The source event type.target - The forwarded event target.forwardType - The forwarded event type. If null, the source event type is used.public void removeEventForward(Class<? extends Event> eventClass, BaseComponent target)
eventClass - The source event type.target - The forwarded event target.public void removeEventForward(Class<? extends Event> eventClass, BaseComponent target, String forwardType)
eventClass - The source event type.target - The forwarded event target.forwardType - The forwarded event type. If null, the source event type is used.public boolean hasEventListener(String eventType)
eventType - The event type.public boolean hasEventListener(Class<? extends Event> eventClass)
eventClass - The event type.public void addEventListener(String eventType, IEventListener eventListener)
eventType - The type of event to listen for.eventListener - The listener for the event.public void addEventListener(Class<? extends Event> eventClass, IEventListener eventListener)
eventClass - The type of event to listen for.eventListener - The listener for the event.public void addEventListener(String eventType, IEventListener eventListener, boolean syncToClient)
eventType - The type of event to listen for.eventListener - The listener for the event.syncToClient - If true, notify the client that a listener has been added. The client
will normally not send events to the server unless it knows that a listener
exists.public void addEventListener(Class<? extends Event> eventClass, IEventListener eventListener, boolean syncToClient)
eventClass - The type of event to listen for.eventListener - The listener for the event.syncToClient - If true, notify the client that a listener has been added. The client
will normally not send events to the server unless it knows that a listener
exists.public void removeEventListener(String eventType, IEventListener eventListener)
eventType - The type of event listened for.eventListener - The listener for the event.public void removeEventListener(Class<? extends Event> eventClass, IEventListener eventListener)
eventClass - The type of event listened for.eventListener - The listener for the event.public void removeEventListener(String eventType, IEventListener eventListener, boolean syncToClient)
eventType - The type of event listened for.eventListener - The listener for the event.syncToClient - If true, notify the client that a listener has been added. The client
will normally not send events to the server unless it knows that a listener
exists.public void removeEventListener(Class<? extends Event> eventClass, IEventListener eventListener, boolean syncToClient)
eventClass - The type of event listened for.eventListener - The listener for the event.syncToClient - If true, notify the client that a listener has been added. The client
will normally not send events to the server unless it knows that a listener
exists.public void fireEvent(String eventType)
eventType - Type of event to send.public void fireEvent(Event event)
event - Event to send.public void fireEventToClient(String eventType, Object data)
eventType - The event type.data - The event payload.public void fireEventToClient(String eventType, IElementIdentifier target, Object data)
eventType - The event type.target - The event target.data - The event payload.public void notifyAncestors(Event event, boolean includeThis)
stopPropagation method on the event.event - Event to send.includeThis - If true, include this component in the recipient chain.public void notifyDescendants(Event event, boolean includeThis)
stopPropagation method on the
event.event - Event to send.includeThis - If true, include this component in the recipient chain.@Component.PropertySetter(value="controller", bindable=false, defer=true, description="Controller to be wired to this component.") public void wireController(Object controller)
controller - The controller to wire. The following values are recognized:
public List<Object> getControllers()
public Object getController()
public void bringToFront()
protected String nullify(String value)
value - String value.protected String trimify(String value)
value - String value.protected <T> T defaultify(T value,
T deflt)
T - The argument class.value - The input value.deflt - The default value.protected boolean areEqual(Object obj1, Object obj2)
obj1 - First object to compare.obj2 - Second object to compare.@Component.PropertyGetter(value="data", description="Data object to associate with this component.") public Object getData()
public <T> T getData(Class<T> type)
T - Expected return type.type - The expected type.@Component.PropertySetter(value="data", description="Data object to associate with this component.") public void setData(Object data)
data - The data object.@Component.PropertyGetter(value="#text") protected String getContent()
@Component.PropertySetter(value="#text") protected void setContent(String content)
content - The text content.protected boolean isContentSynced()
protected void setContentSynced(boolean contentSynced)
contentSynced - If true, the content property is synced to the client.protected boolean propertyChange(String propertyName, Object oldValue, Object newValue, boolean syncToClient)
PropertychangeEvent is fired.propertyName - The property name.oldValue - The old value.newValue - The new value.syncToClient - If true, notify client of change.public void bind(String propertyName, IBinding binding)
propertyName - Name of property in this component to be bound.binding - The binding to apply.protected void trackComponent(BaseComponent comp)
comp - Component to track.protected void untrackComponent(BaseComponent comp)
comp - Component to untrack.protected void swapTrackedComponents(BaseComponent track, BaseComponent untrack)
trackComponent(org.fujion.component.BaseComponent) and untrackComponent(org.fujion.component.BaseComponent) in succession.track - Component to track.untrack - Component to untrack.protected void onDestroyTracked(BaseComponent comp)
comp - The tracked component.Copyright © 2018 Regenstrief Center for Biomedical Informatics. All rights reserved.