
package de.ivu.elect.presentation.konfiguration.table;

import static org.apache.commons.lang3.StringUtils.abbreviate;
import static org.apache.commons.lang3.StringUtils.length;

import java.util.Locale;

import de.ivu.elect.business.konfiguration.entity.CustomParameter;
import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.presentation.dynamictable.ColumnType;
import de.ivu.elect.presentation.table.DefaultColumnEntry;

public class CustomParameterWertColumn<E extends CustomParameter< ? >> extends DefaultColumnEntry<E> {

  private static final long serialVersionUID = 1L;

  private static final int DISPLAY_VALUE_MAX_LENGTH = 200;

  public CustomParameterWertColumn(Messages messages, Locale locale) {
    super("CustomParameter-Wert", messages, "custom.parameter.wert", ColumnType.STRING, parameter -> {
      String result = "";

      if ((parameter) != null) {
        result = parameter.getColumnDisplayValue(messages, locale);
      }

      return abbreviate(result, DISPLAY_VALUE_MAX_LENGTH);
    });
  }

  @Override
  public String getTooltip(E parameter) {
    if ((parameter) != null && length(parameter.getWert()) > DISPLAY_VALUE_MAX_LENGTH) {
      return parameter.getWert();
    }

    return super.getTooltip(parameter);
  }
}
