Search in sources :

Example 6 with IScriptableProvider

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

the class ScrollResponseHeaderContainer method distributeExtraSpace.

private void distributeExtraSpace() {
    int totalDefaultWidth = 0;
    int totalWidthToStretch = 0;
    int stretchedElementsCount = 0;
    for (IPersist element : elementToColumnIdentifierComponent.keySet()) {
        Object scriptobject = elementToColumnIdentifierComponent.get(element);
        if (!((Component) scriptobject).isVisible())
            continue;
        if (scriptobject instanceof IScriptableProvider) {
            scriptobject = ((IScriptableProvider) scriptobject).getScriptObject();
        }
        if (scriptobject instanceof IRuntimeComponent) {
            int width = ((IRuntimeComponent) scriptobject).getWidth();
            totalDefaultWidth += width;
            if (element instanceof ISupportAnchors) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                if (((anchors & IAnchorConstants.EAST) != 0) && ((anchors & IAnchorConstants.WEST) != 0)) {
                    totalWidthToStretch += width;
                    stretchedElementsCount++;
                }
            }
        }
    }
    boolean shouldFillAllHorizSpace = shouldFillAllHorizontalSpace();
    if (shouldFillAllHorizSpace) {
        if (stretchedElementsCount > 0) {
            int delta = getDisplayBodyWidthHint() - totalDefaultWidth;
            distributeExtraSpace(delta, totalWidthToStretch, null, true);
            setHeadersWidth();
        }
    }
}
Also used : ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) Point(java.awt.Point)

Example 7 with IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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)

Example 8 with IScriptableProvider

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

the class WebEventExecutor method handleEvent.

/**
 * @param type
 * @param target
 * @param comp
 * @param webModifiers
 * @param mouseLocation
 * @param page
 */
private void handleEvent(EventType type, AjaxRequestTarget target, Component comp, int webModifiers, Point mouseLocation, Point absoluteMouseLocation, Page page) {
    // process model changes from web components
    WebClientSession.get().getWebClient().executeEvents();
    Component renderScriptProvider = comp;
    ISupplyFocusChildren<?> componentWithChildren = renderScriptProvider.findParent(ISupplyFocusChildren.class);
    if (componentWithChildren != null)
        renderScriptProvider = (Component) componentWithChildren;
    if (renderScriptProvider instanceof WrapperContainer)
        renderScriptProvider = ((WrapperContainer) renderScriptProvider).getDelegate();
    RenderEventExecutor renderEventExecutor = null;
    if (renderScriptProvider instanceof IScriptableProvider) {
        IScriptable s = ((IScriptableProvider) renderScriptProvider).getScriptObject();
        if (s instanceof ISupportOnRenderCallback) {
            renderEventExecutor = ((ISupportOnRenderCallback) s).getRenderEventExecutor();
            if (!renderEventExecutor.hasRenderCallback())
                renderEventExecutor = null;
        }
    }
    if (type == EventType.focusGained || type == EventType.action || type == EventType.focusLost) {
        if (type == EventType.focusGained || type == EventType.action) {
            ((MainPage) page).setFocusedComponent(comp);
        } else {
            ((MainPage) page).setFocusedComponent(null);
        }
        if (renderEventExecutor != null) {
            renderEventExecutor.setRenderStateChanged();
            // if component's onRender did not change any properties, don't add it to the target
            if (renderScriptProvider instanceof ISupportOnRender && WebOnRenderHelper.doRender((ISupportOnRender) renderScriptProvider)) {
                target.addComponent(renderScriptProvider);
            }
        }
    }
    if (type == EventType.focusLost || setSelectedIndex(comp, target, convertModifiers(webModifiers), type == EventType.focusGained || type == EventType.action)) {
        if (skipFireFocusGainedCommand && type.equals(JSEvent.EventType.focusGained)) {
            skipFireFocusGainedCommand = false;
        } else {
            switch(type) {
                case action:
                    fireActionCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
                    break;
                case focusGained:
                    fireEnterCommands(false, comp, convertModifiers(webModifiers));
                    break;
                case focusLost:
                    fireLeaveCommands(comp, false, convertModifiers(webModifiers));
                    break;
                case doubleClick:
                    fireDoubleclickCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
                    break;
                case rightClick:
                    // if right click, mark the meta flag as it is on the smart client
                    fireRightclickCommand(false, comp, convertModifiers(webModifiers | 8), null, mouseLocation, absoluteMouseLocation);
                    break;
                case none:
                case dataChange:
                case form:
                case onDrag:
                case onDragOver:
                case onDrop:
            }
        }
    }
}
Also used : WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 9 with IScriptableProvider

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

the class FormController method getJSApplicationNames.

/**
 * @param src
 * @param function
 * @param useFormAsEventSourceEventually
 */
@Override
protected FormAndComponent getJSApplicationNames(Object source, Function function, boolean useFormAsEventSourceEventually) {
    Object src = source;
    if (src == null) {
        Object window = application.getRuntimeWindowManager().getCurrentWindowWrappedObject();
        if (window != null) {
            src = ((Window) window).getFocusOwner();
            while (src != null && !(src instanceof IComponent)) {
                src = ((Component) src).getParent();
            }
            // Test if this component really comes from the the controllers UI.
            if (src instanceof Component) {
                Container container = ((Component) src).getParent();
                while (container != null && !(container instanceof IFormUIInternal<?>)) {
                    container = container.getParent();
                }
                if (container != getFormUI()) {
                    // if not then this is not the trigger element for this form.
                    src = null;
                }
            }
        }
    }
    Scriptable thisObject = null;
    if (src instanceof IComponent && src instanceof IScriptableProvider) {
        // $NON-NLS-1$
        Object esObj = formScope.get("elements", formScope);
        if (esObj != Scriptable.NOT_FOUND) {
            ElementScope es = (ElementScope) esObj;
            String name = ((IComponent) src).getName();
            if (name != null && name.length() != 0) {
                Object o = es.get(name, es);
                if (o instanceof Scriptable) {
                    thisObject = (Scriptable) o;
                }
            }
            if (thisObject == null) {
                if (name == null || name.length() == 0) {
                    name = ComponentFactory.WEB_ID_PREFIX + System.currentTimeMillis();
                    // Check Web components always have a name! Because name can't be set
                    ((IComponent) src).setName(name);
                }
                IScriptable scriptObject = ((IScriptableProvider) src).getScriptObject();
                if (scriptObject != null) {
                    try {
                        Context.enter();
                        JavaMembers jm = ScriptObjectRegistry.getJavaMembers(scriptObject.getClass(), ScriptableObject.getTopLevelScope(formScope));
                        thisObject = new NativeJavaObject(formScope, scriptObject, jm);
                        es.setLocked(false);
                        es.put(name, es, thisObject);
                        es.setLocked(true);
                    } finally {
                        Context.exit();
                    }
                }
            }
        }
    }
    if (src == null && useFormAsEventSourceEventually)
        src = formScope;
    return new FormAndComponent(src, getName());
}
Also used : JavaMembers(org.mozilla.javascript.JavaMembers) IComponent(com.servoy.j2db.ui.IComponent) ElementScope(com.servoy.j2db.scripting.ElementScope) Scriptable(org.mozilla.javascript.Scriptable) IScriptable(com.servoy.j2db.scripting.IScriptable) IScriptable(com.servoy.j2db.scripting.IScriptable) FormAndComponent(com.servoy.j2db.scripting.JSApplication.FormAndComponent) Container(java.awt.Container) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) FormAndComponent(com.servoy.j2db.scripting.JSApplication.FormAndComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Example 10 with IScriptableProvider

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

the class BasicFormController method executeFunction.

@SuppressWarnings("nls")
protected Object executeFunction(Function f, Object[] args, Scriptable scope, Scriptable thisObject, boolean saveData, Object src, boolean testFindMode, boolean focusEvent, String methodKey, boolean executeWhenFieldValidationFailed, boolean useFormAsEventSourceEventually, boolean throwException) throws Exception {
    if (// only run certain methods in find
    !(testFindMode && isInFindMode())) {
        // this is a semi saveData , we do NOT want the record go out of edit(!) and is updated in db
        if (saveData) {
            application.getFoundSetManager().getEditRecordList().prepareForSave(false);
        }
        if (f != null) {
            if (!executeWhenFieldValidationFailed && Boolean.TRUE.equals(application.getRuntimeProperties().get(IServiceProvider.RT_LASTFIELDVALIDATIONFAILED_FLAG))) {
                if (Debug.tracing()) {
                    Debug.trace("Function not executed because a field is marked invalid");
                }
                return null;
            }
            FormAndComponent formAndComponent = getJSApplicationNames(src, f, useFormAsEventSourceEventually);
            try {
                currentFormExecutingFunctionCount.incrementAndGet();
                Object[] newArgs = args;
                if (formAndComponent != null) {
                    // for use of deprecated aplication.getMethodTriggerElementName() and aplication.getMethodTriggerFormName()
                    IExecutingEnviroment scriptEngine = application.getScriptEngine();
                    if (scriptEngine instanceof ScriptEngine) {
                        ((ScriptEngine) scriptEngine).getJSApplication().pushLastNames(formAndComponent);
                    }
                    if (methodKey != null) {
                        // add form event if needed
                        MethodTemplate methodTemplate = MethodTemplate.getTemplate(null, methodKey);
                        if (methodTemplate != null) {
                            MethodArgument[] methodArguments = methodTemplate.getArguments();
                            for (int i = 0; methodArguments != null && i < methodArguments.length; i++) {
                                if (methodArguments[i].getType() == ArgumentType.JSEvent) {
                                    // method template declares an event argument
                                    if (args == null || args.length <= i || args[i] == null) {
                                        // no event argument there yet, insert a form event
                                        JSEvent event = getJSEvent(formAndComponent.src, methodKey);
                                        if (args == null || args.length <= i) {
                                            newArgs = new Object[i + 1];
                                            if (args != null) {
                                                System.arraycopy(args, 0, newArgs, 0, args.length);
                                            }
                                        }
                                        newArgs[i] = event;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                if (newArgs != null && newArgs.length > 0) {
                    for (Object newArg : newArgs) {
                        if (newArg instanceof JSEvent) {
                            JSEvent event = (JSEvent) newArg;
                            if (formScope != null && event.getSource() instanceof IComponent && ((IComponent) event.getSource()).getName() != null) {
                                Object elementScope = formScope.get("elements");
                                if (elementScope instanceof Scriptable) {
                                    Object elementSrc = ((Scriptable) elementScope).get(((IComponent) event.getSource()).getName(), (Scriptable) elementScope);
                                    if (elementSrc != null) {
                                        if (elementSrc instanceof ITwoNativeJavaObject) {
                                            Object scriptable = event.getSource();
                                            if (scriptable instanceof IScriptableProvider) {
                                                scriptable = ((IScriptableProvider) scriptable).getScriptObject();
                                            }
                                            ((ITwoNativeJavaObject) elementSrc).setRealObject(scriptable);
                                        }
                                        event.setSource(elementSrc);
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                return application.getScriptEngine().executeFunction(f, scope, thisObject, newArgs, focusEvent, throwException);
            } finally {
                currentFormExecutingFunctionCount.decrementAndGet();
                if (formAndComponent != null) {
                    IExecutingEnviroment scriptEngine = application.getScriptEngine();
                    if (scriptEngine instanceof ScriptEngine) {
                        ((ScriptEngine) scriptEngine).getJSApplication().popLastStackNames(formAndComponent);
                    }
                }
                // after a script clear the unchanged records so that no records keep hanging around.
                if (!focusEvent && !"onRecordEditStopMethodID".equals(methodKey) && !"onRenderMethodID".equals(methodKey) && application.getFoundSetManager() != null) {
                    application.getFoundSetManager().getEditRecordList().removeUnChangedRecords(false, false);
                }
            }
        }
    }
    return null;
}
Also used : IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) JSEvent(com.servoy.j2db.scripting.JSEvent) MethodArgument(com.servoy.j2db.persistence.MethodArgument) IComponent(com.servoy.j2db.ui.IComponent) MethodTemplate(com.servoy.j2db.persistence.MethodTemplate) Scriptable(org.mozilla.javascript.Scriptable) FormAndComponent(com.servoy.j2db.scripting.JSApplication.FormAndComponent) ScriptEngine(com.servoy.j2db.scripting.ScriptEngine) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

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