Example usage for org.apache.wicket.util.string Strings defaultIfEmpty

List of usage examples for org.apache.wicket.util.string Strings defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String originalString, String defaultValue) 

Source Link

Document

Returns the original string if this one is not empty (i.e.

Usage

From source file:org.opensingular.form.wicket.WicketBuildContext.java

License:Apache License

/**
 * Calcula o caminho completo de labels do campo, concatenando os nomes separados por ' > ',
 * para ser usado em mensagens de erro.//w w  w  .j  a  va2  s.  co m
 * Exemplo: "O campo 'Contato > Endereos > Endereo > Logradouro'  obrigatrio"
 */
protected static String resolveFullPathLabel(FormComponent<?> formComponent) {
    IModel<?> model = formComponent.getModel();
    if (model instanceof ISInstanceAwareModel<?>) {
        SInstance instancia = ((ISInstanceAwareModel<?>) model).getSInstance();
        List<String> labels = new ArrayList<>();
        while (instancia != null) {
            labels.add(instancia.asAtr().getLabel());
            instancia = instancia.getParent();
        }
        labels.removeIf(it -> Strings.defaultIfEmpty(it, "").trim().isEmpty());
        Collections.reverse(labels);
        if (!labels.isEmpty())
            return Strings.join(" > ", labels);
    }
    return "[" + formComponent.getId() + "]";
}