package com.acme.util.ui;


import com.acme.resource.ResourceHelper;
import com.acme.util.utilities.JSFUtils;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;


public class UIHelper
{
    public static String getStringResourceItem(String moduleShortName, String itemName)
    {
        return ResourceHelper.getStringResourceItem(moduleShortName, itemName, getCurrentLocale());
    }

    public static String getStringResourceItem(String moduleShortName, String itemName, Locale currentLocale)
    {
        return ResourceHelper.getStringResourceItem(moduleShortName, itemName, currentLocale);
    }

    public static Object getVisualResourceItem(String itemName)
    {
        return ResourceHelper.getVisualResourceItem(itemName);
    }

    public static Locale getCurrentLocale()
    {
        return JSFUtils.getCurrentLocale();
    }

    public static void showInformationMessages(Collection<UserInformationMessage> informationMessageList)
    {
        UserInformationMessage informationMessage = null;
        Iterator<UserInformationMessage> itr = informationMessageList.iterator();
        while (itr.hasNext())
        {
            informationMessage = itr.next();
            showInformationMessage(informationMessage);
        }
    }

    public static void showInformationMessage(UserInformationMessage informationMessage)
    {
        switch (informationMessage.getMessageType())
        {
        case UserInformationMessage.INFO_MESSAGE_TYPE_ERROR:
            JSFUtils.addFacesErrorMessage(informationMessage.getMessage());
            break;
        case UserInformationMessage.INFO_MESSAGE_TYPE_INFO:
            JSFUtils.addFacesInformationMessage(informationMessage.getMessage());
            break;
        case UserInformationMessage.INFO_MESSAGE_TYPE_WARNING:
            JSFUtils.addFacesWarningMessage(informationMessage.getMessage());
            break;
        default:
        }

    }

    //    public static RichImage createImageIcon(String path)
    //    {
    //        try
    //        {
    //            return ResourceHelper.createImageIcon(path);
    //        }
    //        catch (Exception exc)
    //        {
    //            return null;
    //        }
    //    }
}
