Search in sources :

Example 1 with RuntimeLegacyComponent

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

the class ValueListTypeSabloValue method filterValuelist.

/**
 * Filters the values of the valuelist for type-ahead-like usage.
 */
private void filterValuelist(JSONObject newJSONValue) {
    if (!initialized) {
        Debug.warn("Trying to send to client an uninitialized valuelist property: " + vlPD + " of " + webObjectContext);
        return;
    }
    this.valuesRequested = true;
    this.handledIDForResponse = Long.valueOf(newJSONValue.getLong(ID_KEY));
    String filterString = newJSONValue.optString(FILTER);
    if (filteredValuelist == null) {
        filteredValuelist = createFilteredValueList();
        if (filteredValuelist != null) {
            filteredValuelist.addListDataListener(new ListDataListener() {

                @Override
                public void intervalRemoved(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void intervalAdded(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void contentsChanged(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }
            });
        }
    }
    if (filteredValuelist != null) {
        try {
            valueList.removeListDataListener(this);
            Object realValue = dataAdapterListToUse.getValueObject(dataAdapterListToUse.getRecord(), dataproviderID);
            // do mark it as changed but don't notify yet (false arg) because fill below will probably trigger listener above and notify anyway; that would mean that although
            // we do call notify after fill that is likely to end up in a NO_OP changesToJSON in case of foundset-linked valuelist properties
            changeMonitor.markFullyChanged(false);
            boolean useContains = Utils.getAsBoolean(dataAdapterListToUse.getApplication().getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH));
            if (!useContains && webObjectContext != null && webObjectContext.getUnderlyingWebObject() instanceof WebFormComponent) {
                WebFormComponent webObject = (WebFormComponent) webObjectContext.getUnderlyingWebObject();
                RuntimeWebComponent webComponentElement = dataAdapterListToUse.getForm().getWebComponentElement(webObject.getFormElement().getRawName());
                if (webComponentElement != null && webComponentElement.getPrototype() instanceof RuntimeLegacyComponent) {
                    RuntimeLegacyComponent legacy = (RuntimeLegacyComponent) webComponentElement.getPrototype();
                    useContains = Utils.getAsBoolean(legacy.getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH, legacy));
                }
            }
            if (useContains && filterString != null)
                filterString = '%' + filterString;
            filteredValuelist.fill(dataAdapterListToUse.getRecord(), dataproviderID, filterString, realValue, false);
            // in case fill really somehow did not result in the filteredValuelist listener doing a notify
            changeMonitor.notifyOfChange();
            valueList.addListDataListener(this);
        } catch (ServoyException e) {
            Debug.error(e);
        }
    }
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) JSONObject(org.json.JSONObject) RuntimeLegacyComponent(com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent) ListDataListener(javax.swing.event.ListDataListener) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) ServoyException(com.servoy.j2db.util.ServoyException)

Example 2 with RuntimeLegacyComponent

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

Example 3 with RuntimeLegacyComponent

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

the class WebFormUI method contributeComponentToElementsScope.

private void contributeComponentToElementsScope(ElementScope elementsScope, FormElement fe, WebObjectSpecification componentSpec, WebFormComponent component) {
    Object lengthOfEl = elementsScope.get("length", elementsScope);
    int lastElementByIndex = (lengthOfEl instanceof Integer ? ((Integer) lengthOfEl).intValue() : 0);
    if (!FormElement.ERROR_BEAN.equals(componentSpec.getName()) && (!fe.getName().startsWith("svy_") || ((fe.getPersistIfAvailable() instanceof IFormElement) && ((IFormElement) fe.getPersistIfAvailable()).getGroupID() != null))) {
        RuntimeWebComponent runtimeComponent = new RuntimeWebComponent(component, componentSpec);
        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("servoydefault-"))) {
            // add legacy behavior
            runtimeComponent.setPrototype(new RuntimeLegacyComponent(component));
        }
        if (!fe.getName().startsWith("svy_")) {
            elementsScope.put(fe.getRawName(), formController.getFormScope(), runtimeComponent);
            elementsScope.put(lastElementByIndex, formController.getFormScope(), runtimeComponent);
        }
        String groupID = fe.getPersistIfAvailable() instanceof IFormElement ? ((IFormElement) fe.getPersistIfAvailable()).getGroupID() : null;
        if (groupID != null) {
            if (groups == null)
                groups = new HashMap<String, RuntimeWebGroup>(4);
            RuntimeWebGroup group = groups.get(groupID);
            if (group == null) {
                String groupName = FormElementGroup.getName(groupID);
                group = new RuntimeWebGroup(groupName);
                group.setParentScope(component.getDataConverterContext().getApplication().getScriptEngine().getSolutionScope());
                elementsScope.put(groupName, formController.getFormScope(), group);
                groups.put(groupID, group);
            }
            group.add(runtimeComponent);
        }
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) RuntimeWebGroup(com.servoy.j2db.server.ngclient.component.RuntimeWebGroup) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) RuntimeLegacyComponent(com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) Point(java.awt.Point)

Aggregations

RuntimeLegacyComponent (com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent)3 RuntimeWebComponent (com.servoy.j2db.server.ngclient.component.RuntimeWebComponent)3 JSONObject (org.json.JSONObject)3 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 Point (java.awt.Point)2 IFormElement (com.servoy.j2db.persistence.IFormElement)1 ElementScope (com.servoy.j2db.scripting.ElementScope)1 FormScope (com.servoy.j2db.scripting.FormScope)1 FormElement (com.servoy.j2db.server.ngclient.FormElement)1 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)1 IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)1 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)1 RuntimeWebGroup (com.servoy.j2db.server.ngclient.component.RuntimeWebGroup)1 ServoyException (com.servoy.j2db.util.ServoyException)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ListDataEvent (javax.swing.event.ListDataEvent)1 ListDataListener (javax.swing.event.ListDataListener)1 JSONException (org.json.JSONException)1