Package com.adobe.granite.ui.components
Class LayoutBuilder
- java.lang.Object
-
- com.adobe.granite.ui.components.LayoutBuilder
-
public class LayoutBuilder extends java.lang.ObjectA builder to create a layout. A layout is a configuration map consisting a set of properties. A layout at very least requires anameproperty.
-
-
Constructor Summary
Constructors Constructor Description LayoutBuilder()LayoutBuilder(Resource resource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String key, java.lang.Object value)Adds the given key-value pair of property to this layout.voidadd(java.util.Map<java.lang.String,java.lang.Object> data)Adds a map of properties to this layout.static LayoutBuilderfrom(Config config)Builds a layout from the given config.static LayoutBuilderfrom(Config config, java.lang.String defaultResourceType)Builds a layout from the given config.static LayoutBuilderfrom(Resource resource)Builds a layout from the given resource.static LayoutBuilderfrom(Resource resource, java.lang.String defaultResourceType)Builds a layout from the given resource.java.lang.StringgetName()Returns the name of this layout.java.lang.StringgetResourceType()Returns the resource type of this layout.booleanhasName()trueif this layout has name.voidsetName(java.lang.String name)Sets the name of this layout.voidsetResourceType(java.lang.String resourceType)Sets the resource type of this layout.JSONObjecttoJSON()Returns this layout as JSON.
-
-
-
Constructor Detail
-
LayoutBuilder
public LayoutBuilder()
-
LayoutBuilder
public LayoutBuilder(@CheckForNull Resource resource)
-
-
Method Detail
-
from
@Nonnull public static LayoutBuilder from(@Nonnull Config config)
Builds a layout from the given config. The actual layout resource is retrieved based onConfig.LAYOUTpath. This method doesn't set default resource type of layout, usefrom(Config, String)orComponentHelper.getLayout()instead.- Parameters:
config- the config- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@Nonnull Config config, @Nonnull java.lang.String defaultResourceType)
Builds a layout from the given config. The actual layout resource is retrieved based onConfig.LAYOUTpath. The given defaultResourceType will be used when sling:resourceType property of the resource is not set.- Parameters:
config- the configdefaultResourceType- the default resource type- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@CheckForNull Resource resource)
Builds a layout from the given resource. This method doesn't set default resource type of layout, usefrom(Resource, String)orComponentHelper.getLayout()instead.- Parameters:
resource- the resource- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@CheckForNull Resource resource, @CheckForNull java.lang.String defaultResourceType)
Builds a layout from the given resource. The given defaultResourceType will be used when sling:resourceType property of the resource is not set.- Parameters:
resource- the resourcedefaultResourceType- the default resource type- Returns:
- the layout builder
-
hasName
public boolean hasName()
trueif this layout has name.falseotherwise.- Returns:
trueif this layout has a name,falseotherwise
-
getName
@CheckForNull public java.lang.String getName()
Returns the name of this layout.- Returns:
- returns the name of this layout
-
setName
public void setName(@CheckForNull java.lang.String name)Sets the name of this layout.- Parameters:
name- the name to set
-
getResourceType
@CheckForNull public java.lang.String getResourceType()
Returns the resource type of this layout. This will be used to point to the renderer of the layout using standard Sling mechanism.- Returns:
- the resource type as a string
-
setResourceType
public void setResourceType(@CheckForNull java.lang.String resourceType)Sets the resource type of this layout.- Parameters:
resourceType- the resource type to set
-
add
public void add(@Nonnull java.lang.String key, @CheckForNull java.lang.Object value)Adds the given key-value pair of property to this layout.- Parameters:
key- the property keyvalue- the property value
-
add
public void add(@Nonnull java.util.Map<java.lang.String,java.lang.Object> data)Adds a map of properties to this layout. Entry with key having a namespace (e.g. jcr:primaryType) will be excluded.- Parameters:
data- the map of properties to add
-
toJSON
@Nonnull public JSONObject toJSON()
Returns this layout as JSON.- Returns:
- the layout as JSON
-
-