Search in sources :

Example 1 with Record

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

the class ScrollResponseHeaderContainer method createScriptEvent.

public JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
    JSDNDEvent jsEvent = new JSDNDEvent();
    jsEvent.setType(type);
    jsEvent.setFormName(getDragFormName());
    if (dragSource instanceof IDataRenderer) {
        IDataRenderer dr = (IDataRenderer) dragSource;
        FormController fct = dr.getDataAdapterList().getFormController();
        jsEvent.setSource(fct.getFormScope());
    } else {
        jsEvent.setSource(dragSource);
        if (dragSource != null) {
            if (dragSource instanceof Component) {
                WebCellBasedViewListItem listItem = ((Component) dragSource).findParent(WebCellBasedViewListItem.class);
                if (listItem != null) {
                    IRecordInternal dragRecord = listItem.getModelObject();
                    if (dragRecord instanceof Record)
                        jsEvent.setRecord((Record) dragRecord);
                }
            }
            String dragSourceName = dragSource.getName();
            if (dragSourceName == null)
                dragSourceName = dragSource.getId();
            jsEvent.setElementName(dragSourceName);
        }
    }
    if (xy != null)
        jsEvent.setLocation(xy);
    jsEvent.setModifiers(modifiers);
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) Record(com.servoy.j2db.dataprocessing.Record) 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)

Example 2 with Record

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

the class WebDataRenderer method createScriptEvent.

private JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
    JSDNDEvent jsEvent = new JSDNDEvent();
    jsEvent.setType(type);
    jsEvent.setFormName(getDragFormName());
    IRecordInternal dragRecord = getDragRecord(xy);
    if (dragRecord instanceof Record)
        jsEvent.setRecord((Record) dragRecord);
    if (dragSource instanceof IDataRenderer) {
        IDataRenderer dr = (IDataRenderer) dragSource;
        FormController fct = dr.getDataAdapterList().getFormController();
        jsEvent.setSource(fct.getFormScope());
    } else {
        jsEvent.setSource(dragSource);
        if (dragSource != null) {
            String dragSourceName = dragSource.getName();
            if (dragSourceName == null)
                dragSourceName = dragSource.getId();
            jsEvent.setElementName(dragSourceName);
        }
    }
    if (xy != null)
        jsEvent.setLocation(xy);
    jsEvent.setModifiers(modifiers);
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) Record(com.servoy.j2db.dataprocessing.Record)

Example 3 with Record

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

the class FormDataTransferHandler method createScriptEvent.

@Override
protected JSDNDEvent createScriptEvent(EventType type, ICompositeDragNDrop ddComponent, Object event) {
    JSDNDEvent jsEvent = super.createScriptEvent(type, ddComponent, event);
    if (ddComponent instanceof IFormDataDragNDrop) {
        IFormDataDragNDrop formDataDDComponent = (IFormDataDragNDrop) ddComponent;
        jsEvent.setFormName(formDataDDComponent.getDragFormName());
        Point location = getEventXY(event);
        if (location != null) {
            Object dragSource = ddComponent.getDragSource(location);
            if (dragSource instanceof IDataRenderer) {
                IDataRenderer dr = (IDataRenderer) dragSource;
                FormController fc = dr.getDataAdapterList().getFormController();
                jsEvent.setSource(fc.getFormScope());
            } else if (dragSource instanceof IComponent) {
                jsEvent.setSource(dragSource);
                if (dragSource != null) {
                    String name = ((IComponent) dragSource).getName();
                    if (name != null && name.startsWith(ComponentFactory.WEB_ID_PREFIX)) {
                        name = null;
                    }
                    jsEvent.setElementName(name);
                }
            }
            IRecordInternal dragRecord = formDataDDComponent.getDragRecord(location);
            if (dragRecord instanceof Record)
                jsEvent.setRecord((Record) dragRecord);
        }
    }
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IComponent(com.servoy.j2db.ui.IComponent) Record(com.servoy.j2db.dataprocessing.Record) Point(java.awt.Point)

Example 4 with Record

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

the class TableScope method getCalculationValue.

private Object getCalculationValue(Function calculation, String name) {
    Scriptable proto = getPrototype();
    // we can't return then anything.
    if (proto == null) {
        return null;
    }
    Object[] array = getThreadLocalArray();
    List<String> callStack = (List<String>) array[2];
    if (callStack == null) {
        callStack = new ArrayList<String>();
        array[2] = callStack;
    }
    Record record = null;
    String callStackName = name;
    if (proto instanceof Record) {
        record = (Record) proto;
        callStackName = callStackName + '_' + record.getRawData().getPKHashKey();
    }
    UsedDataProviderTracker tracker = null;
    try {
        boolean contains = callStack.contains(callStackName);
        // first add before doing anything else!
        callStack.add(callStackName);
        // now we decide if we try to return from row cache or calculate again
        if (contains) {
            if (record != null) {
                return record.getRawData().getValue(name);
            }
            // $NON-NLS-1$
            throw new RuntimeException(Messages.getString("servoy.error.cycleDetected", new Object[] { name, table.getName(), callStack }));
        }
        tracker = usedDataProviderTracker.get();
        if (tracker != null) {
            ((RecordingScriptable) getFunctionParentScriptable()).pushRecordingTracker(tracker);
            setUsedDataProviderTracker(null);
        }
        Object o = scriptEngine.executeFunction(calculation, this, getFunctionParentScriptable(), (Object[]) array[1], false, false);
        // record value trick
        if (o instanceof Undefined && record != null)
            o = record.getRawData().getValue(name);
        return o;
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getString("servoy.error.executingCalculation", new Object[] { name, table.getName(), e.toString() }), e);
    } finally {
        if (tracker != null) {
            ((RecordingScriptable) getFunctionParentScriptable()).popRecordingTracker();
        }
        callStack.remove(callStackName);
        if (callStack.size() == 0) {
            // clear the thread locals.
            values.remove();
        }
    }
}
Also used : Undefined(org.mozilla.javascript.Undefined) Scriptable(org.mozilla.javascript.Scriptable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.servoy.j2db.dataprocessing.Record)

Example 5 with Record

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

the class Utils method getScriptableString.

/**
 * Returns a js/json string representation of the given {@link Scriptable}
 * @param scriptable
 * @param processed map to prevent loops in graph
 * @return the scriptable as string
 */
private static CharSequence getScriptableString(Scriptable scriptable, Map<Scriptable, CharSequence> processed) {
    Context.enter();
    try {
        if (scriptable instanceof Record || scriptable instanceof FoundSet)
            return scriptable.toString();
        if (scriptable instanceof XMLObject || scriptable instanceof NativeError)
            return scriptable.toString();
        CharSequence processedString = processed.get(scriptable);
        if (processedString != null) {
            return processedString;
        }
        if (processed.size() > 10)
            return scriptable.toString();
        if (// $NON-NLS-1$
        scriptable instanceof NativeArray)
            // $NON-NLS-1$
            processed.put(scriptable, "Array[SelfRef]");
        else
            // $NON-NLS-1$
            processed.put(scriptable, "Object[SelfRef]");
        Object[] ids = scriptable.getIds();
        if (ids != null && ids.length > 0) {
            StringBuilder sb = new StringBuilder();
            if (scriptable instanceof NativeArray)
                sb.append('[');
            else
                sb.append('{');
            for (Object object : ids) {
                if (!(object instanceof Integer)) {
                    sb.append(object);
                    sb.append(':');
                }
                Object value = null;
                if (object instanceof String) {
                    value = scriptable.get((String) object, scriptable);
                } else if (object instanceof Number) {
                    value = scriptable.get(((Number) object).intValue(), scriptable);
                }
                if (!(value instanceof NativeJavaMethod)) {
                    if (value instanceof Scriptable) {
                        sb.append(getScriptableString((Scriptable) value, processed));
                    } else {
                        sb.append(value);
                    }
                    sb.append(',');
                }
            }
            sb.setLength(sb.length() - 1);
            if (scriptable instanceof NativeArray)
                sb.append(']');
            else
                sb.append('}');
            processed.put(scriptable, sb);
            return sb;
        }
        Object defaultValue;
        try {
            defaultValue = scriptable.getDefaultValue(String.class);
        } catch (Exception e) {
            defaultValue = null;
        }
        if (defaultValue == null)
            defaultValue = scriptable.toString();
        processed.put(scriptable, defaultValue.toString());
        return defaultValue.toString();
    } finally {
        Context.exit();
    }
}
Also used : NativeArray(org.mozilla.javascript.NativeArray) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) XMLObject(org.mozilla.javascript.xml.XMLObject) NativeError(org.mozilla.javascript.NativeError) Scriptable(org.mozilla.javascript.Scriptable) IScriptable(com.servoy.j2db.scripting.IScriptable) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) BigInteger(java.math.BigInteger) NativeJavaMethod(org.mozilla.javascript.NativeJavaMethod) Record(com.servoy.j2db.dataprocessing.Record) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) JSONObject(org.json.JSONObject) XMLObject(org.mozilla.javascript.xml.XMLObject)

Aggregations

Record (com.servoy.j2db.dataprocessing.Record)5 FormController (com.servoy.j2db.FormController)3 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)3 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)3 JSDNDEvent (com.servoy.j2db.dnd.JSDNDEvent)2 IComponent (com.servoy.j2db.ui.IComponent)2 Scriptable (org.mozilla.javascript.Scriptable)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 IScriptable (com.servoy.j2db.scripting.IScriptable)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigInteger (java.math.BigInteger)1