Search in sources :

Example 1 with Container

use of org.sablo.Container in project servoy-client by Servoy.

the class AngularFormGenerator method generateJS.

@SuppressWarnings("nls")
@Override
public String generateJS() throws IOException {
    IWebFormController cachedFormController = client != null ? client.getFormManager().getCachedFormController(realFormName) : null;
    FormTemplateObjectWrapper formTemplate = new FormTemplateObjectWrapper(getAContext(), true, false);
    FormWrapper formWrapper = formTemplate.getFormWrapper(form);
    // for this form it is really just some json.
    StringWriter stringWriter = new StringWriter();
    final JSONWriter writer = new JSONWriter(stringWriter);
    writer.object();
    writer.key(realFormName);
    writer.object();
    writer.key("responsive");
    writer.value(form.isResponsiveLayout());
    writer.key("size");
    writer.object();
    writer.key("width");
    writer.value(form.getWidth());
    writer.key("height");
    writer.value(form.getSize().getHeight());
    writer.endObject();
    String styleClasses = form.getStyleClass();
    if (styleClasses != null) {
        writer.key("styleclass");
        String[] classes = styleClasses.split(" ");
        writer.array();
        for (String cls : classes) {
            writer.value(cls);
        }
        writer.endArray();
    }
    writer.key("children");
    // write the default form value object.
    writer.array();
    writer.object();
    writer.key("name");
    writer.value("");
    writer.key("model");
    writer.object();
    Map<String, Object> containerProperties = null;
    if (cachedFormController != null && cachedFormController.getFormUI() instanceof Container) {
        Container con = (Container) cachedFormController.getFormUI();
        DataConversion dataConversion = new DataConversion();
        TypedData<Map<String, Object>> typedProperties = con.getProperties();
        con.writeProperties(FullValueToJSONConverter.INSTANCE, null, writer, typedProperties, dataConversion);
        JSONUtils.writeClientConversions(writer, dataConversion);
        containerProperties = typedProperties.content;
    }
    final Map<String, Object> finalContainerProperties = containerProperties;
    if (formWrapper != null) {
        Map<String, Object> properties = formWrapper.getProperties();
        properties.forEach((key, value) -> {
            if (finalContainerProperties == null || !finalContainerProperties.containsKey(key)) {
                writer.key(key);
                if (value instanceof Integer || value instanceof Long) {
                    writer.value(((Number) value).longValue());
                } else if (value instanceof Float || value instanceof Double) {
                    writer.value(((Number) value).doubleValue());
                } else if (value instanceof Boolean) {
                    writer.value(((Boolean) value).booleanValue());
                } else if (value instanceof Dimension) {
                    writer.object();
                    writer.key("width");
                    writer.value(((Dimension) value).getWidth());
                    writer.key("height");
                    writer.value(((Dimension) value).getHeight());
                    writer.endObject();
                } else {
                    writer.value(value);
                }
            }
        });
    }
    writer.endObject();
    writer.endObject();
    if (form.isResponsiveLayout()) {
        if (zoomedInContainer != null) {
            zoomedInContainer.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, null, form, true, isDesigner), PositionComparator.XY_PERSIST_COMPARATOR);
        } else {
            form.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, null, form, true, isDesigner), PositionComparator.XY_PERSIST_COMPARATOR);
        }
    } else {
        Iterator<Part> it = form.getParts();
        while (it.hasNext()) {
            Part part = it.next();
            if (!Part.rendersOnlyInPrint(part.getPartType())) {
                writer.object();
                writer.key("part");
                writer.value(true);
                writer.key("classes");
                writer.array();
                writer.value("svy-" + PartWrapper.getName(part));
                if (part.getStyleClass() != null) {
                    writer.value(part.getStyleClass());
                }
                writer.endArray();
                writer.key("layout");
                writer.object();
                writer.key("position");
                writer.value("absolute");
                writer.key("left");
                writer.value("0px");
                writer.key("right");
                writer.value("0px");
                int top = form.getPartStartYPos(part.getID());
                if (part.getPartType() <= Part.BODY) {
                    writer.key("top");
                    writer.value(top + "px");
                }
                if (part.getPartType() >= Part.BODY) {
                    writer.key("bottom");
                    writer.value(form.getSize().height - part.getHeight() + "px");
                }
                if (part.getPartType() != Part.BODY) {
                    writer.key("height");
                    writer.value((part.getHeight() - top) + "px");
                }
                if (part.getBackground() != null && !form.getTransparent()) {
                    writer.key("background-color");
                    writer.value(PersistHelper.createColorString(part.getBackground()));
                }
                if (part.getPartType() == Part.BODY) {
                    writer.key("overflow-x");
                    writer.value(AbstractFormLayoutProvider.getCSSScrolling(form.getScrollbars(), true));
                    writer.key("overflow-y");
                    writer.value(AbstractFormLayoutProvider.getCSSScrolling(form.getScrollbars(), false));
                } else {
                    writer.key("overflow");
                    // $NON-NLS-1$
                    writer.value("hidden");
                }
                writer.endObject();
                writer.key("children");
                // write the default form value object.
                writer.array();
                form.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, part, form, true, isDesigner), ChildrenJSONGenerator.FORM_INDEX_WITH_HIERARCHY_COMPARATOR);
                writer.endArray();
                writer.endObject();
            }
        }
    }
    writer.endArray();
    writer.endObject();
    writer.endObject();
    return stringWriter.toString();
}
Also used : JSONWriter(org.json.JSONWriter) FormWrapper(com.servoy.j2db.server.ngclient.template.FormWrapper) Dimension(java.awt.Dimension) FormTemplateObjectWrapper(com.servoy.j2db.server.ngclient.template.FormTemplateObjectWrapper) Point(java.awt.Point) DataConversion(org.sablo.websocket.utils.DataConversion) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) Container(org.sablo.Container) StringWriter(java.io.StringWriter) Part(com.servoy.j2db.persistence.Part) Map(java.util.Map)

Example 2 with Container

use of org.sablo.Container in project servoy-client by Servoy.

the class FoundsetTest method foundsetReadByDataprovidersPushToServerAllow.

@Test
public void foundsetReadByDataprovidersPushToServerAllow() throws JSONException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    String full = NGUtils.formComponentPropertiesToString(form.getFormUI(), FullValueToJSONConverter.INSTANCE);
    JSONObject object = new JSONObject(full);
    JSONObject bean = object.getJSONObject("mycustombean");
    JSONObject foundset = bean.getJSONObject("myfoundsetWithAllow");
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    JSONObject viewPort = foundset.getJSONObject("viewPort");
    Assert.assertEquals(0, viewPort.getInt("startIndex"));
    // 15 is default preferredViewPortSize
    Assert.assertEquals(15, viewPort.getInt("size"));
    Assert.assertEquals(15, viewPort.getJSONArray("rows").length());
    // fake incomming request for view port change.
    endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundsetWithAllow\":[{\"newViewPort\":{\"startIndex\":0,\"size\":18}, \"id\": 1234}]}},\"service\":\"formService\"}", true);
    String changes = NGUtils.formChangesToString(((Container) form.getFormUI()), FullValueToJSONConverter.INSTANCE);
    object = new JSONObject(changes).getJSONObject("changes");
    bean = object.getJSONObject("mycustombean");
    foundset = bean.getJSONObject("myfoundsetWithAllow");
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    JSONArray handledClientReqIds = foundset.getJSONArray("handledClientReqIds");
    Assert.assertEquals(1, handledClientReqIds.length());
    Assert.assertEquals(1234, handledClientReqIds.getJSONObject(0).getInt("id"));
    Assert.assertTrue(handledClientReqIds.getJSONObject(0).getBoolean("value"));
    viewPort = foundset.getJSONObject("viewPort");
    Assert.assertEquals(0, viewPort.getInt("startIndex"));
    Assert.assertEquals(18, viewPort.getInt("size"));
    JSONArray rows = viewPort.getJSONArray("rows");
    Assert.assertEquals(18, rows.length());
    JSONObject row0 = rows.getJSONObject(0);
    Assert.assertEquals("value1", row0.getString("firstname"));
    Assert.assertEquals("value2", row0.getString("lastname"));
    JSONObject row1 = rows.getJSONObject(1);
    Assert.assertEquals("value3", row1.getString("firstname"));
    Assert.assertEquals("value4", row1.getString("lastname"));
    // fake an update
    endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundsetWithAllow\":[{\"viewportDataChanged\":{\"_svyRowId\":\"" + row1.getString("_svyRowId") + "\",\"value\":\"value5\",\"dp\":\"lastname\"}}]}},\"service\":\"formService\"}", true);
    Assert.assertEquals("value5", form.getFormModel().getRecord(1).getValue("test2"));
}
Also used : Container(org.sablo.Container) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONArray(org.json.JSONArray) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 3 with Container

use of org.sablo.Container in project servoy-client by Servoy.

the class FormComponentSabloValue method getCache.

public FormComponentCache getCache() {
    Container parent = component.findParent(WebFormUI.class);
    if (parent instanceof WebFormUI) {
        // cache it on the FormUI object, because FormElementHelper can only cache when it is not solution model, but then the cache is constantly changing..
        FormComponentCache fcc = ((WebFormUI) parent).getFormComponentCache(component);
        if (fcc != null)
            return fcc;
        fcc = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
        ((WebFormUI) parent).cacheFormComponentCache(component, fcc);
        return fcc;
    }
    return FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
}
Also used : Container(org.sablo.Container) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)

Example 4 with Container

use of org.sablo.Container in project servoy-client by Servoy.

the class WebFormUI method addAllChildren.

private void addAllChildren(Container parent, Collection<WebComponent> allComponents) {
    Collection<WebComponent> directChildren = parent.getComponents();
    allComponents.addAll(directChildren);
    for (WebComponent component : directChildren) {
        if (component instanceof Container) {
            addAllChildren((Container) component, allComponents);
        }
    }
}
Also used : WebComponent(org.sablo.WebComponent) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) Container(org.sablo.Container)

Example 5 with Container

use of org.sablo.Container 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

Container (org.sablo.Container)8 IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)3 JSONArray (org.json.JSONArray)3 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)2 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)1 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)1 Part (com.servoy.j2db.persistence.Part)1 FormElement (com.servoy.j2db.server.ngclient.FormElement)1 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)1 INGClientWindow (com.servoy.j2db.server.ngclient.INGClientWindow)1 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)1 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)1 RuntimeWebComponent (com.servoy.j2db.server.ngclient.component.RuntimeWebComponent)1 FormTemplateObjectWrapper (com.servoy.j2db.server.ngclient.template.FormTemplateObjectWrapper)1 FormWrapper (com.servoy.j2db.server.ngclient.template.FormWrapper)1 JSONWrapperList (com.servoy.j2db.util.JSONWrapperList)1 Dimension (java.awt.Dimension)1