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
,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 private static String
__DEFAULT_TYPE_ID
Id for model item group typesprivate List<ModelItem>
_children
private ElementDefinition<Boolean>
_switcher
private ModelItemType
_type
-
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 void
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 containerElementDefinition<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()
Converts the model item in a JSON mapMap<String,Object>
toJSON(boolean includeChildren)
Converts the model item group in a JSON map-
Methods inherited from class org.ametys.runtime.model.AbstractModelItem
addItemChecker, compareTo, equals, getDescription, getItemCheckers, getLabel, getModel, getName, getParent, getPath, hashCode, setDescription, setLabel, setName, setParent, setServiceManager, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ametys.runtime.model.ModelItemContainer
getChild, getModelItem, hasModelItem
-
-
-
-
Field Detail
-
__DEFAULT_TYPE_ID
private static final String __DEFAULT_TYPE_ID
Id for model item group types- See Also:
- Constant Field Values
-
_switcher
private ElementDefinition<Boolean> _switcher
-
_type
private ModelItemType _type
-
-
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:ModelItemContainer
Retrieves all the model items of this container- Specified by:
getModelItems
in interfaceModelItemContainer
- 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
public Map<String,Object> toJSON() throws ProcessingException
Description copied from interface:ModelItem
Converts the model item in a JSON map- Specified by:
toJSON
in interfaceModelItem
- Overrides:
toJSON
in classAbstractModelItem
- 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(boolean includeChildren) throws ProcessingException
Converts the model item group in a JSON map- Parameters:
includeChildren
- 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
-
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
-
-