use of com.servoy.j2db.dataprocessing.LookupValueList in project servoy-client by Servoy.
the class ValueListTypeSabloValue method getDisplayValue.
/**
* @param newJSONValue
*/
private void getDisplayValue(JSONObject newJSONValue) {
this.handledIDForResponse = Long.valueOf(newJSONValue.getLong(ID_KEY));
Object realValue = newJSONValue.opt(DISPLAYVALUE);
displayValue = realValue;
int realValueIndex = valueList.realValueIndexOf(realValue);
if (realValueIndex != -1) {
try {
displayValue = valueList.getElementAt(realValueIndex);
} catch (Exception ex) {
Debug.error(ex);
}
} else {
if (valueList instanceof DBValueList) {
try {
LookupValueList lookup = new LookupValueList(valueList.getValueList(), dataAdapterListToUse.getApplication(), ComponentFactory.getFallbackValueList(dataAdapterListToUse.getApplication(), dataproviderID, format != null ? format.uiType : 0, format != null ? format.parsedFormat : null, valueList.getValueList()), format != null && format.parsedFormat != null ? format.parsedFormat.getDisplayFormat() : null, dataAdapterListToUse.getRecord());
if (lookup.realValueIndexOf(realValue) != -1) {
displayValue = lookup.getElementAt(lookup.realValueIndexOf(realValue));
}
lookup.deregister();
} catch (Exception e) {
Debug.error(e);
}
}
}
changeMonitor.markFullyChanged(true);
}
use of com.servoy.j2db.dataprocessing.LookupValueList 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.dataprocessing.LookupValueList 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.LookupValueList in project servoy-client by Servoy.
the class ComboModelListModelWrapper method register.
public void register(IValueList vlModel) {
IValueList newModel = vlModel;
if (newModel instanceof LookupValueList) {
// We never expect a LookupValueList here, these are not made for listing all values.
// When we get a LookupValueList, this is probably a value list that was used as fallback (we create LookupValueList), replace with real value list.
newModel = ((LookupValueList) newModel).getRealValueList();
}
deregister();
Set<Integer> newSelectedSet = Collections.synchronizedSet(new HashSet<Integer>());
if (selectedSet != null && selectedSet.size() > 0) {
for (Integer selected : selectedSet) {
Object obj = getRealElementAt(selected.intValue());
int newRow = newModel.realValueIndexOf(obj);
if (newRow >= 0) {
if (newRow > 0 && hideFirstValue && newModel.getAllowEmptySelection())
newRow--;
newSelectedSet.add(Integer.valueOf(newRow));
}
}
}
int prevSize = getSize();
if (listModel instanceof SeparatorProcessingValueList)
((SeparatorProcessingValueList) listModel).setWrapped(newModel);
else
listModel = newModel;
selectedSet = newSelectedSet;
listModel.addListDataListener(listener);
this.hideFirstValue = (listModel.getAllowEmptySelection() && shouldHideEmptyValueIfPresent);
int currentSize = getSize();
if (currentSize > prevSize) {
listener.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, prevSize, currentSize - 1));
listener.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, prevSize - 1));
} else if (prevSize != currentSize) {
listener.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, currentSize, prevSize - 1));
listener.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, currentSize - 1));
} else {
listener.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, currentSize - 1));
}
}
use of com.servoy.j2db.dataprocessing.LookupValueList in project servoy-client by Servoy.
the class DataLookupField method commitSelectedValue.
/**
*/
private void commitSelectedValue() {
if (jlist == null)
return;
int index = jlist.getSelectedIndex();
if (index >= 0) {
Object real = dlm.getRealElementAt(index);
Object display = real;
if (dlm.getSize() != 0) {
display = dlm.getElementAt(index);
}
if (list instanceof LookupValueList) {
((LookupValueList) list).addRow(real, display);
}
Object currentValue = getValue();
setValueObject(real);
if (Utils.equalObjects(currentValue, real)) {
// for example you have entry "aabb" as current value, and "aab" in field resulting in the selection of "aabb" in list;
// so in this case although the current value is the same as the one seleced in the list, the text in the field is not up to date;
// commit selected value must make sure the text is updated as well in this case...
AbstractFormatter formatter = getFormatter();
if (formatter != null) {
try {
setText(formatter.valueToString(currentValue));
} catch (ParseException e) {
// $NON-NLS-1$
Debug.error("Cannot put back text for already selected value when commiting value from list in lookup field: ", e);
}
}
}
if (editProvider != null) {
editProvider.commitData();
}
popup.setVisible(false);
}
}
Aggregations