use of com.servoy.j2db.smart.scripting.TwoNativeJavaObject in project servoy-client by Servoy.
the class SwingForm method registerComponentsToScope.
private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Object[] compsRenderer, Component controller, Map<String, Object[]> hmChildrenJavaMembers) {
if (comps != null) {
for (int j = 0; j < comps.length; j++) {
Object comp = comps[j];
if (comp instanceof PortalComponent) {
PortalComponent portal = (PortalComponent) comp;
counter = registerComponentsToScope(fs, es, counter, portal.getEditorComponents(), portal.getRendererComponents(), portal, hmChildrenJavaMembers);
}
String name = null;
if (comp instanceof IComponent) {
name = ((IComponent) comp).getName();
} else if (comp instanceof Component) {
name = ((Component) comp).getName();
}
Object obj = comp;
if (comp instanceof InvisibleBean) {
obj = ((InvisibleBean) comp).getDelegate();
} else if (comp instanceof VisibleBean) {
obj = ((VisibleBean) comp).getDelegate();
}
String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
if (obj instanceof IScriptableProvider)
obj = ((IScriptableProvider) obj).getScriptObject();
IRuntimeComponent baseMethodsObj = null;
if (obj instanceof IRuntimeComponent) {
baseMethodsObj = (IRuntimeComponent) obj;
}
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(obj.getClass(), ScriptableObject.getTopLevelScope(fs));
// $NON-NLS-1$
boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
if (groupName != null || named) {
Object obj2 = null;
if (compsRenderer != null) {
obj2 = compsRenderer[j];
if (obj2 instanceof InvisibleBean) {
obj2 = ((InvisibleBean) obj2).getDelegate();
}
}
try {
Scriptable s = null;
if (obj2 != null) {
if (obj2 instanceof IScriptableProvider)
obj2 = ((IScriptableProvider) obj2).getScriptObject();
NativeJavaObject s2 = new NativeJavaObject(fs, obj2, jm);
s = new TwoNativeJavaObject(fs, obj, s2, jm, controller);
// group properties have to be set to both
if (groupName != null && obj2 instanceof IRuntimeComponent) {
if (baseMethodsObj == null) {
baseMethodsObj = (IRuntimeComponent) obj2;
} else {
RuntimeGroup runtimeGroup = new RuntimeGroup(baseMethodsObj.getName());
runtimeGroup.addScriptBaseMethodsObj(baseMethodsObj);
runtimeGroup.addScriptBaseMethodsObj((IRuntimeComponent) obj2);
baseMethodsObj = runtimeGroup;
}
}
} else {
s = new NativeJavaObject(fs, obj, jm);
}
if (named) {
es.put(name, fs, s);
es.put(counter++, fs, s);
hmChildrenJavaMembers.put(name, new Object[] { jm, obj });
}
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 (baseMethodsObj != null && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj(baseMethodsObj);
}
}
} catch (Throwable ex) {
// incase classdefnot founds are thrown for beans,applets/plugins
Debug.error(ex);
}
}
}
}
return counter;
}
Aggregations