/*
 * Copyright
 *   2005 axYus - www.axyus.com
 *   2005 Y.Laurelut - yann.laurelut@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS 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, or
 * (at your option) any later version.
 *
 * XEMELIOS 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 XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package fr.gouv.finances.cp.xemelios.ui.importDialog;

import java.io.File;


/**
 * Represents a file that is candidate for import.
 * This class is used in the ImportFileTreeTableModel, in each node.
 * 
 * @author Yann Laurelut
 */
public class ImportFile {

	/** to mark this file for import */
	private boolean toBeImported = true;
	/** the underlying file */
	private File fichier = null;

	public ImportFile(File fic) {
		this.fichier = fic;
	}

	public boolean isFile() {
		return fichier.isFile();
	}
	public String getName() {
		return fichier.getName();
	}
	public String getPath() {
		return fichier.getPath();
	}
	public boolean isToBeImported() {
		return toBeImported;
	}
	public void setToBeImported(boolean toBeImported) {
		this.toBeImported = toBeImported;
	}
	public File getFile() {
		return fichier;
	}
	public void setFile(File fic) {
		this.fichier = fic;
	}
	
	/**
	 * Returns the last path element (directory) 
	 * of this full path
	 * @return a path, which can be an empty String
	 */
	public String getRelativePath() {
		String result = "";
		String pathSeparator = System.getProperty("file.separator");
		if(isFile()) {
			result = this.getName();
		} else {
			String path = this.getPath();
			result = path.substring(path.lastIndexOf(pathSeparator)+1);
		}
		return result;
	}

	@Override
	public String toString() {
            return fichier.getName();
	}
	
	@Override
	public boolean equals(Object other) {
		boolean result = false;
		if(other instanceof ImportFile) {
			ImportFile otherFile = (ImportFile)other;
                        result = getFile().equals(otherFile.getFile());
		}
		return result;
	}
}

