use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSValueList method getGlobalMethod.
/**
* The global method of the valuelist is called to fill in or adjust the values of the valuelist.
* The method returns a dataset with one or two columns, first column is the display value, second column is real value(if present).
* The valuelist will be filled in with the dataset data. If second column is not present real value and display value will be the same.
* The method has to handle three different scenarios:
* 1. 'displayValue' parameter is not null, this parameter should be used to filter the list of values(in a typeahead fashion)
* 2. 'realValue' parameter is specified, that means value was not found in current list, so must be specified manually.
* In this case method should return only one row in the dataset, with the missing value, that will be added to the valuelist
* 3. 'realValue' and 'displayValue' are both null , in this case the complete list of values should be returned.
*
* Scenario 1 and 3 will completely replace any older results in the valuelist while scenario 2 will append results.
*
* In find mode the record will be the FindRecord which is just like a normal JSRecord (DataRecord) it has the same properties (column/dataproviders) but doesnt have its methods (like isEditing())
*
* The last argument is rawDisplayValue which contains the same text as displayValue but without converting it to lowercase.
*
* @sample
* var listProvider = solutionModel.newGlobalMethod('globals', 'function getDataSetForValueList(displayValue, realValue, record, valueListName, findMode, rawDisplayValue) {' +
* ' ' +
* 'var args = null;' +
* 'var query = datasources.db.example_data.employees.createSelect();' +
* '/** @type {JSDataSet} */' +
* 'var result = null;' +
* 'query.result.add(query.columns.firstname.concat(' ').concat(query.columns.lastname)).add(query.columns.employeeid);' +
* 'if (displayValue == null && realValue == null) {' +
* ' // TODO think about caching this result. can be called often!' +
* ' // return the complete list' +
* ' result = databaseManager.getDataSetByQuery(query,100);' +
* '} else if (displayValue != null) {' +
* ' // TYPE_AHEAD filter call, return a filtered list' +
* ' args = [displayValue + "%", displayValue + "%"]' +
* ' query.result.root.where.add(query.or.add(query.columns.firstname.lower.like(args[0] + '%')).add(query.columns.lastname.lower.like(args[1] + '%')));' +
* ' result = databaseManager.getDataSetByQuery(query,100);' +
* '} else if (realValue != null) {' +
* ' // TODO think about caching this result. can be called often!' +
* ' // real object not found in the current list, return 1 row with display,realvalue that will be added to the current list' +
* ' // dont return a complete list in this mode because that will be added to the list that is already there' +
* ' args = [realValue];' +
* ' query.result.root.where.add(query.columns.employeeid.eq(args[0]));' +
* ' result = databaseManager.getDataSetByQuery(query,1);' +
* '}' +
* 'return result;' +
* '}');
* var vlist = solutionModel.newValueList('vlist', JSValueList.CUSTOM_VALUES);
* vlist.globalMethod = listProvider;
*/
@JSGetter
public JSMethod getGlobalMethod() {
String uuid = valuelist.getCustomValues();
ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(uuid);
if (scriptMethod != null) {
return new JSMethod(scriptMethod, application, true);
}
return null;
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSValueList method toString.
/**
* @see java.lang.Object#toString()
*/
@SuppressWarnings("nls")
@Override
public String toString() {
int type = valuelist.getValueListType();
String typeString = "";
switch(type) {
case IValueListConstants.CUSTOM_VALUES:
typeString = "Custom";
break;
case IValueListConstants.GLOBAL_METHOD_VALUES:
ScriptMethod globalMethod = application.getFlattenedSolution().getScriptMethod(valuelist.getCustomValues());
typeString = "GlobalMethod:" + globalMethod != null ? globalMethod.getPrefixedName() : valuelist.getCustomValues();
break;
case IValueListConstants.TABLE_VALUES:
typeString = valuelist.getDatabaseValuesType() == IValueListConstants.TABLE_VALUES ? "Table:" + valuelist.getDataSource() : "Related:" + valuelist.getRelationName();
}
return "JSValueList[name:" + valuelist.getName() + ',' + typeString + ']';
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSValueList method setGlobalMethod.
@JSSetter
public void setGlobalMethod(IBaseSMMethod method) {
checkModification();
if (method == null) {
valuelist.setCustomValues(null);
valuelist.setValueListType(IValueListConstants.CUSTOM_VALUES);
} else {
ScriptMethod scriptMethod = ((JSMethod) method).getScriptMethod();
if (scriptMethod.getParent() instanceof Solution) {
valuelist.setCustomValues(scriptMethod.getUUID().toString());
valuelist.setValueListType(IValueListConstants.GLOBAL_METHOD_VALUES);
} else {
// $NON-NLS-1$
throw new RuntimeException("Only global methods are supported for a valuelist");
}
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class PropertyListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
int align = LEFT;
Font f = normalFont;
// $NON-NLS-1$
String newvalue = "";
if (value != null)
newvalue = value.toString();
if (value instanceof ScriptMethod) {
newvalue = ((ScriptMethod) value).getDisplayName();
}
if (value instanceof Pair && ((Pair) value).getLeft() != null) {
newvalue = ((Pair) value).getLeft().toString();
}
if (// $NON-NLS-1$
newvalue != null && newvalue.startsWith("*")) {
newvalue = newvalue.substring(1);
f = boldFont;
align = CENTER;
} else {
f = normalFont;
align = LEFT;
}
Component c = super.getListCellRendererComponent(list, newvalue, index, isSelected, cellHasFocus);
if (showToolTips) {
if (value instanceof ISupportHTMLToolTipText) {
String html = ((ISupportHTMLToolTipText) value).toHTML();
if (!html.startsWith("<html>"))
html = "<html>" + html + "</html>";
((JComponent) c).setToolTipText(html);
} else {
((JComponent) c).setToolTipText(null);
}
}
if (normalFont == null) {
normalFont = c.getFont();
boldFont = normalFont.deriveFont(Font.BOLD);
f = normalFont;
}
c.setFont(f);
if (c instanceof JLabel) {
((JLabel) c).setHorizontalAlignment(align);
}
return c;
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class FormScope method get.
@Override
public Object get(String name, Scriptable start) {
if (_fp == null) {
Debug.warn("Error accessing a form " + formName + " that is already destroyed for getting: " + name);
throw new ExitScriptException("killing current script, client/solution already terminated");
}
_fp.touch();
if (// $NON-NLS-1$
"alldataproviders".equals(name)) {
List<String> al = new ArrayList<String>();
Table table = (Table) _fp.getTable();
if (table != null) {
al = getDataproviderIdList(table);
}
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allmethods".equals(name)) {
List<String> al = new ArrayList<String>();
Iterator<ScriptMethod> it = _fp.getForm().getScriptMethods(true);
while (it.hasNext()) {
ScriptMethod sm = it.next();
al.add(sm.getName());
}
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allrelations".equals(name)) {
List<String> al = getFormRelationsIdList(_fp.getForm());
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allvariables".equals(name)) {
List<String> al = getAllVariablesIdList(_fp.getForm());
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
Object object = super.get(name, start);
if ((object == null || object == Scriptable.NOT_FOUND) && ("foundset".equals(name) || "elements".equals(name))) {
Debug.error(Thread.currentThread().getName() + ": For form " + _fp + " the foundset/elements were asked for but that was not (or was no longer) set. ", new RuntimeException());
if (name.equals("foundset"))
return _fp.getFormModel();
}
return object;
}
Aggregations