Package org.ametys.runtime.model
Class ViewHelper
- java.lang.Object
-
- org.ametys.runtime.model.ViewHelper
-
public final class ViewHelper extends Object
Helper class for views
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classViewHelper.ViewItemGetter
-
Constructor Summary
Constructors Modifier Constructor Description privateViewHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Optional<String>_getModelItemContainerIdentifier(ModelItemContainer container)private static Map<String,ModelItem>_getModelItemsFromViewItemContainer(ViewItemContainer viewItemContainer)Retrieves all model items in the givenViewItemContainer, indexed by their pathsstatic voidaddViewContainerItems(ViewItemContainer currentContainer, ViewItemContainer containerToInclude, View referenceView)Add the items of the view item container to include if they are not already present in the current view item container or in the reference viewstatic voidaddViewItem(String relativePath, ViewItemContainer viewItemContainer, ModelItemContainer... modelItemContainers)Add a view item in the given containerstatic <T extends ViewItemContainer>
TcreateEmptyViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers)Creates an emptyViewItemContainerThe created container can be aViewor aModelViewItemGroup, according to the givenModelItemContainers.static <T extends ViewItemContainer>
TcreateViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers)Creates aViewItemContainerwith the items of the givenModelItemContainerstatic <T extends ViewItemContainer>
TcreateViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers, String... itemPaths)Creates aViewItemContainerwith the given itemsstatic Collection<ModelItem>getModelItemsFromView(View view)Retrieves all model items in the givenViewstatic Set<String>getModelItemsPathsFromView(View view)Retrieves the paths of all model items in the givenViewstatic ModelViewItemgetModelViewItem(ViewItemContainer itemContainer, String itemPath)Gets theModelViewItemfrom theViewItemContainerat the given path.static ModelViewItemGroupgetModelViewItemGroup(ViewItemContainer itemContainer, String itemPath)Gets theModelViewItemGroupfrom theViewItemContainerat the given path.static ViewElementgetViewElement(ViewItemContainer itemContainer, String itemPath)Gets theViewElementfrom theViewItemContainerat the given path.
-
-
-
Constructor Detail
-
ViewHelper
private ViewHelper()
-
-
Method Detail
-
addViewContainerItems
public static void addViewContainerItems(ViewItemContainer currentContainer, ViewItemContainer containerToInclude, View referenceView)
Add the items of the view item container to include if they are not already present in the current view item container or in the reference view- Parameters:
currentContainer- the current containercontainerToInclude- the container to includereferenceView- the reference view
-
createViewItemContainer
public static <T extends ViewItemContainer> T createViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers) throws IllegalArgumentException
Creates aViewItemContainerwith the items of the givenModelItemContainer- Type Parameters:
T- Type of theViewItemContainerto create (VieworModelViewItemGroup)- Parameters:
modelItemContainers- the model item containers- Returns:
- the created
ViewItemContainer - Throws:
IllegalArgumentException- if the model item containers collection is empty
-
createViewItemContainer
public static <T extends ViewItemContainer> T createViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers, String... itemPaths) throws IllegalArgumentException, BadItemTypeException
Creates aViewItemContainerwith the given items- Type Parameters:
T- Type of theViewItemContainerto create (VieworModelViewItemGroup)- Parameters:
modelItemContainers- the model items containing items definitionsitemPaths- the paths of the items to put in the view item container- Returns:
- the created
ViewItemContainer - Throws:
IllegalArgumentException- if the model item containers collection is empty or if an item path isnull, empty, or is not defined in the given model item containersBadItemTypeException- if a segment in a path (but not the last) does not represent a group item
-
createEmptyViewItemContainer
public static <T extends ViewItemContainer> T createEmptyViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers) throws IllegalArgumentException
Creates an emptyViewItemContainerThe created container can be aViewor aModelViewItemGroup, according to the givenModelItemContainers.- Type Parameters:
T- The type of the created container- Parameters:
modelItemContainers- the model items containing items definitions- Returns:
- the created
ViewItemContainer - Throws:
IllegalArgumentException- if the model item containers collection is empty
-
addViewItem
public static void addViewItem(String relativePath, ViewItemContainer viewItemContainer, ModelItemContainer... modelItemContainers) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException
Add a view item in the given container- Parameters:
relativePath- path of the item to addviewItemContainer- the view item containermodelItemContainers- the corresponding model item containers- Throws:
IllegalArgumentException- if the path isnullor emptyUndefinedItemPathException- if the path is not defined in the given model item containersBadItemTypeException- if a segment in a path (but not the last) does not represent a group item
-
_getModelItemContainerIdentifier
private static Optional<String> _getModelItemContainerIdentifier(ModelItemContainer container)
-
getModelItemsPathsFromView
public static Set<String> getModelItemsPathsFromView(View view)
Retrieves the paths of all model items in the givenView- Parameters:
view- theView- Returns:
- the paths of all items
-
getModelItemsFromView
public static Collection<ModelItem> getModelItemsFromView(View view)
Retrieves all model items in the givenView- Parameters:
view- theView- Returns:
- all model items
-
_getModelItemsFromViewItemContainer
private static Map<String,ModelItem> _getModelItemsFromViewItemContainer(ViewItemContainer viewItemContainer)
Retrieves all model items in the givenViewItemContainer, indexed by their paths- Parameters:
viewItemContainer- theViewItemContainer- Returns:
- all model items
-
getModelViewItem
public static ModelViewItem getModelViewItem(ViewItemContainer itemContainer, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theModelViewItemfrom theViewItemContainerat the given path.
UnlikeViewItemContainer.getModelViewItem(String), this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
itemContainer- The container of view itemsitemPath- The path of the item to get- Returns:
- The
ModelViewItem. Can never benull - Throws:
UndefinedItemPathException- If one of the parts of the given path is undefinedBadItemTypeException- If one of the parts of the given path is defined, but is not of the correct type
-
getViewElement
public static ViewElement getViewElement(ViewItemContainer itemContainer, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theViewElementfrom theViewItemContainerat the given path.
UnlikeViewItemContainer.getModelViewItem(String), this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
itemContainer- The container of view itemsitemPath- The path of the item to get- Returns:
- The
ViewElement. Can never benull - Throws:
UndefinedItemPathException- If one of the parts of the given path is undefinedBadItemTypeException- If one of the parts of the given path is defined, but is not of the correct type
-
getModelViewItemGroup
public static ModelViewItemGroup getModelViewItemGroup(ViewItemContainer itemContainer, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theModelViewItemGroupfrom theViewItemContainerat the given path.
UnlikeViewItemContainer.getModelViewItem(String), this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
itemContainer- The container of view itemsitemPath- The path of the container to get- Returns:
- The
ModelViewItemGroup. Can never benull - Throws:
UndefinedItemPathException- If one of the parts of the given path is undefinedBadItemTypeException- If one of the parts of the given path is defined, but is not of the correct type
-
-