package interactivefeaturelocator.views;

import interactivefeaturelocator.model.DerivationManager;
import interactivefeaturelocator.model.DerivationUnit;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.ntlab.trace.MethodExecution;
import org.ntlab.trace.ThreadInstance;
import org.ntlab.trace.Trace;

public class InteractiveDerivationView extends ViewPart {
	
	public static final String ID = "interactivefeaturelocator.views.interactivederivationview";
	public static InteractiveDerivationView theInstance = null;
	private ArrayList<InteractiveDerivationTabFolder> tabFolders = new ArrayList<>();
	private InteractiveDerivationTabFolder focusFolder = null;
	private Composite parent;
//	private HashMap<ThreadInstance, HashSet<MethodExecution>> threadToMethods = new HashMap<>();
//	private HashMap<Trace, ThreadInstance> traceToThreads = new HashMap<>();
	private HashMap<Trace, HashSet<MethodExecution>> traceToMethods = new HashMap<>();
//	private SelectMethodTabFolder tabFolder;

	public InteractiveDerivationView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		theInstance = this;
		setParent(parent);
	}
		
	public void createTabFolder(DerivationUnit unit) {
		InteractiveDerivationTabFolder tabFolder = new InteractiveDerivationTabFolder(this.getParent(), SWT.NONE | SWT.BOTTOM, unit.getMethodExecutions());
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		tabFolder.setSimple(false);
		if (focusFolder == null) {
			focusFolder = tabFolder;
		}
		tabFolders.add(tabFolder);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}
	
	public void changeFolder(int index) {
		
		focusFolder = tabFolders.get(index);
		focusFolder.showFolder();
	}
	
	public ArrayList<InteractiveDerivationTabFolder> getTabFolders() {
		return tabFolders;
	}

	public void setTabFolders(ArrayList<InteractiveDerivationTabFolder> tabFolders) {
		this.tabFolders = tabFolders;
	}

	public InteractiveDerivationTabFolder getFocusFolder() {
		return focusFolder;
	}

	public void setFocusFolder(InteractiveDerivationTabFolder focus) {
		this.focusFolder = focus;
	}

	public Composite getParent() {
		return parent;
	}

	public void setParent(Composite parent) {
		this.parent = parent;
	}

//	public HashMap<ThreadInstance, HashSet<MethodExecution>> getThreadToMethods() {
//		return threadToMethods;
//	}
//
//	public void setThreadToMethods(
//			HashMap<ThreadInstance, HashSet<MethodExecution>> threadToMethods) {
//		this.threadToMethods = threadToMethods;
//	}
//
//	public HashMap<Trace, ThreadInstance> getTraceToThreads() {
//		return traceToThreads;
//	}
//
//	public void setTraceToThreads(HashMap<Trace, ThreadInstance> traceToThreads) {
//		this.traceToThreads = traceToThreads;
//	}
	
	public HashMap<Trace, HashSet<MethodExecution>> getTraceToMethods() {
		return traceToMethods;
	}
	
	public void setTraceToMethods(HashMap<Trace, HashSet<MethodExecution>> traceToMethods) {
		this.traceToMethods = traceToMethods;
	}
	
	public void reset() {
		this.tabFolders.clear();
		this.traceToMethods.clear();
	}
}
