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;
}
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;
}
}
Aggregations