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