Search in sources :

Example 11 with IScriptableProvider

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

the class DisplaysAdapter method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationlistener
	 */
public void valueChanged(ModificationEvent e) {
    if (!adjusting) {
        try {
            adjusting = true;
            Object obj = null;
            boolean formVariable = false;
            if (dataProviderID != null) {
                if (dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
                    formVariable = true;
                    obj = dal.getFormScope().get(dataProviderID);
                } else if (record != null) {
                    obj = record.getValue(dataProviderID);
                    if (obj == Scriptable.NOT_FOUND) {
                        obj = null;
                    }
                    // have to do this because for calcs in calcs. Better was to had a check for previous value.
                    fireModificationEvent(obj);
                }
            }
            // do not set value for form variable except when really changed
            if (!formVariable || dataProviderID == null || dataProviderID.equals(e.getName())) {
                setValueToDisplays(obj);
            }
        } finally {
            adjusting = false;
        }
    }
    // do fire on render on all components for record change
    for (IDisplayData displayData : displays) {
        if (displayData instanceof ISupportOnRender && displayData instanceof IScriptableProvider) {
            IScriptable so = ((IScriptableProvider) displayData).getScriptObject();
            if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                if (e.getRecord() != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                    ((ISupportOnRender) displayData).fireOnRender(true);
                }
            }
        }
    }
}
Also used : ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 12 with IScriptableProvider

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

the class DataAdapterList method setDataRendererComponentsRenderState.

public static void setDataRendererComponentsRenderState(IDataRenderer dataRenderer, IRecordInternal rec) {
    if (rec != null) {
        Object[] recordStatus = null;
        if (dataRenderer.getOnRenderComponent().getRenderEventExecutor().hasRenderCallback()) {
            recordStatus = getRecordIndexAndSelectStatus(rec);
            dataRenderer.getOnRenderComponent().getRenderEventExecutor().setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
        }
        @SuppressWarnings("rawtypes") Iterator compIte = dataRenderer.getComponentIterator();
        Object comp;
        while (compIte.hasNext()) {
            comp = compIte.next();
            if (comp instanceof IScriptableProvider) {
                IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
                if (scriptable instanceof ISupportOnRenderCallback) {
                    RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                    if (rendererEventExecutor != null && rendererEventExecutor.hasRenderCallback()) {
                        if (recordStatus == null)
                            recordStatus = getRecordIndexAndSelectStatus(rec);
                        rendererEventExecutor.setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
                    }
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 13 with IScriptableProvider

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

the class PropertyCopy method copyElementProps.

public static void copyElementProps(IComponent org, IComponent copy) {
    if (org == null || copy == null)
        return;
    // if (org instanceof IDelegate && copy instanceof IDelegate)
    // {
    // org = (JComponent)((IDelegate)org).getDelegate();
    // copy = (JComponent) ((IDelegate)copy).getDelegate();
    // }
    copy.setLocation(org.getLocation());
    copy.setSize(org.getSize());
    copy.setBackground(org.getBackground());
    copy.setForeground(org.getForeground());
    copy.setToolTipText(org.getToolTipText());
    copy.setComponentVisible(org.isVisible());
    copy.setComponentEnabled(org.isEnabled());
    copy.setOpaque(org.isOpaque());
    copy.setFont(org.getFont());
    if (org instanceof ILabel && copy instanceof ILabel) {
        ((ILabel) copy).setMediaIcon(((ILabel) org).getMediaIcon());
        ((ILabel) copy).setText(((ILabel) org).getText());
    }
    if (org instanceof IFieldComponent && copy instanceof IFieldComponent) {
        ((IFieldComponent) copy).setEditable(((IFieldComponent) org).isEditable());
    }
    if (org instanceof IScriptableProvider && copy instanceof IScriptableProvider) {
        IScriptable source = ((IScriptableProvider) org).getScriptObject();
        IScriptable destination = ((IScriptableProvider) copy).getScriptObject();
        if (source instanceof IFormatScriptComponent && destination instanceof IFormatScriptComponent) {
            ((IFormatScriptComponent) destination).setComponentFormat(((IFormatScriptComponent) source).getComponentFormat());
        }
        if (source instanceof HasRuntimeReadOnly && destination instanceof HasRuntimeReadOnly) {
            ((HasRuntimeReadOnly) destination).setReadOnly(((HasRuntimeReadOnly) source).isReadOnly());
        }
        if (source instanceof HasRuntimeVisible && destination instanceof HasRuntimeVisible) {
            ((HasRuntimeVisible) destination).setVisible(((HasRuntimeVisible) source).isVisible());
        }
        if (source instanceof HasRuntimeImage && destination instanceof HasRuntimeImage) {
            String imageURL = ((HasRuntimeImage) source).getImageURL();
            if (imageURL != null) {
                // only copy if explicitly set with a url
                ((HasRuntimeImage) destination).setImageURL(imageURL);
            }
            String rolloverImageURL = ((HasRuntimeImage) source).getRolloverImageURL();
            if (rolloverImageURL != null) {
                // only copy if explicitly set with a url
                ((HasRuntimeImage) destination).setRolloverImageURL(rolloverImageURL);
            }
        }
        if (source instanceof IRuntimeTabPaneAlike && destination instanceof IRuntimeTabPaneAlike) {
            // keep active tab when printing
            ((IRuntimeTabPaneAlike) destination).setTabIndex(((IRuntimeTabPaneAlike) source).getTabIndex());
        }
    }
    if (org instanceof IProviderStylePropertyChanges && copy instanceof IProviderStylePropertyChanges) {
        ((IProviderStylePropertyChanges) copy).getStylePropertyChanges().setChanges(((IProviderStylePropertyChanges) org).getStylePropertyChanges().getChanges());
    }
}
Also used : HasRuntimeReadOnly(com.servoy.j2db.ui.runtime.HasRuntimeReadOnly) HasRuntimeImage(com.servoy.j2db.ui.runtime.HasRuntimeImage) HasRuntimeVisible(com.servoy.j2db.ui.runtime.HasRuntimeVisible) IRuntimeTabPaneAlike(com.servoy.j2db.ui.runtime.IRuntimeTabPaneAlike) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 14 with IScriptableProvider

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

the class DataRenderer method fireDataRendererOnRender.

private void fireDataRendererOnRender() {
    dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
    @SuppressWarnings("rawtypes") Iterator compIte = getComponentIterator();
    Object comp;
    while (compIte.hasNext()) {
        comp = compIte.next();
        if (comp instanceof IScriptableProvider && !(comp instanceof IDisplayData) && !(comp instanceof IDisplayRelatedData)) {
            IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
            if (scriptable instanceof ISupportOnRenderCallback) {
                RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                boolean hasFocus = (comp instanceof Component) ? ((Component) comp).hasFocus() : false;
                rendererEventExecutor.fireOnRender(hasFocus);
            }
        }
    }
}
Also used : IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) Iterator(java.util.Iterator) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 15 with IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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;
}
Also used : JavaMembers(org.mozilla.javascript.JavaMembers) IComponent(com.servoy.j2db.ui.IComponent) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) VisibleBean(com.servoy.j2db.smart.dataui.VisibleBean) InvisibleBean(com.servoy.j2db.smart.dataui.InvisibleBean) Scriptable(org.mozilla.javascript.Scriptable) IScriptable(com.servoy.j2db.scripting.IScriptable) Point(java.awt.Point) RuntimeGroup(com.servoy.j2db.scripting.RuntimeGroup) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Aggregations

IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)35 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)21 IComponent (com.servoy.j2db.ui.IComponent)20 IScriptable (com.servoy.j2db.scripting.IScriptable)18 Point (java.awt.Point)14 Component (org.apache.wicket.Component)13 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)11 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)11 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)9 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)8 JComponent (javax.swing.JComponent)8 BaseComponent (com.servoy.j2db.persistence.BaseComponent)7 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)7 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)6 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)6 Component (java.awt.Component)6 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)5 IPersist (com.servoy.j2db.persistence.IPersist)5 EventObject (java.util.EventObject)5 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4