Search in sources :

Example 1 with RuntimeWebGroup

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

Example 2 with RuntimeWebGroup

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

the class WebFormUI method removeComponentFromElementsScope.

// this should be the opposite of formUI.contributeComponentToElementsScope(...)
public void removeComponentFromElementsScope(FormElement fe, WebObjectSpecification componentSpec, WebFormComponent component) {
    ElementScope elementsScope = getElementsScope();
    if (elementsScope != null) {
        if (!FormElement.ERROR_BEAN.equals(componentSpec.getName()) && (!fe.getName().startsWith("svy_") || ((fe.getPersistIfAvailable() instanceof IFormElement) && ((IFormElement) fe.getPersistIfAvailable()).getGroupID() != null))) {
            if (!fe.getName().startsWith("svy_")) {
                RuntimeWebComponent runtimeComponent = (RuntimeWebComponent) elementsScope.remove(fe.getRawName());
                elementsScope.removeIndexByValue(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.remove(component);
                    if (group.getComponentCount() == 0)
                        elementsScope.remove(groupName);
                    groups.remove(groupID);
                }
            }
        }
    } else {
        Debug.error(new RuntimeException("Trying to remove component from a non-existent elements scope for form: " + getName()));
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) RuntimeWebGroup(com.servoy.j2db.server.ngclient.component.RuntimeWebGroup) HashMap(java.util.HashMap) ElementScope(com.servoy.j2db.scripting.ElementScope) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent)

Aggregations

IFormElement (com.servoy.j2db.persistence.IFormElement)2 RuntimeWebComponent (com.servoy.j2db.server.ngclient.component.RuntimeWebComponent)2 RuntimeWebGroup (com.servoy.j2db.server.ngclient.component.RuntimeWebGroup)2 HashMap (java.util.HashMap)2 ElementScope (com.servoy.j2db.scripting.ElementScope)1 RuntimeLegacyComponent (com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent)1 Point (java.awt.Point)1 JSONObject (org.json.JSONObject)1