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
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addViewAccessorItems(ViewItemAccessor currentAccessor, ViewItemAccessor accessorToInclude, View referenceView, String accessorPath)
Add the items of the view item accessor to include if they are not already present in the current view item accessor or in the reference viewstatic void
addViewItem(String relativePath, ViewItemAccessor viewItemAccessor, ModelItemAccessor... modelItemAccessors)
Add a view item in the given accessorstatic boolean
areItemsPresentsOnlyOnce(View view)
Checks if all the items of the given view are present only once in the view Children of accessors that are not containers are not taken into accountstatic <T extends ViewItemAccessor>
TcreateEmptyViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors)
Creates an emptyViewItemAccessor
The created container can be aView
, aModelViewItemGroup
or aViewElementAccessor
, according to the givenModelItemAccessor
s.static <T extends ViewItemAccessor>
TcreateViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors)
Creates aViewItemAccessor
with the items of the givenModelItemAccessor
static <T extends ViewItemAccessor>
TcreateViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors, String... itemPaths)
Creates aViewItemAccessor
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(ViewItemAccessor viewItemAccessor, String itemPath)
Gets theModelViewItem
from theViewItemAccessor
at the given path.static ModelViewItemGroup
getModelViewItemGroup(ViewItemAccessor viewItemAccessor, String itemPath)
Gets theModelViewItemGroup
from theViewItemAccessor
at the given path.static View
getTruncatedView(View originalView)
Retrieves a View corresponding to the given one, avoiding the view items below theViewItemAccessor
s that are notViewItemContainer
sstatic ViewElement
getViewElement(ViewItemAccessor viewItemAccessor, String itemPath)
Gets theViewElement
from theViewItemAccessor
at the given path.static boolean
hasModelViewItem(ViewItemAccessor viewItemAccessor, String itemPath)
Checks if there is aModelViewItem
in theViewItemAccessor
at the given pathstatic View
mergeDuplicatedItems(View originalView)
Retrieves a View corresponding to the given one, where items that appears several times are mergedstatic Map<String,Object>
viewItemsToJSON(List<ViewItem> viewItems, DefinitionContext context)
Converts the given view items as a JSON map
-
-
-
Method Detail
-
addViewAccessorItems
public static void addViewAccessorItems(ViewItemAccessor currentAccessor, ViewItemAccessor accessorToInclude, View referenceView, String accessorPath)
Add the items of the view item accessor to include if they are not already present in the current view item accessor or in the reference view- Parameters:
currentAccessor
- the current accessoraccessorToInclude
- the accessor to includereferenceView
- the reference viewaccessorPath
- the path of the accessor in the reference view
-
createViewItemAccessor
public static <T extends ViewItemAccessor> T createViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors) throws IllegalArgumentException
Creates aViewItemAccessor
with the items of the givenModelItemAccessor
- Type Parameters:
T
- Type of theViewItemAccessor
to create (View
,ModelViewItemGroup
orViewElementAccessor
)- Parameters:
modelItemAccessors
- the model item accessors- Returns:
- the created
ViewItemAccessor
- Throws:
IllegalArgumentException
- if the model item accessors collection is empty
-
createViewItemAccessor
public static <T extends ViewItemAccessor> T createViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors, String... itemPaths) throws IllegalArgumentException, BadItemTypeException
Creates aViewItemAccessor
with the given items- Type Parameters:
T
- Type of theViewItemAccessor
to create (View
,ModelViewItemGroup
orViewElementAccessor
)- Parameters:
modelItemAccessors
- the model items accessing the items definitionsitemPaths
- the paths of the items to put in the view item accessor- Returns:
- the created
ViewItemAccessor
- 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
-
createEmptyViewItemAccessor
public static <T extends ViewItemAccessor> T createEmptyViewItemAccessor(Collection<? extends ModelItemAccessor> modelItemAccessors) throws IllegalArgumentException
Creates an emptyViewItemAccessor
The created container can be aView
, aModelViewItemGroup
or aViewElementAccessor
, according to the givenModelItemAccessor
s.- Type Parameters:
T
- The type of the created accessor- Parameters:
modelItemAccessors
- the model items accessing the items definitions- Returns:
- the created
ViewItemAccessor
- Throws:
IllegalArgumentException
- if the model item accessors collection is empty
-
addViewItem
public static void addViewItem(String relativePath, ViewItemAccessor viewItemAccessor, ModelItemAccessor... modelItemAccessors) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException
Add a view item in the given accessor- Parameters:
relativePath
- path of the item to addviewItemAccessor
- the view item accessormodelItemAccessors
- the corresponding model item accessors- Throws:
IllegalArgumentException
- if the path isnull
or emptyUndefinedItemPathException
- if the path is not defined in the given model item accessorsBadItemTypeException
- if a segment in a path (but not the last) does not represent a group item
-
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
-
areItemsPresentsOnlyOnce
public static boolean areItemsPresentsOnlyOnce(View view)
Checks if all the items of the given view are present only once in the view Children of accessors that are not containers are not taken into account- Parameters:
view
- the view to check- Returns:
true
if all items are presents only once,false
otherwise
-
getTruncatedView
public static View getTruncatedView(View originalView)
Retrieves a View corresponding to the given one, avoiding the view items below theViewItemAccessor
s that are notViewItemContainer
s- Parameters:
originalView
- the view to truncate- Returns:
- the truncated view
-
mergeDuplicatedItems
public static View mergeDuplicatedItems(View originalView)
Retrieves a View corresponding to the given one, where items that appears several times are merged- Parameters:
originalView
- the view to merge- Returns:
- the merged view
-
hasModelViewItem
public static boolean hasModelViewItem(ViewItemAccessor viewItemAccessor, String itemPath)
Checks if there is aModelViewItem
in theViewItemAccessor
at the given path- Parameters:
viewItemAccessor
- The accessor of the view itemsitemPath
- The path of the item to check- Returns:
true
if there is a model view item at the given path,false
otherwise
-
viewItemsToJSON
public static Map<String,Object> viewItemsToJSON(List<ViewItem> viewItems, DefinitionContext context) throws ProcessingException
Converts the given view items as a JSON map- Parameters:
viewItems
- the view items to convertcontext
- the context of the items' definitions- Returns:
- The view items as a JSON map
- Throws:
ProcessingException
- If an error occurs when converting the view items
-
getModelViewItem
public static ModelViewItem getModelViewItem(ViewItemAccessor viewItemAccessor, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theModelViewItem
from theViewItemAccessor
at the given path.
UnlikeViewItemAccessor.getModelViewItem(String)
, this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
viewItemAccessor
- The accessor 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(ViewItemAccessor viewItemAccessor, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theViewElement
from theViewItemAccessor
at the given path.
UnlikeViewItemAccessor.getModelViewItem(String)
, this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
viewItemAccessor
- The accessor 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(ViewItemAccessor viewItemAccessor, String itemPath) throws UndefinedItemPathException, BadItemTypeException
Gets theModelViewItemGroup
from theViewItemAccessor
at the given path.
UnlikeViewItemAccessor.getModelViewItem(String)
, this method accepts a path and not only a name, allowing to traverse composites.- Parameters:
viewItemAccessor
- The accessor 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
-
-