use of com.servoy.j2db.dataprocessing.LookupValueList in project servoy-client by Servoy.
the class DataLookupField method processKeyEvent.
/*
* (non-Javadoc)
*
* @see javax.swing.JComponent#processKeyEvent(java.awt.event.KeyEvent)
*/
@Override
protected void processKeyEvent(KeyEvent e) {
if (list instanceof LookupValueList) {
((LookupValueList) list).setDoNotQuery(true);
}
try {
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ENTER) {
boolean doFill = false;
synchronized (this) {
if (task != null) {
task.cancel();
task = null;
doFill = true;
}
}
if (doFill)
fillValueListImpl(false);
Object value = getValue();
commitSelectedValue();
super.processKeyEvent(e);
if (!eventExecutor.getValidationEnabled() && !Utils.equalObjects(value, getValue()) && popup != null && popup.isVisible()) {
// consume the enter release key in find mode.
consumeEnterReleased = true;
}
} else if (e.getID() == KeyEvent.KEY_PRESSED && jlist != null && popup.isVisible()) {
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
int index = jlist.getSelectedIndex() + 1;
if (index < dlm.getSize()) {
jlist.setSelectedIndex(index);
}
e.consume();
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
int index = jlist.getSelectedIndex() - 1;
if (index >= 0) {
jlist.setSelectedIndex(index);
}
e.consume();
} else {
super.processKeyEvent(e);
}
} else if (e.getID() == KeyEvent.KEY_RELEASED && consumeEnterReleased) {
// consume the enter release key in find mode.
consumeEnterReleased = false;
e.consume();
super.processKeyEvent(e);
} else {
super.processKeyEvent(e);
}
} finally {
if (list instanceof LookupValueList) {
((LookupValueList) list).setDoNotQuery(false);
}
}
}
use of com.servoy.j2db.dataprocessing.LookupValueList in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method getValueForToJSON.
protected Object getValueForToJSON(Object uiValue, IBrowserConverterContext dataConverterContext) throws JSONException {
Object jsonValueRepresentation;
boolean valuelistDisplayValue = false;
int valuelistDisplayType = 0;
if (shouldResolveFromValuelistWithName != null) {
ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(shouldResolveFromValuelistWithName));
if (valuelistSabloValue != null && valuelistSabloValue.getValueList() != null) {
valuelistDisplayValue = true;
valuelistDisplayType = valuelistSabloValue.getValueList().getValueList().getDisplayValueType();
if (valuelistSabloValue.getValueList().realValueIndexOf(uiValue) != -1) {
try {
// TODO don't we have to apply the UI converter's toObject here as well in the unlikely case of a valuelist + UI converter? and also
// when searching we should then use the fromObject(uiValue) rather then uiValue directly I think
uiValue = valuelistSabloValue.getValueList().getElementAt(valuelistSabloValue.getValueList().realValueIndexOf(uiValue));
} catch (Exception ex) {
Debug.error(ex);
}
} else if (valuelistSabloValue.getValueList() instanceof DBValueList) {
try {
LookupValueList lookup = new LookupValueList(valuelistSabloValue.getValueList().getValueList(), dataAdapterList.getApplication(), ComponentFactory.getFallbackValueList(dataAdapterList.getApplication(), null, Types.OTHER, null, valuelistSabloValue.getValueList().getValueList()), null, dataAdapterList.getRecord());
if (lookup.realValueIndexOf(uiValue) != -1) {
// TODO don't we have to apply the UI converter's toObject here as well in the unlikely case of a valuelist + UI converter? and also
// when searching we should then use the fromObject(uiValue) rather then uiValue directly I think
uiValue = lookup.getElementAt(lookup.realValueIndexOf(uiValue));
}
lookup.deregister();
} catch (Exception ex) {
Debug.error(ex);
}
}
}
}
if (findMode) {
// in UI show only strings in find mode (just like SC/WC do); if they are something else like real dates/numbers which could happen
// from scripting, then show string representation
jsonValueRepresentation = uiValue instanceof String ? uiValue : (uiValue != null ? String.valueOf(uiValue) : "");
} else if (typeOfDP != null && !valuelistDisplayValue) {
Object value = uiValue;
// merged this change from SC, DisplaysAdapter
if (value == null && com.servoy.j2db.dataprocessing.DataAdapterList.isCountOrAvgOrSumAggregateDataProvider(dataProviderID, new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), dataAdapterList.getRecord() != null ? dataAdapterList.getRecord().getParentFoundSet().getTable() : null)))
value = Integer.valueOf(0);
// that 'true' is a workaround for allowing directly a value instead of object or array
EmbeddableJSONWriter ejw = new EmbeddableJSONWriter(true);
DataConversion jsonDataConversion = new DataConversion();
FullValueToJSONConverter.INSTANCE.toJSONValue(ejw, null, value, typeOfDP, jsonDataConversion, dataConverterContext);
if (jsonDataConversion.getConversions().size() == 0)
jsonDataConversion = null;
String str = ejw.toJSONString();
if (str == null || str.trim().length() == 0) {
Debug.error("A dataprovider that is not able to send itself to client... (" + typeOfDP + ", " + uiValue + ")");
str = "null";
}
jsonValueRepresentation = new JSONStringWithConversions(str, jsonDataConversion);
} else if (valuelistDisplayValue && (valuelistDisplayType == IColumnTypes.DATETIME || valuelistDisplayType == IColumnTypes.INTEGER || valuelistDisplayType == IColumnTypes.NUMBER || valuelistDisplayType == IColumnTypes.MEDIA) && !(uiValue instanceof String)) {
// that 'true' is a workaround for allowing directly a value instead of object or array
EmbeddableJSONWriter ejw = new EmbeddableJSONWriter(true);
DataConversion jsonDataConversion = new DataConversion();
if (valuelistDisplayType == IColumnTypes.DATETIME) {
NGDatePropertyType.NG_INSTANCE.toJSON(ejw, null, (Date) uiValue, null, jsonDataConversion, dataConverterContext);
} else if (valuelistDisplayType == IColumnTypes.INTEGER) {
IntPropertyType.INSTANCE.toJSON(ejw, null, (Integer) uiValue, null, jsonDataConversion, dataConverterContext);
} else if (valuelistDisplayType == IColumnTypes.NUMBER) {
DoublePropertyType.INSTANCE.toJSON(ejw, null, (Number) uiValue, null, jsonDataConversion, dataConverterContext);
} else if (valuelistDisplayType == IColumnTypes.MEDIA) {
MediaDataproviderPropertyType.INSTANCE.toJSON(ejw, null, uiValue, null, jsonDataConversion, dataConverterContext);
}
if (jsonDataConversion.getConversions().size() == 0)
jsonDataConversion = null;
String str = ejw.toJSONString();
if (str == null || str.trim().length() == 0) {
Debug.error("A dataprovider with resolveValuelist that is not able to send itself to client... (" + valuelistDisplayType + ", " + uiValue + ")");
str = "null";
}
jsonValueRepresentation = new JSONStringWithConversions(str, jsonDataConversion);
} else {
jsonValueRepresentation = uiValue;
}
return jsonValueRepresentation;
}
Aggregations