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

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

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.apt.generate;

import br.com.jarch.util.FileUtils;
import br.com.jarch.util.LogUtils;
import br.com.jarch.util.ProcessorUtils;

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

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

public final class ListXhtmlCodeGenerate {

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

    public 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 void create(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/templateListaV2.xhtml\">");
        addCode(listXhtml, "\t<ui:define name=\"panelBodyTemplateLista\">");
        addCode(listXhtml, "\t\t<e:form>");
        addCode(listXhtml, "\t\t\t<e:divTitle");
        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:divListFilter");
        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:divListDatatable 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</e: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>