
/* Genomic Comparison Tool
   Master Thesis of computer science

   Author: Yue Lu
   Version: 1.1

*/


/* This is the class which connects with database and
   get the distinct values of the selected attribute
   and put them into the ColorShape table
*/

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.*;

/**
 * Attribute Selection
 */
public class AttributeSelection
{


	//constructor
    /**
     * Attribute Selection Overridden method
     */    
	public AttributeSelection(ListSelectionEvent evt, JTable jTable1, String Table_Name)
	{

		if(evt.getValueIsAdjusting() == false)
		{
		//getting the values from the list
	 	JList source = (JList)evt.getSource();
     		Object[] values1 = source.getSelectedValues();
     		String Column_Name = "";

     		//get the column names
     		for (int i = 0; i < values1.length; i++)
     		{
		   String word = (String)values1[i];
           	   Column_Name += word + " ";
     		}

                System.out.println("The Column Name is " + Column_Name + "inside Attribute selection in AttributeSelection class");
		//get the distinct values from the database
		String query="select distinct ["+ Column_Name +"] from ["+Table_Name+"]";
		DatabaseQueryString List=new DatabaseQueryString(query);
		Vector words=List.getList();

		//put the value into the ColorShapeTableModel
		for (int i=0; i<words.size(); i++)
		{
				rowData[0]=Column_Name;
				rowData[1]=words.elementAt(i);
				rowData[2]=Color.white;
				Icon blank=new blank();
				rowData[3]=blank;

				DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
				model.addRow(rowData);//add data to the rows using superclass methods

		}
	}
}

	private  Object[] rowData=new Object[4];
}
