/**
 * Copyright (C) 2004-2007 Aelitis SAS, All rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * 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 ( see the LICENSE file ).
 *
 * 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
 *
 * AELITIS, SAS au capital de 46,603.30 euros,
 * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
 */

package com.aelitis.azureus.ui.common.table;

import java.util.Comparator;
import java.util.List;
import java.util.Map;

import org.gudy.azureus2.core3.util.IndentWriter;

import org.gudy.azureus2.plugins.ui.tables.TableCell;
import org.gudy.azureus2.plugins.ui.tables.TableCellMouseEvent;
import org.gudy.azureus2.plugins.ui.tables.TableColumn;
import org.gudy.azureus2.plugins.ui.tables.TableContextMenuItem;

/** 
 * Core Table Column functions are those available to plugins plus
 * some core-only functions.  The core-only functions are listed here.
 *
 * @see TableColumnManager
 */
public interface TableColumnCore
	extends TableColumn, Comparator
{
	/** 
	 * Set the internal flag specifying whether the column has been added to the
	 * TableColumnManager.  Some functions can not be run after a column has been
	 * added.
	 *
	 * @param bAdded true - Column has been added<br>
	 *               false - Column has not been added
	 *               
	 * @since 2.1.0.0
	 */
	public void setColumnAdded(boolean bAdded);

	/** 
	 * Retrieve whether the column has been added to the TableColumnManager
	 * 
	 * @return true - Column has been added<br>
	 *         false - Column has not been added
	 *               
	 * @since 2.1.0.0
	 */
	public boolean getColumnAdded();

	/** 
	 * Changes what {@link TableCellCore.getDataSource()} and 
	 * {@link TableRowCore.getDataSource()} return.
	 *
	 * @param bCoreDataSource true - returns a core object<br>
	 *                        false - returns a plugin object (if available)
	 *               
	 * @since 2.1.0.0
	 */
	public void setUseCoreDataSource(boolean bCoreDataSource);

	/** 
	 * Retrieve whether a core or plugin object is sent via getDataSource()
	 *
	 * @return true - returns a core object<br>
	 *         false - returns a plugin object (if available)
	 *               
	 * @since 2.1.0.0
	 */
	public boolean getUseCoreDataSource();

	/** 
	 * Send a refresh trigger to all listeners stored in TableColumn
	 *
	 * @param cell the cell is being refreshed
	 * @throws Throwable 
	 *               
	 * @since 2.1.0.0
	 */
	public void invokeCellRefreshListeners(TableCell cell, boolean fastRefresh) throws Throwable;

	/**
	 * Retrieve all the refresh listeners for the cell
	 * 
	 * @return Cell refresh listeners
	 *
	 * @since 2.5.0.0
	 */
	public List getCellRefreshListeners();

	/** 
	 * Send a cellAdded trigger to all listeners stored in TableColumn
	 *
	 * @param cell the cell is being added
	 *               
	 * @since 2.1.0.0
	 */
	public void invokeCellAddedListeners(TableCell cell);

	/**
	 * Retreive all the Cell Added listeners
	 * 
	 * @return cell added listeners for this cell
	 *
	 * @since 2.5.0.0
	 */
	public List getCellAddedListeners();

	/** 
	 * Send a dispose trigger to all listeners stored in TableColumn
	 *
	 * @param cell the cell is being disposed
	 *               
	 * @since 2.1.0.0
	 */
	public void invokeCellDisposeListeners(TableCell cell);

	/**
	 * Send a tool tip event to the tool tip listeners
	 * 
	 * @param cell Cell to get the tool tip event
	 * @param type
	 *
	 * @since 2.1.0.2
	 */
	public void invokeCellToolTipListeners(TableCellCore cell, int type);

	/**
	 * Send a mouse event to the cell mouse listeners
	 * 
	 * @param event Mouse Event to send
	 *
	 * @since 2.4.0.0
	 */
	public void invokeCellMouseListeners(TableCellMouseEvent event);

	/**
	 * Send a visibility event to the cell's visibility listeners
	 * 
	 * @param visibility Visibility state
	 *               
	 * @since 2.5.0.2
	 */
	public void invokeCellVisibilityListeners(TableCellCore cell, int visibility);

	/** 
	 * Sets the position of the column without adjusting the other columns.
	 * This will cause duplicate columns, and is only usefull if you are
	 * adjusting the positions of multiple columns at once.
	 *
	 * @param position new position (0 based)
	 *
	 * @see TableColumnManager.ensureIntegrity()
	 *               
	 * @since 2.1.0.0
	 */
	public void setPositionNoShift(int position);

	/** 
	 * Load width and position settings from config.
	 * @param mapSettings map to place settings into
	 *               
	 * @since 2.1.0.0
	 */
	public void loadSettings(Map mapSettings);

	/** 
	 * Save width and position settings to config.
	 * @param mapSettings map to place settings into
	 *               
	 * @since 2.1.0.0
	 */
	public void saveSettings(Map mapSettings);

	/** 
	 * Returns the key in the properties bundle that has the title of the
	 * column.
	 *
	 * @return Title's language key
	 */
	public String getTitleLanguageKey();

	/**
	 * @return # of consecutive errors
	 *
	 * @since 2.1.0.0
	 */
	public int getConsecutiveErrCount();

	/**
	 * @param iCount # of consecutive errors
	 *
	 * @since 2.1.0.0
	 */
	public void setConsecutiveErrCount(int iCount);

	/**
	 * @param menuItem
	 *
	 * @since 2.1.0.0
	 */
	public void removeContextMenuItem(TableContextMenuItem menuItem);

	/**
	 * 
	 * @return
	 *
	 * @since 2.1.0.0
	 */
	public TableContextMenuItem[] getContextMenuItems();

	/**
	 * @return
	 *               
	 * @since 2.5.0.0
	 */
	boolean hasCellRefreshListener();

	/**
	 * @return
	 *               
	 * @since 2.5.0.0
	 */
	long getLastSortValueChange();

	/**
	 * @param lastSortValueChange
	 *               
	 * @since 2.5.0.0
	 */
	void setLastSortValueChange(long lastSortValueChange);

	/**
	 * @param live
	 *               
	 * @since 2.5.0.0
	 */
	public void setSortValueLive(boolean live);

	/**
	 * @return
	 *               
	 * @since 2.5.0.0
	 */
	public boolean isSortValueLive();

	/**
	 * @param ms
	 *               
	 * @since 2.5.0.0
	 */
	public void addRefreshTime(long ms);

	/**
	 * @param writer
	 *               
	 * @since 2.5.0.0
	 */
	void generateDiagnostics(IndentWriter writer);

	/**
	 * @param tableID
	 *
	 * @since 2.5.0.2
	 */
	void setTableID(String tableID);

	/**
	 * @return
	 *
	 * @since 2.5.0.2
	 */
	boolean isSortAscending();

	/**
	 * @param bAscending
	 *
	 * @since 2.5.0.2
	 */
	void setSortAscending(boolean bAscending);

	/**
	 * @return
	 *
	 * @since 3.0.1.1
	 */
	boolean hasCellMouseMoveListener();

	void triggerColumnSizeChange();
	
	void setAutoTooltip(boolean auto_tooltip);
	boolean doesAutoTooltip();
	

	boolean isInplaceEdit();
	void setInplaceEdit(boolean editable);
	
	/**
	 * Override this function to obtain edited values 
	 * @param cell that is being edited
	 * @param value the new value
	 * @param finalEdit true if the user finalizes his editing
	 * @return should be false if the currently entered value is invalid
	 */
	boolean inplaceValueSet(TableCell cell, String value, boolean finalEdit);
}
