All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.aemds.guide.common.GuideTable Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2014 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/

package com.adobe.aemds.guide.common;

import com.adobe.aemds.guide.utils.GuideConstants;
import org.apache.commons.lang3.StringUtils;

import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.List;



/**
 * Class representing the table component
 *
 * @since        AEM 6.1
 */
public class GuideTable extends GuidePanel{

    /**
     * Gets the column present in the table at the specified row
     * @param row GuideNode bean representing the row
     * @return number of columns
     */
    public int getColumns(GuideNode row){
        GuidePanel panel = new GuidePanel();
        SimpleBindings bindings = new SimpleBindings();
        bindings.put("resource",slingRequest.getResourceResolver().getResource(row.getPath()));
        bindings.put("request",slingRequest);
        panel.init(bindings);
        return panel.getItems().size();
    }


    /**
     * @return ArrayList of HeaderRow on which sorting is enabled.
     */
    public ArrayList getSortingAllowedHeader(){
        List elements = this.getItems();
        ArrayList sortableHeaderList = new ArrayList<>();
        int currColumn = 0;
        int totalColumns = this.getColumns();
        Boolean isSortingAllowed = "true".equals(this.isSortingEnabled());
        for(currColumn = 0 ; currColumn < totalColumns; currColumn++){
            sortableHeaderList.add(isSortingAllowed);
        }
        if(isSortingAllowed){
            try {
                for(GuideNode guideNode : elements){
                    if(!(guideNode.getResourceType().equals(GuideConstants.RT_WEB_DOCUMENT_HEADER_ROW) ||
                            guideNode.getResourceType().equals(GuideConstants.RT_TABLE_HEADER))){
                        List tableCellNode = this.getTableRowItems(guideNode);
                        for(currColumn = 0; currColumn < tableCellNode.size(); currColumn++){
                            if(sortableHeaderList.get(currColumn)){
                                String guideNodeClass = tableCellNode.get(currColumn).getNodeClass();
                                if(isTableCellPrimitiveComponent(guideNodeClass)){
                                    sortableHeaderList.set(currColumn,false);
                                }
                            }
                        }
                    }
                }
            }catch (Exception e){
                logger.error("Error in updating tableHeader info",e);
            }
        }
        return sortableHeaderList;
    }


    /**
     * @param row tableRow
     * @return childItems of given tableRow.
     */
    private List getTableRowItems(GuideNode row){
        GuidePanel panel = new GuidePanel();
        SimpleBindings bindings = new SimpleBindings();
        bindings.put("resource",row.getResource());
        bindings.put("request",slingRequest);
        panel.init(bindings);
        return panel.getItems();
    }


    /**
     * @param guideNodeClass nodeClass of tableCell
     * @return is tableCell not of primitive component.
     */
    private Boolean isTableCellPrimitiveComponent(String guideNodeClass){
        return (guideNodeClass!=null && !(guideNodeClass.equals(GuideConstants.GUIDE_FIELD_TEXTBOX)|| guideNodeClass.equals(GuideConstants.GUIDE_FIELD_NUMERICBOX)||
                guideNodeClass.equals(GuideConstants.GUIDE_FIELD_DATEPICKER)|| guideNodeClass.equals(GuideConstants.GUIDE_FIELD_TEXTDRAW)));
    }
    /**
     * API to return the number of columns present in the table.
     * This API would return the maximum of all the columns present in each row
     * @return  Columns present in the table
     */
    public int getColumns(){
        List elements = this.getItems();
        int max = -1,
            j = 0,
            size = elements.size();
        for(;j max) {
                max = columns;
            }
        }
        return max;
    }

    /**
     * API to get the mobile layout associated with the table
     * @return mobile layout of the table
     */
    public String getMobileLayout(){
        // column width would be comma separated values
        return resourceProps.get("./layout/mobileLayout", "");
    }

    /**
     * API to get the summary text required for accessibility
     * @return summary text of the table
     */
    public String getSummary(){
        // Summary can be empty string
        return resourceProps.get("./tableSummaryText", "");
    }

    public String isSortingEnabled(){
        return resourceProps.get("./sortingEnabled", "false");
    }

    /**
     * API to get column width of table configured during authoring
     * @return column width configured for the table
     */
    public String getColumnWidth(){
        return resourceProps.get("columnWidth", "");
        // column width would be comma separated values
        /*String columnWidth = resourceProps.get("columnWidth", "");
        int columns = getColumns();
        if(columnWidth.length() > 0){
            String[] arr = StringUtils.split(columnWidth, ",");
            if(arr.length == columns){
                int a[] = new int[arr.length];
                double perc[] = new double[arr.length];
                int sum = 0;
                for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy