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

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

import com.patrikdufresne.util.Localized;
import com.planimod.core.ProposedTasks.ProposedWarning;

/**
 * Converter to create a string for a collection of warnings.
 * 
 * @author Patrik Dufresne
 * 
 */
public class ProposedWarningToStringConverter extends Converter {

	/**
	 * Used for localization.
	 */
	private static Localized localized = Localized
			.load(ProposedWarningToStringConverter.class);

	/**
	 * Empty string (value "").
	 */
	private static final Object EMPTY = ""; //$NON-NLS-1$

	/**
	 * Create a new converter.
	 */
	public ProposedWarningToStringConverter() {
		super(ProposedWarning.class, String.class);
	}

	/**
	 * This implementation convert the warning into a description.
	 */
	@Override
	public Object convert(Object fromObject) {
		if (fromObject instanceof ProposedWarning) {
			ProposedWarning warning = (ProposedWarning) fromObject;
			switch (warning.getCode()) {
			case ProposedWarning.AS_SENIORITY_TO_WORK_ON_PREFERRED_TEAM:
				return localized
						.get("ProposedWarningToStringConverter.asSeniorityToWorkOnPreferredTeam"); //$NON-NLS-1$
			default:
				return localized
						.get("ProposedWarningToStringConverter.default"); //$NON-NLS-1$
			}
		}
		return EMPTY;
	}
}
