Search in sources :

Example 6 with IValueList

use of com.servoy.j2db.dataprocessing.IValueList 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 7 with IValueList

use of com.servoy.j2db.dataprocessing.IValueList 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)

Example 8 with IValueList

use of com.servoy.j2db.dataprocessing.IValueList 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 9 with IValueList

use of com.servoy.j2db.dataprocessing.IValueList in project servoy-client by Servoy.

the class DataLookupField method setValidationEnabled.

/**
 * @see com.servoy.j2db.smart.dataui.DataField#setValidationEnabled(boolean)
 */
@Override
public void setValidationEnabled(boolean b) {
    if (eventExecutor.getValidationEnabled() == b)
        return;
    if (dataProviderID != null && ScopesUtils.isVariableScope(dataProviderID))
        return;
    if (list != null && list.getFallbackValueList() != null) {
        IValueList vlist = list;
        if (!b) {
            vlist = list.getFallbackValueList();
        }
        if (vlist instanceof CustomValueList) {
            createCustomListModel((CustomValueList) vlist);
        } else {
            createLookupListModel((LookupValueList) vlist);
        }
        if (jlist != null) {
            jlist.setModel(dlm);
        }
    }
    try {
        focusGainedOrValidationChange = true;
        eventExecutor.setValidationEnabled(b);
        consumeEnterReleased = false;
        boolean prevEditState = editState;
        if (b) {
            setEditable(wasEditable);
            if (editProvider != null) {
                editProvider.setAdjusting(true);
            }
            try {
                // prevent errors
                setValue(null);
            } finally {
                if (editProvider != null) {
                    editProvider.setAdjusting(false);
                }
            }
        } else {
            wasEditable = isEditable();
            if (!Boolean.TRUE.equals(application.getClientProperty(IApplication.LEAVE_FIELDS_READONLY_IN_FIND_MODE))) {
                setEditable(true);
            }
        }
        editState = prevEditState;
    } finally {
        focusGainedOrValidationChange = false;
    }
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 10 with IValueList

use of com.servoy.j2db.dataprocessing.IValueList in project servoy-client by Servoy.

the class AbstractRuntimeValuelistComponent method setValueListItems.

public void setValueListItems(Object value) {
    if (getComponent() instanceof ISupportValueList) {
        IValueList list = ((ISupportValueList) getComponent()).getValueList();
        if (list != null && (value instanceof JSDataSet || value instanceof IDataSet)) {
            String name = list.getName();
            ValueList valuelist = application.getFlattenedSolution().getValueList(name);
            if (valuelist != null && valuelist.getValueListType() == ValueList.CUSTOM_VALUES) {
                ParsedFormat format = null;
                int type = 0;
                if (list instanceof CustomValueList) {
                    format = ((CustomValueList) list).getFormat();
                    type = ((CustomValueList) list).getValueType();
                }
                IValueList newVl = ValueListFactory.fillRealValueList(application, valuelist, ValueList.CUSTOM_VALUES, format, type, value);
                ((ISupportValueList) getComponent()).setValueList(newVl);
            }
        }
    }
}
Also used : ParsedFormat(com.servoy.j2db.util.FormatParser.ParsedFormat) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) ValueList(com.servoy.j2db.persistence.ValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Aggregations

IValueList (com.servoy.j2db.dataprocessing.IValueList)15 ValueList (com.servoy.j2db.persistence.ValueList)11 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)8 LookupValueList (com.servoy.j2db.dataprocessing.LookupValueList)5 ISupportValueList (com.servoy.j2db.ui.ISupportValueList)4 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 ApplicationException (com.servoy.j2db.ApplicationException)2 ExitScriptException (com.servoy.j2db.ExitScriptException)2 IRefreshValueList (com.servoy.j2db.IRefreshValueList)2 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)2 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)2 ParsedFormat (com.servoy.j2db.util.FormatParser.ParsedFormat)2 ServoyException (com.servoy.j2db.util.ServoyException)2 Point (java.awt.Point)2 JavaScriptException (org.mozilla.javascript.JavaScriptException)2 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)1