Search in sources :

Example 11 with ValueList

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;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IRefreshValueList(com.servoy.j2db.IRefreshValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ApplicationException(com.servoy.j2db.ApplicationException) ExitScriptException(com.servoy.j2db.ExitScriptException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 12 with ValueList

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;
    }
}
Also used : IBaseSMValueList(com.servoy.base.solutionmodel.IBaseSMValueList) ValueList(com.servoy.j2db.persistence.ValueList) ISMValueList(com.servoy.j2db.solutionmodel.ISMValueList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSGetter(org.mozilla.javascript.annotations.JSGetter)

Example 13 with ValueList

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()]);
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IRefreshValueList(com.servoy.j2db.IRefreshValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ArrayList(java.util.ArrayList) ApplicationException(com.servoy.j2db.ApplicationException) ExitScriptException(com.servoy.j2db.ExitScriptException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 14 with ValueList

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()]);
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 15 with ValueList

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;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

ValueList (com.servoy.j2db.persistence.ValueList)26 IValueList (com.servoy.j2db.dataprocessing.IValueList)16 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)10 LookupValueList (com.servoy.j2db.dataprocessing.LookupValueList)7 FlattenedSolution (com.servoy.j2db.FlattenedSolution)6 Form (com.servoy.j2db.persistence.Form)5 ISupportValueList (com.servoy.j2db.ui.ISupportValueList)5 ServoyException (com.servoy.j2db.util.ServoyException)5 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)4 Relation (com.servoy.j2db.persistence.Relation)4 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 ArrayList (java.util.ArrayList)4 ApplicationException (com.servoy.j2db.ApplicationException)3 ExitScriptException (com.servoy.j2db.ExitScriptException)3 IRefreshValueList (com.servoy.j2db.IRefreshValueList)3 DBValueList (com.servoy.j2db.dataprocessing.DBValueList)3 Field (com.servoy.j2db.persistence.Field)3 ITable (com.servoy.j2db.persistence.ITable)3 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)3 Point (java.awt.Point)3