package org.richfaces;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

public class Bean {

private ArrayList testList = new ArrayList();

	private String selectedInfo;
    private String targetListWidth="140px"; 
    private String sourceListWidth="140px";
    private String listsHeight="100px";
    private String copyAllLabel;    
    private String copyLabel;
    private String removeLabel;
    private String removeAllLabel;
    
    private String [] values = new String[]{"polecat","suricate"};
    private List listValues = new ArrayList();
    
    public Bean() {
        testList.add(new SelectItem("polecat", "polecat"));
        testList.add(new SelectItem("suricate", "suricate"));
        testList.add(new SelectItem("marshotter", "marshotter"));
        
        listValues.add("polecat");
        listValues.add("suricate");
        
    }

    public void selectionChanged(ValueChangeEvent evt) {
        
    	Object newValue =  evt.getNewValue();
    	Object[] selectedValues = null;
    	if (newValue instanceof List) {
    		List list = (List)newValue;
    		selectedValues = list.toArray();
    	} else if (newValue instanceof String[] ) {
        	selectedValues = (String[]) evt.getNewValue();
    	} 
    	
    	if (selectedValues.length == 0) {
            selectedInfo = "No selected values";
        } else {
            StringBuffer sb = new StringBuffer("Selected values: ");
            for (int i = 0; i < selectedValues.length; i++) {
                if (i > 0) { 
                    sb.append(", ");
                }    
                sb.append(selectedValues[i]);
            }
            selectedInfo = sb.toString();
        }
    }

    public ArrayList getTestList() {
        return testList;
    }

    public String getSelectedInfo() {
        return selectedInfo;
    }

	public String getTargetListWidth() {
		return targetListWidth;
	}

	public void setTargetListWidth(String targetListWidth) {
		this.targetListWidth = targetListWidth;
	}

	public String getSourceListWidth() {
		return sourceListWidth;
	}

	public void setSourceListWidth(String sourceListWidth) {
		this.sourceListWidth = sourceListWidth;
	}

	public String getListsHeight() {
		return listsHeight;
	}

	public void setListsHeight(String listsHeight) {
		this.listsHeight = listsHeight;
	}

	public void setTestList(ArrayList testList) {
		this.testList = testList;
	}

	public String[] getValues() {
		return values;
	}

	public void setValues(String[] values) {
		this.values = values;
	}

	public String getCopyAllLabel() {
		return copyAllLabel;
	}

	public void setCopyAllLabel(String copyAllLabel) {
		this.copyAllLabel = copyAllLabel;
	}

	public String getCopyLabel() {
		return copyLabel;
	}

	public void setCopyLabel(String copyLabel) {
		this.copyLabel = copyLabel;
	}

	public String getRemoveLabel() {
		return removeLabel;
	}

	public void setRemoveLabel(String removeLabel) {
		this.removeLabel = removeLabel;
	}

	public String getRemoveAllLabel() {
		return removeAllLabel;
	}

	public void setRemoveAllLabel(String removeAllLabel) {
		this.removeAllLabel = removeAllLabel;
	}

	public List getListValues() {
		return listValues;
	}

	public void setListValues(List listValues) {
		this.listValues = listValues;
	}

	public void setSelectedInfo(String selectedInfo) {
		this.selectedInfo = selectedInfo;
	}

}