/**
 * @author tyl
 * @Action  ini
 * 2011-3-21
 */
package cn.com.origin.autocodemanager.views.listcodeview;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import cn.com.origin.autocodemanager.common.tree.AbstractTreeData;
import cn.com.origin.autocodemanager.common.treetable.AbstractTreeTable;

public class CreateListCodeView extends AbstractTreeTable {
	public CreateListCodeView(Composite composite, String rootName, ViewPart viewPart) {
		super(composite, rootName, viewPart);

	}

	public CreateListCodeView() {

	}

	public void addRightKeyAction() {
		tree.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent e) {
				if (e.button == 3) {
					CodeListViewRightKeyAction rightAction = new CodeListViewRightKeyAction(CreateListCodeView.this);
					rightAction.fillContextMenu();
				}
			}
		});
	}

	public void createTree(Composite parent, String rootName) {
		Composite composite = parent;
		treeViewer = new TreeViewer(composite, SWT.BORDER);
		tree = treeViewer.getTree();
		initTree(rootName);

		treeViewer.expandToLevel(1);
		tree.addTreeListener(new TreeListener() {
			public void treeCollapsed(TreeEvent treeEvent) {
			}
			public void treeExpanded(TreeEvent treeEvent) {
				AbstractTreeData codeData = (AbstractTreeData) treeEvent.item.getData();
				if (codeData == null) {
					return;
				}
				try {
					expandNode(codeData);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		tree.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AbstractTreeData selectedData = (AbstractTreeData) e.item.getData();
				if (selectedData == null) {
					return;
				}
				if (selectedData.getParentTreeData() == null) {
					expandNode(selectedData);
				}
			}
		});
	}

	public void createOrgAutoCodeNodeChildren(AbstractTreeData[] codeDatas) throws Exception {
			super.createOrgAutoCodeNodeChildren(codeDatas);
	}
}
