Search in sources :

Example 1 with ValueMapResource

use of com.adobe.granite.ui.components.ds.ValueMapResource in project acs-aem-commons by Adobe-Consulting-Services.

the class DataSourceBuilderImpl method addDataSource.

@Override
public void addDataSource(final SlingHttpServletRequest slingRequest, final List<DataSourceOption> options) {
    final ArrayList<Resource> resourceList = new ArrayList<Resource>();
    DataSource dataSource = null;
    for (final DataSourceOption option : options) {
        final Map map = new HashMap();
        map.put(TEXT, option.getText());
        map.put(VALUE, option.getValue());
        resourceList.add(new ValueMapResource(slingRequest.getResourceResolver(), new ResourceMetadata(), "", new ValueMapDecorator(map)));
    }
    if (resourceList.size() > 0) {
        dataSource = new SimpleDataSource(resourceList.iterator());
    } else {
        dataSource = EmptyDataSource.instance();
    }
    slingRequest.setAttribute(DataSource.class.getName(), dataSource);
}
Also used : HashMap(java.util.HashMap) DataSourceOption(com.adobe.acs.commons.wcm.datasources.DataSourceOption) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) Map(java.util.Map) EmptyDataSource(com.adobe.granite.ui.components.ds.EmptyDataSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Aggregations

DataSourceOption (com.adobe.acs.commons.wcm.datasources.DataSourceOption)1 DataSource (com.adobe.granite.ui.components.ds.DataSource)1 EmptyDataSource (com.adobe.granite.ui.components.ds.EmptyDataSource)1 SimpleDataSource (com.adobe.granite.ui.components.ds.SimpleDataSource)1 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)1