All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.apt.generate.ListXhtmlCodeGenerate Maven / Gradle / Ivy

The newest version!
package br.com.jarch.apt.generate;

import br.com.jarch.core.annotation.JArchGenerateCrud;
import br.com.jarch.util.FileUtils;
import br.com.jarch.util.LogUtils;
import br.com.jarch.apt.util.ProcessorUtils;

import javax.lang.model.element.Element;
import java.io.File;
import java.io.IOException;

import static br.com.jarch.apt.util.ProcessorUtils.addCode;

public final class ListXhtmlCodeGenerate {

    private final Element element;
    private final File fileListXhtml;
    private final File fileListaXhtml;
    private final String nomeSemCaracterEspecial;
    private final String nomeSemCaracterEspecialMinusculo;

    private ListXhtmlCodeGenerate(Element element, String name, String nameSubPackage) {
        this.element = element;
        nomeSemCaracterEspecial = ProcessorUtils.getNameWithoutCharEspecialCapitalize(name);
        nomeSemCaracterEspecialMinusculo = ProcessorUtils.getNameWithoutCharEspecialStartLowerCase(name);

        File folder = new File(ProcessorUtils.getPathPage(element, nameSubPackage));

        if (!folder.exists()) {
            folder.mkdir();
        }

        fileListXhtml = new File(ProcessorUtils.getPathPage(element, nameSubPackage) + nomeSemCaracterEspecialMinusculo  + "List.xhtml");
        fileListaXhtml = new File(ProcessorUtils.getPathPage(element, nameSubPackage) + "lista" + nomeSemCaracterEspecial  + ".xhtml");
    }

    public static void generate(Element element, JArchGenerateCrud generateCrud) {
        new ListXhtmlCodeGenerate(element, generateCrud.master().name(), generateCrud.nameSubPackage())
                .generate(generateCrud.allowInsert(), generateCrud.allowClone(), generateCrud.allowChange(),
                        generateCrud.allowDelete());
    }

    private void generate(boolean allowInsert, boolean allowClone, boolean allowChange, boolean allowDelete) {
        if (ProcessorUtils.isFileExistsClientOrWebOrWs(fileListXhtml) || ProcessorUtils.isFileExistsClientOrWebOrWs(fileListaXhtml)) {
            return;
        }

        StringBuilder listXhtml = new StringBuilder();
        addCode(listXhtml, "");
        addCode(listXhtml, "");
        addCode(listXhtml, "\t");
        addCode(listXhtml, "\t\t");
        addCode(listXhtml, "\t</h:head>");
        addCode(listXhtml, "<ui:composition template=\"/paginas/templates/templateList.xhtml\">");
        addCode(listXhtml, "\t<ui:define name=\"panelBodyTemplateLista\">");
        addCode(listXhtml, "\t\t<h:form>");
        addCode(listXhtml, "\t\t\t<e:panelTitle");
        addCode(listXhtml, "\t\t\t\ttitle=\"#{e:bundle('label.lista')} - #{e:bundle('label." + nomeSemCaracterEspecialMinusculo + "')}\"");
        addCode(listXhtml, "\t\t\t\tdescription=\"#{e:bundle('label.manter')} #{e:bundle('label." + nomeSemCaracterEspecialMinusculo + "')}\"/>");
        addCode(listXhtml, "\t\t\t<e:panelListFilter");
        addCode(listXhtml, "\t\t\t\ttitle=\"#{e:bundle('label.filtro')} - #{e:bundle('label." + nomeSemCaracterEspecialMinusculo + "')}\"");
        addCode(listXhtml, "\t\t\t\tactionList=\"#{" + nomeSemCaracterEspecialMinusculo + "ListController}\"");
//        addCode(listXhtml, "\t\t\t\tupdate=\"@form:listEntityDataTable" + nomeSemCaracterEspecial + "\"/>");
        addCode(listXhtml, "\t\t\t\tupdate=\"@(.list-datatable)\"/>");
        addCode(listXhtml, "\t\t\t<e:panelListDatatable id=\"listEntityDataTable" + nomeSemCaracterEspecial + "\"");
        addCode(listXhtml, "\t\t\t\ttitle=\"#{e:bundle('label.lista')} - #{e:bundle('label." + nomeSemCaracterEspecialMinusculo + "')}\"");
        addCode(listXhtml, "\t\t\t\tactionList=\"#{" + nomeSemCaracterEspecialMinusculo + "ListController}\" " + (allowInsert ? "" : "hideInsert=\"true\" ") +
                (allowClone ? "" : "hideClone=\"true\" ") +
                (allowChange ? "" : "hideChange=\"true\" ") +
                (allowDelete ? "" : "hideDelete=\"true\" ") +"/>");
        addCode(listXhtml, "\t\t</h:form>");
        addCode(listXhtml, "\t</ui:define>");
        addCode(listXhtml, "</ui:composition>");
        addCode(listXhtml, "</html>");

        try {
            FileUtils.save(fileListXhtml, listXhtml.toString());
            ProcessorUtils.messageNote("JARCH Created ==> " + fileListXhtml.getAbsoluteFile(), element);
        } catch (IOException e) {
            LogUtils.generate(e);
        }
    }
}
</code></pre>    <br/>
    <br/>
<div class='clear'></div>
</main>
</div>
<br/><br/>
    <div class="align-center">© 2015 - 2024 <a href="/legal-notice.php">Weber Informatics LLC</a> | <a href="/data-protection.php">Privacy Policy</a></div>
<br/><br/><br/><br/><br/><br/>
</body>
</html>