Search in sources :

Example 11 with GlobalScope

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

the class DataAdapterList method getValueObject.

public static Object getValueObject(IRecord record, FormScope fs, String dataProviderID) {
    if (dataProviderID == null || fs == null)
        return null;
    Object value = null;
    Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
    if (scope.getLeft() != null) {
        try {
            GlobalScope gs = fs.getFormController().getApplication().getScriptEngine().getScopesScope().getGlobalScope(scope.getLeft());
            value = gs == null ? null : gs.get(scope.getRight());
        } catch (Exception e) {
            Debug.error(e);
        }
    } else if (record != null) {
        value = record.getValue(dataProviderID);
    }
    if ((value == Scriptable.NOT_FOUND || value == null) && fs.has(dataProviderID, fs)) {
        value = fs.get(dataProviderID);
    }
    return value;
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 12 with GlobalScope

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

the class GlobalMethodValueList method fill.

public void fill(IRecordInternal state, String filter, Object real, boolean force) {
    String display = filter == null ? null : filter.toLowerCase();
    if (filling) {
        return;
    }
    try {
        filling = true;
        if (force || this.record != state || !Utils.equalObjects(display, this.displayString) || !Utils.equalObjects(real, this.realObject)) {
            this.displayString = display;
            this.realObject = real;
            this.record = state;
            super.fill(state);
            GlobalScope globalScope = application.getScriptEngine().getScopesScope().getGlobalScope(globalFunction.getLeft());
            if (globalScope != null) {
                Function function = globalScope.getFunctionByName(globalFunction.getRight());
                try {
                    if (// $NON-NLS-1$
                    real == null || "".equals(real)) {
                        application.invokeAndWait(new Runnable() {

                            public void run() {
                                realValues = new SafeArrayList<Object>();
                                removeAllElements();
                            }
                        });
                    } else if (realValues == null) {
                        realValues = new SafeArrayList<Object>();
                    }
                    Object[] args = null;
                    if (// $NON-NLS-1$
                    display != null && !"".equals(display)) {
                        args = new Object[] { display, null, state, valueList.getName(), Boolean.valueOf(state instanceof FindState), filter };
                    } else if (// $NON-NLS-1$
                    real != null && !"".equals(real)) {
                        args = new Object[] { null, real, state, valueList.getName(), Boolean.valueOf(state instanceof FindState), null };
                    } else {
                        args = new Object[] { null, null, state, valueList.getName(), Boolean.valueOf(state instanceof FindState), null };
                    }
                    final Object retValue = application.getScriptEngine().executeFunction(function, globalScope, globalScope, args, false, true);
                    application.invokeAndWait(new Runnable() {

                        public void run() {
                            // add empty row
                            if (valueList.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS) {
                                // $NON-NLS-1$
                                addElement("");
                                realValues.add(null);
                            }
                            if (retValue instanceof IDataSet && ((IDataSet) retValue).getRowCount() > 0) {
                                startBundlingEvents();
                                try {
                                    hasRealValue = false;
                                    IDataSet dataSet = (IDataSet) retValue;
                                    for (int i = 0; i < dataSet.getRowCount(); i++) {
                                        Object[] row = dataSet.getRow(i);
                                        if (row.length == 1) {
                                            realValues.add(CustomValueList.handleRowData(valueList, false, 1, row, application));
                                        } else {
                                            hasRealValue = true;
                                            realValues.add(CustomValueList.handleRowData(valueList, false, 2, row, application));
                                        }
                                        addElement(CustomValueList.handleRowData(valueList, false, 1, row, application));
                                    }
                                } finally {
                                    stopBundlingEvents();
                                }
                            }
                        }
                    });
                } catch (Exception e) {
                    // $NON-NLS-1$
                    application.reportError("error getting data from global method valuelist", e);
                }
            }
        }
    } finally {
        filling = false;
    }
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) Function(org.mozilla.javascript.Function) SafeArrayList(com.servoy.j2db.util.SafeArrayList)

Aggregations

GlobalScope (com.servoy.j2db.scripting.GlobalScope)12 Function (org.mozilla.javascript.Function)7 Scriptable (org.mozilla.javascript.Scriptable)7 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 ServoyException (com.servoy.j2db.util.ServoyException)4 Solution (com.servoy.j2db.persistence.Solution)3 FormScope (com.servoy.j2db.scripting.FormScope)3 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)3 IJSFoundSet (com.servoy.base.scripting.api.IJSFoundSet)2 ApplicationException (com.servoy.j2db.ApplicationException)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)2 IFoundSet (com.servoy.j2db.dataprocessing.IFoundSet)2 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)2 RelatedFoundSet (com.servoy.j2db.dataprocessing.RelatedFoundSet)2 ViewFoundSet (com.servoy.j2db.dataprocessing.ViewFoundSet)2 Form (com.servoy.j2db.persistence.Form)2 ITwoNativeJavaObject (com.servoy.j2db.scripting.ITwoNativeJavaObject)2 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2