Search in sources :

Example 6 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class FormComponentSabloValue method getComponents.

private ComponentTypeSabloValue[] getComponents() {
    FormComponentCache formComponentCache = getCache();
    if (currentFormComponentCache != formComponentCache) {
        List<FormElement> elements = formComponentCache.getFormComponentElements();
        List<ComponentTypeSabloValue> componentsList = new ArrayList<ComponentTypeSabloValue>(elements.size());
        PropertyPath path = new PropertyPath();
        path.add(component.getName());
        path.add("containedForm");
        path.add("childElements");
        JSONObject tags = new JSONObject();
        tags.put(ComponentTypeSabloValue.TAG_ADD_TO_ELEMENTS_SCOPE, true);
        PropertyDescription compPd = new PropertyDescriptionBuilder().withName(pd.getName()).withType(ComponentPropertyType.INSTANCE).withConfig(pd.getConfig()).withTags(tags).build();
        int j = 0;
        for (FormElement element : elements) {
            path.add(j);
            ComponentTypeFormElementValue elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, element, dal.getApplication().getFlattenedSolution());
            ComponentTypeSabloValue ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, element, component, dal);
            if (ctsv != null) {
                // if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
                j++;
                componentsList.add(ctsv);
            }
            path.backOneLevel();
            if (element.getWebComponentSpec() != null) {
                Collection<PropertyDescription> properties = element.getWebComponentSpec().getProperties(FormComponentPropertyType.INSTANCE);
                if (properties.size() > 0) {
                    for (PropertyDescription pd : properties) {
                        Object propertyValue = element.getPropertyValue(pd.getName());
                        Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, dal.getApplication().getFlattenedSolution());
                        if (frm == null)
                            continue;
                        FormComponentCache innerCache = FormElementHelper.INSTANCE.getFormComponentCache(element, pd, (JSONObject) propertyValue, frm, dal.getApplication().getFlattenedSolution());
                        List<FormElement> innerElements = innerCache.getFormComponentElements();
                        for (FormElement innerElement : innerElements) {
                            path.add(j);
                            elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, innerElement, dal.getApplication().getFlattenedSolution());
                            // use main property
                            ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, innerElement, component, dal);
                            if (ctsv != null) {
                                // if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
                                j++;
                                componentsList.add(ctsv);
                            }
                            path.backOneLevel();
                        }
                    }
                }
            }
        }
        // re-attach
        if (currentFormComponentCache != null && changeMonitor != null && webObjectContext != null) {
            for (ComponentTypeSabloValue componentTypeSabloValue : componentsList) {
                componentTypeSabloValue.attachToBaseObject(changeMonitor, webObjectContext);
            }
        }
        currentFormComponentCache = formComponentCache;
        components = componentsList.toArray(new ComponentTypeSabloValue[0]);
    }
    return components;
}
Also used : FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) Form(com.servoy.j2db.persistence.Form) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) ArrayList(java.util.ArrayList) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) ComponentTypeSabloValue(com.servoy.j2db.server.ngclient.property.ComponentTypeSabloValue) ComponentTypeFormElementValue(com.servoy.j2db.server.ngclient.property.ComponentTypeFormElementValue) PropertyDescription(org.sablo.specification.PropertyDescription) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Example 7 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class FormWrapper method getAbsoluteLayoutElements.

public List<FormElement> getAbsoluteLayoutElements() {
    List<FormElement> elements = new ArrayList<FormElement>();
    Collection<IFormElement> components = getBaseComponents();
    if (components != null) {
        for (IFormElement component : components) {
            if (CSSPositionUtils.isInAbsoluteLayoutMode(component)) {
                elements.add(FormElementHelper.INSTANCE.getFormElement(component, context.getSolution(), null, design));
            }
        }
    }
    return elements;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) ArrayList(java.util.ArrayList) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 8 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class FormWrapper method getProperties.

/**
 * @return
 */
public Map<String, Object> getProperties() {
    // a copy of form properties
    Map<String, Object> properties = form.getFlattenedPropertiesMap();
    // form.getSize() computes the form height from form parts so do call it instead of relying on the height from size taken from raw form.getPropertiesMap() - where the height is not kept in sync in developer - we have to call getSize()
    properties.put("size", form.getSize());
    properties.put("designSize", form.getSize());
    properties.put("addMinSize", !form.isResponsiveLayout() && (form.getView() == IForm.RECORD_VIEW || form.getView() == IForm.LOCKED_RECORD_VIEW));
    properties.put("hasExtraParts", Boolean.valueOf(FormElementHelper.INSTANCE.hasExtraParts(form)));
    HashMap<String, Boolean> absolute = new HashMap<>(formComponentsLayout);
    absolute.put("", !form.isResponsiveLayout());
    for (FormElement fe : getAbsoluteLayoutElements()) {
        absolute.put(fe.getName(), Boolean.TRUE);
    }
    properties.put("absoluteLayout", absolute);
    properties.put(IContentSpecConstants.PROPERTY_USE_CSS_POSITION, getCSSPositionElementNames());
    if (design && !form.isResponsiveLayout()) {
        properties.put(StaticContentSpecLoader.PROPERTY_SCROLLBARS.getPropertyName(), Integer.valueOf(ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER + ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER));
    }
    if (form.getView() == IForm.LIST_VIEW || form.getView() == IFormConstants.VIEW_TYPE_LIST_LOCKED) {
        // handle horizontal scrollbar on form level for listview
        int horizontalScrollBars = ISupportScrollbars.HORIZONTAL_SCROLLBAR_AS_NEEDED;
        if ((form.getScrollbars() & ISupportScrollbars.HORIZONTAL_SCROLLBAR_ALWAYS) != 0) {
            horizontalScrollBars = ISupportScrollbars.HORIZONTAL_SCROLLBAR_ALWAYS;
        } else if ((form.getScrollbars() & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) != 0) {
            horizontalScrollBars = ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER;
        }
        int scrollbars = ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER + horizontalScrollBars;
        properties.put(StaticContentSpecLoader.PROPERTY_SCROLLBARS.getPropertyName(), Integer.valueOf(scrollbars));
    }
    removeUnneededFormProperties(properties);
    if (properties.containsKey(StaticContentSpecLoader.PROPERTY_BORDERTYPE.getPropertyName())) {
        Border border = ComponentFactoryHelper.createBorder((String) properties.get(StaticContentSpecLoader.PROPERTY_BORDERTYPE.getPropertyName()), false);
        properties.put(StaticContentSpecLoader.PROPERTY_BORDERTYPE.getPropertyName(), BorderPropertyType.writeBorderToJson(border));
    }
    return properties;
}
Also used : HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) Border(javax.swing.border.Border) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) Point(java.awt.Point)

Example 9 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class FormWrapper method getContainerSizesString.

public String getContainerSizesString() throws JSONException, IllegalArgumentException {
    Map<String, Dimension> sizes = new HashMap<String, Dimension>();
    sizes.putAll(formComponentParentSizes);
    for (FormElement fe : getAbsoluteLayoutElements()) {
        sizes.put(fe.getName(), ((LayoutContainer) fe.getPersistIfAvailable().getParent()).getSize());
    }
    return JSONUtils.writeDataWithConversions(new JSONStringer().object(), sizes, null, null).endObject().toString();
}
Also used : HashMap(java.util.HashMap) Dimension(java.awt.Dimension) JSONStringer(org.json.JSONStringer) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 10 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class RuntimeWebComponent method isApiFunctionEnabled.

protected boolean isApiFunctionEnabled(String functionName) {
    boolean isLocationOrSize = "getLocationX".equals(functionName) || "getLocationY".equals(functionName) || "getWidth".equals(functionName) || "getHeight".equals(functionName);
    if (isLocationOrSize) {
        // if parent form not visible, don't call api, let it get from the model on the server
        Container parent = component.getParent();
        while (parent != null) {
            if (parent instanceof WebFormUI) {
                boolean isFormVisible = false;
                IWindow currentWindow = CurrentWindow.safeGet();
                if (currentWindow instanceof INGClientWindow) {
                    isFormVisible = ((INGClientWindow) currentWindow).hasForm(parent.getName());
                }
                if (isFormVisible) {
                    // it is reported to be still on the client
                    // but do check also if it is not about to be hidden, by having
                    // formVisible already set to false in the controller
                    isFormVisible = ((WebFormUI) parent).getController().isFormVisible();
                }
                if (!isFormVisible) {
                    return false;
                }
                // if this form is in designer mode then it has to go to the client to get the current size/location
                if (((WebFormUI) parent).getController().getDesignModeCallbacks() != null)
                    return true;
                break;
            }
            parent = parent.getParent();
        }
        // if it is not table view (it can have columns moved/resize) and not anchored, no need to call api, let it get from the model on the server
        FormElement fe = component.getFormElement();
        if (fe.isLegacy() && fe.getPersistIfAvailable() instanceof ISupportAnchors && (fe.getForm().getView() != FormController.TABLE_VIEW && fe.getForm().getView() != FormController.LOCKED_TABLE_VIEW)) {
            // ((ISupportAnchors)fe.getPersistIfAvailable()).getAnchors();
            int anchor = Utils.getAsInteger(component.getProperty(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName()));
            if ((anchor == 0 || anchor == (IAnchorConstants.NORTH + IAnchorConstants.WEST))) {
                return false;
            }
        }
    }
    return true;
}
Also used : Container(org.sablo.Container) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) IWindow(org.sablo.websocket.IWindow) FormElement(com.servoy.j2db.server.ngclient.FormElement)

Aggregations

FormElement (com.servoy.j2db.server.ngclient.FormElement)22 IFormElement (com.servoy.j2db.persistence.IFormElement)12 Form (com.servoy.j2db.persistence.Form)11 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)10 HashMap (java.util.HashMap)10 JSONObject (org.json.JSONObject)9 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)6 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 Dimension (java.awt.Dimension)5 Map (java.util.Map)5 Test (org.junit.Test)5 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)4 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)4 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)4 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)4 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)4 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)3 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 IPersist (com.servoy.j2db.persistence.IPersist)3