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;
	}
}

