blob: 69b2ac59184d52014bd791fb74fa87851a51576f [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.internal.data;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.eclipse.osbp.runtime.common.i18n.I18nUtil;
import org.eclipse.osbp.runtime.common.i18n.II18nService;
// TODO: Auto-generated Javadoc
/**
* The Class EnumOptionBeanHelper.
*/
public class EnumOptionBeanHelper {
/**
* Creates a list of enum options for the given enum. The services are used for internationalization und to find a proper image for the enum literal. Services and locale may be
* <code>null</code>.
*
* @param enumClass
* the enum class
* @param i18nService
* the i18n service
* @param locale
* the locale
* @return the beans
*/
public static List<EnumOptionBean> getBeans(Class<? extends Enum<?>> enumClass, II18nService i18nService, Locale locale) {
// String enumName = enumClass.getCanonicalName();
String enumName = enumClass.getSimpleName();
List<EnumOptionBean> result = new ArrayList<EnumOptionBean>();
for (Enum<?> literal : enumClass.getEnumConstants()) {
String description = literal.name();
if (i18nService != null) {
// String temp = i18nService.getValue(I18nUtil.getI18nKey(enumName, literal), locale);
String temp = i18nService.getValue(literal.name(), locale);
if (temp != null && !temp.equals("")) {
description = temp;
}
}
String imagePath = null;
if (i18nService != null) {
// imagePath = i18nService.getValue(I18nUtil.getImageI18nKey(enumName, literal), locale);
imagePath = I18nUtil.getImageI18nKey(enumName, literal);
}
result.add(new EnumOptionBean(literal, description, imagePath));
}
return result;
}
}