Search in sources :

Example 21 with IFormElement

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(">");
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with IFormElement

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);
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) IPersist(com.servoy.j2db.persistence.IPersist) HashMap(java.util.HashMap) Part(com.servoy.j2db.persistence.Part) BasicFormManager(com.servoy.j2db.BasicFormManager) IFormController(com.servoy.j2db.IFormController) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 23 with IFormElement

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);
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) IOException(java.io.IOException)

Example 24 with IFormElement

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;
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) TemplateModel(freemarker.template.TemplateModel) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) WebComponent(org.sablo.WebComponent) JSONObject(org.json.JSONObject) Part(com.servoy.j2db.persistence.Part) PropertyPath(com.servoy.j2db.server.ngclient.property.types.PropertyPath) JSONObject(org.json.JSONObject) FormElementContext(com.servoy.j2db.server.ngclient.FormElementContext)

Example 25 with IFormElement

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());
            }
        }
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) JSONObject(org.json.JSONObject) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Aggregations

IFormElement (com.servoy.j2db.persistence.IFormElement)42 IPersist (com.servoy.j2db.persistence.IPersist)20 ArrayList (java.util.ArrayList)15 Point (java.awt.Point)14 HashMap (java.util.HashMap)12 JSONObject (org.json.JSONObject)12 PropertyDescription (org.sablo.specification.PropertyDescription)11 Form (com.servoy.j2db.persistence.Form)8 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)8 Part (com.servoy.j2db.persistence.Part)8 FormElement (com.servoy.j2db.server.ngclient.FormElement)8 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)8 Dimension (java.awt.Dimension)7 AbstractBase (com.servoy.j2db.persistence.AbstractBase)6 PropertyPath (com.servoy.j2db.server.ngclient.property.types.PropertyPath)6 BaseComponent (com.servoy.j2db.persistence.BaseComponent)5 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)5 Portal (com.servoy.j2db.persistence.Portal)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 IBasicWebObject (com.servoy.j2db.persistence.IBasicWebObject)3