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 class
ViewHelper.ViewItemGetter
-
Constructor Summary
Constructors Modifier Constructor Description private
ViewHelper()
-
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 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 viewstatic void
addViewItem(String relativePath, ViewItemContainer viewItemContainer, ModelItemContainer... modelItemContainers)
Add a view item in the given containerstatic <T extends ViewItemContainer>
TcreateEmptyViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers)
Creates an emptyViewItemContainer
The created container can be aView
or aModelViewItemGroup
, according to the givenModelItemContainer
s.static <T extends ViewItemContainer>
TcreateViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers)
Creates aViewItemContainer
with the items of the givenModelItemContainer
static <T extends ViewItemContainer>
TcreateViewItemContainer(Collection<? extends ModelItemContainer> modelItemContainers, String... itemPaths)
Creates aViewItemContainer
with the given itemsstatic Collection<ModelItem>
getModelItemsFromView(View view)
Retrieves all model items in the givenView
static Set<String>
getModelItemsPathsFromView(View view)
Retrieves the paths of all model items in the givenView
static ModelViewItem
getModelViewItem(ViewItemContainer itemContainer, String itemPath)
Gets theModelViewItem
from theViewItemContainer
at the given path.static ModelViewItemGroup
getModelViewItemGroup(ViewItemContainer itemContainer, String itemPath)
Gets theModelViewItemGroup
from theViewItemContainer
at the given path.static ViewElement
getViewElement(ViewItemContainer itemContainer, String itemPath)
Gets theViewElement
from theViewItemContainer
at 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 aViewItemContainer
with the items of the givenModelItemContainer
- Type Parameters:
T
- Type of theViewItemContainer
to create (View
orModelViewItemGroup
)- 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 aViewItemContainer
with the given items- Type Parameters:
T
- Type of theViewItemContainer
to create (View
orModelViewItemGroup
)- 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 emptyViewItemContainer
The created container can be aView
or aModelViewItemGroup
, according to the givenModelItemContainer
s.- 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 isnull
or 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 theModelViewItem
from theViewItemContainer
at 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 theViewElement
from theViewItemContainer
at 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 theModelViewItemGroup
from theViewItemContainer
at 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
-
-