package semorg.gui.provider;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

import semorg.gui.list.AssociateListWindow;
import semorg.gui.list.CompanyListWindow;
import semorg.sql.tables.Company;
import semorg.sql.util.Utility;

/**
 * This class provides the data of the items in the GUI table in the
 * {@link CompanyListWindow}.
 */
public class CompanyTableProvider implements ITableLabelProvider {
    // not implemented
    public void dispose() {
    }

    // not implemented
    public Image getColumnImage(Object arg0, int arg1) {
	return null;
    }

    /**
     * Returns for given object and column number the appropriate value from the
     * object for the specified column.
     * 
     * @param input
     *                the object which contains the information
     * @param column
     *                the number of the column which should display a particular
     *                attribute of the given object.
     * @return particular attribute as a String.
     */
    public String getColumnText(Object input, int column) {
	Company company = (Company) input;
	switch (column) {
	case 0:
	    return "" + company.getId();
	case 1:
	    return company.getShortName();
	case 2:
	    return company.getSalutation();
	case 3:
	    return company.getTitle();
	case 4:
	    return company.getFirstname();
	case 5:
	    return company.getName();
	case 6:
	    return company.getStreet();
	case 7:
	    return company.getZipCode();
	case 8:
	    return company.getCity();
	case 9:
	    return company.getCountry();
	case 10:
	    return company.getAnnex();
	case 11:
	    return company.getPhone();
	case 12:
	    return company.getMobile();
	case 13:
	    return company.getFax();
	case 14:
	    return company.getEmail();
	case 15:
	    return company.getCpSalutation();
	case 16:
	    return company.getCpTitle();
	case 17:
	    return company.getCpFirstname();
	case 18:
	    return company.getCpName();
	case 19:
	    return company.getCpPhone();
	case 20:
	    return company.getCpMobile();
	case 21:
	    return company.getCpFax();
	case 22:
	    return company.getCpEmail();
	case 23:
	    return company.getCpDepartment();

	case 24:
	    if (company.getCpBirthDay() != null) {
		return Utility.dateOnlyFormatter
			.format(company.getCpBirthDay());
	    } else
		return null;

	case 25:
	    return company.getCpTask();
	case 26:
	    return company.getShortInfo();
	case 27:
	    return company.getNotices();
	case 28:
	    if (company.getTurnover() != null)
		return Utility.createFloatText(company.getTurnover());
	    else
		return null;

	case 29:
	    if (company.getCustomerSince() != null)
		return Utility.dateOnlyFormatter.format(company
			.getCustomerSince());
	    else
		return null;

	case 30:
	    if (company.getCreationDate() != null) {
		return Utility.dateAndTimeFormatter.format(company
			.getCreationDate());
	    } else
		return null;

	case 31:
	    if (company.getModificationDate() != null) {
		return Utility.dateAndTimeFormatter.format(company
			.getModificationDate());
	    } else
		return null;
	default:
	    return null;
	}
    }

    // not implemented
    public void addListener(ILabelProviderListener arg0) {
    }

    // not implemented
    public boolean isLabelProperty(Object arg0, String arg1) {
	return false;
    }

    // not implemented
    public void removeListener(ILabelProviderListener arg0) {
    }
}
