Search in sources :

Example 1 with IServoyBeanFactory

use of com.servoy.j2db.IServoyBeanFactory in project servoy-client by Servoy.

the class ComponentFactory method createBean.

protected static IComponent createBean(IApplication application, Form form, Bean bean, FlattenedSolution flattenedSolution) {
    IComponent c = null;
    try {
        Object obj = getBeanInstanceFromXML(application, bean.getBeanClassName(), bean.getBeanXML());
        if (flattenedSolution != null && obj != null) {
            obj = flattenedSolution.setBeanDesignInstance(bean, obj);
        }
        if (obj instanceof Component) {
            ((Component) obj).setName(bean.getName());
        } else if (obj instanceof IComponent) {
            ((IComponent) obj).setName(bean.getName());
        }
        if (obj instanceof IServoyAwareBean) {
            ((IServoyAwareBean) obj).initialize((IClientPluginAccess) application.getPluginAccess());
        }
        if (obj instanceof IServoyBeanFactory) {
            testReturnTypesForBean(application, obj);
            obj = ((IServoyBeanFactory) obj).getBeanInstance(application.getApplicationType(), (IClientPluginAccess) application.getPluginAccess(), new Object[] { ComponentFactory.getWebID(form, bean), form.getName(), form.getStyleName() });
        }
        testReturnTypesForBean(application, obj);
        if (obj instanceof Applet) {
            ((FormManager) application.getFormManager()).initializeApplet((Applet) obj, bean.getSize());
        }
        if (obj == null) {
            c = application.getItemFactory().createLabel(ComponentFactory.getWebID(form, bean), "bean missing " + bean.getBeanClassName());
        } else if (!(obj instanceof java.awt.Component) && !(obj instanceof IComponent)) {
            c = application.getItemFactory().createInvisibleBean(ComponentFactory.getWebID(form, bean), obj);
        } else if (!(obj instanceof IComponent)) {
            c = application.getItemFactory().createBeanHolder(ComponentFactory.getWebID(form, bean), (Component) obj, bean.getAnchors());
        } else {
            c = (IComponent) obj;
        }
        // beans do not store the transparent property, keep the value from component
        boolean isOpaque = c.isOpaque();
        applyBasicComponentProperties(application, c, bean, null);
        c.setOpaque(isOpaque);
    } catch (// sometimes setting size or location throws exception or even error...create label instead
    Throwable e) {
        Debug.error(e);
        c = application.getItemFactory().createLabel(bean.getName(), "error acessing bean" + bean.getBeanClassName());
        java.awt.Dimension dim = bean.getSize();
        if (dim != null)
            c.setSize(bean.getSize());
    }
    return c;
}
Also used : IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) IServoyBeanFactory(com.servoy.j2db.IServoyBeanFactory) Applet(java.applet.Applet) FormManager(com.servoy.j2db.FormManager) IComponent(com.servoy.j2db.ui.IComponent) IClientPluginAccess(com.servoy.j2db.plugins.IClientPluginAccess) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Dimension(java.awt.Dimension) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) AbstractRuntimeValuelistComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IAnchoredComponent(com.servoy.j2db.ui.IAnchoredComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) WebComponent(com.servoy.j2db.persistence.WebComponent) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Aggregations

FormManager (com.servoy.j2db.FormManager)1 IServoyBeanFactory (com.servoy.j2db.IServoyBeanFactory)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 WebComponent (com.servoy.j2db.persistence.WebComponent)1 IClientPluginAccess (com.servoy.j2db.plugins.IClientPluginAccess)1 IAnchoredComponent (com.servoy.j2db.ui.IAnchoredComponent)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 AbstractRuntimeValuelistComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent)1 IFormatScriptComponent (com.servoy.j2db.ui.scripting.IFormatScriptComponent)1 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1 Applet (java.applet.Applet)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 JComponent (javax.swing.JComponent)1