Class HtmlShadowElement
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zk.ui.HtmlShadowElement
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Component,AfterCompose,Scope,ShadowElement,ShadowElementCtrl,ComponentCtrl
public abstract class HtmlShadowElement extends AbstractComponent implements ShadowElement, ShadowElementCtrl
A skeleton of shadow element that represents as a shadow tree.- Since:
- 8.0.0
- Author:
- jumperchen
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHtmlShadowElement.DirectionA help class for an insertion direction.-
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children, AbstractComponent.ForwardInfo, AbstractComponent.TargetInfo
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_afterComposedprotected java.lang.Boolean_dynamicValueprotected static java.lang.StringBIND_ANNOprotected static java.lang.StringBINDERstatic java.lang.StringFOREACH_IN_RENDERinternal used onlyprotected static java.lang.StringINIT_ANNOprotected static java.lang.StringLOAD_ANNOprotected static java.lang.StringON_REBUILD_SHADOW_TREE_LATERprotected static java.lang.StringREFERENCE_ANNOprotected static java.lang.StringSAVE_ANNOstatic java.lang.StringSKIP_DISTRIBUTED_CHILDREN_PROPERTY_CHANGEinternal used only-
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
-
Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
-
-
Constructor Summary
Constructors Constructor Description HtmlShadowElement()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidafterCompose()Creates the distributed children after apply dynamic propertiesvoidafterHostChildAdded(Component child, int indexOfChild)Called when a child is added to the host.voidafterHostChildRemoved(Component child)Called when a child is removed to the host.protected static <T extends HtmlShadowElement>
TasShadow(java.lang.Object o)voidbeforeChildAdded(Component child, Component refChild)Default: does nothing.voidbeforeHostChildAdded(Component child, Component insertBefore, int indexOfInsertBefore)Called before the host adding a child.voidbeforeHostChildRemoved(Component child, int indexOfChild)Called before the host removing a child.voidbeforeHostParentChanged(Component parent)Called before the host changing the parent.voidbeforeParentChanged(Component parent)Default: If parent is null, execute the @Destroy method if any.voidclearChildren()java.lang.Objectclone()Clones the component.protected abstract voidcompose(Component host)Composes the shadow element.voiddestroyIndexCacheMap(Component host)Internal usevoiddetach()Removes the relation points between shadow host and this shadow element.<T extends Component>
java.util.List<T>getDistributedChildren()Returns a list of distributed components of the shadow tree, including its descendant.ComponentgetFirstInsertion()Returns the first component of its insertion range.static intgetIndex(ShadowElement owner, Component insertion, java.util.Map<Component,java.lang.Integer> cacheMap)java.util.Map<Component,java.lang.Integer>getIndexCacheMap(Component host)Internal useComponentgetLastInsertion()Returns the last component of its insertion range.ComponentgetNextInsertion()Returns the next insertion point, it may be a component, a shadow element, or null.ComponentgetNextInsertionComponentIfAny()Returns the next component before this shadow, if any.ComponentgetPreviousInsertion()Returns the previous insertion point, it may be a component, a shadow element, or null.ComponentgetPreviousInsertionComponentIfAny()Returns the first component before this shadow, if any.ComponentgetShadowHost()Returns the owner component that hosts this shadow element.ComponentgetShadowHostIfAny()Return the shadow host from it or its ancestor, if any.protected voidinitClone(AbstractComponent cloneHost)java.util.Map<Component,java.lang.Integer>initIndexCacheMap(Component host)Internal usestatic HtmlShadowElement.DirectioninRange(HtmlShadowElement se, Component target)Returns the direction of the target component according to the given shadow element.voidinvalidate()Invalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later.booleanisDynamicValue()Returns whether the shadow element contains a dynamic value, it means the shadow element cannot be destroyed after evaluated.protected booleanisDynamicValue(java.lang.String propName)Returns whether the property name contains with a dynamic value.protected abstract booleanisEffective()Returns whether the shadow element is effectiveprotected voidmergeSubTree()Merge the all sub-tree into the parent's insertions, unlikeAbstractComponent.appendChild(Component)booleanmergeToHost(Component host)Merge the host into the current shadow, unlikesetShadowHost(Component, Component)voidonChildAdded(Component child)Default: handles special event listeners.protected voidonHostAttached(Component host)voidonHostChildAdded(Component child)Default: does nothing.voidonHostChildRemoved(Component child)Default: does nothing.protected voidonHostDetached(Component host)protected voidrebuildSubShadowTree()Rebuilds the shadow tree if the shadow element contains a dynamic value, it should be alive, otherwise, it will be detached.voidrecreate()Detaches all child components and then recreate them by use ofcompose(org.zkoss.zk.ui.Component).protected voidremoveFromParent()java.lang.ObjectresolveVariable(Component child, java.lang.String name, boolean recurse)Returns the variable associated with this base component or null if not found.voidsetDynamicValue(boolean dynamicValue)Sets whether the shadow element contains a dynamic value, if true means the shadow element cannot be destroyed after evaluated, if false it will detect its attribute automatically.voidsetParent(Component parent)Sets the parent component.protected static voidsetPrevInsertion(Component target, Component prevInsertion)voidsetShadowHost(Component host, Component insertBefore)Sets the owner component that hosts this shadow element.protected voidshrinkRange(Component firstChild, Component lastChild)protected voidstretchRange(Component firstChild, Component lastChild)java.lang.StringtoString()voidupdateFirstInsertion(Component newFirstInsertion)Updates the given first insertion to this shadow element.voidupdateLastInsertion(Component newLastInsertion)Updates the given last insertion to this shadow element.voidupdateNextInsertion(Component newNextInsertion)Updates the given next insertion to this shadow element.voidupdatePreviousInsertion(Component newPreviousInsertion)Updates the given previous insertion to this shadow element.protected voidupdateSubBindingAnnotationCount(int diff)-
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildRemoved, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getExtraCtrl, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getPropertyAccess, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, insertBefore, isChildable, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderProperties, renderPropertiesOnly, replace, response, response, response, service, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, updateByClient, willPassivate, willPassivate, willSerialize, willSerialize
-
-
-
-
Field Detail
-
_afterComposed
protected boolean _afterComposed
-
ON_REBUILD_SHADOW_TREE_LATER
protected static java.lang.String ON_REBUILD_SHADOW_TREE_LATER
-
FOREACH_IN_RENDER
public static java.lang.String FOREACH_IN_RENDER
internal used only
-
SKIP_DISTRIBUTED_CHILDREN_PROPERTY_CHANGE
public static java.lang.String SKIP_DISTRIBUTED_CHILDREN_PROPERTY_CHANGE
internal used only
-
INIT_ANNO
protected static final java.lang.String INIT_ANNO
- See Also:
- Constant Field Values
-
BIND_ANNO
protected static final java.lang.String BIND_ANNO
- See Also:
- Constant Field Values
-
LOAD_ANNO
protected static final java.lang.String LOAD_ANNO
- See Also:
- Constant Field Values
-
SAVE_ANNO
protected static final java.lang.String SAVE_ANNO
- See Also:
- Constant Field Values
-
REFERENCE_ANNO
protected static final java.lang.String REFERENCE_ANNO
- See Also:
- Constant Field Values
-
BINDER
protected static final java.lang.String BINDER
- See Also:
- Constant Field Values
-
_dynamicValue
protected java.lang.Boolean _dynamicValue
-
-
Method Detail
-
resolveVariable
public java.lang.Object resolveVariable(Component child, java.lang.String name, boolean recurse)
Description copied from interface:ShadowElementCtrlReturns the variable associated with this base component or null if not found.Notice that it doesn't check any variable defined in
VariableResolver(ofPage.addVariableResolver(org.zkoss.xel.VariableResolver)).- Specified by:
resolveVariablein interfaceShadowElementCtrl- Parameters:
child- the child component of the shadow hostrecurse- whether to look up the parent shadow for the existence of the variable.
If recurse is true, it will look up all parents until found.
-
getNextInsertionComponentIfAny
public Component getNextInsertionComponentIfAny()
Returns the next component before this shadow, if any. (it will invoke recursively from its parent.)
-
getPreviousInsertionComponentIfAny
public Component getPreviousInsertionComponentIfAny()
Returns the first component before this shadow, if any. (it will invoke recursively from its parent.)
-
onHostAttached
protected void onHostAttached(Component host)
-
onHostDetached
protected void onHostDetached(Component host)
-
getNextInsertion
public Component getNextInsertion()
Returns the next insertion point, it may be a component, a shadow element, or null.- Specified by:
getNextInsertionin interfaceShadowElement- Specified by:
getNextInsertionin interfaceShadowElementCtrl
-
getPreviousInsertion
public Component getPreviousInsertion()
Returns the previous insertion point, it may be a component, a shadow element, or null.- Specified by:
getPreviousInsertionin interfaceShadowElement- Specified by:
getPreviousInsertionin interfaceShadowElementCtrl
-
updatePreviousInsertion
public void updatePreviousInsertion(Component newPreviousInsertion)
Updates the given previous insertion to this shadow element. (Internal use only)- Since:
- 10.0.0
-
updateFirstInsertion
public void updateFirstInsertion(Component newFirstInsertion)
Updates the given first insertion to this shadow element. (Internal use only)- Since:
- 10.0.0
-
updateNextInsertion
public void updateNextInsertion(Component newNextInsertion)
Updates the given next insertion to this shadow element. (Internal use only)- Since:
- 10.0.0
-
updateLastInsertion
public void updateLastInsertion(Component newLastInsertion)
Updates the given last insertion to this shadow element. (Internal use only)- Since:
- 10.0.0
-
getFirstInsertion
public Component getFirstInsertion()
Returns the first component of its insertion range.- Specified by:
getFirstInsertionin interfaceShadowElement- Specified by:
getFirstInsertionin interfaceShadowElementCtrl
-
getLastInsertion
public Component getLastInsertion()
Returns the last component of its insertion range.- Specified by:
getLastInsertionin interfaceShadowElement- Specified by:
getLastInsertionin interfaceShadowElementCtrl
-
setShadowHost
public void setShadowHost(Component host, Component insertBefore)
Description copied from interface:ShadowElementCtrlSets the owner component that hosts this shadow element.- Specified by:
setShadowHostin interfaceShadowElementCtrl- Parameters:
host- the host of the shadow elementinsertBefore- a component or a shadow element to indicate where the shadow's insertion point is added.
-
detach
public void detach()
Removes the relation points between shadow host and this shadow element.- Specified by:
detachin interfaceComponent- Specified by:
detachin interfaceShadowElement- Overrides:
detachin classAbstractComponent
-
setParent
public void setParent(Component parent)
Description copied from interface:ComponentSets the parent component.Note:
Component.setParent(org.zkoss.zk.ui.Component)always calls backComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)and/orComponent.removeChild(org.zkoss.zk.ui.Component), whileComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.removeChild(org.zkoss.zk.ui.Component)always calls backComponent.setParent(org.zkoss.zk.ui.Component), if the parent is changed. Thus, you don't need to override bothComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.setParent(org.zkoss.zk.ui.Component), if you want to customize the behavior.- Specified by:
setParentin interfaceComponent- Overrides:
setParentin classAbstractComponent
-
beforeParentChanged
public void beforeParentChanged(Component parent)
Description copied from class:AbstractComponentDefault: If parent is null, execute the @Destroy method if any.- Specified by:
beforeParentChangedin interfaceComponentCtrl- Overrides:
beforeParentChangedin classAbstractComponent- Parameters:
parent- the new parent. If null, it means detachment.- See Also:
ComponentCtrl.beforeParentChanged(org.zkoss.zk.ui.Component)
-
beforeChildAdded
public void beforeChildAdded(Component child, Component refChild)
Description copied from class:AbstractComponentDefault: does nothing.- Specified by:
beforeChildAddedin interfaceComponentCtrl- Overrides:
beforeChildAddedin classAbstractComponent- Parameters:
child- the child to be added (never null).refChild- another child component that the new child will be inserted before it. If null, the new child will be the last child.- See Also:
ComponentCtrl.beforeChildAdded(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
-
onChildAdded
public void onChildAdded(Component child)
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onChildAddedin interfaceComponentCtrl- Overrides:
onChildAddedin classAbstractComponent- See Also:
ComponentCtrl.onChildAdded(org.zkoss.zk.ui.Component)
-
invalidate
public void invalidate()
Description copied from interface:ComponentInvalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later. And, the widget associated with this component and all its descendant at the client will be deleted and recreated, too.If the application is totally controlled by the server side (i.e., you don't write client codes), you rarely need to access this method.
It can be called only in the request-processing and event-processing phases. However, it is NOT allowed in the rendering phase.
- Specified by:
invalidatein interfaceComponent- Overrides:
invalidatein classAbstractComponent
-
clone
public java.lang.Object clone()
Description copied from interface:ComponentClones the component. All of its children and descendants are cloned. Also, ID are preserved.- Specified by:
clonein interfaceComponent- Overrides:
clonein classAbstractComponent- Returns:
- the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
-
initClone
protected void initClone(AbstractComponent cloneHost)
-
getShadowHost
public Component getShadowHost()
Description copied from interface:ShadowElementReturns the owner component that hosts this shadow element.- Specified by:
getShadowHostin interfaceShadowElement
-
afterCompose
public void afterCompose()
Creates the distributed children after apply dynamic propertiesIf a shadow element is created by ZK loader, this method is invoked automatically. Developers rarely need to invoke this method.
Default: it invokes
compose(org.zkoss.zk.ui.Component)to compose the shadow element.The method will invoke the following methods in order.
- Check if
isEffective()to be true. - If true, invokes
compose(org.zkoss.zk.ui.Component)method to create the distributed children, otherwise, nothing happened.
Instead of overriding this method, it is suggested to override
compose(org.zkoss.zk.ui.Component), since all other methods depend oncompose(org.zkoss.zk.ui.Component)(rather thanafterCompose()).- Specified by:
afterComposein interfaceAfterCompose
- Check if
-
mergeSubTree
protected void mergeSubTree()
Merge the all sub-tree into the parent's insertions, unlikeAbstractComponent.appendChild(Component)
-
mergeToHost
public boolean mergeToHost(Component host)
Merge the host into the current shadow, unlikesetShadowHost(Component, Component)- Parameters:
host-
-
rebuildSubShadowTree
protected void rebuildSubShadowTree()
Rebuilds the shadow tree if the shadow element contains a dynamic value, it should be alive, otherwise, it will be detached.- Throws:
java.util.ConcurrentModificationException- if caller use the same collection, it may throw this exception when merging sub-tree.
-
isEffective
protected abstract boolean isEffective()
Returns whether the shadow element is effective
-
compose
protected abstract void compose(Component host)
Composes the shadow element. It is called byafterCompose()if the shadow host is not null. Otherwise, it will skip this method call.The second invocation is ignored. If you want to recreate child components, use
recreate()instead.- Parameters:
host- the shadow host component, never null.
-
beforeHostChildRemoved
public void beforeHostChildRemoved(Component child, int indexOfChild)
Description copied from interface:ShadowElementCtrlCalled before the host removing a child.- Specified by:
beforeHostChildRemovedin interfaceShadowElementCtrl- Parameters:
child- the child to be removed (never null)indexOfChild- the index of the removed child
-
onHostChildRemoved
public void onHostChildRemoved(Component child)
Default: does nothing.- Specified by:
onHostChildRemovedin interfaceShadowElementCtrl- See Also:
ComponentCtrl.onChildAdded(org.zkoss.zk.ui.Component)
-
onHostChildAdded
public void onHostChildAdded(Component child)
Default: does nothing.- Specified by:
onHostChildAddedin interfaceShadowElementCtrl- See Also:
ComponentCtrl.onChildAdded(org.zkoss.zk.ui.Component)
-
beforeHostParentChanged
public void beforeHostParentChanged(Component parent)
Description copied from interface:ShadowElementCtrlCalled before the host changing the parent.- Specified by:
beforeHostParentChangedin interfaceShadowElementCtrl- Parameters:
parent- the new parent. If null, it means detachment.
-
beforeHostChildAdded
public void beforeHostChildAdded(Component child, Component insertBefore, int indexOfInsertBefore)
Description copied from interface:ShadowElementCtrlCalled before the host adding a child.- Specified by:
beforeHostChildAddedin interfaceShadowElementCtrl- Parameters:
child- the child to be added (never null).insertBefore- another child component that the new child will be inserted before it. If null, the new child will be the last child.indexOfInsertBefore- the index of the insertBefore, if any. Otherwise -1 is assumed.
-
asShadow
protected static <T extends HtmlShadowElement> T asShadow(java.lang.Object o)
-
getIndex
public static int getIndex(ShadowElement owner, Component insertion, java.util.Map<Component,java.lang.Integer> cacheMap)
-
inRange
public static HtmlShadowElement.Direction inRange(HtmlShadowElement se, Component target)
Returns the direction of the target component according to the given shadow element.- Parameters:
se- the shadow elementtarget- the target to check.
-
afterHostChildAdded
public void afterHostChildAdded(Component child, int indexOfChild)
Description copied from interface:ShadowElementCtrlCalled when a child is added to the host.- Specified by:
afterHostChildAddedin interfaceShadowElementCtrl- Parameters:
child- the child has been added (never null).indexOfChild- the index of the added child.
-
afterHostChildRemoved
public void afterHostChildRemoved(Component child)
Description copied from interface:ShadowElementCtrlCalled when a child is removed to the host.- Specified by:
afterHostChildRemovedin interfaceShadowElementCtrl- Parameters:
child- the child has been added (never null).
-
recreate
public void recreate()
Detaches all child components and then recreate them by use ofcompose(org.zkoss.zk.ui.Component).- Specified by:
recreatein interfaceShadowElement
-
clearChildren
public void clearChildren()
-
removeFromParent
protected void removeFromParent()
-
getShadowHostIfAny
public Component getShadowHostIfAny()
Description copied from interface:ShadowElementCtrlReturn the shadow host from it or its ancestor, if any.- Specified by:
getShadowHostIfAnyin interfaceShadowElementCtrl- Returns:
- null or a host component
-
getDistributedChildren
public <T extends Component> java.util.List<T> getDistributedChildren()
Description copied from interface:ShadowElementReturns a list of distributed components of the shadow tree, including its descendant.It's better to manipulate with the component children from the host component.
- Specified by:
getDistributedChildrenin interfaceShadowElement- Returns:
- a list of distributed components (removeable only)
-
isDynamicValue
protected boolean isDynamicValue(java.lang.String propName)
Returns whether the property name contains with a dynamic value.
-
isDynamicValue
public boolean isDynamicValue()
Description copied from interface:ShadowElementCtrlReturns whether the shadow element contains a dynamic value, it means the shadow element cannot be destroyed after evaluated.- Specified by:
isDynamicValuein interfaceShadowElementCtrl
-
setDynamicValue
public void setDynamicValue(boolean dynamicValue)
Sets whether the shadow element contains a dynamic value, if true means the shadow element cannot be destroyed after evaluated, if false it will detect its attribute automatically.Default: false (auto detection)
- Specified by:
setDynamicValuein interfaceShadowElementCtrl- Since:
- 8.0.1
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractComponent
-
updateSubBindingAnnotationCount
protected void updateSubBindingAnnotationCount(int diff)
- Overrides:
updateSubBindingAnnotationCountin classAbstractComponent
-
initIndexCacheMap
public java.util.Map<Component,java.lang.Integer> initIndexCacheMap(Component host)
Internal use- Overrides:
initIndexCacheMapin classAbstractComponent- Since:
- 10.0.0
-
getIndexCacheMap
public java.util.Map<Component,java.lang.Integer> getIndexCacheMap(Component host)
Internal use- Overrides:
getIndexCacheMapin classAbstractComponent- Since:
- 10.0.0
-
destroyIndexCacheMap
public void destroyIndexCacheMap(Component host)
Internal use- Overrides:
destroyIndexCacheMapin classAbstractComponent- Since:
- 10.0.0
-
-