Search in sources :

Example 1 with IFormatScriptComponent

use of com.servoy.j2db.ui.scripting.IFormatScriptComponent in project servoy-client by Servoy.

the class PropertyCopy method copyElementProps.

public static void copyElementProps(IComponent org, IComponent copy) {
    if (org == null || copy == null)
        return;
    // if (org instanceof IDelegate && copy instanceof IDelegate)
    // {
    // org = (JComponent)((IDelegate)org).getDelegate();
    // copy = (JComponent) ((IDelegate)copy).getDelegate();
    // }
    copy.setLocation(org.getLocation());
    copy.setSize(org.getSize());
    copy.setBackground(org.getBackground());
    copy.setForeground(org.getForeground());
    copy.setToolTipText(org.getToolTipText());
    copy.setComponentVisible(org.isVisible());
    copy.setComponentEnabled(org.isEnabled());
    copy.setOpaque(org.isOpaque());
    copy.setFont(org.getFont());
    if (org instanceof ILabel && copy instanceof ILabel) {
        ((ILabel) copy).setMediaIcon(((ILabel) org).getMediaIcon());
        ((ILabel) copy).setText(((ILabel) org).getText());
    }
    if (org instanceof IFieldComponent && copy instanceof IFieldComponent) {
        ((IFieldComponent) copy).setEditable(((IFieldComponent) org).isEditable());
    }
    if (org instanceof IScriptableProvider && copy instanceof IScriptableProvider) {
        IScriptable source = ((IScriptableProvider) org).getScriptObject();
        IScriptable destination = ((IScriptableProvider) copy).getScriptObject();
        if (source instanceof IFormatScriptComponent && destination instanceof IFormatScriptComponent) {
            ((IFormatScriptComponent) destination).setComponentFormat(((IFormatScriptComponent) source).getComponentFormat());
        }
        if (source instanceof HasRuntimeReadOnly && destination instanceof HasRuntimeReadOnly) {
            ((HasRuntimeReadOnly) destination).setReadOnly(((HasRuntimeReadOnly) source).isReadOnly());
        }
        if (source instanceof HasRuntimeVisible && destination instanceof HasRuntimeVisible) {
            ((HasRuntimeVisible) destination).setVisible(((HasRuntimeVisible) source).isVisible());
        }
        if (source instanceof HasRuntimeImage && destination instanceof HasRuntimeImage) {
            String imageURL = ((HasRuntimeImage) source).getImageURL();
            if (imageURL != null) {
                // only copy if explicitly set with a url
                ((HasRuntimeImage) destination).setImageURL(imageURL);
            }
            String rolloverImageURL = ((HasRuntimeImage) source).getRolloverImageURL();
            if (rolloverImageURL != null) {
                // only copy if explicitly set with a url
                ((HasRuntimeImage) destination).setRolloverImageURL(rolloverImageURL);
            }
        }
        if (source instanceof IRuntimeTabPaneAlike && destination instanceof IRuntimeTabPaneAlike) {
            // keep active tab when printing
            ((IRuntimeTabPaneAlike) destination).setTabIndex(((IRuntimeTabPaneAlike) source).getTabIndex());
        }
    }
    if (org instanceof IProviderStylePropertyChanges && copy instanceof IProviderStylePropertyChanges) {
        ((IProviderStylePropertyChanges) copy).getStylePropertyChanges().setChanges(((IProviderStylePropertyChanges) org).getStylePropertyChanges().getChanges());
    }
}
Also used : HasRuntimeReadOnly(com.servoy.j2db.ui.runtime.HasRuntimeReadOnly) HasRuntimeImage(com.servoy.j2db.ui.runtime.HasRuntimeImage) HasRuntimeVisible(com.servoy.j2db.ui.runtime.HasRuntimeVisible) IRuntimeTabPaneAlike(com.servoy.j2db.ui.runtime.IRuntimeTabPaneAlike) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 2 with IFormatScriptComponent

use of com.servoy.j2db.ui.scripting.IFormatScriptComponent in project servoy-client by Servoy.

the class CellAdapter method getCellEditorValue.

public Object getCellEditorValue() {
    // test if currentEditing state isn't deleted already
    if (currentEditingState == null || dataProviderID == null || (currentEditingState != null && currentEditingState.getParentFoundSet() == null))
        return null;
    Object comp = editor;
    if ((comp instanceof IDisplay && ((IDisplay) comp).isReadOnly()) || gettingEditorValue) {
        return currentEditingState.getValue(getDataProviderID());
    }
    try {
        gettingEditorValue = true;
        if (comp instanceof IDelegate<?>) {
            comp = ((IDelegate<?>) comp).getDelegate();
        }
        // HACK:needed for commit value copied from other hack 'processfocus' in DataField
        if (comp instanceof DataField && ((DataField) comp).isEditable()) {
            DataField edit = (DataField) comp;
            boolean needEntireState = edit.needEntireState();
            try {
                edit.setNeedEntireState(false);
                int fb = edit.getFocusLostBehavior();
                if (fb == JFormattedTextField.COMMIT || fb == JFormattedTextField.COMMIT_OR_REVERT) {
                    try {
                        edit.commitEdit();
                        // Give it a chance to reformat.
                        edit.setValueObject(edit.getValue());
                    } catch (ParseException pe) {
                        return null;
                    }
                } else if (fb == JFormattedTextField.REVERT) {
                    edit.setValueObject(edit.getValue());
                }
            } finally {
                edit.setNeedEntireState(needEntireState);
            }
        }
        Object obj = null;
        if (editor instanceof IDisplayData) {
            IDisplayData displayData = (IDisplayData) editor;
            obj = Utils.removeJavascripLinkFromDisplay(displayData, null);
            if (!findMode) {
                // use UI converter to convert from UI value to record value
                obj = ComponentFormat.applyUIConverterFromObject(displayData, obj, dataProviderID, application.getFoundSetManager());
            }
            // if the editor is not enable or is readonly dont try to set any value.
            if (!displayData.isEnabled() || displayData.isReadOnly())
                return obj;
            // this can happen when toggeling with readonly. case 233226 or 232188
            if (!currentEditingState.isEditing() && !currentEditingState.startEditing())
                return obj;
            try {
                if (// $NON-NLS-1$
                currentEditingState != null && (obj == null || "".equals(obj)) && currentEditingState.getValue(dataProviderID) == null) {
                    return null;
                }
            } catch (IllegalArgumentException iae) {
                Debug.error(iae);
            }
            Object oldVal = null;
            if (currentEditingState instanceof FindState) {
                if (displayData instanceof IScriptableProvider && ((IScriptableProvider) displayData).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) currentEditingState).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat().parsedFormat);
                }
                try {
                    oldVal = currentEditingState.getValue(dataProviderID);
                } catch (IllegalArgumentException iae) {
                    // $NON-NLS-1$
                    Debug.error("Error getting the previous value", iae);
                    oldVal = null;
                }
                currentEditingState.setValue(dataProviderID, obj);
                if (!Utils.equalObjects(oldVal, obj)) {
                    // call notifyLastNewValue changed so that the onChangeEvent will be fired and called when attached.
                    displayData.notifyLastNewValueWasChange(oldVal, obj);
                    obj = dal.getValueObject(currentEditingState, dataProviderID);
                }
            } else {
                if (!displayData.isValueValid() && Utils.equalObjects(lastInvalidValue, obj)) {
                    // already validated
                    return obj;
                }
                try {
                    adjusting = true;
                    try {
                        oldVal = currentEditingState.getValue(dataProviderID);
                    } catch (IllegalArgumentException iae) {
                        // $NON-NLS-1$
                        Debug.error("Error getting the previous value", iae);
                    }
                    try {
                        if (oldVal == Scriptable.NOT_FOUND && dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
                            oldVal = dal.getFormScope().get(dataProviderID);
                            dal.getFormScope().put(dataProviderID, obj);
                            IFoundSetInternal foundset = currentEditingState.getParentFoundSet();
                            if (foundset instanceof FoundSet)
                                ((FoundSet) foundset).fireFoundSetChanged();
                        } else
                            currentEditingState.setValue(dataProviderID, obj);
                    } catch (IllegalArgumentException e) {
                        Debug.trace(e);
                        displayData.setValueValid(false, oldVal);
                        application.handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                        Object stateValue = null;
                        try {
                            stateValue = dal.getValueObject(currentEditingState, dataProviderID);
                        } catch (IllegalArgumentException iae) {
                            Debug.error(iae);
                        }
                        Object displayValue;
                        if (Utils.equalObjects(oldVal, stateValue)) {
                            // reset display to typed value
                            displayValue = obj;
                        } else {
                            // reset display to changed value in validator method
                            displayValue = stateValue;
                        }
                        convertAndSetValue(displayData, displayValue);
                        return displayValue;
                    }
                    if (!Utils.equalObjects(oldVal, obj)) {
                        fireModificationEvent(currentEditingState);
                        displayData.notifyLastNewValueWasChange(oldVal, obj);
                        obj = dal.getValueObject(currentEditingState, dataProviderID);
                        // we also want to reset the value in the current display if changed by script
                        convertAndSetValue(displayData, obj);
                    } else if (!displayData.isValueValid()) {
                        displayData.notifyLastNewValueWasChange(null, obj);
                    } else {
                        displayData.setValueValid(true, null);
                    }
                } finally {
                    adjusting = false;
                    if (displayData.isValueValid()) {
                        lastInvalidValue = NONE;
                    } else {
                        lastInvalidValue = obj;
                    }
                }
            }
        }
        return obj;
    } finally {
        gettingEditorValue = false;
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) EventObject(java.util.EventObject) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) ParseException(java.text.ParseException) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IDelegate(com.servoy.j2db.util.IDelegate)

Example 3 with IFormatScriptComponent

use of com.servoy.j2db.ui.scripting.IFormatScriptComponent in project servoy-client by Servoy.

the class RecordItemModel method setValue.

/**
 * @param obj
 * @param dataProviderID
 * @param prevValue
 */
public void setValue(Component component, String dataProviderID, Object value) {
    Object obj = value;
    String compDpid = getDataProviderID(component);
    boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
    Object prevValue = null;
    if (ownComponentsValue && component instanceof IResolveObject) {
        obj = ((IResolveObject) component).resolveRealValue(obj);
    }
    if (component instanceof IDisplayData) {
        obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
    }
    WebForm webForm = component.findParent(WebForm.class);
    IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
    // use UI converter to convert from UI value to record value
    if (!(record instanceof FindState)) {
        obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
    }
    FormScope fs = webForm.getController().getFormScope();
    try {
        Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
        if (scope.getLeft() != null) {
            if (record == null) {
                webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
            } else {
                // does an additional fire in foundset!
                prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
            }
        } else if (fs.has(dataProviderID, fs)) {
            prevValue = fs.get(dataProviderID);
            fs.put(dataProviderID, obj);
        } else {
            if (record != null && record.startEditing()) {
                try {
                    prevValue = record.getValue(dataProviderID);
                    record.setValue(dataProviderID, obj);
                } catch (IllegalArgumentException e) {
                    Debug.trace(e);
                    ((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                    Object stateValue = record.getValue(dataProviderID);
                    if (!Utils.equalObjects(prevValue, stateValue)) {
                        // reset display to changed value in validator method
                        obj = stateValue;
                    }
                    if (ownComponentsValue) {
                        ((IDisplayData) component).setValueValid(false, prevValue);
                    }
                    return;
                }
                if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
                }
            }
        }
        // then dont call notify
        if (ownComponentsValue) {
            ((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
        }
    } finally {
        // then touch the lastInvalidValue
        if (ownComponentsValue) {
            if (((IDisplayData) component).isValueValid()) {
                lastInvalidValue = NONE;
            } else {
                lastInvalidValue = obj;
            }
        }
    }
    return;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) FormScope(com.servoy.j2db.scripting.FormScope) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 4 with IFormatScriptComponent

use of com.servoy.j2db.ui.scripting.IFormatScriptComponent in project servoy-client by Servoy.

the class ComponentFactory method createField.

private static IComponent createField(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
    ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
    ComponentFormat fieldFormat = ComponentFormat.getComponentFormat(field.getFormat(), field.getDataProviderID(), dataProviderLookup, application);
    IDataProvider dp = null;
    if (field.getDataProviderID() != null && dataProviderLookup != null) {
        try {
            dp = dataProviderLookup.getDataProvider(field.getDataProviderID());
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    // apply any style
    Insets style_margin = null;
    int style_halign = -1;
    boolean hasBorder = false;
    Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, field, form);
    if (styleInfo != null) {
        IStyleSheet ss = styleInfo.getLeft();
        IStyleRule s = styleInfo.getRight();
        if (ss != null && s != null) {
            style_margin = ss.getMargin(s);
            style_halign = ss.getHAlign(s);
            hasBorder = ss.hasBorder(s);
        }
    }
    IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
    IFieldComponent fl;
    AbstractRuntimeField<? extends IFieldComponent> scriptable;
    switch(field.getDisplayType()) {
        case Field.PASSWORD:
            {
                RuntimeDataPassword so;
                scriptable = so = new RuntimeDataPassword(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataPassword(so, getWebID(form, field));
                so.setComponent(fl, field);
            }
            break;
        case Field.RTF_AREA:
            {
                RuntimeRtfArea so;
                scriptable = so = new RuntimeRtfArea(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), RTF_AREA, field.getEditable());
                so.setComponent(fl, field);
                if (fl instanceof IScrollPane) {
                    applyScrollBarsProperty((IScrollPane) fl, field);
                }
            }
            break;
        case Field.HTML_AREA:
            {
                RuntimeHTMLArea so;
                scriptable = so = new RuntimeHTMLArea(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), HTML_AREA, field.getEditable());
                so.setComponent(fl, field);
                if (fl instanceof IScrollPane) {
                    applyScrollBarsProperty((IScrollPane) fl, field);
                }
            }
            break;
        case Field.TEXT_AREA:
            {
                RuntimeTextArea so;
                scriptable = so = new RuntimeTextArea(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataTextArea(so, getWebID(form, field));
                so.setComponent(fl, field);
                if (fl instanceof IScrollPane) {
                    applyScrollBarsProperty((IScrollPane) fl, field);
                }
            }
            break;
        case Field.CHECKS:
            {
                AbstractRuntimeValuelistComponent<IFieldComponent> so;
                if (valuelist != null) {
                    IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
                    if (isSingleValue(valuelist)) {
                        scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
                        fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
                    } else {
                        scriptable = so = new RuntimeCheckBoxChoice(jsChangeRecorder, application);
                        fl = application.getItemFactory().createDataChoice((RuntimeCheckBoxChoice) so, getWebID(form, field), list, false, fieldFormat == null || fieldFormat.dpType == IColumnTypes.TEXT);
                        if (fl instanceof IScrollPane) {
                            applyScrollBarsProperty((IScrollPane) fl, field);
                        }
                    }
                } else {
                    scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
                    fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), null);
                }
                so.setComponent(fl, field);
            }
            break;
        case Field.RADIOS:
            {
                AbstractRuntimeValuelistComponent<IFieldComponent> so;
                IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
                if (isSingleValue(valuelist)) {
                    scriptable = so = new RuntimeRadioButton(jsChangeRecorder, application);
                    fl = application.getItemFactory().createRadioButton((RuntimeRadioButton) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
                } else {
                    scriptable = so = new RuntimeRadioChoice(jsChangeRecorder, application);
                    fl = application.getItemFactory().createDataChoice((RuntimeRadioChoice) so, getWebID(form, field), list, true, false);
                    if (fl instanceof IScrollPane) {
                        applyScrollBarsProperty((IScrollPane) fl, field);
                    }
                }
                so.setComponent(fl, field);
            }
            break;
        case Field.COMBOBOX:
            {
                RuntimeDataCombobox so;
                scriptable = so = new RuntimeDataCombobox(jsChangeRecorder, application);
                IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
                fl = application.getItemFactory().createDataComboBox(so, getWebID(form, field), list);
                so.setComponent(fl, field);
            }
            break;
        case Field.CALENDAR:
            {
                RuntimeDataCalendar so;
                scriptable = so = new RuntimeDataCalendar(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataCalendar(so, getWebID(form, field));
                so.setComponent(fl, field);
            }
            break;
        case Field.IMAGE_MEDIA:
            {
                RuntimeMediaField so;
                scriptable = so = new RuntimeMediaField(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataImgMediaField(so, getWebID(form, field));
                if (fl instanceof IScrollPane) {
                    applyScrollBarsProperty((IScrollPane) fl, field);
                }
                so.setComponent(fl, field);
            }
            break;
        case Field.TYPE_AHEAD:
            if (field.getValuelistID() > 0) {
                fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
                if (fl == null)
                    return null;
                scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
                break;
            }
            if (// only allow plain columns
            dp != null && dp.getColumnWrapper() != null && dp.getColumnWrapper().getRelations() == null) {
                RuntimeDataLookupField so;
                scriptable = so = new RuntimeDataLookupField(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataLookupField(so, getWebID(form, field), form.getServerName(), form.getTableName(), dp == null ? field.getDataProviderID() : dp.getDataProviderID());
                so.setComponent(fl, field);
                break;
            } else {
                RuntimeDataField so;
                scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataField(so, getWebID(form, field));
                so.setComponent(fl, field);
                break;
            }
        // $FALL-THROUGH$
        case Field.LIST_BOX:
        case Field.MULTISELECT_LISTBOX:
            {
                boolean multiSelect = (field.getDisplayType() == Field.MULTISELECT_LISTBOX);
                RuntimeListBox so;
                scriptable = so = new RuntimeListBox(jsChangeRecorder, application, multiSelect);
                IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
                fl = application.getItemFactory().createListBox(so, getWebID(form, field), list, multiSelect);
                so.setComponent(fl, field);
            }
            break;
        case Field.SPINNER:
            {
                RuntimeSpinner so;
                scriptable = so = new RuntimeSpinner(jsChangeRecorder, application);
                IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
                fl = application.getItemFactory().createSpinner(so, getWebID(form, field), list);
                so.setComponent(fl, field);
                break;
            }
        // else treat as the default case: TEXT_FIELD
        default:
            // Field.TEXT_FIELD
            if (field.getValuelistID() > 0) {
                fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
                if (fl == null)
                    return null;
                scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
            } else {
                RuntimeDataField so;
                scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
                fl = application.getItemFactory().createDataField(so, getWebID(form, field));
                so.setComponent(fl, field);
            }
    }
    if (fl instanceof ISupportAsyncLoading) {
        ((ISupportAsyncLoading) fl).setAsyncLoadingEnabled(!printing);
    }
    fl.setSelectOnEnter(field.getSelectOnEnter());
    fl.setEditable(field.getEditable());
    try {
        int halign = field.getHorizontalAlignment();
        if (halign != -1) {
            fl.setHorizontalAlignment(halign);
        } else if (style_halign != -1) {
            fl.setHorizontalAlignment(style_halign);
        }
    } catch (RuntimeException e) {
    // just ignore...Debug.error(e);
    }
    fl.setToolTipText(application.getI18NMessageIfPrefixed(field.getToolTipText()));
    fl.setTitleText(application.getI18NMessageIfPrefixed(field.getText()));
    fl.setDataProviderID(dp == null ? field.getDataProviderID() : dp.getDataProviderID());
    if (field.getDataProviderID() != null && dataProviderLookup != null) {
        if (scriptable instanceof IFormatScriptComponent) {
            ((IFormatScriptComponent) scriptable).setComponentFormat(fieldFormat);
        }
        if (dp != null) {
            // if (valuelist != null && valuelist.getValueListType() != ValueList.CUSTOM_VALUES) type = valuelist.getDisplayValueType();
            int l = dp.getLength();
            int defaultType = Column.mapToDefaultType(fieldFormat.dpType);
            boolean skipMaxLength = false;
            if (valuelist != null) {
                // if the display values are different than the real values, then maxlength should be skipped
                IValueList vl = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, dp.getDataProviderID());
                skipMaxLength = vl.hasRealValues();
            }
            if (l > 0 && (defaultType == IColumnTypes.TEXT || defaultType == IColumnTypes.MEDIA) && !skipMaxLength) {
                fl.setMaxLength(l);
            }
        }
    }
    // fl.setOpaque(!field.getTransparent());
    if (field.getDisplaysTags()) {
        fl.setNeedEntireState(true);
        if (field.getDataProviderID() == null && field.getText() != null && fl instanceof IDisplayTagText) {
            ((IDisplayTagText) fl).setTagText(field.getText());
        }
    }
    if (// el is an ActionListener
    el != null) {
        fl.addScriptExecuter(el);
        Object[] cmds = combineMethodsToCommands(form, form.getOnElementFocusGainedMethodID(), "onElementFocusGainedMethodID", field, field.getOnFocusGainedMethodID(), "onFocusGainedMethodID");
        if (cmds != null)
            fl.setEnterCmds((String[]) cmds[0], (Object[][]) cmds[1]);
        cmds = combineMethodsToCommands(form, form.getOnElementFocusLostMethodID(), "onElementFocusLostMethodID", field, field.getOnFocusLostMethodID(), "onFocusLostMethodID");
        if (cmds != null)
            fl.setLeaveCmds((String[]) cmds[0], (Object[][]) cmds[1]);
        if (field.getOnActionMethodID() > 0)
            fl.setActionCmd(Integer.toString(field.getOnActionMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onActionMethodID")));
        if (field.getOnDataChangeMethodID() > 0)
            fl.setChangeCmd(Integer.toString(field.getOnDataChangeMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onDataChangeMethodID")));
        if (field.getOnRightClickMethodID() > 0)
            fl.setRightClickCommand(Integer.toString(field.getOnRightClickMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onRightClickMethodID")));
    }
    int onRenderMethodID = field.getOnRenderMethodID();
    AbstractBase onRenderPersist = field;
    if (onRenderMethodID <= 0) {
        onRenderMethodID = form.getOnRenderMethodID();
        onRenderPersist = form;
    }
    if (onRenderMethodID > 0) {
        RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
        renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
        IForm rendererForm = application.getFormManager().getForm(form.getName());
        IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
        renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
    }
    applyBasicComponentProperties(application, fl, field, styleInfo);
    if (fl instanceof INullableAware) {
        INullableAware nullAware = (INullableAware) fl;
        boolean allowNull = true;
        // become 0 (because it is unchecked) so that the user does not need to check/uncheck it for save
        try {
            if (dataProviderLookup != null && dataProviderLookup.getTable() != null && field.getDataProviderID() != null) {
                String dataproviderId = dp == null ? field.getDataProviderID() : dp.getDataProviderID();
                if (dataProviderLookup.getTable().getColumn(dataproviderId) != null) {
                    allowNull = dataProviderLookup.getTable().getColumn(dataproviderId).getAllowNull();
                }
            }
        } catch (RepositoryException e) {
        // maybe this field is not linked to a table column... so leave it true
        }
        nullAware.setAllowNull(allowNull);
    }
    Insets m = field.getMargin();
    if (m == null)
        m = style_margin;
    if (m != null) {
        fl.setMargin(m);
        if (fl instanceof IMarginAwareBorder) {
            if (field.getBorderType() != null || hasBorder) {
                Border b = fl.getBorder();
                if (b != null) {
                    fl.setBorder(BorderFactory.createCompoundBorder(b, BorderFactory.createEmptyBorder(m.top, m.left, m.bottom, m.right)));
                }
            }
        }
    }
    if (fl.getScriptObject() instanceof HasRuntimePlaceholder) {
        ((HasRuntimePlaceholder) fl.getScriptObject()).setPlaceholderText(field.getPlaceholderText());
    }
    return fl;
}
Also used : RuntimeDataCombobox(com.servoy.j2db.ui.scripting.RuntimeDataCombobox) Insets(java.awt.Insets) IScrollPane(com.servoy.j2db.ui.IScrollPane) ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) RuntimeHTMLArea(com.servoy.j2db.ui.scripting.RuntimeHTMLArea) IForm(com.servoy.j2db.IForm) IDataProvider(com.servoy.j2db.persistence.IDataProvider) RuntimeMediaField(com.servoy.j2db.ui.scripting.RuntimeMediaField) RuntimeRtfArea(com.servoy.j2db.ui.scripting.RuntimeRtfArea) HasRuntimePlaceholder(com.servoy.j2db.ui.runtime.HasRuntimePlaceholder) RuntimeDataPassword(com.servoy.j2db.ui.scripting.RuntimeDataPassword) RuntimeDataCalendar(com.servoy.j2db.ui.scripting.RuntimeDataCalendar) IValueList(com.servoy.j2db.dataprocessing.IValueList) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) FormController(com.servoy.j2db.FormController) RuntimeRadioButton(com.servoy.j2db.ui.scripting.RuntimeRadioButton) RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) IStyleSheet(com.servoy.j2db.util.IStyleSheet) RuntimeCheckbox(com.servoy.j2db.ui.scripting.RuntimeCheckbox) IScriptExecuter(com.servoy.j2db.IScriptExecuter) AbstractBase(com.servoy.j2db.persistence.AbstractBase) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RuntimeRadioChoice(com.servoy.j2db.ui.scripting.RuntimeRadioChoice) RuntimeCheckBoxChoice(com.servoy.j2db.ui.scripting.RuntimeCheckBoxChoice) RuntimeTextArea(com.servoy.j2db.ui.scripting.RuntimeTextArea) AbstractRuntimeValuelistComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent) IStyleRule(com.servoy.j2db.util.IStyleRule) RuntimeListBox(com.servoy.j2db.ui.scripting.RuntimeListBox) RuntimeSpinner(com.servoy.j2db.ui.scripting.RuntimeSpinner) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) IStylePropertyChangesRecorder(com.servoy.j2db.ui.IStylePropertyChangesRecorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) IDisplayTagText(com.servoy.j2db.ui.IDisplayTagText)

Aggregations

IFormatScriptComponent (com.servoy.j2db.ui.scripting.IFormatScriptComponent)4 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)3 ApplicationException (com.servoy.j2db.ApplicationException)2 FindState (com.servoy.j2db.dataprocessing.FindState)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 FormController (com.servoy.j2db.FormController)1 IForm (com.servoy.j2db.IForm)1 IScriptExecuter (com.servoy.j2db.IScriptExecuter)1 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)1 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1 LookupValueList (com.servoy.j2db.dataprocessing.LookupValueList)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 ValueList (com.servoy.j2db.persistence.ValueList)1