Class ComponentModel
- java.lang.Object
-
- com.github.bordertech.wcomponents.ComponentModel
-
- All Implemented Interfaces:
WebModel,Externalizable,Serializable
- Direct Known Subclasses:
AbstractWFieldIndicator.FieldIndicatorModel,DataBoundComponentModel,WAjaxControl.AjaxControlModel,WApplication.WApplicationModel,WAudio.AudioModel,WCardManager.CardManagerModel,WCollapsible.CollapsibleModel,WCollapsibleToggle.CollapsibleModel,WColumn.ColumnModel,WComponentGroup.ComponentGroupModel,WContent.ContentModel,WDecoratedLabel.DecoratedLabelModel,WDefinitionList.DefinitionListModel,WDialog.DialogModel,WField.FieldModel,WFieldLayout.FieldLayoutModel,WFieldSet.FieldSetModel,WFigure.FigureModel,WImageEditor.ImageEditModel,WInternalLink.InternalLinkModel,WLabel.LabelModel,WMenu.MenuModel,WMenuItem.MenuItemModel,WMessageBox.MessageModel,WPopup.PopupModel,WRow.RowModel,WSection.SectionModel,WSelectToggle.SelectToggleModel,WSubMenu.SubMenuModel,WSuggestions.SuggestionsModel,WTab.TabModel,WTableColumn.WTableColumnModel,WTabSet.TabSetModel,WTimeoutWarning.TimeoutWarningModel,WValidationErrors.ValidationErrorsModel,WVideo.VideoModel,WWindow.WindowModel
public class ComponentModel extends Object implements WebModel, Externalizable
Holds the extrinsic state information of a WComponent. Subclasses can extend this class and add extra model attributes.Subclasses must adhere to the following rules:
- They must define a public no-args constructor (requirement of
Externalizable). - They must not contain any final fields (needed for initialising from shared model).
- They must not contain any non-serializable data.
- Since:
- 1.0.0
- Author:
- Yiannis Paschalidis
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDISABLED_FLAGThe bit-mask for the flag that indicates whether a component is disabled.static intENCODE_TEXT_FLAGThe bit-mask for the flag that indicates whether a component's text needs to be encoded before output.protected static intFLAGS_DEFAULTThe bit-mask for the default set of flags: visible, validation required and text encoded.static intHIDE_FLAGThe bit-mask for the flag that indicates whether a component is rendered as "hidden" on the client side.static intINITIALISED_FLAGThe bit-mask for the flag that indicates whether a component is initialised.static intMANDATORY_FLAGThe bit-mask for the flag that indicates whether a component is mandatory.static intNAMING_CONTEXT_FLAGThe bit-mask for the flag that indicates whether a component is a naming context.static intREADONLY_FLAGThe bit-mask for the flag that indicates whether a component is read only.static intSUBMIT_ON_CHANGE_FLAGDeprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.static intTRACKABLE_FLAGThe bit-mask for the flag that indicates whether a component is trackable via analytics.static intUSER_DATA_SETThe bit-mask for the flag that indicates whether that user data has been set.static intVALIDATE_FLAGThe bit-mask for the flag that indicates whether a component needs validation.static intVISIBLE_FLAGThe bit-mask for the flag that indicates whether a component is visible.
-
Constructor Summary
Constructors Constructor Description ComponentModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddHtmlClass(HtmlClassProperties className)protected voidaddHtmlClass(String text)protected ObjectcopyData(Object data)Creates a copy of mutable data, to ensure updates to one component model do not update the other.booleanequals(Object obj)Indicates whether this ComponentModel is equal to the given object.protected SerializablegetAccessibleText()SerializablegetAttribute(String key)Retrieves an attribute.protected Map<String,Serializable>getAttributes()protected List<WComponent>getChildren()protected Map<String,WComponent>getContextIds()protected intgetFlags()protected SerializablegetHtmlClass()protected SetgetHtmlClasses()protected StringgetIdName()WLabelgetLabel()protected ContainergetParent()protected ComponentModelgetSharedModel()protected StringgetTag()Deprecated.UseWTemplateinsteadStringgetTemplateMarkUp()Deprecated.UseWTemplateinsteadStringgetTemplateUrl()Deprecated.UseWTemplateinsteadprotected SerializablegetToolTip()inthashCode()voidreadExternal(ObjectInput in)Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by thesharedModel.SerializableremoveAttribute(String key)Removes an attribute.protected voidremoveHtmlClass(HtmlClassProperties className)Remove a value from the HTML class name list.protected voidremoveHtmlClass(String className)Remove a value from the HTML class name list.protected voidsetAccessibleText(String text, Serializable... args)voidsetAttribute(String key, Serializable value)Sets an attribute.protected voidsetAttributes(Map<String,Serializable> attributes)protected voidsetChildren(List<WComponent> children)protected voidsetContextIds(Map<String,WComponent> contextIds)protected voidsetFlags(int flags)protected voidsetHtmlClass(HtmlClassProperties className)protected voidsetHtmlClass(String text)protected voidsetIdName(String idName)voidsetLabel(WLabel label)Sets the label associated with this component.protected voidsetParent(Container parent)protected voidsetSharedModel(ComponentModel sharedModel)Sets the shared component model.protected voidsetTag(String tag)Deprecated.UseWTemplateinsteadvoidsetTemplateMarkUp(String templateMarkUp)Deprecated.UseWTemplateinsteadvoidsetTemplateUrl(String templateUrl)Deprecated.UseWTemplateinsteadprotected voidsetToolTip(String text, Serializable... args)voidwriteExternal(ObjectOutput out)Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by thesharedModel.
-
-
-
Field Detail
-
VISIBLE_FLAG
public static final int VISIBLE_FLAG
The bit-mask for the flag that indicates whether a component is visible.- See Also:
- Constant Field Values
-
INITIALISED_FLAG
public static final int INITIALISED_FLAG
The bit-mask for the flag that indicates whether a component is initialised.- See Also:
- Constant Field Values
-
DISABLED_FLAG
public static final int DISABLED_FLAG
The bit-mask for the flag that indicates whether a component is disabled.- See Also:
- Constant Field Values
-
READONLY_FLAG
public static final int READONLY_FLAG
The bit-mask for the flag that indicates whether a component is read only.- See Also:
- Constant Field Values
-
MANDATORY_FLAG
public static final int MANDATORY_FLAG
The bit-mask for the flag that indicates whether a component is mandatory.- See Also:
- Constant Field Values
-
VALIDATE_FLAG
public static final int VALIDATE_FLAG
The bit-mask for the flag that indicates whether a component needs validation.- See Also:
- Constant Field Values
-
SUBMIT_ON_CHANGE_FLAG
@Deprecated public static final int SUBMIT_ON_CHANGE_FLAG
Deprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.The bit-mask for the flag that indicates whether a component is submitted on change/click (client side).- See Also:
- Constant Field Values
-
HIDE_FLAG
public static final int HIDE_FLAG
The bit-mask for the flag that indicates whether a component is rendered as "hidden" on the client side.- See Also:
- Constant Field Values
-
USER_DATA_SET
public static final int USER_DATA_SET
The bit-mask for the flag that indicates whether that user data has been set. This is necessary, as some components do not contain enough values to determine this automatically. For example, WCheckBox only has two states (on/off), and could already contain two different "default" values from the shared model and a bean.
Note: This bit mask must never be set on a component's shared model.
- See Also:
- Constant Field Values
-
ENCODE_TEXT_FLAG
public static final int ENCODE_TEXT_FLAG
The bit-mask for the flag that indicates whether a component's text needs to be encoded before output.- See Also:
- Constant Field Values
-
TRACKABLE_FLAG
public static final int TRACKABLE_FLAG
The bit-mask for the flag that indicates whether a component is trackable via analytics.- See Also:
- Constant Field Values
-
NAMING_CONTEXT_FLAG
public static final int NAMING_CONTEXT_FLAG
The bit-mask for the flag that indicates whether a component is a naming context.- See Also:
- Constant Field Values
-
FLAGS_DEFAULT
protected static final int FLAGS_DEFAULT
The bit-mask for the default set of flags: visible, validation required and text encoded.- See Also:
- Constant Field Values
-
-
Method Detail
-
setAttribute
public void setAttribute(String key, Serializable value)
Sets an attribute.- Parameters:
key- the attribute keyvalue- the attribute value
-
getAttribute
public Serializable getAttribute(String key)
Retrieves an attribute.- Parameters:
key- the attribute key- Returns:
- the value of the attribute, or null if the attribute does not exist.
-
removeAttribute
public Serializable removeAttribute(String key)
Removes an attribute.- Parameters:
key- the attribute key- Returns:
- the value of the attribute that was removed, or null if the attribute did not exist.
-
equals
public boolean equals(Object obj)
Indicates whether this ComponentModel is equal to the given object. Subclasses should not need to override this method, as reflection is used to read in all fields.
-
setSharedModel
protected final void setSharedModel(ComponentModel sharedModel)
Sets the shared component model. If there are any unset fields, they are set from the values in the shared model.- Parameters:
sharedModel- the shared ComponentModel
-
copyData
protected Object copyData(Object data)
Creates a copy of mutable data, to ensure updates to one component model do not update the other.- Parameters:
data- the data to copy- Returns:
- a copy of the data, if it is mutable, otherwise the original data.
-
getAttributes
protected Map<String,Serializable> getAttributes()
- Returns:
- Returns the attributes.
-
setAttributes
protected void setAttributes(Map<String,Serializable> attributes)
- Parameters:
attributes- The attributes to set.
-
getChildren
protected List<WComponent> getChildren()
- Returns:
- Returns the children.
-
setChildren
protected void setChildren(List<WComponent> children)
- Parameters:
children- The children to set.
-
getFlags
protected int getFlags()
- Returns:
- Returns the flags.
-
setFlags
protected void setFlags(int flags)
- Parameters:
flags- The flags to set.
-
getParent
protected Container getParent()
- Returns:
- Returns the parent.
-
setParent
protected void setParent(Container parent)
- Parameters:
parent- The parent to set.
-
getTag
@Deprecated protected String getTag()
Deprecated.UseWTemplateinstead- Returns:
- Returns the tag.
-
setTag
@Deprecated protected void setTag(String tag)
Deprecated.UseWTemplateinstead- Parameters:
tag- The tag to set.
-
getTemplateUrl
@Deprecated public String getTemplateUrl()
Deprecated.UseWTemplateinstead- Returns:
- Returns the templateUrl.
-
setTemplateUrl
@Deprecated public void setTemplateUrl(String templateUrl)
Deprecated.UseWTemplateinstead- Parameters:
templateUrl- The templateUrl to set.
-
getTemplateMarkUp
@Deprecated public String getTemplateMarkUp()
Deprecated.UseWTemplateinstead- Returns:
- Returns the template mark-up.
-
setTemplateMarkUp
@Deprecated public void setTemplateMarkUp(String templateMarkUp)
Deprecated.UseWTemplateinstead- Parameters:
templateMarkUp- The template mark-up to set.
-
getToolTip
protected Serializable getToolTip()
- Returns:
- Returns the tool tip text.
-
setToolTip
protected void setToolTip(String text, Serializable... args)
- Parameters:
text- The tool tip to set.args- optional message format arguments.
-
getAccessibleText
protected Serializable getAccessibleText()
- Returns:
- Returns the accessible text.
-
setAccessibleText
protected void setAccessibleText(String text, Serializable... args)
- Parameters:
text- The accessible text to set.args- optional message format arguments.
-
getHtmlClass
protected Serializable getHtmlClass()
- Returns:
- the HTML class list as a single space separated String.
-
setHtmlClass
protected void setHtmlClass(String text)
- Parameters:
text- The HTML class name text to set.
-
setHtmlClass
protected void setHtmlClass(HtmlClassProperties className)
- Parameters:
className- The HTML class name to set.
-
addHtmlClass
protected void addHtmlClass(String text)
- Parameters:
text- The HTML class name text to set.
-
addHtmlClass
protected void addHtmlClass(HtmlClassProperties className)
- Parameters:
className- The HTML class name to set.
-
getHtmlClasses
protected Set getHtmlClasses()
- Returns:
- the set of HTML classes to add to the current component.
-
removeHtmlClass
protected void removeHtmlClass(String className)
Remove a value from the HTML class name list.- Parameters:
className- the value to remove
-
removeHtmlClass
protected void removeHtmlClass(HtmlClassProperties className)
Remove a value from the HTML class name list.- Parameters:
className- the property representing the value to remove
-
getLabel
public WLabel getLabel()
- Returns:
- the label associated with this component.
-
setLabel
public void setLabel(WLabel label)
Sets the label associated with this component.- Parameters:
label- the label to associate with this component.
-
getSharedModel
protected ComponentModel getSharedModel()
- Returns:
- Returns the sharedModel.
-
getIdName
protected String getIdName()
- Returns:
- the id name.
-
setIdName
protected void setIdName(String idName)
- Parameters:
idName- the id name to set.
-
getContextIds
protected Map<String,WComponent> getContextIds()
- Returns:
- the map of registered ids for the naming context
-
setContextIds
protected void setContextIds(Map<String,WComponent> contextIds)
- Parameters:
contextIds- the map holding the registered ids for the naming context
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by the
sharedModel.Data is obtained using reflection so that subclasses don't need concern themselves with the ComponentModel serialization mechanism.
After the ComponentModel data is read in, some fields may be in a "unset" state. The static model needs to be supplied using
setSharedModel(ComponentModel)- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- the ObjectInput to read from.- Throws:
IOException- if there is an error reading from the ObjectInputClassNotFoundException- If the class of a serialized object cannot be found.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by the
sharedModel.Data is obtained using reflection so that subclasses don't need concern themselves with the ComponentModel serialization mechanism.
- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- the ObjectOutput to write to.- Throws:
IOException- if there is an error writing to the ObjectOutput
-
-