/*
 * Copyright (c) 2011, Patrik Dufresne. All rights reserved.
 * Patrik Dufresne PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.ui.viewers;

import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.conversion.IConverter;

import com.planimod.core.ProductionEvent;
import com.planimod.ui.databinding.Converters;

//TODO The label provide should be deprecated.
public class ProductionEventViewerUtils {

	/**
	 * Create a converter to display a Product object as string.
	 * <p>
	 * This converter return the product's name.
	 * 
	 * @return the converter
	 */
	public static IConverter labelConverter() {
		return new Converter(ProductionEvent.class, String.class) {

			private IConverter shortDate = Converters.shortDateTimeConverter();

			@Override
			public Object convert(Object fromObject) {
				ProductionEvent event = (ProductionEvent) fromObject;

				return this.shortDate.convert(event.getShift()
						.getStartDate())
						+ " - " //$NON-NLS-1$
						+ this.shortDate.convert(event.getShift()
								.getEndDate()) + " - " //$NON-NLS-1$
						+ event.getProduct().getName();
			}
		};
	}

}
