Search in sources :

Example 1 with WebFormUI

use of com.servoy.j2db.server.ngclient.WebFormUI 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 2 with WebFormUI

use of com.servoy.j2db.server.ngclient.WebFormUI 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)

Example 3 with WebFormUI

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

the class PersistFieldInstanceTest method testFieldWithValueList.

@Test
public void testFieldWithValueList() throws RepositoryException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    ValueList vl = solution.getValueList("test");
    Assert.assertNotNull(vl);
    Field field = form.createNewField(new Point(0, 0));
    field.setDataProviderID("mycolumn");
    field.setFormat("#,###.00");
    field.setDisplayType(Field.TYPE_AHEAD);
    field.setValuelistID(vl.getID());
    // needed for a valuelist property type that searches it's form's table via the webform ui
    WebFormUI formUI = new WebFormUI(client.getFormManager().getForm(form.getName()));
    IDataAdapterList dataAdapterList = formUI.getDataAdapterList();
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), formUI, form);
    Object property = wc.getProperty("valuelistID");
    Assert.assertTrue(property != null ? property.getClass().getName() : "null", property instanceof ValueListTypeSabloValue && ((ValueListTypeSabloValue) property).getValueList() instanceof CustomValueList);
    Assert.assertEquals("#,###.00", ((CustomValueList) ((ValueListTypeSabloValue) property).getValueList()).getFormat().getDisplayFormat());
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) Form(com.servoy.j2db.persistence.Form) ValueList(com.servoy.j2db.persistence.ValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ValueListTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.ValueListTypeSabloValue) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) Point(java.awt.Point) FormElement(com.servoy.j2db.server.ngclient.FormElement) Field(com.servoy.j2db.persistence.Field) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Test(org.junit.Test)

Example 4 with WebFormUI

use of com.servoy.j2db.server.ngclient.WebFormUI 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 5 with WebFormUI

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

the class JSEventType method fillJSEvent.

/**
 * @param event Event that needs to be filled
 * @param jsonObject The json data for that has the event data.
 * @param webObject The webObject element (WEbFormComponent or WebFormUI)
 * @param controller Optional the controller object if the caller knows this already
 * @return
 */
@SuppressWarnings("nls")
public static void fillJSEvent(JSBaseEvent event, JSONObject jsonObject, BaseWebObject webObject, IWebFormController controller) {
    event.setType(jsonObject.optString("eventType"));
    String formName = controller != null ? controller.getName() : "";
    String elementName = "";
    if (webObject instanceof WebFormComponent) {
        elementName = ((WebFormComponent) webObject).getFormElement().getRawName();
        if (elementName == null)
            elementName = "";
        if (formName.isEmpty()) {
            BaseWebObject parentWebObject = ((WebFormComponent) webObject).getParent();
            while (parentWebObject != null && !(parentWebObject instanceof WebFormUI)) {
                parentWebObject = ((WebFormComponent) parentWebObject).getParent();
            }
            if (parentWebObject instanceof WebFormUI) {
                formName = parentWebObject.getName();
            }
        }
    }
    if (formName.isEmpty()) {
        formName = jsonObject.optString("formName");
    }
    if (formName.isEmpty() && webObject instanceof WebFormUI) {
        // executeInlineScript with an event in params tells a DAL to execute it and it gives a formui as context to the fromJSON conversion
        // for JSEventType problem is that it can give any formName from the client (the component/service can give anything there as an arg); or, if the function
        // (sent to client before through "function" type) that will be used to execute the script is a global/scope function
        // then formName can be null and in that case the WebFormUI will be the main form or the window (not the most nested one)
        // so this is just a fallback and we do give priority to the form name determined on client through $window.createJSEvent(...) an put into
        // "jsonObject" (see if above) - to target the correct form - closest one to event
        formName = webObject.getName();
    }
    if (elementName.isEmpty()) {
        elementName = jsonObject.optString("elementName");
    }
    if (!formName.isEmpty())
        event.setFormName(formName);
    if (!elementName.isEmpty())
        event.setElementName(elementName);
    if (!formName.isEmpty()) {
        INGApplication application = ((IContextProvider) webObject).getDataConverterContext().getApplication();
        IWebFormController formController = controller != null ? controller : application.getFormManager().getForm(formName);
        if (formController != null) {
            FormScope formScope = formController.getFormScope();
            if (formScope != null) {
                ElementScope elementsScope = (ElementScope) formScope.get("elements", null);
                if (elementsScope != null) {
                    Object scriptableElement = !elementName.isEmpty() ? elementsScope.get(elementName, null) : null;
                    if (scriptableElement != null && scriptableElement != Scriptable.NOT_FOUND) {
                        event.setSource(scriptableElement);
                    } else if (webObject instanceof WebFormComponent) {
                        // quickly create a scriptable wrapper around the component so that the source can be set to a value that we expect.
                        FormElement fe = ((WebFormComponent) webObject).getFormElement();
                        RuntimeWebComponent runtimeComponent = new RuntimeWebComponent((WebFormComponent) webObject, webObject.getSpecification());
                        if (fe.isLegacy() || ((fe.getForm().getView() == IForm.LIST_VIEW || fe.getForm().getView() == FormController.LOCKED_LIST_VIEW || fe.getForm().getView() == FormController.TABLE_VIEW || fe.getForm().getView() == FormController.LOCKED_TABLE_VIEW) && fe.getTypeName().startsWith("svy-"))) {
                            // add legacy behavior
                            runtimeComponent.setPrototype(new RuntimeLegacyComponent((WebFormComponent) webObject));
                        }
                        event.setSource(runtimeComponent);
                    }
                }
            }
        }
    }
    try {
        if (jsonObject.has("x"))
            event.setLocation(new Point(jsonObject.optInt("x"), jsonObject.optInt("y")));
        if (jsonObject.has("modifiers"))
            event.setModifiers(jsonObject.optInt("modifiers"));
        if (jsonObject.has("data"))
            event.setData(jsonObject.opt("data"));
        if (jsonObject.has("timestamp"))
            event.setTimestamp(new Timestamp(jsonObject.getLong("timestamp")));
        else
            event.setTimestamp(new Date());
    } catch (Exception e) {
        Debug.error("error setting event properties from " + jsonObject + ", for component: " + elementName + " on form " + formName, e);
    }
}
Also used : WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) ElementScope(com.servoy.j2db.scripting.ElementScope) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Point(java.awt.Point) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) Timestamp(java.sql.Timestamp) FormElement(com.servoy.j2db.server.ngclient.FormElement) Date(java.util.Date) JSONException(org.json.JSONException) BaseWebObject(org.sablo.BaseWebObject) FormScope(com.servoy.j2db.scripting.FormScope) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) JSONObject(org.json.JSONObject) BaseWebObject(org.sablo.BaseWebObject) RuntimeLegacyComponent(com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent)

Aggregations

WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)6 FormElement (com.servoy.j2db.server.ngclient.FormElement)4 IFormController (com.servoy.j2db.IFormController)2 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 Point (java.awt.Point)2 Container (org.sablo.Container)2 BasicFormManager (com.servoy.j2db.BasicFormManager)1 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1 Field (com.servoy.j2db.persistence.Field)1 Form (com.servoy.j2db.persistence.Form)1 IFormElement (com.servoy.j2db.persistence.IFormElement)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)1 Part (com.servoy.j2db.persistence.Part)1 ValueList (com.servoy.j2db.persistence.ValueList)1 ElementScope (com.servoy.j2db.scripting.ElementScope)1 FormScope (com.servoy.j2db.scripting.FormScope)1 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)1