/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * published by the Free Software Foundation; either version 2.1 of
 * the license, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite
 * 330, Boston, MA  02111-1307, USA.
 * 
 */
 
package com.k_int.AdminApp.gui.RecordView;

import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.ListSelectionModel;

import java.awt.event.MouseListener;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Title:       TableManager
 * @version     $Id: TableManager.java,v 1.1 2004/11/15 13:47:50 rob Exp $
 * Copyright:   Copyright (C) 1999 - 2004,Knowledge Integration Ltd.
 * @author      Rob Tice (rob.tice@k-int.com)
 * Company:     Knowledge Integration Ltd.
 * Description: 
 * 
 * Created 		Jul 2, 2004 11:24:59 AM
 * 
 * History:		
 * 				$Log: TableManager.java,v $
 * 				Revision 1.1  2004/11/15 13:47:50  rob
 * 				*** empty log message ***
 * 				
 * 				Revision 1.1  2004/08/05 18:42:29  rob
 * 				*** empty log message ***
 * 				
 *
 */
public class TableManager implements ListSelectionListener, ActionListener
{
    private JTable table;
    private SetComponentModel set_model;
    private JButton delete_button;
    private int selected_row=-1;
    
    
    public TableManager()
    {
       
    }
    public TableManager(SetComponentModel set_model, JTable table)
    {
        this.table=table;
        this.set_model=set_model;
        addMouseListener();
    }
    
    public void setTable(JTable table)
    {
        this.table=table;
        addMouseListener();
    }
    
    private void addMouseListener()
    {
        table.addMouseListener( new MouseAdapter() 
          {
            public void mouseClicked(MouseEvent e) 
            {
              if ( e.getClickCount() == 2 ) 
              {
                set_model.notifyDoubleClickRow(selected_row);
              }
            }
          });
    }
    
    public void setComponentModel(SetComponentModel set_model)
    {
        this.set_model=set_model;
    }
    
    public void setDeleteButton(JButton delete_button)
    {
        this.delete_button=delete_button;
    }
    
    public void setShowAllButton(JButton show_all_button)
    {
        show_all_button.addActionListener(this);
        
    }
    
    public void valueChanged(ListSelectionEvent e)
    {
        if (e.getValueIsAdjusting()) 
          return;

         ListSelectionModel lsm = (ListSelectionModel)e.getSource();
         if (lsm.isSelectionEmpty()) 
         {
            
         } 
         else 
         {
             selected_row = lsm.getMinSelectionIndex();    
         }      
      
    }
    
    public void actionPerformed(ActionEvent e)
    {
        set_model.showAllRows();
    }
}
