Search in sources :

Example 1 with WebImageBeanHolder

use of com.servoy.j2db.server.headlessclient.dataui.WebImageBeanHolder in project servoy-client by Servoy.

the class WebForm method registerComponentsToScope.

private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Map<String, Object[]> hmChildrenJavaMembers, Object parent) {
    if (comps != null) {
        for (Object comp : comps) {
            if (comp instanceof WebCellBasedView) {
                WebCellBasedView portal = (WebCellBasedView) comp;
                counter = registerComponentsToScope(fs, es, counter, portal.getComponents(), hmChildrenJavaMembers, comp);
            }
            String name = null;
            if (comp instanceof WrapperContainer) {
                comp = ((WrapperContainer) comp).getDelegate();
            }
            if (comp instanceof IComponent) {
                name = ((IComponent) comp).getName();
            } else if (comp instanceof java.awt.Component) {
                name = ((java.awt.Component) comp).getName();
            }
            if (comp instanceof WebImageBeanHolder) {
                comp = ((WebImageBeanHolder) comp).getDelegate();
            } else if (comp instanceof WebBeanHolder) {
                comp = ((WebBeanHolder) comp).getDelegate();
            }
            String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
            Object scriptable = comp;
            if (comp instanceof IScriptableProvider)
                scriptable = ((IScriptableProvider) comp).getScriptObject();
            JavaMembers jm = ScriptObjectRegistry.getJavaMembers(scriptable.getClass(), ScriptableObject.getTopLevelScope(fs));
            // $NON-NLS-1$
            boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
            if (groupName != null || named) {
                try {
                    Scriptable s;
                    if (parent instanceof WebCellBasedView) {
                        s = new CellNativeJavaObject(fs, comp, jm, (WebCellBasedView) parent);
                    } else {
                        s = new NativeJavaObject(fs, scriptable, jm);
                    }
                    if (named) {
                        es.put(name, fs, s);
                        es.put(counter++, fs, s);
                        hmChildrenJavaMembers.put(name, new Object[] { jm, scriptable });
                    }
                    if (groupName != null) {
                        Object group = es.get(groupName, fs);
                        if (group == Scriptable.NOT_FOUND) {
                            group = new NativeJavaObject(fs, new RuntimeGroup(groupName), ScriptObjectRegistry.getJavaMembers(RuntimeGroup.class, ScriptableObject.getTopLevelScope(fs)));
                            es.put(groupName, fs, group);
                            es.put(counter++, fs, group);
                        }
                        if (scriptable instanceof IRuntimeComponent && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
                            ((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj((IRuntimeComponent) scriptable);
                        }
                    }
                } catch (Throwable ex) {
                    // incase classdefnot founds are thrown for beans,applets/plugins
                    Debug.error(ex);
                }
            }
        }
    }
    return counter;
}
Also used : WebImageBeanHolder(com.servoy.j2db.server.headlessclient.dataui.WebImageBeanHolder) JavaMembers(org.mozilla.javascript.JavaMembers) IComponent(com.servoy.j2db.ui.IComponent) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Scriptable(org.mozilla.javascript.Scriptable) RuntimeGroup(com.servoy.j2db.scripting.RuntimeGroup) WebBeanHolder(com.servoy.j2db.server.headlessclient.dataui.WebBeanHolder) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) 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) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Aggregations

BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)1 RuntimeGroup (com.servoy.j2db.scripting.RuntimeGroup)1 WebBeanHolder (com.servoy.j2db.server.headlessclient.dataui.WebBeanHolder)1 WebCellBasedView (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView)1 WebImageBeanHolder (com.servoy.j2db.server.headlessclient.dataui.WebImageBeanHolder)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 Component (org.apache.wicket.Component)1 JavaMembers (org.mozilla.javascript.JavaMembers)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1 Scriptable (org.mozilla.javascript.Scriptable)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1