package com.connor.ml.tcm.outfile.ML_01;

import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import org.jdesktop.swingx.JXTreeTable;

import com.connor.ml.tcm.outfile.bean.NodeBean;

public class JTreeTable extends JXTreeTable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<Integer> isNotEditableRow;
	//CheckBoxCellEditor checkBoxCellEditor = new CheckBoxCellEditor(this);
	private TableCellCheckboxRenderer checkboxRenderer = new TableCellCheckboxRenderer(this);
	
	public List<Integer> getIsNotEditableRow() {
		return isNotEditableRow;
	}

	public void setIsNotEditableRow(List<Integer> isNotEditableRow) {
		this.isNotEditableRow = isNotEditableRow;
	}

	public JTreeTable(JTreeTableModel testTreeTableModel) {
		//  Auto-generated constructor stub
		super(testTreeTableModel);
	}

	@Override
	public boolean isCellEditable(int arg0, int arg1) {
		//  Auto-generated method stub
		return true;//super.isCellEditable(arg0, arg1);
	}
	
	@Override
	public TableCellEditor getCellEditor(int row, int column) {
		//  Auto-generated method stub
		//if(isNotEditableRow.contains(row) && column == 2)

		
		return cellEditor;
		//return super.getCellEditor(row, column);
	}
	
	public String getToolTipText(MouseEvent e) {
		int row = this.rowAtPoint(e.getPoint());
		int col = this.columnAtPoint(e.getPoint());
		String tiptextString = null;
		if (row > -1 && col > -1) {
			Object value = this.getValueAt(row, col);
			if (null != value && !"".equals(value))
				tiptextString = value.toString();// 悬浮显示单元格内容
		}
		return tiptextString;
	}
	
	@Override
	public TableCellRenderer getCellRenderer(int row, int column) {
		//  Auto-generated method stub
		Object val = getValueAt(row, NodeBean.LABEL);
		if(column == NodeBean.LABEL && val != null && (val.equals("0") || val.equals("1")))
		{
			return checkboxRenderer;
		}
		else
		{
			return super.getCellRenderer(row, column);
		}
	}
	
	// 隐藏列
	public void HiddenCell(int column) {
		TableColumn tc = this.getTableHeader().getColumnModel()
				.getColumn(column);
		tc.setMaxWidth(0);
		tc.setPreferredWidth(0);
		tc.setWidth(0);
		tc.setMinWidth(0);
		this.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
		this.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
	}
	
}
