use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormLayoutGenerator method generateFormElement.
// private static boolean canContainComponents(WebComponentSpecification spec)
// {
// Map<String, PropertyDescription> properties = spec.getProperties();
// for (PropertyDescription propertyDescription : properties.values())
// {
// String simpleTypeName = propertyDescription.getType().getName().replaceFirst(spec.getName() + ".", "");
// if (simpleTypeName.equals(ComponentPropertyType.TYPE_NAME)) return true;
// Object configObject = propertyDescription.getConfig();
// if (configObject != null)
// {
// try
// {
// if (configObject instanceof JSONObject && ((JSONObject)configObject).has(DesignerFilter.DROPPABLE))
// {
// Object droppable = ((JSONObject)configObject).get(DesignerFilter.DROPPABLE);
// if (droppable instanceof Boolean && (Boolean)droppable)
// {
// if (simpleTypeName.equals("tab")) return true;
// }
// }
// }
// catch (JSONException e)
// {
// Debug.log(e);
// }
// }
// }
// return false;
// }
public static void generateFormElement(PrintWriter writer, FormElement fe, Form form) {
IPersist fePersist = fe.getPersistIfAvailable();
String name = fe.getName();
boolean selectable = fe.isFormComponentChild() ? name.indexOf('$' + FormElement.SVY_NAME_PREFIX) == -1 : true;
writer.print("<");
writer.print(fe.getTagname());
writer.print(" name='");
writer.print(name);
writer.print("'");
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
String elementName = name;
if (elementName.startsWith("svy_") && fePersist != null) {
elementName = "svy_" + fePersist.getUUID().toString();
}
writer.print(" data-svy-name='");
writer.print(form.getName() + "." + elementName);
writer.print("'");
}
String designId = getDesignId(fe);
if (designId != null) {
if (form.isResponsiveLayout()) {
writer.print(" svy-id='");
writer.print(designId);
writer.print("'");
if (fePersist instanceof ISupportBounds) {
writer.print(" svy-location='");
writer.print(((ISupportBounds) fePersist).getLocation().x);
writer.print("'");
}
if (!selectable) {
writer.print(" svy-non-selectable='noname'");
}
writer.print(" svy-formelement-type='");
writer.print(fe.getTypeName());
writer.print("'");
JSONObject ngClass = new JSONObject();
List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
if (typeAndPropertyNames[0].size() > 0) {
writer.print(" svy-types='");
writer.print("[" + String.join(",", typeAndPropertyNames[0]) + "]");
writer.print("'");
writer.print(" svy-types-properties='");
writer.print("[" + String.join(",", typeAndPropertyNames[1]) + "]");
writer.print("'");
ngClass.put("drop_highlight", "<canContainDraggedElement('" + fe.getTypeName() + "',['" + String.join("','", typeAndPropertyNames[0]) + "'])<");
}
List<String> forbiddenComponentNames = fe.getForbiddenComponentNames();
if (forbiddenComponentNames.size() > 0) {
writer.print(" svy-forbidden-components='");
writer.print("[" + String.join(",", forbiddenComponentNames) + "]");
writer.print("'");
}
String directEditPropertyName = getDirectEditProperty(fe);
if (directEditPropertyName != null) {
writer.print(" directEditPropertyName='");
writer.print(directEditPropertyName);
writer.print("'");
}
if (// is this inherited or override element?
!fe.getForm().equals(form) || fePersist instanceof ISupportExtendsID && PersistHelper.getSuperPersist((ISupportExtendsID) fePersist) != null) {
ngClass.put("inheritedElement", true);
}
if (fe.isFormComponentChild()) {
ngClass.put("formComponentChild", true);
}
ngClass.put("invisible_element", "<getDesignFormControllerScope().model('" + designId + "').svyVisible == false<".toString());
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("highlight_child_element", "<design_highlight=='highlight_element'<".toString());
writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
}
writer.print(" svy-model=\"model('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-api=\"api('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-handlers=\"handlers('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-servoyApi=\"servoyApi('");
writer.print(designId);
writer.print("')\"");
if (fePersist instanceof IFormElement) {
writer.print(" form-index=" + ((IFormElement) fePersist).getFormIndex() + "");
}
} else {
writer.print(" svy-model='model.");
writer.print(name);
writer.print("'");
writer.print(" svy-api='api.");
writer.print(name);
writer.print("'");
writer.print(" svy-handlers='handlers.");
writer.print(name);
writer.print("'");
writer.print(" svy-servoyApi='handlers.");
writer.print(name);
writer.print(".svy_servoyApi'");
}
writer.print(">");
writer.print("</");
writer.print(fe.getTagname());
writer.print(">");
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormLayoutGenerator method generateRecordViewForm.
public static void generateRecordViewForm(PrintWriter writer, Form form, String realFormName, IServoyDataConverterContext context, boolean design) {
generateFormStartTag(writer, form, realFormName, false, design);
Iterator<Part> it = form.getParts();
if (design) {
while (it.hasNext()) {
Part part = it.next();
if (!Part.rendersOnlyInPrint(part.getPartType())) {
writer.print("<div ng-style=\"");
writer.print(PartWrapper.getName(part));
writer.print("Style\"");
String partClass = "svy-" + PartWrapper.getName(part);
if (part.getStyleClass() != null) {
partClass += " " + part.getStyleClass();
}
writer.print(" class=\"");
writer.print(partClass);
writer.print("\">");
generateEndDiv(writer);
}
}
}
Map<IPersist, FormElement> cachedElementsMap = new HashMap<IPersist, FormElement>();
if (context != null && context.getApplication() != null) {
IFormController controller = ((BasicFormManager) context.getApplication().getFormManager()).getCachedFormController(realFormName);
if (controller != null && controller.getFormUI() instanceof WebFormUI) {
List<FormElement> cachedFormElements = ((WebFormUI) controller.getFormUI()).getFormElements();
for (FormElement fe : cachedFormElements) {
if (fe.getPersistIfAvailable() != null) {
cachedElementsMap.put(fe.getPersistIfAvailable(), fe);
}
}
}
}
it = form.getParts();
while (it.hasNext()) {
Part part = it.next();
if (!Part.rendersOnlyInPrint(part.getPartType())) {
if (!design) {
writer.print("<div svy-ng-style=\"");
writer.print(PartWrapper.getName(part));
writer.print("Style\"");
String partClass = "svy-" + PartWrapper.getName(part);
if (part.getStyleClass() != null) {
partClass += " " + part.getStyleClass();
}
writer.print(" class=\"");
writer.print(partClass);
writer.print("\">");
}
for (IFormElement bc : PartWrapper.getBaseComponents(part, form, context, design, false)) {
FormElement fe = null;
if (cachedElementsMap.containsKey(bc)) {
fe = cachedElementsMap.get(bc);
}
if (fe == null) {
fe = FormElementHelper.INSTANCE.getFormElement(bc, context.getSolution(), null, design);
}
generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
generateFormElement(writer, fe, form);
generateEndDiv(writer);
}
if (!design)
generateEndDiv(writer);
}
}
generateFormEndTag(writer, design);
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormLayoutStructureGenerator method generateLayout.
public static void generateLayout(Form form, String realFormName, FlattenedSolution fs, PrintWriter writer, DesignProperties design) {
try {
FormLayoutGenerator.generateFormStartTag(writer, form, realFormName, false, design != null);
Iterator<IPersist> components = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, FormElementHelper.INSTANCE);
} else if (component instanceof IFormElement) {
FormLayoutGenerator.generateFormElement(writer, FormElementHelper.INSTANCE.getFormElement((IFormElement) component, fs, null, false), form);
}
}
FormLayoutGenerator.generateFormEndTag(writer, design != null);
} catch (Exception e) {
Debug.error(e);
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormTemplateObjectWrapper method wrap.
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
TemplateModel model = wrapperCache.get(obj);
if (model != null)
return model;
Object wrapped;
if (obj instanceof Form) {
wrapped = getFormWrapper((Form) obj);
} else if (obj instanceof Object[]) {
this.flattenedForm = context.getSolution().getFlattenedForm((Form) ((Object[]) obj)[0]);
wrapped = new FormWrapper(flattenedForm, (String) ((Object[]) obj)[1], useControllerProvider, context, design, runtimeProperties != null ? runtimeProperties.getJSONObject("") : null);
} else if (obj == DefaultNavigator.INSTANCE) {
wrapped = new FormElement(DefaultNavigator.INSTANCE, context.getSolution(), new PropertyPath(), design);
JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(((FormElement) wrapped).getName()) : null;
if (object != null) {
wrapped = new FormElementContext((FormElement) wrapped, context, object);
}
} else if (obj instanceof Part) {
wrapped = new PartWrapper((Part) obj, flattenedForm, context, design);
} else if (obj instanceof IFormElement) {
FormElement fe = null;
if (formUI != null) {
List<FormElement> cachedFormElements = formUI.getFormElements();
for (FormElement cachedFE : cachedFormElements) {
if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
fe = cachedFE;
break;
}
}
if (fe == null) {
Form parentForm = (Form) ((IFormElement) obj).getAncestor(IRepository.FORMS);
if (parentForm != null && parentForm.isFormComponent()) {
for (WebComponent webComponent : formUI.getAllComponents()) {
if (webComponent instanceof WebFormComponent) {
FormElement cachedFE = ((WebFormComponent) webComponent).getFormElement();
if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
fe = cachedFE;
break;
}
}
}
}
}
}
FormElement formElement = fe != null ? fe : FormElementHelper.INSTANCE.getFormElement((IFormElement) obj, context.getSolution(), null, false);
JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(formElement.getName()) : null;
wrapped = new FormElementContext(formElement, context, object);
} else {
wrapped = obj;
}
TemplateModel wrap = super.wrap(wrapped);
wrapperCache.put(obj, wrap);
return wrap;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormWrapper method checkFormComponents.
private void checkFormComponents(List<IFormElement> components, FormElement formComponentFormElement, Set<String> recursiveCheck) {
// if it's not a form component then .spec will not contain properties of type FormComponentPropertyType.INSTANCE and nothing will happen below
WebObjectSpecification spec = formComponentFormElement.getWebComponentSpec();
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
for (PropertyDescription pd : properties) {
Object config = pd.getConfig();
boolean isRepeating = config instanceof ComponentTypeConfig && ((ComponentTypeConfig) config).forFoundset != null;
Object propertyValue = formComponentFormElement.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
if (frm == null)
continue;
if (!recursiveCheck.add(frm.getName())) {
// $NON-NLS-1$
Debug.error("recursive reference found between (List)FormComponents: " + recursiveCheck);
continue;
}
FormComponentCache cache = FormElementHelper.INSTANCE.getFormComponentCache(formComponentFormElement, pd, (JSONObject) propertyValue, frm, context.getSolution());
Dimension frmSize = frm.getSize();
for (FormElement element : cache.getFormComponentElements()) {
IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
if ((!isRepeating || design))
components.add(persistOfElement);
formComponentParentSizes.put(element.getName(), frmSize);
if (!frm.isResponsiveLayout()) {
formComponentsLayout.put(element.getName(), Boolean.TRUE);
}
if (frm.getUseCssPosition()) {
String name = element.getDesignId() != null ? element.getDesignId() : element.getName();
if (!formComponentCSSPositionElementNames.containsKey(name)) {
formComponentCSSPositionElementNames.put(name, Boolean.TRUE);
}
}
checkFormComponents(components, element, recursiveCheck);
}
formComponentTemplates.put(cache.getHtmlTemplateUUIDForAngular(), cache.getTemplate());
recursiveCheck.remove(frm.getName());
}
}
}
}
Aggregations