package interactivefeaturelocator.views;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import interactivefeaturelocator.model.DerivationSession;
import interactivefeaturelocator.model.MethodInfo;
import interactivefeaturelocator.model.MethodProperty;
import interactivefeaturelocator.model.CallTreeGraphNode;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.ntlab.trace.MethodExecution;

public class InteractiveDerivationSession extends CTabItem {
	private DerivationSession session;
	private Composite bodyComposite;
	private CallTreeGraph graph;
	private SelectionComposite selectionComposite;
	private CTabFolder parent;

	public InteractiveDerivationSession(CTabFolder parent, int style, MethodExecution seed) {
		super(parent, style);
		// TODO Auto-generated constructor stub
		this.parent = parent;
		session = new DerivationSession(seed);
//		SelectMethodLayout layout = new SelectMethodLayout(this);
		bodyComposite = new Composite(this.getParent(), SWT.NONE);
		bodyComposite.setLayout(new FormLayout());

		createCallTreeGraph();
		createSelectionComposite();
		
		setControl(bodyComposite);

	}
	
	public void createCallTreeGraph() {
		// 上部の呼び出し木を描画するComposite
		graph = new CallTreeGraph(bodyComposite, SWT.BORDER);
		FormData graphForm = new FormData();
		graphForm.top = new FormAttachment(0, 0);
		graphForm.left = new FormAttachment(0, 0);
		graphForm.right = new FormAttachment(100, 0);
		graphForm.bottom = new FormAttachment(70, -5);
		graph.setLayoutData(graphForm);
		graph.setPreferredSize(1000, 500);
		graph.createGraph(session);
	}
	
	public void createSelectionComposite() {
		createSelectionComposite(false);
	}
	
	public void createSelectionComposite(boolean dataflow) {
		// 下部のカレントメソッドの説明と選択ボタンを表示するComposite
				selectionComposite = new SelectionComposite(bodyComposite, SWT.NONE, session.getCurrentMethodExecution(), false);
				selectionComposite.setLayout(new FormLayout());
				FormData selectionData = new FormData();
				selectionData.top = new FormAttachment(graph, 0);
				selectionData.left = new FormAttachment(0, 0);
				selectionData.right = new FormAttachment(100, 0);
				selectionData.bottom = new FormAttachment(100, 0);
				selectionComposite.setLayoutData(selectionData);
	}
		
	public CallTreeGraph getCallTreeGraph() {
		return this.graph;
	}
	
	public DerivationSession getSession() {
		return this.session;
	}
}
