Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
de.knightsoftnet.gwtp.spring.annotation.processor.BackofficeUiBinderCreator Maven / Gradle / Ivy
package de.knightsoftnet.gwtp.spring.annotation.processor;
import de.knightsoftnet.gwtp.spring.client.annotation.BackofficeClientGenerator;
import de.knightsoftnet.validators.shared.data.FieldTypeEnum;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
/**
* Create localization property file.
*/
public class BackofficeUiBinderCreator
extends AbstractBackofficeCreator {
protected static final String CLASS_EXTENSION = ".ui.xml";
protected static final List> GRID_COLUMNS = List.of(
List.of(11, 1), //
List.of(6, 5, 1), //
List.of(4, 4, 3, 1), //
List.of(3, 3, 3, 2, 1), //
List.of(4, 4, 4, 4, 7, 1), //
List.of(4, 4, 4, 4, 4, 3, 1), //
List.of(3, 3, 3, 3, 3, 3, 5, 1), //
List.of(3, 3, 3, 3, 3, 3, 3, 2, 1), //
List.of(3, 3, 3, 3, 3, 3, 3, 3, 11, 1), //
List.of(3, 3, 3, 3, 3, 3, 3, 3, 3, 8, 1), //
List.of(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 1), //
List.of(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1)
);
public BackofficeUiBinderCreator() {
super(CLASS_SUFFIX_VIEW + CLASS_EXTENSION);
}
/**
* write ui binder file.
*/
public void writeUiBinder(final Element element, final BackofficeClientGenerator generator,
final ProcessingEnvironment processingEnv) {
final String serverPackage = detectPackage(element, processingEnv);
final String resourceName = getEntityNameOfElement(element) + suffix;
try {
final FileObject builderFile = processingEnv.getFiler()
.createResource(StandardLocation.SOURCE_OUTPUT, serverPackage, resourceName);
try (PrintWriter out = new PrintWriter(builderFile.openWriter())) {
writeUiBinder(out, element, generator, serverPackage, processingEnv);
}
} catch (final IOException e) {
e.printStackTrace();
}
}
private void writeUiBinder(final PrintWriter out, final Element element,
final BackofficeClientGenerator generator, final String serverPackage,
final ProcessingEnvironment processingEnv) throws IOException {
final String entityName = getEntityNameOfElement(element);
final List widgets =
detectBackofficeWidgetsOfElement("", null, element, processingEnv, true);
writeXmlHeader(out, generator, serverPackage, entityName, widgets);
writeXmlTokenImports(out, serverPackage, entityName);
out.print(" ");
writeXmlAdminNavigation(out, generator);
writeXmlFieldWidgets(out, generator, widgets, serverPackage, entityName, StringUtils.EMPTY,
true, processingEnv);
out.println(" ");
out.println("");
}
private void writeEmbeddedUiBinder(final BackofficeWidget widget,
final BackofficeClientGenerator generator, final String serverPackage,
final String entityName, final String prefix, final ProcessingEnvironment processingEnv)
throws IOException {
final List widgets = widget.getChildWidgets();
final FileObject builderFile = processingEnv.getFiler().createResource(
StandardLocation.SOURCE_OUTPUT, serverPackage, widget.getWidgetName() + CLASS_EXTENSION);
try (PrintWriter out = new PrintWriter(builderFile.openWriter())) {
writeXmlHeader(out, generator, serverPackage, entityName, widgets);
out.println(" ");
writeXmlFieldWidgets(out, generator, widgets, serverPackage, entityName, prefix, false,
processingEnv);
out.println(" ");
out.println("");
}
}
private void writeXmlFieldWidgets(final PrintWriter out,
final BackofficeClientGenerator generator, final List widgets,
final String serverPackage, final String entityName, final String prefix,
final boolean autofocusHandling, final ProcessingEnvironment processingEnv)
throws IOException {
boolean divOpen = false;
boolean autofocusSet = !autofocusHandling;
boolean idExists = false;
int widgetsInLine = 2;
for (final BackofficeWidget widget : widgets) {
if (!widget.isIgnore()) {
if (widgetsInLine >= 2 || widget.getFieldType() == FieldTypeEnum.EMBEDED
|| widget.getFieldType() == FieldTypeEnum.ONE_TO_MANY) {
if (divOpen) {
out.println("