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