Search in sources :

Example 1 with IServoyAwareBean

use of com.servoy.j2db.dataui.IServoyAwareBean 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)

Example 2 with IServoyAwareBean

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

the class DataAdapterList method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationListner
	 */
/**
 * listen for global var changes via own listener and state vars(mainly columns) via state listener if via javascript any var is changed it will be noted
 * here,and dispatched to refresh the displays
 */
public void valueChanged(ModificationEvent e) {
    if (destroyed) {
        Debug.error("Destroyed DataAdapterList " + formController + " was still attached to the record: " + e.getRecord() + ", removing it if possible, currentRecord: " + currentRecord, new RuntimeException());
        if (e.getRecord() != null)
            e.getRecord().removeModificationListener(this);
        else if (currentRecord != null)
            currentRecord.removeModificationListener(this);
        return;
    }
    if (formController != null && formController.isDestroyed()) {
        Debug.error("Destroying DataAdapterList of a destroyed " + formController, new RuntimeException());
        destroy();
        return;
    }
    FormScope formScope = getFormScope();
    if (visible && (currentRecord != null || (formScope != null && formScope.has(e.getName(), formScope)))) {
        for (IDataAdapter da : dataAdapters.values()) {
            // dataAdapter should call state.getValue if name from event is same as its dataProviderID
            da.valueChanged(e);
        }
        // check if a related adapter depends on he global
        if (e != null && e.getName() != null) {
            for (IDisplayRelatedData drd : relatedDataAdapters) {
                boolean depends = false;
                String[] allRelationNames = drd.getAllRelationNames();
                for (int a = 0; !depends && allRelationNames != null && a < allRelationNames.length; a++) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(allRelationNames[a]);
                    for (int r = 0; !depends && relations != null && r < relations.length; r++) {
                        try {
                            IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(application.getFlattenedSolution());
                            for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
                                depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
                            }
                        } catch (RepositoryException ex) {
                            Debug.log(ex);
                        }
                    }
                }
                if (depends) {
                    // related adapter depends on the modified global
                    if (drd instanceof IDisplayDependencyData)
                        ((IDisplayDependencyData) drd).dependencyChanged(currentRecord);
                    else
                        drd.setRecord(currentRecord, true);
                }
            }
        }
        // inform servoy aware beans
        for (IServoyAwareBean drd : servoyAwareBeans) {
            if (drd instanceof IModificationListener) {
                try {
                    ((IModificationListener) drd).valueChanged(e);
                } catch (RuntimeException ex) {
                    // never make the app break on faulty beans
                    Debug.error(ex);
                }
            }
        }
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) FormScope(com.servoy.j2db.scripting.FormScope) Relation(com.servoy.j2db.persistence.Relation) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean)

Example 3 with IServoyAwareBean

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

the class DataAdapterList method destroy.

/**
 */
public void destroy() {
    if (currentRecord != null) {
        // With prototype you can still get global foundsets
        // setRecord(new PrototypeState(currentRecord.getParentFoundSet()), true);
        setRecord(null, false);
    }
    if (formController != null && !formController.isDestroyed() && formController.getFormScope() != null) {
        formController.getFormScope().getModificationSubject().removeModificationListener(this);
    }
    IExecutingEnviroment er = application.getScriptEngine();
    if (er != null) {
        SolutionScope ss = er.getSolutionScope();
        if (ss != null) {
            ScopesScope gs = ss.getScopesScope();
            if (gs != null) {
                gs.getModificationSubject().removeModificationListener(this);
            }
        }
    }
    if (servoyAwareBeans != null) {
        for (IServoyAwareBean b : servoyAwareBeans) {
            try {
                if (b instanceof IDestroyable) {
                    ((IDestroyable) b).destroy();
                }
            } catch (RuntimeException e) {
                // never make the app break on faulty beans
                Debug.error(e);
            }
        }
    }
    servoyAwareBeans = null;
    if (relatedDataAdapters != null) {
        for (IDisplayRelatedData drd : relatedDataAdapters) {
            drd.destroy();
        }
    }
    relatedDataAdapters = null;
    if (dataDisplays != null) {
        for (IDisplayData dd : dataDisplays) {
            if (dd instanceof IDestroyable) {
                ((IDestroyable) dd).destroy();
            }
        }
    }
    dataDisplays = null;
    if (dataAdapters != null) {
        for (IDataAdapter da : dataAdapters.values()) {
            if (da instanceof IDestroyable) {
                ((IDestroyable) da).destroy();
            }
        }
    }
    dataAdapters = null;
    currentDisplay = null;
    visible = false;
    destroyed = true;
    if (currentRecord != null) {
        // $NON-NLS-1$
        Debug.error("After destroy there is still a current record in DataAdapterList of formcontroller: " + formController, new RuntimeException());
        currentRecord.removeModificationListener(this);
    }
}
Also used : IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) IDestroyable(com.servoy.j2db.util.IDestroyable) ScopesScope(com.servoy.j2db.scripting.ScopesScope) SolutionScope(com.servoy.j2db.scripting.SolutionScope)

Example 4 with IServoyAwareBean

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

the class WebDataRendererFactory method placeElements.

protected Map placeElements(IApplication app, Form form, IScriptExecuter listener, Map emptyDataRenderers, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
    // $NON-NLS-1$
    final boolean useAJAX = Utils.getAsBoolean(app.getRuntimeProperties().get("useAJAX"));
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    String orientation = OrientationApplier.getHTMLContainerOrientation(app.getLocale(), app.getSolution().getTextOrientation());
    // $NON-NLS-1$
    boolean leftToRight = !"rtl".equalsIgnoreCase(orientation);
    // $NON-NLS-1$
    boolean isAnchoringEnabled = Utils.getAsBoolean(app.getRuntimeProperties().get("enableAnchors"));
    // Insets insets = new Insets(0, 0, 0, 0);
    for (IFormElement obj : Utils.iterate(form.getFormElementsSortedByFormIndex())) {
        Point l = null;
        l = (obj).getLocation();
        // unknown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            WebDataRenderer panel = (WebDataRenderer) it.next();
            // Border border = panel.getBorder();
            // if (border instanceof EmptyBorder)
            // {
            // insets = ((EmptyBorder)border).getBorderInsets();
            // }
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                org.apache.wicket.Component comp = (org.apache.wicket.Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listener, printing);
                if (comp != null) {
                    if (obj instanceof Field) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && (comp instanceof WebBaseLabel || comp instanceof WebBaseSubmitLink)) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if ((obj instanceof ISupportTabSeq) && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    org.apache.wicket.Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    } else if (newComp instanceof WebImageBeanHolder) {
                        WebImageBeanHolder wiBeanHolder = (WebImageBeanHolder) newComp;
                        Object bean = wiBeanHolder.getDelegate();
                        if (bean instanceof IServoyAwareBean) {
                            IServoyAwareBean ourBean = (IServoyAwareBean) bean;
                            panel.addDisplayComponent(obj, ourBean);
                        }
                    }
                    ((IComponent) comp).setLocation(new Point((l.x), (l.y - start)));
                    if (form.getOnRecordEditStartMethodID() > 0 && comp instanceof IFieldComponent) {
                        if (useAJAX && comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null && !ScopesUtils.isVariableScope(((IDisplayData) comp).getDataProviderID())) {
                            StartEditOnFocusGainedEventBehavior.addNewBehaviour(comp);
                        }
                    }
                    // - beans
                    if (isAnchoringEnabled && (((obj instanceof Field) && WebAnchoringHelper.needsWrapperDivForAnchoring((Field) obj)) || (obj instanceof Bean) || ((obj instanceof GraphicalComponent) && ComponentFactory.isButton((GraphicalComponent) obj)))) {
                        panel.add(WebAnchoringHelper.getWrapperComponent(comp, obj, start, panel.getSize(), leftToRight, false));
                    } else {
                        panel.add(comp);
                    }
                }
            }
        }
    }
    Iterator it = labelForComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Entry) it.next();
        Object key = entry.getKey();
        if (key instanceof WebBaseLabel || key instanceof WebBaseSubmitLink) {
            IFieldComponent component = (IFieldComponent) labelForComponents.get(entry.getValue());
            if (component != null) {
                if (key instanceof WebBaseLabel) {
                    ((WebBaseLabel) entry.getKey()).setLabelFor(component);
                } else {
                    ((WebBaseSubmitLink) entry.getKey()).setLabelFor(component);
                }
                (component).addLabelFor((ILabel) entry.getKey());
                if (!component.isVisible()) {
                    component.setComponentVisible(component.isVisible());
                }
                if (!component.isEnabled()) {
                    component.setComponentEnabled(component.isEnabled());
                }
            }
        }
    }
    it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        WebDataRenderer panel = (WebDataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listener, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Bean(com.servoy.j2db.persistence.Bean) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Field(com.servoy.j2db.persistence.Field) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) Component(org.apache.wicket.Component) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) HashMap(java.util.HashMap) Map(java.util.Map) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 5 with IServoyAwareBean

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

the class ScrollResponseHeaderContainer method initializeComponent.

@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
    if (dal != null && dal.isDestroyed()) {
        Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
        return;
    }
    if (// Don't know any other place for this
    view instanceof Portal && c instanceof IDisplayData) {
        String id = ((IDisplayData) c).getDataProviderID();
        if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
            ((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
        }
    }
    if (!isListViewMode() && c instanceof WebDataCheckBox) {
        // $NON-NLS-1$
        ((WebDataCheckBox) c).setText("");
    }
    if (element != null) {
        // apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
        // for listview this is the location to use.
        Point loc = ((IComponent) c).getLocation();
        int height = ((IComponent) c).getSize().height;
        PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
        if (!isListViewMode()) {
            ((IComponent) c).setLocation(loc);
            // it shouldn't be possible to change the height
            if (c instanceof IScriptableProvider) {
                IScriptable so = ((IScriptableProvider) c).getScriptObject();
                if (so instanceof IRuntimeComponent) {
                    IRuntimeComponent ic = (IRuntimeComponent) so;
                    if (ic.getHeight() != height) {
                        ic.setSize(ic.getWidth(), height);
                    }
                }
            }
        }
    } else {
        // $NON-NLS-1$
        Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
    }
    if (c instanceof IDisplayData) {
        IDisplayData cdd = (IDisplayData) c;
        if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
        dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
            cdd.setValidationEnabled(validationEnabled);
        }
    } else if (c instanceof IDisplayRelatedData) {
        ((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
    } else if (c instanceof IServoyAwareBean) {
        ((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
    }
    addClassToCellComponent(c);
    if (// the check could be extended against IDelegate<?>
    c instanceof WebDataCompositeTextField) {
        Object delegate = ((WebDataCompositeTextField) c).getDelegate();
        if (delegate instanceof Component) {
            // make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
            addClassToCellComponent((Component) delegate);
        }
    }
    if (c instanceof ISupportValueList) {
        ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
        IValueList list;
        if (idVl != null && (list = idVl.getValueList()) != null) {
            ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
            if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
                ((ISupportValueList) c).setValueList(list);
            }
        }
    }
    applyClientProperties(c, element);
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) DBValueList(com.servoy.j2db.dataprocessing.DBValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) IComponent(com.servoy.j2db.ui.IComponent) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) Point(java.awt.Point) Point(java.awt.Point) IScriptable(com.servoy.j2db.scripting.IScriptable) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Aggregations

IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)11 IComponent (com.servoy.j2db.ui.IComponent)5 Point (java.awt.Point)5 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)4 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 IScriptable (com.servoy.j2db.scripting.IScriptable)3 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)3 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)2 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)2 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)2 FormScope (com.servoy.j2db.scripting.FormScope)2