Search in sources :

Example 6 with LookupValueList

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);
        }
    }
}
Also used : LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) Point(java.awt.Point)

Example 7 with LookupValueList

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;
}
Also used : DBValueList(com.servoy.j2db.dataprocessing.DBValueList) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IJSONStringWithConversions(org.sablo.websocket.utils.JSONUtils.IJSONStringWithConversions) JSONStringWithConversions(org.sablo.websocket.utils.JSONUtils.JSONStringWithConversions) DataConversion(org.sablo.websocket.utils.DataConversion) EmbeddableJSONWriter(org.sablo.websocket.utils.JSONUtils.EmbeddableJSONWriter) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList)

Aggregations

LookupValueList (com.servoy.j2db.dataprocessing.LookupValueList)7 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 JSONException (org.json.JSONException)3 DBValueList (com.servoy.j2db.dataprocessing.DBValueList)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ValueList (com.servoy.j2db.persistence.ValueList)2 ServoyException (com.servoy.j2db.util.ServoyException)2 Point (java.awt.Point)2 ParseException (java.text.ParseException)2 ApplicationException (com.servoy.j2db.ApplicationException)1 ExitScriptException (com.servoy.j2db.ExitScriptException)1 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)1 IRefreshValueList (com.servoy.j2db.IRefreshValueList)1 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 ISupportValueList (com.servoy.j2db.ui.ISupportValueList)1 RuntimeDataField (com.servoy.j2db.ui.scripting.RuntimeDataField)1 RuntimeDataLookupField (com.servoy.j2db.ui.scripting.RuntimeDataLookupField)1 IOException (java.io.IOException)1