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;
}
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);
}
}
}
}
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);
}
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;
}
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);
}
}
}
}
Aggregations