Search in sources :

Example 6 with ValueList

use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.

the class ValueListTypeSabloValue method getValuelistPersist.

public static ValueList getValuelistPersist(Object valuelistId, IApplication application) {
    ValueList valuelistPersist = null;
    int valuelistID = Utils.getAsInteger(valuelistId);
    if (valuelistID > 0) {
        valuelistPersist = application.getFlattenedSolution().getValueList(valuelistID);
    } else {
        // just try to get the valuelist by name or by uuid string (the FS will cache for both)
        if (valuelistId instanceof String)
            valuelistPersist = application.getFlattenedSolution().getValueList(valuelistId.toString());
        if (valuelistPersist == null) {
            if (valuelistId != null)
                valuelistPersist = (ValueList) application.getFlattenedSolution().searchPersist(valuelistId.toString());
        }
    }
    return valuelistPersist;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) ColumnBasedValueList(com.servoy.j2db.server.ngclient.ColumnBasedValueList) DBValueList(com.servoy.j2db.dataprocessing.DBValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 7 with ValueList

use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.

the class ComponentFactory method createTypeAheadWithValueList.

/**
 * @param application
 * @param field
 * @param dataProviderLookup
 * @param fl
 * @return
 */
private static IFieldComponent createTypeAheadWithValueList(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, int type, ParsedFormat format, IStylePropertyChangesRecorder jsChangeRecorder) {
    RuntimeDataField scriptable;
    IFieldComponent fl;
    ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
    if (valuelist == null) {
        scriptable = new RuntimeDataField(jsChangeRecorder, application);
        fl = application.getItemFactory().createDataField(scriptable, getWebID(form, field));
    } else {
        scriptable = new RuntimeDataLookupField(jsChangeRecorder, application);
        if (valuelist.getValueListType() == IValueListConstants.DATABASE_VALUES) {
            try {
                IValueList secondLookup = getFallbackValueList(application, field.getDataProviderID(), type, format, valuelist);
                LookupValueList lookupValueList = new LookupValueList(valuelist, application, secondLookup, format != null ? format.getDisplayFormat() : null);
                fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), lookupValueList);
            } catch (Exception e1) {
                Debug.error(e1);
                return null;
            }
        } else if (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES || valuelist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
            fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), (CustomValueList) getRealValueList(application, valuelist, true, type, format, field.getDataProviderID()));
        } else {
            return null;
        }
    }
    scriptable.setComponent(fl, field);
    return fl;
}
Also used : RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) IValueList(com.servoy.j2db.dataprocessing.IValueList) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 8 with ValueList

use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.

the class ClientState method setValueListItems.

/**
 * @param name
 * @param displayValues
 * @param realValues
 * @param autoconvert
 */
public void setValueListItems(String name, Object[] displayValues, Object[] realValues, boolean autoconvert) {
    ValueList vl = getFlattenedSolution().getValueList(name);
    if (vl != null && vl.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
        // TODO should getValueListItems not specify type and format??
        IValueList valuelist = ComponentFactory.getRealValueList(this, vl, false, Types.OTHER, null, null);
        if (valuelist instanceof CustomValueList) {
            int guessedType = Types.OTHER;
            if (autoconvert && realValues != null) {
                guessedType = guessValuelistType(realValues);
            } else if (autoconvert && displayValues != null) {
                guessedType = guessValuelistType(displayValues);
            }
            if (guessedType != Types.OTHER) {
                ((CustomValueList) valuelist).setValueType(guessedType);
            }
            ((CustomValueList) valuelist).fillWithArrayValues(displayValues, realValues);
            ((CustomValueList) valuelist).setRuntimeChanged(true);
            IBasicFormManager fm = getFormManager();
            List<IFormController> cachedFormControllers = fm.getCachedFormControllers();
            for (IFormController form : cachedFormControllers) {
                form.refreshView();
            }
        }
    }
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) ValueList(com.servoy.j2db.persistence.ValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 9 with ValueList

use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.

the class FormTemplateGenerator method isSingleValueComponent.

/**
 * @return false if the persist has no valuelist or at most one value in the valuelist, true otherwise
 */
public static boolean isSingleValueComponent(IFormElement persist) {
    Field field = (Field) persist;
    if (field.getValuelistID() > 0) {
        try {
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            FlattenedSolution fs = new FlattenedSolution((SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(((Solution) persist.getRootObject()).getName(), IRepository.SOLUTIONS), new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
            ValueList valuelist = fs.getValueList(field.getValuelistID());
            return isSingleValue(valuelist);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : Field(com.servoy.j2db.persistence.Field) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) ValueList(com.servoy.j2db.persistence.ValueList) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IRepository(com.servoy.j2db.persistence.IRepository) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 10 with ValueList

use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.

the class JSApplication method js_getValueListArray.

/**
 * Retrieve a valuelist as array, to get real-values for display-values.
 * NOTE: this doesn't return a value for a valuelist that depends on a database relation or is a global method valuelist.
 *
 * @sample
 * var packet_types = application.getValueListArray('packet_types');
 * if (a_realValue == packet_types['displayValue'])
 * {
 * }
 *
 * @param name The name of the valuelist
 *
 * @return Named array for the valuelist
 */
public NativeArray js_getValueListArray(String name) {
    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) {
                // TODO check if this works
                NativeArray retval = (NativeArray) Context.getCurrentContext().newArray(application.getScriptEngine().getSolutionScope(), 0);
                retval.setPrototype(ScriptableObject.getClassPrototype(application.getScriptEngine().getSolutionScope(), "Array"));
                for (int i = 0; i < valuelist.getSize(); i++) {
                    Object obj = valuelist.getElementAt(i);
                    if (obj == null)
                        continue;
                    String strObj = null;
                    int index = i;
                    if (valuelist.hasRealValues()) {
                        strObj = obj.toString();
                        // test to see if the key is an indexable number, apply same logic as in ScriptRuntime.getElem(Object obj, Object id, Scriptable scope)
                        long indexTest = indexFromString(strObj);
                        if (indexTest >= 0) {
                            index = (int) indexTest;
                            strObj = null;
                        }
                    }
                    if (strObj == null) {
                        retval.put(index, retval, valuelist.getRealElementAt(i));
                    } else {
                        retval.put(strObj, retval, valuelist.getRealElementAt(i));
                    }
                }
                return retval;
            }
        }
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
Also used : NativeArray(org.mozilla.javascript.NativeArray) 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) ScriptableObject(org.mozilla.javascript.ScriptableObject) 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)

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