Search in sources :

Example 16 with ValueList

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

the class JSSolutionModel method getValueList.

/**
 * Gets an existing valuelist by the specified name and returns a JSValueList Object that can be assigned to a field.
 *
 * NOTE: Changes to valuelist should be done before showing any form that has component using the valuelist.
 *
 * @sample
 * var myValueList = solutionModel.getValueList('myValueListHere')
 * //now set the valueList property of your field
 * //myField.valuelist = myValueList
 *
 * @param name the specified name of the valuelist
 *
 * @return a JSValueList object
 */
@JSFunction
public JSValueList getValueList(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ValueList valuelist = fs.getValueList(name);
    if (valuelist != null) {
        return new JSValueList(valuelist, application, false);
    }
    return null;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 17 with ValueList

use of com.servoy.j2db.persistence.ValueList 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)

Example 18 with ValueList

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

the class PersistFieldInstanceTest method fillTestSolution.

@Override
protected void fillTestSolution() throws RepositoryException {
    Form form = solution.createNewForm(validator, null, "test", null, false, new Dimension(600, 400));
    form.setNavigatorID(-1);
    ValueList valuelist = solution.createNewValueList(validator, "test");
    valuelist.setValueListType(IValueListConstants.CUSTOM_VALUES);
    valuelist = solution.createNewValueList(validator, "test_items");
    valuelist.setValueListType(IValueListConstants.CUSTOM_VALUES);
    valuelist.setAddEmptyValue(IValueListConstants.EMPTY_VALUE_NEVER);
}
Also used : Form(com.servoy.j2db.persistence.Form) ValueList(com.servoy.j2db.persistence.ValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) Dimension(java.awt.Dimension)

Example 19 with ValueList

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

the class ValueListPropertyType method toSabloComponentValue.

@Override
public ValueListTypeSabloValue toSabloComponentValue(Object rhinoValue, ValueListTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext webObjectContext) {
    if (rhinoValue == null || RhinoConversion.isUndefinedOrNotFound(rhinoValue))
        return null;
    if (previousComponentValue == null) {
        return rhinoValue instanceof String ? createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext) : null;
    }
    if (!previousComponentValue.isInitialized()) {
        if (rhinoValue instanceof String) {
            // weird; but we are going to create a new value anyway so it doesn't matter much
            return createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
        } else {
            // we cannot set values from a dataset if the previous value is not ready for it
            Debug.error("Trying to make changes (assignment) to an uninitialized valuelist property (this is not allowed): " + pd + " of " + webObjectContext, new RuntimeException());
            return previousComponentValue;
        }
    }
    ParsedFormat format = null;
    int type = -1;
    IValueList list = previousComponentValue.getValueList();
    if (list.getName().equals(rhinoValue)) {
        // no need to create a new value if we have the same valuelist name
        return previousComponentValue;
    }
    ValueListTypeSabloValue newValue;
    IValueList newVl = null;
    // see if it's a component.setValuelistItems (legacy) equivalent
    if (list != null && list instanceof CustomValueList && (rhinoValue instanceof JSDataSet || rhinoValue instanceof IDataSet)) {
        // here we create a NEW, separate (runtime) custom valuelist instance for this component only (no longer the 'global' custom valuelist with that name that can be affected by application.setValuelistItems(...))
        INGApplication application = previousComponentValue.getDataAdapterList().getApplication();
        ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
        if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
            format = ((CustomValueList) list).getFormat();
            type = ((CustomValueList) list).getValueType();
            newVl = ValueListFactory.fillRealValueList(application, valuelist, IValueListConstants.CUSTOM_VALUES, format, type, rhinoValue);
            if (newVl != null) {
                previousComponentValue.setNewCustomValuelistInstance(newVl, rhinoValue);
                newValue = previousComponentValue;
            } else {
                // should never happen; ValueListFactory.fillRealValueList seems to always return non-null
                Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed for an unknown reason; dataset: " + rhinoValue, new RuntimeException());
                // just keep old value
                newValue = previousComponentValue;
            }
        } else {
            Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning a dataset is ONLY allowed for custom valuelists; dataset: " + rhinoValue, new RuntimeException());
            newValue = previousComponentValue;
        }
    } else if (rhinoValue instanceof String) {
        // the Rhino value is a different valuelist name; create a full new one
        newValue = createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
    } else {
        Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning this value is not supported: " + rhinoValue, new RuntimeException());
        // whatever was set here is not supported; so keep the previous value
        newValue = previousComponentValue;
    }
    return newValue;
}
Also used : ParsedFormat(com.servoy.j2db.util.FormatParser.ParsedFormat) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) ValueList(com.servoy.j2db.persistence.ValueList) JSValueList(com.servoy.j2db.scripting.solutionmodel.JSValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 20 with ValueList

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

the class ValueListTypeSabloValue method initializeValuelistAndFormat.

private void initializeValuelistAndFormat() {
    INGApplication application = dataAdapterListToUse.getApplication();
    ValueList valuelistPersist = getValuelistPersist(valuelistIdentifier, application);
    format = getComponentFormat(vlPD, dataAdapterListToUse, getConfig(), dataproviderID, webObjectContext);
    if (valuelistPersist != null) {
        valueList = getRealValueList(application, valuelistPersist, format, dataproviderID);
        if (customValueListDataSet != null && valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
            valueList = ValueListFactory.fillRealValueList(application, valuelistPersist, IValueListConstants.CUSTOM_VALUES, ((CustomValueList) valueList).getFormat(), ((CustomValueList) valueList).getValueType(), customValueListDataSet);
        }
    } else {
        if ("autoVL".equals(getConfig().getDefaultValue())) {
            ITable table = getTableForDp();
            if (dataproviderID != null && table != null && table.getColumnType(dataproviderID) != 0) {
                valueList = new ColumnBasedValueList(application, table.getServerName(), table.getName(), dataproviderID);
            } else {
                // not supported empty valuelist (based on relations) just return an empty valuelist
                valueList = new CustomValueList(application, null, "", false, IColumnTypes.TEXT, null);
            }
        }
    }
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) ColumnBasedValueList(com.servoy.j2db.server.ngclient.ColumnBasedValueList) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) 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) ITable(com.servoy.j2db.persistence.ITable)

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