/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the
 * License at
 * http://www.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.faces.facelets.component.table.richdatagrid;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import java.util.List;

public class RichDataListColumn extends BaseRichDataColumn {

    private String listEL;
    private List items;

    public List getItems() {
        return items;
    }

    public RichDataListColumn(String property, String title, boolean editable,
                              boolean moveable, boolean shownByDefault, boolean sortable, String listEL) {
        super(property, title, COLUMN_TYPE_LIST, editable, moveable, shownByDefault, sortable, false, true);
        this.listEL = listEL;
    }

    public RichDataListColumn(String property, String title, boolean editable,
                              boolean moveable, boolean shownByDefault, boolean sortable, boolean hideable, String listEL) {
        super(property, title, COLUMN_TYPE_LIST, editable, moveable, shownByDefault, sortable, false, hideable);
        this.listEL = listEL;
    }

    public RichDataListColumn(String property, String title, String listEL) {
        super(property, title, COLUMN_TYPE_LIST);
        this.listEL = listEL;
        this.filterable = false;
    }


    public RichDataListColumn(String property, String title, boolean editable,
                              boolean moveable, boolean shownByDefault, boolean sortable, List items) {
        super(property, title, COLUMN_TYPE_LIST, editable, moveable, shownByDefault, sortable, false, true);
        this.items = items;
    }

    public RichDataListColumn(String property, String title, boolean editable,
                              boolean moveable, boolean shownByDefault, boolean sortable, boolean hideable, List items) {
        super(property, title, COLUMN_TYPE_LIST, editable, moveable, shownByDefault, sortable, false, hideable);
        this.items = items;
    }

    public RichDataListColumn(String property, String title, List items) {
        super(property, title, COLUMN_TYPE_LIST);
        this.items = items;
        this.filterable = false;
    }


    public List getList() {
        if (items != null)
            return items;
        else {
            FacesContext fc = FacesContext.getCurrentInstance();
            ValueBinding vb = fc.getApplication().createValueBinding(listEL);
            return (List) vb.getValue(fc);
        }
    }


}
