Search in sources :

Example 1 with LookupValueList

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);
}
Also used : DBValueList(com.servoy.j2db.dataprocessing.DBValueList) JSONObject(org.json.JSONObject) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) JSONException(org.json.JSONException) ServoyException(com.servoy.j2db.util.ServoyException)

Example 2 with LookupValueList

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;
}
Also used : RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) IValueList(com.servoy.j2db.dataprocessing.IValueList) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 3 with LookupValueList

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;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IRefreshValueList(com.servoy.j2db.IRefreshValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ApplicationException(com.servoy.j2db.ApplicationException) ExitScriptException(com.servoy.j2db.ExitScriptException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 4 with LookupValueList

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));
    }
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 5 with LookupValueList

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

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