use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class JSApplication method js_getValueListDisplayValue.
/**
* Retrieve a valuelist display-value for a real-value.
* NOTE: this doesn't return a value for a valuelist that depends on a database relation or is a global method valuelist.
*
* @sample var displayable_status = application.getValueListDisplayValue('case_status',status);
*
* @param name Name of the valuelist
*
* @param realValue Real value of the valuelist
*
* @return Display value of the real value from the valuelist
*/
public Object js_getValueListDisplayValue(String name, Object realValue) {
try {
ValueList vl = application.getFlattenedSolution().getValueList(name);
if (vl != null) {
// TODO should getValueListItems not specify type and format??
IValueList valuelist = ComponentFactory.getRealValueList(application, vl, true, Types.OTHER, null, null);
if (valuelist != null) {
int index = valuelist.realValueIndexOf(realValue);
if (index != -1) {
return valuelist.getElementAt(index);
} else {
// maybe is missing because of 500 limit of valuelist, look it up
LookupValueList lvl = new LookupValueList(vl, application, ComponentFactory.getFallbackValueList(application, null, Types.OTHER, null, vl), null);
index = lvl.realValueIndexOf(realValue, false);
if (index != -1) {
return lvl.getElementAt(index);
}
}
}
}
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class JSValueList method getFallbackValueList.
/**
* Gets or sets the fallback valuelist.
*
* @sample
* var myValueList = solutionModel.getValueList('myValueListHere')
* //get fallback value list
* var fallbackValueList = myValueList.fallbackValueList
*/
@JSGetter
public JSValueList getFallbackValueList() {
FlattenedSolution fs = application.getFlattenedSolution();
int fallbackVLID = valuelist.getFallbackValueListID();
ValueList fallbackVL = fs.getValueList(fallbackVLID);
if (fallbackVL != null) {
return new JSValueList(fallbackVL, application, false);
} else {
return null;
}
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class JSApplication method js_getValueListNames.
/**
* Get all the valuelist names as array.
*
* @sample var array = application.getValueListNames();
*
* @return Array with all valuelist names
*/
public String[] js_getValueListNames() {
List<String> retval = new ArrayList<String>();
try {
Iterator<ValueList> it = application.getFlattenedSolution().getValueLists(true);
while (it.hasNext()) {
ValueList vl = it.next();
retval.add(vl.getName());
}
} catch (Exception e) {
Debug.error(e);
}
return retval.toArray(new String[retval.size()]);
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class JSSolutionModel method getValueLists.
/**
* Gets an array of all valuelists for the currently active solution.
*
* NOTE: Changes to valuelist should be done before showing any form that has component using the valuelist.
*
* @sample
* var valueLists = solutionModel.getValueLists();
* if (valueLists != null && valueLists.length != 0)
* for (var i in valueLists)
* application.output(valueLists[i].name);
*
* @return an array of JSValueList objects
*/
@JSFunction
public JSValueList[] getValueLists() {
FlattenedSolution fs = application.getFlattenedSolution();
ArrayList<JSValueList> valuelists = new ArrayList<JSValueList>();
Iterator<ValueList> iterator = fs.getValueLists(true);
while (iterator.hasNext()) {
valuelists.add(new JSValueList(iterator.next(), application, false));
}
return valuelists.toArray(new JSValueList[valuelists.size()]);
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class JSSolutionModel method removeValueList.
/**
* Removes the specified valuelist.
*
* @sample
* var vlName = "customValueList";
* var vl = solutionModel.newValueList(vlName,JSValueList.CUSTOM_VALUES);
* vl.customValues = "customvalue1\ncustomvalue2";
*
* var status = solutionModel.removeValueList(vlName);
* if (status) application.output("Removal has been done.");
* else application.output("ValueList not removed.");
*
* var vls = solutionModel.getValueLists();
* if (vls != null) {
* for (var i = 0; i < vls.length; i++) {
* application.output(vls[i]);
* }
* application.output("");
* }
*
* @param name name of the valuelist to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeValueList(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
ValueList valueList = fs.getValueList(name);
if (valueList != null) {
fs.deletePersistCopy(valueList, false);
return true;
}
return false;
}
Aggregations