use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.
the class ChildrenJSONGenerator method writeLayoutContainer.
public static void writeLayoutContainer(JSONWriter writer, LayoutContainer layoutContainer, WebFormUI formUI, boolean designer) {
WebLayoutSpecification spec = null;
if (layoutContainer.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(layoutContainer.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(layoutContainer.getSpecName());
}
}
writer.key("layout");
writer.value(true);
writer.key("cssPositionContainer");
writer.value(CSSPositionUtils.isCSSPositionContainer(layoutContainer));
String tagType = layoutContainer.getTagType();
if (spec != null && spec.getDirectives().size() > 0) {
tagType = spec.getName();
}
if (!"div".equals(tagType)) {
writer.key("tagname");
writer.value("svyResponsive" + tagType);
}
String styleClasses = layoutContainer.getCssClasses();
if (styleClasses != null) {
writer.key("styleclass");
String[] classes = styleClasses.split(" ");
writer.array();
for (String cls : classes) {
writer.value(cls);
}
writer.endArray();
}
Map<String, String> attributes = new HashMap<String, String>(layoutContainer.getMergedAttributes());
if (spec != null) {
for (String propertyName : spec.getAllPropertiesNames()) {
PropertyDescription pd = spec.getProperty(propertyName);
if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
attributes.put(propertyName, pd.getDefaultValue().toString());
}
}
}
if (formUI != null && layoutContainer.getName() != null) {
attributes.put("name", formUI.getName() + "." + layoutContainer.getName());
}
if (designer) {
attributes.put("svy-id", layoutContainer.getUUID().toString());
if (spec != null) {
attributes.put("svy-layoutname", spec.getPackageName() + "." + spec.getName());
String solutionStyleClasses = FormLayoutStructureGenerator.getSolutionSpecificClasses(spec, layoutContainer);
if (solutionStyleClasses != null && !solutionStyleClasses.isEmpty()) {
attributes.put("svy-solution-layout-class", solutionStyleClasses);
}
}
if (layoutContainer.getName() != null) {
attributes.put("svy-name", layoutContainer.getName());
}
attributes.put("svy-priority", String.valueOf(layoutContainer.getLocation().x));
String designClass = spec.getDesignStyleClass() != null && spec.getDesignStyleClass().length() > 0 ? spec.getDesignStyleClass() : "customDivDesign";
if ("customDivDesign".equals(designClass) && FormLayoutStructureGenerator.hasSameDesignClassAsParent(layoutContainer, spec)) {
designClass = FormLayoutStructureGenerator.isEvenLayoutContainer(layoutContainer) ? "customDivDesignOdd" : "customDivDesignEven";
}
attributes.put("designclass", designClass);
attributes.put("svy-title", FormLayoutStructureGenerator.getLayouContainerTitle(layoutContainer));
}
writer.key("attributes");
writer.object();
attributes.remove("class");
attributes.forEach((key, value) -> {
writer.key(key);
writer.value(value);
});
writer.endObject();
}
use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.
the class ContainersScope method fillNames.
private static void fillNames(Iterator<LayoutContainer> iterator, Map<String, List<String>> namesToLayout, FlattenedSolution fs) {
while (iterator.hasNext()) {
LayoutContainer lc = iterator.next();
if (lc.getName() != null) {
WebLayoutSpecification spec = null;
if (lc.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(lc.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(lc.getSpecName());
}
}
if (spec != null) {
List<String> styleClassValues = new ArrayList<String>();
String cssClasses = lc.getCssClasses();
if (cssClasses != null) {
styleClassValues.addAll(Arrays.asList(cssClasses.split(" ")));
}
namesToLayout.put(lc.getName(), styleClassValues);
} else {
Debug.warn("Couldn't register form container '" + lc.getName() + "' to the 'containers' because spec '" + lc.getPackageName() + "' not found");
}
}
fillNames(lc.getLayoutContainers(), namesToLayout, fs);
findFormComponentContainers(lc.getWebComponents(), namesToLayout, fs);
}
}
use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.
the class FormLayoutStructureGenerator method generateLayoutContainer.
public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, DesignProperties design, IFormElementCache cache) {
WebLayoutSpecification spec = null;
if (container.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(container.getSpecName());
}
}
boolean isCSSPositionContainer = CSSPositionUtils.isCSSPositionContainer(spec);
writer.print("<");
writer.print(container.getTagType());
Set<String> writtenAttributes = new HashSet<>();
if (design != null) {
writer.print(" svy-id='");
writer.print(container.getUUID().toString());
writer.print("'");
writer.print(" svy-location='");
writer.print(container.getLocation().x);
writer.print("'");
boolean highSet = false;
JSONObject ngClass = new JSONObject();
String layoutStyleClasses = "";
String solutionStyleClasses = "";
if (spec != null) {
writer.print(" svy-layoutname='");
writer.print(spec.getPackageName() + "." + spec.getName());
writer.print("'");
ngClass.put("svy-layoutcontainer", true);
if (// is this inherited?
!(container.getAncestor(IRepository.FORMS).getID() == form.getID())) {
ngClass.put("inheritedElement", true);
}
String designClass = spec.getDesignStyleClass() != null && spec.getDesignStyleClass().length() > 0 ? spec.getDesignStyleClass() : "customDivDesign";
if ("customDivDesign".equals(designClass) && hasSameDesignClassAsParent(container, spec)) {
designClass = isEvenLayoutContainer(container) ? "customDivDesignOdd" : "customDivDesignEven";
}
highSet = true;
if (design.mainContainer != container.getID()) {
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put(designClass, "<showWireframe<");
} else {
writer.print(" data-maincontainer='true'");
ngClass.put(designClass, "<false<");
}
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
List<String> containerStyleClasses = getStyleClassValues(spec, container.getCssClasses());
solutionStyleClasses = getSolutionSpecificClasses(spec, container);
if (!containerStyleClasses.isEmpty()) {
layoutStyleClasses = containerStyleClasses.stream().collect(Collectors.joining(" "));
writer.print(" class='" + layoutStyleClasses + "'");
}
if (container.getCssClasses() != null && container.getCssClasses().trim().length() > 0) {
writtenAttributes.add("class");
}
if (spec.getAllowedChildren().size() > 0 || spec.getExcludedChildren() != null) {
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("drop_highlight", "<canContainDraggedElement('" + spec.getPackageName() + "." + spec.getName() + "')<");
}
}
if (!highSet)
ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
if (ngClass.length() > 0) {
writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
}
if (writtenAttributes.contains("class")) {
writer.print(" svy-layout-class='" + layoutStyleClasses + "'");
writer.print(" svy-solution-layout-class='" + solutionStyleClasses + "'");
}
writer.print(" svy-title='" + getLayouContainerTitle(container) + "'");
}
if (container.getName() != null) {
writer.print(" svy-name='");
writer.print(container.getName());
writer.print("' ");
}
if (container.getElementId() != null) {
writer.print(" id='");
writer.print(container.getElementId());
writer.print("' ");
}
writer.print(" svy-autosave ");
if (isCSSPositionContainer) {
// we need to specify the height
writer.print(" style='height:");
writer.print(container.getSize().height);
writer.print("px;position: relative;' ");
}
Map<String, String> attributes = new HashMap<String, String>(container.getMergedAttributes());
if (spec != null) {
for (String propertyName : spec.getAllPropertiesNames()) {
PropertyDescription pd = spec.getProperty(propertyName);
if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
attributes.put(propertyName, pd.getDefaultValue().toString());
}
}
}
String classes = attributes.get("class");
if (classes == null)
classes = "svy-layoutcontainer";
else
classes += " svy-layoutcontainer";
attributes.put("class", classes);
for (Entry<String, String> entry : attributes.entrySet()) {
if (design != null && writtenAttributes.contains(entry.getKey()))
continue;
writer.print(" ");
try {
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
if (entry.getValue() != null && entry.getValue().length() > 0) {
writer.print("=\"");
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
writer.print("\"");
}
} catch (IOException e) {
Debug.error(e);
}
}
writer.print(">");
Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, cache);
} else if (component instanceof IFormElement) {
FormElement fe = cache.getFormElement((IFormElement) component, fs, null, design != null);
if (!isSecurityVisible(fs, fe.getPersistIfAvailable(), form)) {
continue;
}
if (isCSSPositionContainer) {
FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, false);
}
FormLayoutGenerator.generateFormElement(writer, fe, form);
if (isCSSPositionContainer) {
FormLayoutGenerator.generateEndDiv(writer);
}
}
}
writer.print("</");
writer.print(container.getTagType());
writer.print(">");
}
use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.
the class JSBaseContainer method createLayoutContainer.
protected JSLayoutContainer createLayoutContainer(int x, int y, String spec, JSONObject config) {
checkModification();
try {
AbstractContainer container = getContainer();
Form form = (Form) container.getAncestor(IRepository.FORMS);
if (form.isResponsiveLayout()) {
String packageName = null;
String specName = null;
if (spec != null) {
String[] split = spec.split("-");
if (split.length == 1) {
specName = spec.trim();
} else if (split.length == 2) {
specName = split[1].trim();
packageName = split[0].trim();
} else {
Debug.warn("Illegal spec given: " + spec);
}
}
if (specName == null || packageName == null) {
if (container instanceof LayoutContainer) {
LayoutContainer parent = (LayoutContainer) (getContainer());
packageName = parent.getPackageName();
if (specName == null && parent.getAllowedChildren() != null && !parent.getAllowedChildren().isEmpty()) {
specName = parent.getAllowedChildren().get(0);
if (specName.contains("."))
specName = specName.split("\\.")[1];
}
}
}
if (specName == null) {
// the parent container could be a layout container or the form
// check if we have a sibling of the container we want to create
LayoutContainer sibling = container.getLayoutContainers().hasNext() ? container.getLayoutContainers().next() : null;
if (sibling != null) {
packageName = sibling.getPackageName();
specName = sibling.getSpecName();
}
}
LayoutContainer layoutContainer = getContainer().createNewLayoutContainer();
layoutContainer.setLocation(new Point(x, y));
layoutContainer.setPackageName(packageName);
layoutContainer.setSpecName(specName);
JSLayoutContainer jsLayoutContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer(this, layoutContainer);
JSONObject conf = config;
if (config == null) {
Map<String, PackageSpecification<WebLayoutSpecification>> layoutSpecifications = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications();
if (packageName != null && specName != null && layoutSpecifications != null && layoutSpecifications.get(packageName) != null) {
WebLayoutSpecification layoutSpec = layoutSpecifications.get(packageName).getSpecification(specName);
if (layoutSpec != null && (layoutSpec.getConfig() instanceof JSONObject || layoutSpec.getConfig() instanceof String)) {
conf = layoutSpec.getConfig() instanceof String ? new JSONObject((String) layoutSpec.getConfig()) : ((JSONObject) layoutSpec.getConfig());
}
}
}
return configLayoutContainer(jsLayoutContainer, layoutContainer, conf);
} else {
// check if form was just created with the solution model and suggest correct method to use
if (application.getFlattenedSolution().getSolutionCopy().getAllObjectsAsList().contains(form) && !application.getSolution().getAllObjectsAsList().contains(form)) {
throw new RuntimeException("Form " + form.getName() + " is not a responsive form, cannot add a layout container on it. Please use solutionModel.newForm('" + form.getName() + "',true) to create a responsive form.");
}
throw new RuntimeException("Form " + form.getName() + " is not responsive, cannot add a layout container on it. Please use a responsive form or create a responsive form with solutionModel.newForm(formName, true);");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.
the class DesignFormLayoutStructureGenerator method generateLayoutContainer.
public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, int nested) {
WebLayoutSpecification spec = null;
if (container.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(container.getSpecName());
}
}
writer.print("<");
writer.print(container.getTagType());
if (container.getName() != null) {
writer.print(" svy-name='");
writer.print(container.getName());
writer.print("' ");
}
if (container.getElementId() != null) {
writer.print(" id='");
writer.print(container.getElementId());
writer.print("' ");
}
Map<String, String> attributes = new HashMap<String, String>(container.getMergedAttributes());
if (spec != null) {
for (String propertyName : spec.getAllPropertiesNames()) {
PropertyDescription pd = spec.getProperty(propertyName);
if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
attributes.put(propertyName, pd.getDefaultValue().toString());
}
}
}
for (Entry<String, String> entry : attributes.entrySet()) {
writer.print(" ");
try {
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
if (entry.getValue() != null && entry.getValue().length() > 0) {
writer.print("=\"");
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
writer.print("\"");
}
} catch (IOException e) {
Debug.error(e);
}
}
writer.print(" svy-id='");
writer.print(container.getID());
writer.print("'");
writer.print(">\n");
Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
int count = 0;
while (count++ < nested) {
writer.print('\t');
}
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, nested + 1);
} else if (component instanceof IFormElement) {
generateFormElement(writer, (IFormElement) component, form, fs);
}
}
int count = 1;
while (count++ < nested) {
writer.print('\t');
}
writer.print("</");
writer.print(container.getTagType());
writer.print(">\n");
}
Aggregations