
/* Genomic Comparison Tool
   Master Thesis of computer science

   Author: Yue Lu
   Version: 1.1

*/


/* this class will get the database connection instance
	and get the attributes of the selected table which
	distinct values are less than 20
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.*;

public class TableFilteredAttribute
{
	//constructor
	public TableFilteredAttribute(ListSelectionEvent evt, JList jList2)
	{

		if(evt.getValueIsAdjusting() == false)
	 	{
			//get the table name which user selected
 	 		JList source = (JList)evt.getSource();
     		Object[] values1 = source.getSelectedValues();

     		Table_Name = "";

     		for (int i = 0; i < values1.length; i++)
     		{
				String word = (String)values1[i];
           		Table_Name += word + " ";
     		}

			//execute the query to screen the column name
			//which has less than 20 distinct values

  	 		String query="select * from ["+ Table_Name+"]";
     		DatabaseColumnName Column_Name=new DatabaseColumnName(query);

  	 		//put the column name into a Vector
  	 		Vector words2=Column_Name.getColumnName();

  	 		for(int i=0; i<words2.size(); i++)
  	 		{

				// query the database to get the distinct value of each column
		 		String Column_query="Select distinct "+"["+words2.elementAt(i)+"] from ["+Table_Name+"]";

  	 	 		DatabaseRowNumber RowNumber=new DatabaseRowNumber(Column_query);

  	 	 		if(RowNumber.getRowNumber()<20)
  	 	 			Filtered_Column.addElement(words2.elementAt(i));

  	 	 		jList2.setListData (Filtered_Column);
			}
		}
	}

	//get the table name that use selected
	public String getTableName()
	{
		return Table_Name;
	}

	//get the column name which has less than 20 distinct elements
	public Vector getFiltered_Column()
	{
		return  Filtered_Column;
	}


	private String Table_Name;
	Vector Filtered_Column=new Vector(0, 1);

}

