<commit_before>package br.net.mirante.singular.pet.module.wicket.view.form;

import br.net.mirante.singular.flow.core.MTransition;
import br.net.mirante.singular.form.mform.SInstance;
import br.net.mirante.singular.form.mform.context.SFormConfig;
import br.net.mirante.singular.form.mform.core.annotation.AtrAnnotation;
import br.net.mirante.singular.form.mform.core.annotation.SIAnnotation;
import br.net.mirante.singular.form.mform.document.RefType;
import br.net.mirante.singular.form.mform.io.MformPersistenciaXML;
import br.net.mirante.singular.form.util.xml.MElement;
import br.net.mirante.singular.form.wicket.component.SingularButton;
import br.net.mirante.singular.form.wicket.component.SingularSaveButton;
import br.net.mirante.singular.form.wicket.component.SingularValidationButton;
import br.net.mirante.singular.form.wicket.enums.AnnotationMode;
import br.net.mirante.singular.form.wicket.enums.ViewMode;
import br.net.mirante.singular.form.wicket.panel.SingularFormPanel;
import br.net.mirante.singular.pet.module.wicket.view.template.Content;
import br.net.mirante.singular.util.wicket.bootstrap.layout.BSContainer;
import br.net.mirante.singular.util.wicket.bootstrap.layout.TemplatePanel;
import br.net.mirante.singular.util.wicket.modal.BSModalBorder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
import java.util.Optional;

public abstract class AbstractFormContent extends Content {


    protected final BSModalBorder enviarModal = new BSModalBorder("enviar-modal", getMessage("label.title.send"));
    protected final BSModalBorder confirmarAcaoFlowModal = new BSModalBorder("flow-modal", getMessage("label.button.confirm"));
    protected final String formId;
    protected final String typeName;
    protected IModel<String> msgFlowModel = new Model<String>();
    protected IModel<String> transitionNameModel = new Model<String>();
    protected ViewMode viewMode = ViewMode.EDITION;
    protected AnnotationMode annotationMode = AnnotationMode.NONE;
    protected SingularFormPanel<String> singularFormPanel;

    @Inject
    @Named("formConfigWithDatabase")
    private SFormConfig<String> singularFormConfig;

    public AbstractFormContent(String idWicket, String type, String formId, ViewMode viewMode, AnnotationMode annotationMode) {
        super(idWicket, false, true);
        this.viewMode = viewMode;
        this.annotationMode = annotationMode;
        this.typeName = type;
        this.formId = formId;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();
        add(buildForm());
    }

    private Form<?> buildForm() {
        loadOrCreateFormModel(formId, typeName, viewMode, annotationMode);
        Form<?> form = new Form<>("save-form");
        form.setMultiPart(true);
        form.add(buildSingularBasePanel());
        form.add(buildSendButton());
        form.add(buildSaveButton());
        form.add(buildSaveAnnotationButton());
        form.add(buildFlowButtons());
        form.add(buildSaveWithoutValidateButton());
        form.add(buildValidateButton());
        form.add(buildCancelButton());
        form.add(buildConfirmationModal());
        form.add(buildFlowConfirmationModal());
        return form;
    }

    private Component buildFlowButtons() {
        BSContainer container = new BSContainer("custom-buttons");
        container.setVisible(true);
        List<MTransition> trans = currentTaskTransitions(formId);
        if (CollectionUtils.isNotEmpty(trans)) {
            int index = 0;
            for (MTransition t : trans) {
                buildFlowTransitionButton(container, t.getName(), index++);
            }
        } else {
            container.setVisible(false);
            container.setEnabled(false);
        }
        return container;
    }

    private void buildFlowTransitionButton(BSContainer container, String transitionName, Integer index) {
        String btnId = "flow-btn" + index;
        TemplatePanel tp = container
                .newTemplateTag(
                        tt -> "<button  type='submit' class='btn purple' wicket:id='" + btnId + "'>" + transitionName + "</button>");
        tp.add(new SingularButton(btnId) {

            @Override
            public IModel<? extends SInstance> getCurrentInstance() {
                return singularFormPanel.getRootInstance();
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                msgFlowModel.setObject(String.format("Tem certeza que deseja %s ?", transitionName));
                transitionNameModel.setObject(transitionName);
                confirmarAcaoFlowModal.show(target);
            }
        });
    }
<commit_msg>corrigindo layout dos botões<commit_after>package br.net.mirante.singular.pet.module.wicket.view.form;

import br.net.mirante.singular.flow.core.MTransition;
import br.net.mirante.singular.form.mform.SInstance;
import br.net.mirante.singular.form.mform.context.SFormConfig;
import br.net.mirante.singular.form.mform.core.annotation.AtrAnnotation;
import br.net.mirante.singular.form.mform.core.annotation.SIAnnotation;
import br.net.mirante.singular.form.mform.document.RefType;
import br.net.mirante.singular.form.mform.io.MformPersistenciaXML;
import br.net.mirante.singular.form.util.xml.MElement;
import br.net.mirante.singular.form.wicket.component.SingularButton;
import br.net.mirante.singular.form.wicket.component.SingularSaveButton;
import br.net.mirante.singular.form.wicket.component.SingularValidationButton;
import br.net.mirante.singular.form.wicket.enums.AnnotationMode;
import br.net.mirante.singular.form.wicket.enums.ViewMode;
import br.net.mirante.singular.form.wicket.panel.SingularFormPanel;
import br.net.mirante.singular.pet.module.wicket.view.template.Content;
import br.net.mirante.singular.util.wicket.bootstrap.layout.BSContainer;
import br.net.mirante.singular.util.wicket.bootstrap.layout.TemplatePanel;
import br.net.mirante.singular.util.wicket.modal.BSModalBorder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
import java.util.Optional;

public abstract class AbstractFormContent extends Content {


    protected final BSModalBorder enviarModal = new BSModalBorder("enviar-modal", getMessage("label.title.send"));
    protected final BSModalBorder confirmarAcaoFlowModal = new BSModalBorder("flow-modal", getMessage("label.button.confirm"));
    protected final String formId;
    protected final String typeName;
    protected IModel<String> msgFlowModel = new Model<String>();
    protected IModel<String> transitionNameModel = new Model<String>();
    protected ViewMode viewMode = ViewMode.EDITION;
    protected AnnotationMode annotationMode = AnnotationMode.NONE;
    protected SingularFormPanel<String> singularFormPanel;

    @Inject
    @Named("formConfigWithDatabase")
    private SFormConfig<String> singularFormConfig;

    public AbstractFormContent(String idWicket, String type, String formId, ViewMode viewMode, AnnotationMode annotationMode) {
        super(idWicket, false, true);
        this.viewMode = viewMode;
        this.annotationMode = annotationMode;
        this.typeName = type;
        this.formId = formId;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();
        add(buildForm());
    }

    private Form<?> buildForm() {
        loadOrCreateFormModel(formId, typeName, viewMode, annotationMode);
        Form<?> form = new Form<>("save-form");
        form.setMultiPart(true);
        form.add(buildSingularBasePanel());
        form.add(buildSendButton());
        form.add(buildSaveButton());
        form.add(buildSaveAnnotationButton());
        form.add(buildFlowButtons());
        form.add(buildSaveWithoutValidateButton());
        form.add(buildValidateButton());
        form.add(buildCancelButton());
        form.add(buildConfirmationModal());
        form.add(buildFlowConfirmationModal());
        return form;
    }

    private Component buildFlowButtons() {
        BSContainer container = new BSContainer("custom-buttons");
        container.setVisible(true);
        List<MTransition> trans = currentTaskTransitions(formId);
        if (CollectionUtils.isNotEmpty(trans)) {
            int index = 0;
            for (MTransition t : trans) {
                buildFlowTransitionButton(container, t.getName(), index++);
            }
        } else {
            container.setVisible(false);
            container.setEnabled(false);
        }
        return container;
    }

    private void buildFlowTransitionButton(BSContainer container, String transitionName, Integer index) {
        String btnId = "flow-btn" + index;
        TemplatePanel tp = container
                .newTemplateTag(
                        tt -> "<button  type='submit' class='btn purple' wicket:id='" + btnId + "'>\n" + transitionName + "\n</button>\n");
        tp.add(new SingularButton(btnId) {

            @Override
            public IModel<? extends SInstance> getCurrentInstance() {
                return singularFormPanel.getRootInstance();
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                msgFlowModel.setObject(String.format("Tem certeza que deseja %s ?", transitionName));
                transitionNameModel.setObject(transitionName);
                confirmarAcaoFlowModal.show(target);
            }
        });
    }

{'fraction_non_alphanumeric': 0.11022349025202093, 'fraction_numerical': 0.0003804089396100808, 'mean_word_length': 3.546476437527021, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1572324', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2970, 'n_words': 508}