Search in sources :

Example 6 with ISupportBounds

use of com.servoy.j2db.persistence.ISupportBounds in project servoy-client by Servoy.

the class WebForm method getFormAnchorInfo.

@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
    formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
    final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
    Iterator<IPersist> e1 = formController.getForm().getAllObjects();
    while (e1.hasNext()) {
        IPersist obj = e1.next();
        if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
            elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
        }
    }
    // In case we are in table view.
    if (view instanceof WebCellBasedView) {
        WebCellBasedView formPart = (WebCellBasedView) view;
        formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
        formAnchorInfo.isTableView = true;
        formAnchorInfo.bodyContainerId = formPart.getMarkupId();
    }
    // Find the id of the form navigator, if any.
    visitChildren(Component.class, new IVisitor() {

        public Object component(Component component) {
            if (component instanceof WebDefaultRecordNavigator) {
                formAnchorInfo.navigatorWebId = component.getMarkupId();
                return IVisitor.CONTINUE_TRAVERSAL;
            } else if (component instanceof WebTabPanel) {
                return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            } else
                return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    visitChildren(WebDataRenderer.class, new IVisitor() {

        public Object component(Component component) {
            WebDataRenderer formPart = (WebDataRenderer) component;
            final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
            if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
                Component parent = formPart.getParent();
                formAnchorInfo.bodyContainerId = parent.getMarkupId();
            }
            formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {

                public Object component(Component comp) {
                    String id = comp.getId();
                    ISupportAnchors obj = elements.get(id);
                    if (obj != null) {
                        int anchors = obj.getAnchors();
                        if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
                            Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
                            if (r != null) {
                                if (anchors == 0)
                                    anchors = IAnchorConstants.DEFAULT;
                                int hAlign = -1;
                                int vAlign = -1;
                                if (obj instanceof ISupportTextSetup) {
                                    ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
                                    hAlign = alignedObj.getHorizontalAlignment();
                                    vAlign = alignedObj.getVerticalAlignment();
                                }
                                String imageDisplayURL = null;
                                boolean isRandomParamRemoved = false;
                                if (comp instanceof IImageDisplay) {
                                    Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
                                    imageDisplayURL = (String) aImageDisplayURL[0];
                                    isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
                                }
                                part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
                            }
                        }
                    }
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        }
    });
    return formAnchorInfo;
}
Also used : FormPartAnchorInfo(com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) IImageDisplay(com.servoy.j2db.server.headlessclient.dataui.IImageDisplay) ISupportTextSetup(com.servoy.j2db.persistence.ISupportTextSetup) Rectangle(java.awt.Rectangle) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IPersist(com.servoy.j2db.persistence.IPersist) WebDefaultRecordNavigator(com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator) IButton(com.servoy.j2db.ui.IButton) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 7 with ISupportBounds

use of com.servoy.j2db.persistence.ISupportBounds in project servoy-client by Servoy.

the class ChildrenJSONGenerator method writeFormElement.

public static void writeFormElement(JSONWriter writer, IPersist o, Form form, FormElement fe, WebFormUI formUI, ServoyDataConverterContext context, boolean designer) {
    writer.key("name");
    String name = designer ? fe.getDesignId() : fe.getName();
    writer.value(name);
    writer.key("type");
    if (o instanceof TabPanel) {
        // special support for TabPanel so that we have a specific tabpanel,tablesspanel,accordion and splitpane
        String type = "servoydefault-tabpanel";
        int orient = ((TabPanel) o).getTabOrientation();
        if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
            type = "servoydefault-splitpane";
        else if (orient == TabPanel.ACCORDION_PANEL)
            type = "servoydefault-accordion";
        else if (orient == TabPanel.HIDE || (orient == TabPanel.DEFAULT_ORIENTATION && ((TabPanel) o).hasOneTab()))
            type = "servoydefault-tablesspanel";
        writer.value(ClientService.convertToJSName(type));
    } else {
        // hack for now to map it to the types that we know are there, so that we can test responsive without really already having to have bootstrap components.
        writer.value(ClientService.convertToJSName(FormTemplateGenerator.getComponentTypeName((IFormElement) o)));
    }
    WebFormComponent webComponent = (formUI != null) ? formUI.getWebComponent(fe.getName()) : null;
    AngularFormGenerator.writePosition(writer, o, form, webComponent, designer);
    writer.key("model");
    writer.object();
    if (formUI != null) {
        // there is a existing form, take the current properties from that.
        if (webComponent != null) {
            TypedData<Map<String, Object>> properties = webComponent.getProperties();
            TypedData<Map<String, Object>> templateProperties = fe.propertiesForTemplateJSON();
            // remove from the templates properties all the properties that are current "live" in the component
            templateProperties.content.keySet().removeAll(properties.content.keySet());
            DataConversion dataConversion = new DataConversion();
            // write the template properties that are left
            JSONUtils.writeData(FormElementToJSON.INSTANCE, writer, templateProperties.content, templateProperties.contentType, dataConversion, new FormElementContext(fe));
            // write the actual values
            webComponent.writeProperties(FullValueToJSONConverter.INSTANCE, null, writer, properties, dataConversion);
            JSONUtils.writeClientConversions(writer, dataConversion);
        } else {
            System.err.println("null");
        }
    } else {
        fe.propertiesAsTemplateJSON(writer, new FormElementContext(fe, context, null), false);
        if (designer && Utils.isInheritedFormElement(o, form)) {
            writer.key("svyInheritedElement");
            writer.value(true);
        }
    }
    if (designer) {
        DataConversion dataConversion = new DataConversion();
        fe.getWebComponentSpec().getProperties().values().forEach(pd -> {
            if (pd.getType() instanceof IDesignerDefaultWriter)
                ((IDesignerDefaultWriter) pd.getType()).toDesignerDefaultJSONValue(writer, pd.getName(), dataConversion);
        });
        if (!dataConversion.getConversions().isEmpty()) {
            JSONUtils.writeClientConversions(writer, dataConversion);
        }
    }
    if (o instanceof BaseComponent) {
        writer.key("servoyAttributes");
        writer.object();
        Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) fe.getPersistIfAvailable()).getMergedAttributes());
        if (designer) {
            attributes.put("svy-id", fe.getDesignId());
            attributes.put("svy-formelement-type", fe.getTypeName());
            attributes.put("svy-name", fe.getName());
            attributes.put("svy-anchors", Integer.toString(((BaseComponent) o).getAnchors()));
            List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
            if (typeAndPropertyNames[0].size() > 0) {
                attributes.put("svy-types", String.join(",", typeAndPropertyNames[0]));
                attributes.put("svy-types-properties", String.join(",", typeAndPropertyNames[1]));
            }
            attributes.put("svy-priority", form.isResponsiveLayout() ? String.valueOf(((ISupportBounds) o).getLocation().x) : String.valueOf(((BaseComponent) o).getFormIndex()));
        }
        if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
            String elementName = name;
            if (elementName.startsWith("svy_") && o.getUUID() != null) {
                elementName = "svy_" + o.getUUID().toString();
            }
            attributes.put("data-cy", form.getName() + "." + elementName);
        }
        String directEditPropertyName = getDirectEditProperty(fe);
        if (directEditPropertyName != null) {
            attributes.put("directEditPropertyName", directEditPropertyName);
        }
        attributes.forEach((key, value) -> {
            writer.key(StringEscapeUtils.escapeEcmaScript(key));
            writer.value(value);
        });
        writer.endObject();
    }
    writer.endObject();
    WebObjectSpecification spec = fe.getWebComponentSpec();
    if (spec != null) {
        Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
        if (properties.size() > 0) {
            boolean isResponsive = false;
            for (PropertyDescription pd : properties) {
                Object propertyValue = fe.getPropertyValue(pd.getName());
                Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
                if (frm == null)
                    continue;
                isResponsive = frm.isResponsiveLayout();
            }
            // responsive state can change, so send it with updates
            writer.key("responsive");
            writer.value(isResponsive);
        }
    }
    Collection<String> handlers = fe.getHandlers();
    if (handlers.size() > 0) {
        writer.key("handlers");
        writer.array();
        for (String handler : handlers) {
            writer.value(handler);
        }
        writer.endArray();
    }
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) BaseComponent(com.servoy.j2db.persistence.BaseComponent) HashMap(java.util.HashMap) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) Point(java.awt.Point) DataConversion(org.sablo.websocket.utils.DataConversion) PropertyDescription(org.sablo.specification.PropertyDescription) IDesignerDefaultWriter(com.servoy.j2db.server.ngclient.property.types.NGConversions.IDesignerDefaultWriter) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)7 IPersist (com.servoy.j2db.persistence.IPersist)5 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 IFormElement (com.servoy.j2db.persistence.IFormElement)3 HashMap (java.util.HashMap)3 List (java.util.List)3 JSONObject (org.json.JSONObject)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)2 ISupportExtendsID (com.servoy.j2db.persistence.ISupportExtendsID)2 Rectangle (java.awt.Rectangle)2 Map (java.util.Map)2 WeakHashMap (java.util.WeakHashMap)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)2 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)1 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 Form (com.servoy.j2db.persistence.Form)1