<commit_before>package br.net.mirante.singular.showcase.view.page.prototype;

import br.net.mirante.singular.form.mform.*;
import br.net.mirante.singular.form.mform.basic.view.MListMasterDetailView;
import br.net.mirante.singular.form.mform.core.AtrCore;
import br.net.mirante.singular.form.mform.core.STypeBoolean;
import br.net.mirante.singular.form.mform.core.STypeData;
import br.net.mirante.singular.form.mform.core.STypeDataHora;
import br.net.mirante.singular.form.mform.core.STypeDecimal;
import br.net.mirante.singular.form.mform.core.STypeFormula;
import br.net.mirante.singular.form.mform.core.STypeInteger;
import br.net.mirante.singular.form.mform.core.STypeLatitudeLongitude;
import br.net.mirante.singular.form.mform.core.STypeMonetario;
import br.net.mirante.singular.form.mform.core.STypeString;
import br.net.mirante.singular.form.mform.options.MFixedOptionsSimpleProvider;
import br.net.mirante.singular.form.mform.util.comuns.STypeAnoMes;
import br.net.mirante.singular.form.mform.util.comuns.STypeCEP;
import br.net.mirante.singular.form.mform.util.comuns.STypeCNPJ;
import br.net.mirante.singular.form.mform.util.comuns.STypeCPF;
import br.net.mirante.singular.form.mform.util.comuns.STypeEMail;
import br.net.mirante.singular.form.mform.util.comuns.STypeNomePessoa;
import br.net.mirante.singular.form.mform.util.comuns.STypeTelefoneNacional;

import java.util.Optional;
import java.util.function.Predicate;

import static com.google.common.collect.Lists.newArrayList;

/**
 * Created by nuk on 07/03/16.
 */
public class SPackagePrototype extends SPackage {

    public static final String PACOTE = "mform.prototype",
            META_FORM = "MetaForm",
            META_FORM_COMPLETE = PACOTE + "." + META_FORM,
            CHILDREN = "children",
            NAME = "name",
            TYPE = "type",
            IS_LIST = "isList",
            TAMANHO_CAMPO = "tamanhoCampo",
            OBRIGATORIO = "obrigatorio",
            TAMANHO_MAXIMO = "tamanhoMaximo",
            TAMANHO_INTEIRO_MAXIMO = "tamanhoInteiroMaximo",
            TAMANHO_DECIMAL_MAXIMO = "tamanhoDecimalMaximo",
            FIELDS = "fields";
    public static final String NAME_FIELD = "name";

    private STypeInteger tamanhoCampo;
    private STypeBoolean obrigatorio;

    public SPackagePrototype() {
        super(PACOTE);
    }

    @Override
    protected void carregarDefinicoes(PackageBuilder pb) {
        final STypeComposite<?> meta = pb.createTipoComposto(META_FORM);
        meta.addCampoString(NAME_FIELD).asAtrBasic().label("Nome")
                .as(AtrCore::new).obrigatorio();

        STypeLista<STypeComposite<SIComposite>, SIComposite> childFields =
                meta.addCampoListaOfComposto(CHILDREN, "field");

        childFields.asAtrBasic().label("Campos");

        STypeComposite<SIComposite> fieldType = childFields.getTipoElementos();

        STypeString nome = fieldType.addCampoString(NAME);
        nome.asAtrBasic().label("Nome")
                .as(AtrCore::new).obrigatorio()
                .getTipo().asAtrBootstrap().colPreference(4);

        STypeString type = fieldType.addCampoString(TYPE);
        type.asAtrBasic().label("Tipo")
                .getTipo().asAtrCore().obrigatorio()
                .getTipo().asAtrBootstrap().colPreference(2);
        populateOptions(pb, type.withSelection());

        fieldType.addCampoBoolean(IS_LIST)
                .asAtrBasic().label("Múltiplo")
                .getTipo().asAtrBootstrap().colPreference(1);

        addAttributeFields(pb, fieldType, type);

        childFields.withView(new MListMasterDetailView()
                .col(nome)
                .col(type)
                .col(tamanhoCampo)
                .col(obrigatorio)
        );

        addFields(pb, fieldType, type);

    }

    private void populateOptions(PackageBuilder pb, MFixedOptionsSimpleProvider provider) {
        provider.add(typeName(pb, STypeAnoMes.class), "Ano/Mês");
        provider.add(typeName(pb, STypeBoolean.class), "Booleano");
        provider.add(typeName(pb, STypeComposite.class), "Composto");
        provider.add(typeName(pb, STypeCEP.class), "CEP");
        provider.add(typeName(pb, STypeCPF.class), "CPF");
        provider.add(typeName(pb, STypeCNPJ.class), "CNPJ");
        provider.add(typeName(pb, STypeData.class), "Data");
        provider.add(typeName(pb, STypeDataHora.class), "Data/Hora");
        provider.add(typeName(pb, STypeEMail.class), "Email");
        provider.add(typeName(pb, STypeFormula.class), "Formula");
        provider.add(typeName(pb, STypeLatitudeLongitude.class), "Latitude/Longitude");
        provider.add(typeName(pb, STypeMonetario.class), "Monetário");
        provider.add(typeName(pb, STypeNomePessoa.class), "Nome Pessoa");
        provider.add(typeName(pb, STypeInteger.class), "Número");
        provider.add(typeName(pb, STypeDecimal.class), "Número Decimal");
        provider.add(typeName(pb, STypeString.class), "Texto");
        provider.add(typeName(pb, STypeTelefoneNacional.class), "Telefone Nacional");
    }

    private String typeName(PackageBuilder pb, Class<? extends SType> typeClass) {
        return pb.getDicionario().getType(typeClass).getName();
    }

    private void addAttributeFields(PackageBuilder pb, STypeComposite<SIComposite> fieldType, STypeString type) {
        tamanhoCampo = fieldType.addCampoInteger(TAMANHO_CAMPO);
        tamanhoCampo.asAtrBasic().label("Tamanho do Campo").tamanhoMaximo(12)
                .getTipo().asAtrBootstrap().colPreference(3);

        obrigatorio = fieldType.addCampoBoolean(OBRIGATORIO);
        obrigatorio.withRadioView()
                .asAtrBasic().label("Obrigatório")
                .getTipo().asAtrBootstrap().colPreference(1);

        fieldType.addCampoInteger(TAMANHO_MAXIMO)
                .asAtrBootstrap().colPreference(2)
                .getTipo().asAtrBasic().label("Tamanho Máximo")
                .visivel(
                        (instance) -> {
                            Optional<String> optType = instance.findNearestValue(type, String.class);
                            if (!optType.isPresent()) return false;<commit_msg>Inclusão do tipo anexo, remoção do tipo formula.<commit_after>package br.net.mirante.singular.showcase.view.page.prototype;

import br.net.mirante.singular.form.mform.*;
import br.net.mirante.singular.form.mform.basic.view.MListMasterDetailView;
import br.net.mirante.singular.form.mform.core.AtrCore;
import br.net.mirante.singular.form.mform.core.STypeBoolean;
import br.net.mirante.singular.form.mform.core.STypeData;
import br.net.mirante.singular.form.mform.core.STypeDataHora;
import br.net.mirante.singular.form.mform.core.STypeDecimal;
import br.net.mirante.singular.form.mform.core.STypeFormula;
import br.net.mirante.singular.form.mform.core.STypeInteger;
import br.net.mirante.singular.form.mform.core.STypeLatitudeLongitude;
import br.net.mirante.singular.form.mform.core.STypeMonetario;
import br.net.mirante.singular.form.mform.core.STypeString;
import br.net.mirante.singular.form.mform.core.attachment.STypeAttachment;
import br.net.mirante.singular.form.mform.options.MFixedOptionsSimpleProvider;
import br.net.mirante.singular.form.mform.util.comuns.STypeAnoMes;
import br.net.mirante.singular.form.mform.util.comuns.STypeCEP;
import br.net.mirante.singular.form.mform.util.comuns.STypeCNPJ;
import br.net.mirante.singular.form.mform.util.comuns.STypeCPF;
import br.net.mirante.singular.form.mform.util.comuns.STypeEMail;
import br.net.mirante.singular.form.mform.util.comuns.STypeNomePessoa;
import br.net.mirante.singular.form.mform.util.comuns.STypeTelefoneNacional;

import java.util.Optional;
import java.util.function.Predicate;

import static com.google.common.collect.Lists.newArrayList;

/**
 * Created by nuk on 07/03/16.
 */
public class SPackagePrototype extends SPackage {

    public static final String PACOTE = "mform.prototype",
            META_FORM = "MetaForm",
            META_FORM_COMPLETE = PACOTE + "." + META_FORM,
            CHILDREN = "children",
            NAME = "name",
            TYPE = "type",
            IS_LIST = "isList",
            TAMANHO_CAMPO = "tamanhoCampo",
            OBRIGATORIO = "obrigatorio",
            TAMANHO_MAXIMO = "tamanhoMaximo",
            TAMANHO_INTEIRO_MAXIMO = "tamanhoInteiroMaximo",
            TAMANHO_DECIMAL_MAXIMO = "tamanhoDecimalMaximo",
            FIELDS = "fields";
    public static final String NAME_FIELD = "name";

    private STypeInteger tamanhoCampo;
    private STypeBoolean obrigatorio;

    public SPackagePrototype() {
        super(PACOTE);
    }

    @Override
    protected void carregarDefinicoes(PackageBuilder pb) {
        final STypeComposite<?> meta = pb.createTipoComposto(META_FORM);
        meta.addCampoString(NAME_FIELD).asAtrBasic().label("Nome")
                .as(AtrCore::new).obrigatorio();

        STypeLista<STypeComposite<SIComposite>, SIComposite> childFields =
                meta.addCampoListaOfComposto(CHILDREN, "field");

        childFields.asAtrBasic().label("Campos");

        STypeComposite<SIComposite> fieldType = childFields.getTipoElementos();

        STypeString nome = fieldType.addCampoString(NAME);
        nome.asAtrBasic().label("Nome")
                .as(AtrCore::new).obrigatorio()
                .getTipo().asAtrBootstrap().colPreference(4);

        STypeString type = fieldType.addCampoString(TYPE);
        type.asAtrBasic().label("Tipo")
                .getTipo().asAtrCore().obrigatorio()
                .getTipo().asAtrBootstrap().colPreference(2);
        populateOptions(pb, type.withSelection());

        fieldType.addCampoBoolean(IS_LIST)
                .asAtrBasic().label("Múltiplo")
                .getTipo().asAtrBootstrap().colPreference(1);

        addAttributeFields(pb, fieldType, type);

        childFields.withView(new MListMasterDetailView()
                .col(nome)
                .col(type)
                .col(tamanhoCampo)
                .col(obrigatorio)
        );

        addFields(pb, fieldType, type);

    }

    private void populateOptions(PackageBuilder pb, MFixedOptionsSimpleProvider provider) {
        provider.add(typeName(pb, STypeAttachment.class), "Anexo");
        provider.add(typeName(pb, STypeAnoMes.class), "Ano/Mês");
        provider.add(typeName(pb, STypeBoolean.class), "Booleano");
        provider.add(typeName(pb, STypeComposite.class), "Composto");
        provider.add(typeName(pb, STypeCEP.class), "CEP");
        provider.add(typeName(pb, STypeCPF.class), "CPF");
        provider.add(typeName(pb, STypeCNPJ.class), "CNPJ");
        provider.add(typeName(pb, STypeData.class), "Data");
        provider.add(typeName(pb, STypeDataHora.class), "Data/Hora");
        provider.add(typeName(pb, STypeEMail.class), "Email");
        provider.add(typeName(pb, STypeLatitudeLongitude.class), "Latitude/Longitude");
        provider.add(typeName(pb, STypeMonetario.class), "Monetário");
        provider.add(typeName(pb, STypeNomePessoa.class), "Nome Pessoa");
        provider.add(typeName(pb, STypeInteger.class), "Número");
        provider.add(typeName(pb, STypeDecimal.class), "Número Decimal");
        provider.add(typeName(pb, STypeString.class), "Texto");
        provider.add(typeName(pb, STypeTelefoneNacional.class), "Telefone Nacional");
    }

    private String typeName(PackageBuilder pb, Class<? extends SType> typeClass) {
        return pb.getDicionario().getType(typeClass).getName();
    }

    private void addAttributeFields(PackageBuilder pb, STypeComposite<SIComposite> fieldType, STypeString type) {
        tamanhoCampo = fieldType.addCampoInteger(TAMANHO_CAMPO);
        tamanhoCampo.asAtrBasic().label("Tamanho do Campo").tamanhoMaximo(12)
                .getTipo().asAtrBootstrap().colPreference(3);

        obrigatorio = fieldType.addCampoBoolean(OBRIGATORIO);
        obrigatorio.withRadioView()
                .asAtrBasic().label("Obrigatório")
                .getTipo().asAtrBootstrap().colPreference(1);

        fieldType.addCampoInteger(TAMANHO_MAXIMO)
                .asAtrBootstrap().colPreference(2)
                .getTipo().asAtrBasic().label("Tamanho Máximo")
                .visivel(
                        (instance) -> {
                            Optional<String> optType = instance.findNearestValue(type, String.class);
                            if (!optType.isPresent()) return false;
{'fraction_non_alphanumeric': 0.12436609514609998, 'fraction_numerical': 0.0022538839249778638, 'mean_word_length': 3.178943827783384, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '989009', 'n_tokens_mistral': 4201, 'n_tokens_neox': 4067, 'n_words': 522}