Package org.ametys.runtime.model
Class ModelItemGroup
- java.lang.Object
-
- org.ametys.runtime.model.AbstractModelItem
-
- org.ametys.runtime.model.ModelItemGroup
-
- All Implemented Interfaces:
Comparable<ModelItem>
,ModelItem
,ModelItemAccessor
,ModelItemContainer
,Labelable
,ModifiableLabelable
- Direct Known Subclasses:
CompositeDefinition
,RepeaterDefinition
public class ModelItemGroup extends AbstractModelItem implements ModelItemContainer
Class for group of model items
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_TYPE_ID
Id for model item group types-
Fields inherited from class org.ametys.runtime.model.AbstractModelItem
__serviceManager
-
Fields inherited from interface org.ametys.runtime.model.ModelItem
ITEM_PATH_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description ModelItemGroup()
Default constructor.ModelItemGroup(String name, ModelItem... children)
Constructor used to create simple models and items
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>
_toJSON(DefinitionContext context)
Converts the model item in a JSON mapprotected Map<String,Object>
_toJSON(DefinitionContext context, boolean includeChildren)
Converts the model item group in a JSON mapvoid
addChild(ModelItem child)
Add a child in the groupvoid
addChild(ModelItem child, boolean isGroupSwitch)
Add a child in the groupList<ModelItem>
getChildren()
Retrieves the list of children model itemsList<ModelItem>
getChildren(boolean withSwitch)
Retrieves the list of children model items, with or without the switcherCollection<ModelItem>
getModelItems()
Retrieves all the model items of this accessorElementDefinition<Boolean>
getSwitcher()
Retrieves the switcher element definitionModelItemType
getType()
Retrieves the type.static ModelItemGroup
of(String name, ModelItem... children)
Creates aModelItemGroup
void
setModel(Model model)
Sets the model of the elementvoid
setType(ModelItemType type)
Set the type.Map<String,Object>
toJSON(DefinitionContext context, boolean includeChildren)
Converts the model item group in a JSON mapvoid
toSAX(ContentHandler contentHandler, DefinitionContext context)
Generates SAX events for the model item-
Methods inherited from class org.ametys.runtime.model.AbstractModelItem
_shouldJSONBeEmpty, _widgetParameterToSAX, _widgetToSAX, addItemChecker, compareTo, equals, getDescription, getDisableConditions, getItemCheckers, getLabel, getModel, getName, getParent, getPath, getPluginName, getWidget, getWidgetParameters, hashCode, setDescription, setDisableConditions, setLabel, setName, setParent, setPluginName, setServiceManager, setWidget, setWidgetParameters, toJSON, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ametys.runtime.model.ModelItemAccessor
getChild, getModelItem, hasModelItem
-
-
-
-
Field Detail
-
DEFAULT_TYPE_ID
public static final String DEFAULT_TYPE_ID
Id for model item group types- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ModelItemGroup
public ModelItemGroup()
Default constructor.
-
ModelItemGroup
public ModelItemGroup(String name, ModelItem... children)
Constructor used to create simple models and items- Parameters:
name
- the name of the definitionchildren
- the group's children
-
-
Method Detail
-
getModelItems
public Collection<ModelItem> getModelItems()
Description copied from interface:ModelItemAccessor
Retrieves all the model items of this accessor- Specified by:
getModelItems
in interfaceModelItemAccessor
- Returns:
- the model items
-
getChildren
public List<ModelItem> getChildren()
Retrieves the list of children model items- Returns:
- the children
-
getChildren
public List<ModelItem> getChildren(boolean withSwitch)
Retrieves the list of children model items, with or without the switcher- Parameters:
withSwitch
- true to retrieve the switcher with the other children- Returns:
- the children with or without the switcher
-
addChild
public void addChild(ModelItem child)
Add a child in the group- Parameters:
child
- the item to add
-
addChild
public void addChild(ModelItem child, boolean isGroupSwitch)
Add a child in the group- Parameters:
child
- the child to addisGroupSwitch
- true if the child to add is the group switch, false otherwise
-
getSwitcher
public ElementDefinition<Boolean> getSwitcher()
Retrieves the switcher element definition- Returns:
- the switcher
-
setModel
public void setModel(Model model)
Description copied from interface:ModelItem
Sets the model of the element- Specified by:
setModel
in interfaceModelItem
- Overrides:
setModel
in classAbstractModelItem
- Parameters:
model
- the model to set
-
getType
public ModelItemType getType()
Description copied from interface:ModelItem
Retrieves the type.
-
setType
public void setType(ModelItemType type)
Description copied from interface:ModelItem
Set the type.
-
_toJSON
protected Map<String,Object> _toJSON(DefinitionContext context) throws ProcessingException
Description copied from class:AbstractModelItem
Converts the model item in a JSON map- Overrides:
_toJSON
in classAbstractModelItem
- Parameters:
context
- the context of the definition- Returns:
- The model item as a JSON map
- Throws:
ProcessingException
- If an error occurs when converting the model item
-
toJSON
public Map<String,Object> toJSON(DefinitionContext context, boolean includeChildren) throws ProcessingException
Converts the model item group in a JSON map- Parameters:
context
- the context of the definitionincludeChildren
- true to iterate and add children as elements in the returned JSON map, false otherwise- Returns:
- The model item as a JSON map
- Throws:
ProcessingException
- If an error occurs when converting the model item group
-
_toJSON
protected Map<String,Object> _toJSON(DefinitionContext context, boolean includeChildren) throws ProcessingException
Converts the model item group in a JSON map- Parameters:
context
- the context of the definitionincludeChildren
- true to iterate and add children as elements in the returned JSON map, false otherwise- Returns:
- The model item as a JSON map
- Throws:
ProcessingException
- If an error occurs when converting the model item group
-
toSAX
public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException
Generates SAX events for the model item Do not generate SAX events for children. This method has been created to generate SAX events for views, the children are taken into account via view items children- Specified by:
toSAX
in interfaceModelItem
- Overrides:
toSAX
in classAbstractModelItem
- Parameters:
contentHandler
- theContentHandler
that will receive the SAX eventscontext
- the context of the definition- Throws:
SAXException
- if an error occurs during the SAX events generation
-
of
public static ModelItemGroup of(String name, ModelItem... children)
Creates aModelItemGroup
- Parameters:
name
- the group's namechildren
- the group's children- Returns:
- the created
ModelItemGroup
-
-