use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class SwingForm method showSortDialog.
public void showSortDialog(IApplication app, String options) {
ISmartClientApplication application = (ISmartClientApplication) app;
try {
Table t = (Table) formController.getTable();
if (t != null) {
List<SortColumn> sortColumns = null;
if ((options == null || options.length() == 0) && formController.getFormModel() instanceof FoundSet) {
sortColumns = ((FoundSet) formController.getFormModel()).getLastSortColumns();
} else {
sortColumns = ((FoundSetManager) application.getFoundSetManager()).getSortColumns(t, options);
}
Window window = SwingUtilities.getWindowAncestor(this);
if (window == null)
window = application.getMainApplicationFrame();
// $NON-NLS-1$
SortDialog nfd = (SortDialog) application.getWindow("SortDialog");
if (nfd == null || nfd.getOwner() != window) {
if (window instanceof Frame) {
nfd = new SortDialog((Frame) window, application);
} else if (window instanceof Dialog) {
nfd = new SortDialog((Dialog) window, application);
}
// $NON-NLS-1$
application.registerWindow("SortDialog", nfd);
}
List<SortColumn> list = nfd.showDialog(t, sortColumns);
if (list != null)
formController.sort(list, false);
}
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(Messages.getString("servoy.formPanel.error.sortRecordsDialog"), ex);
}
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class JSDataSource method loadRecords.
/**
* get a new foundset containing records based on a dataset of pks.
*
* @sample var fs = datasources.db.example_data.customers.loadRecords(pkDataSet)
*
* @param dataSet
* @return a new JSFoundset
* @throws ServoyException
*/
@JSFunction
public IFoundSet loadRecords(IDataSet dataSet) throws ServoyException {
IFoundSet foundset = application.getFoundSetManager().getFoundSet(datasource);
((FoundSet) foundset).js_loadRecords(dataSet);
return checkDataSourceEquality(foundset) ? foundset : null;
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class JSUtils method js_stringReplaceTags.
/**
* Returns the text with %%tags%% replaced, based on provided record or foundset or form.
*
* @sample
* //Next line places a string in variable x, whereby the tag(%%TAG%%) is filled with the value of the database column 'company_name' of the selected record.
* var x = utils.stringReplaceTags("The companyName of the selected record is %%company_name%% ", foundset)
* //var otherExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails);
* //var recordExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails.getRecord(i);
* //Next line places a string in variable y, whereby the tag(%%TAG%%) is filled with the value of the form variable 'x' of the form named 'main'.
* //var y = utils.stringReplaceTags("The value of form variable is %%x%% ", forms.main);
* //The next sample shows the use of a javascript object
* //var obj = new Object();//create a javascript object
* //obj['x'] = 'test';//assign an named value
* //var y = utils.stringReplaceTags("The value of object variable is %%x%% ", obj);//use the named value in a tag
* @param text the text tags to work with
* @param scriptable the javascript object or foundset,record,form to be used to fill in the tags
* @return the text with replaced tags
*/
public String js_stringReplaceTags(String text, Object scriptable) {
if (text != null) {
ITagResolver tagResolver = null;
Properties settings = null;
if (scriptable instanceof FoundSet) {
IRecordInternal record = ((FoundSet) scriptable).getRecord(((FoundSet) scriptable).getSelectedIndex());
if (record != null) {
settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
tagResolver = TagResolver.createResolver(record);
}
} else if (scriptable instanceof IRecordInternal) {
IRecordInternal record = (IRecordInternal) scriptable;
settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
tagResolver = TagResolver.createResolver(record);
} else if (scriptable instanceof BasicFormController) {
final BasicFormController fc = (BasicFormController) scriptable;
IFoundSetInternal fs = fc.getFoundSet();
final ITagResolver defaultTagResolver = (fs != null) ? TagResolver.createResolver(fs.getRecord(fs.getSelectedIndex())) : null;
settings = fc.getApplication().getSettings();
tagResolver = new ITagResolver() {
public String getStringValue(String name) {
Object value = fc.getFormScope().get(name);
if (value == null || value == Scriptable.NOT_FOUND) {
value = defaultTagResolver != null ? defaultTagResolver.getStringValue(name) : null;
}
// $NON-NLS-1$
return value != null ? value.toString() : "";
}
};
} else if (scriptable instanceof Scriptable) {
Scriptable scriptObject = (Scriptable) scriptable;
settings = Settings.getInstance();
tagResolver = TagResolver.createResolver(scriptObject, application);
}
if (tagResolver != null && settings != null) {
return Text.processTags(TagResolver.formatObject(text, application), tagResolver);
}
// $NON-NLS-1$
return "";
} else {
// $NON-NLS-1$
return "";
}
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class ScriptEngine method compileScriptProvider.
/**
* @param sp
* @param scope
* @param cx
* @return
*/
@SuppressWarnings("nls")
protected Function compileScriptProvider(IScriptProvider sp, Scriptable scope, Context cx, String sourceName) {
String declaration = sp.getDeclaration();
// dont return the calc function itself but still the value.
if (sp instanceof ScriptCalculation) {
declaration = extractFunction(declaration, "function $1_");
} else {
declaration = extractFunction(declaration, "function $1");
}
// f below always seems to be NativeFunction instance as both Codegen.createFunctionObject and Interpreter.createFunctionObject return
// a NativeFunction instance; and that is what cx.compileFunction(...) ends up calling
Function f = cx.compileFunction(scope, declaration, sourceName, sp.getLineNumberOffset(), null);
if (!(sp instanceof ScriptCalculation)) {
if (sp.getScopeName() != null) {
// $NON-NLS-1$
f.put("_scopename_", f, sp.getScopeName());
}
// $NON-NLS-1$
f.put("_methodname_", f, sp.getDataProviderID());
f.put("_AllowToRunInFind_", f, Boolean.valueOf(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
sp.getDeclaration().indexOf("@AllowToRunInFind") != -1 || declaration.indexOf(".search") != -1 || declaration.indexOf("controller.loadAllRecords") != -1));
}
String methodName = sp.getName();
PerformanceData performanceData = application instanceof IPerformanceDataProvider ? ((IPerformanceDataProvider) application).getPerformanceData() : null;
if (performanceData != null) {
String scopeName = scope.getClassName();
if (scope instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) scope).getScopeName();
scopeName = lookForSuperCalls(sp, scopeName);
} else if (scope.getParentScope() instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) scope.getParentScope()).getScopeName();
scopeName = lookForSuperCalls(sp, scopeName);
} else if (scope instanceof FoundSet) {
Scriptable parentScope = ((FoundSet) scope).getPrototype();
if (parentScope instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) parentScope).getScopeName();
}
}
methodName = scopeName + "." + methodName;
return new FunctionWrapper(f, methodName, performanceData, application.getClientID());
}
return f;
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class ScriptVariableScope method put.
public Object put(String name, Object val) {
Object value = Utils.mapToNullIfUnmanageble(val);
Integer variableType = nameType.get(name);
int type = 0;
boolean xmlType = false;
if (variableType == null) {
// global doesn't exist. dynamic new one.. so MEDIA type
type = IColumnTypes.MEDIA;
nameType.put(name, new Integer(type));
// $NON-NLS-1$//$NON-NLS-2$
Debug.trace("Warning: " + name + " is not defined in the variables, a dynamic (media type) variable is created");
} else {
if (variableType.intValue() == Types.OTHER) {
type = IColumnTypes.MEDIA;
xmlType = true;
} else {
type = Column.mapToDefaultType(variableType.intValue());
}
}
if (type == IColumnTypes.TEXT) {
Object txt = value;
while (txt instanceof IDelegate<?>) {
txt = ((IDelegate<?>) txt).getDelegate();
}
if (txt instanceof IDataSet) {
IDataSet set = (IDataSet) txt;
StringBuilder sb = new StringBuilder();
sb.append('\n');
for (int i = 0; i < set.getRowCount(); i++) {
sb.append(set.getRow(i)[0]);
sb.append('\n');
}
value = sb.toString();
} else if (txt instanceof FoundSet) {
StringBuilder sb = new StringBuilder();
sb.append('\n');
FoundSet fs = (FoundSet) txt;
for (int i = 0; i < fs.getSize(); i++) {
IRecordInternal record = fs.getRecord(i);
sb.append(record.getPKHashKey());
sb.append('\n');
}
value = sb.toString();
}
}
if (value != null && variableType != null) {
Object unwrapped = value;
while (unwrapped instanceof Wrapper) {
unwrapped = ((Wrapper) unwrapped).unwrap();
if (unwrapped == value) {
break;
}
}
if (type == IColumnTypes.MEDIA) {
if (!(unwrapped instanceof UUID)) {
Object previousValue = get(name);
if (previousValue instanceof UUID || previousValue == null) {
Iterator<ScriptVariable> scriptVariablesIte = getScriptLookup().getScriptVariables(false);
ScriptVariable sv;
while (scriptVariablesIte.hasNext()) {
sv = scriptVariablesIte.next();
if (name.equals(sv.getName())) {
if (UUID.class.getSimpleName().equals(getDeclaredType(sv))) {
value = Utils.getAsUUID(unwrapped, false);
}
break;
}
}
}
}
} else {
value = unwrapped;
try {
// dont convert with timezone here, its not ui but from scripting
value = Column.getAsRightType(variableType.intValue(), IBaseColumn.NORMAL_COLUMN, value, null, Integer.MAX_VALUE, null, true, false);
} catch (Exception e) {
throw new IllegalArgumentException(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"servoy.conversion.error.global", new Object[] { name, Column.getDisplayTypeString(variableType.intValue()), value }));
}
}
}
if (value instanceof Date) {
// make copy so then when it is further used in js it won't change this one.
value = new Date(((Date) value).getTime());
} else if (xmlType && value instanceof String) {
// $NON-NLS-1$
value = evalValue(name, (String) value, "internal_anon", -1);
}
Object oldVar = allVars.get(name);
allVars.put(name, value);
if (variableType != null && !Utils.equalObjects(oldVar, value)) {
fireModificationEvent(name, value);
}
return oldVar;
}
Aggregations