/*
 *  Draco Econometrics
 *  Copyright (C) 2008-2009 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.application.plugin;

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

public class VariableSelectionColumn {

	private String title = null;
	private boolean selectMany = true;
	private boolean exclusive = true;
	
	private List<String> selections = null;
	
	/** Default constructor */
	public VariableSelectionColumn() {
		selections = new ArrayList<String>();
	}
	
	/** Creates a variable selection column with a specified
	 * title
	 * 
	 * @param title the title to display in the column header
	 */
	public VariableSelectionColumn(String title) {
		this();
		this.title = title;
	}
	
	/** Creates a variable selection column with a specified
	 * title and a flag siginifying if this column can select
	 * many variables at once.
	 * 
	 * @param title the title to display in the column header
	 * @param multiSelect true to allow multiple variables, false to only allow one
	 */
	public VariableSelectionColumn(String title, boolean multiSelect) {
		this(title);
		this.selectMany = multiSelect;
	}
	
	/** Creates a variable selection column with a specified
	 * title and flags signifying that the column is multiselect
	 * and exclusive (selections cannot appear in other columns).
	 * 
	 * @param title the title to display in the column header
	 * @param multiSelect true to allow multiple variables, false to only allow one
	 * @param exclusive true to enforce selection in only this column
	 */
	public VariableSelectionColumn(String title, boolean multiSelect, boolean exclusive) {
		this(title,multiSelect);
		this.exclusive = exclusive;
	}

	/**
	 * @return the selectMany
	 */
	public boolean isSelectMany() {
		return selectMany;
	}

	/**
	 * @param selectMany the selectMany to set
	 */
	public void setSelectMany(boolean selectMany) {
		this.selectMany = selectMany;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	
	public boolean isSelected(String value) {
		return selections.contains(value);
	}
	
	public void setSelected(String value) {
		if(!isSelectMany())
			selections.clear();
		
		if(selections.indexOf(value) == -1)
			selections.add(value);
	}
	
	public void setUnselected(String value) {
		selections.remove(value);
	}
	
	public List<String> getSelected() {
		return selections;
	}
	
	public boolean isExclusive() {
		return exclusive;
	}

	public void setExclusive(boolean exclusive) {
		this.exclusive = exclusive;
	}
}

