Search in sources :

Example 1 with ComponentTypeConfig

use of com.servoy.j2db.server.ngclient.property.ComponentTypeConfig in project servoy-client by Servoy.

the class FormComponentPropertyType method toTemplateJSONValue.

@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion clientConversion, FormElementContext formElementContext) throws JSONException {
    if (formElementValue == null)
        return writer;
    FlattenedSolution fs = formElementContext.getFlattenedSolution();
    Form form = getForm(formElementValue, fs);
    if (form != null) {
        if (pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) pd.getConfig()).forFoundset != null) {
            clientConversion.convert(FormComponentPropertyType.TYPE_NAME);
        }
        // else this info below seems to be needed client-side even for non-foundset linked form components; but it's just some dumb simple JSON, not a client side type
        JSONUtils.addKeyIfPresent(writer, key);
        // we output here a uuid that is a uuid that must be used to get the compiled template from the $formcomponentCache
        String uuid = FormElementHelper.INSTANCE.getFormComponentCache(formElementContext.getFormElement(), pd, (JSONObject) formElementValue, form, fs).getHtmlTemplateUUIDForAngular();
        writer.object();
        writer.key("uuid");
        writer.value(uuid);
        writer.key("formHeight");
        writer.value(form.getSize().height);
        writer.key("formWidth");
        writer.value(form.getSize().width);
        writer.key("absoluteLayout");
        writer.value(!form.isResponsiveLayout());
        writer.endObject();
    }
    return writer;
}
Also used : JSONObject(org.json.JSONObject) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig)

Example 2 with ComponentTypeConfig

use of com.servoy.j2db.server.ngclient.property.ComponentTypeConfig in project servoy-client by Servoy.

the class FormWrapper method checkFormComponents.

private void checkFormComponents(List<IFormElement> components, FormElement formComponentFormElement, Set<String> recursiveCheck) {
    // if it's not a form component then .spec will not contain properties of type FormComponentPropertyType.INSTANCE and nothing will happen below
    WebObjectSpecification spec = formComponentFormElement.getWebComponentSpec();
    if (spec != null) {
        Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
        if (properties.size() > 0) {
            for (PropertyDescription pd : properties) {
                Object config = pd.getConfig();
                boolean isRepeating = config instanceof ComponentTypeConfig && ((ComponentTypeConfig) config).forFoundset != null;
                Object propertyValue = formComponentFormElement.getPropertyValue(pd.getName());
                Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
                if (frm == null)
                    continue;
                if (!recursiveCheck.add(frm.getName())) {
                    // $NON-NLS-1$
                    Debug.error("recursive reference found between (List)FormComponents: " + recursiveCheck);
                    continue;
                }
                FormComponentCache cache = FormElementHelper.INSTANCE.getFormComponentCache(formComponentFormElement, pd, (JSONObject) propertyValue, frm, context.getSolution());
                Dimension frmSize = frm.getSize();
                for (FormElement element : cache.getFormComponentElements()) {
                    IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
                    if ((!isRepeating || design))
                        components.add(persistOfElement);
                    formComponentParentSizes.put(element.getName(), frmSize);
                    if (!frm.isResponsiveLayout()) {
                        formComponentsLayout.put(element.getName(), Boolean.TRUE);
                    }
                    if (frm.getUseCssPosition()) {
                        String name = element.getDesignId() != null ? element.getDesignId() : element.getName();
                        if (!formComponentCSSPositionElementNames.containsKey(name)) {
                            formComponentCSSPositionElementNames.put(name, Boolean.TRUE);
                        }
                    }
                    checkFormComponents(components, element, recursiveCheck);
                }
                formComponentTemplates.put(cache.getHtmlTemplateUUIDForAngular(), cache.getTemplate());
                recursiveCheck.remove(frm.getName());
            }
        }
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) JSONObject(org.json.JSONObject) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 3 with ComponentTypeConfig

use of com.servoy.j2db.server.ngclient.property.ComponentTypeConfig in project servoy-client by Servoy.

the class FormComponentPropertyType method toSabloComponentValue.

@Override
public Object toSabloComponentValue(Object formElementValue, PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
    Form form = getForm(formElementValue, dataAdapterList.getApplication().getFlattenedSolution());
    if (form != null) {
        if (pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) pd.getConfig()).forFoundset != null) {
            return new FormComponentSabloValue(formElement, (JSONObject) formElementValue, pd, dataAdapterList, component, form);
        } else {
            FormComponentCache formComponentCache = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, (JSONObject) formElementValue, form, dataAdapterList.getApplication().getFlattenedSolution());
            List<FormElement> elements = formComponentCache.getFormComponentElements();
            IWebFormUI formUI = component.findParent(IWebFormUI.class);
            for (FormElement element : elements) {
                WebFormComponent child = ComponentFactory.createComponent(dataAdapterList.getApplication(), dataAdapterList, element, component.getParent(), dataAdapterList.getForm().getForm());
                formUI.contributeComponentToElementsScope(element, element.getWebComponentSpec(), child);
            }
        }
    }
    return formElementValue;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 4 with ComponentTypeConfig

use of com.servoy.j2db.server.ngclient.property.ComponentTypeConfig in project servoy-client by Servoy.

the class FormatTypeSabloValue method getSabloValue.

protected ComponentFormat getSabloValue(String formatValue, String dataproviderId, Object valuelistId, String foundsetId, IWebObjectContext webObjectCntxt) {
    INGApplication application = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getApplication();
    IDataProviderLookup dataProviderLookup = null;
    // IMPORTANT: here we use the for: configs in .spec file
    // 
    // if you have for: [valuelist, dataprovider] then 2 things can happen:
    // - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
    // - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
    // defines both "for" valuelist and dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
    // 
    // if you have just for: dataprovider the the dataprovider property determines the type
    // if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
    isValuelistFormatSet = false;
    if (valuelistId != null) {
        // if we have a "for" valuelist, see if this valuelist forces the format type due to display values (when they are separate from real values)
        // otherwise it will do nothing and loop/fallback to the other if clause below which checks the "for" dataprovider
        ValueList valuelistPersist = ValueListTypeSabloValue.getValuelistPersist(valuelistId, application);
        if (valuelistPersist != null) {
            IDataProvider dataProvider = null;
            ITable table;
            try {
                if (valuelistPersist.getRelationName() != null) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(valuelistPersist.getRelationName());
                    table = application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource());
                } else {
                    table = application.getFlattenedSolution().getTable(valuelistPersist.getDataSource());
                }
                if (table != null) {
                    // if the format is for a table valuelist - the type to be used is the one of the dp chosen as 'display' in the valuelist
                    String dp = null;
                    // if show == real then we can use show anyway cause there is only one value for both real and display; if show != real we care about show
                    int showDataProviders = valuelistPersist.getShowDataProviders();
                    if ((showDataProviders & 1) != 0) {
                        dp = valuelistPersist.getDataProviderID1();
                    }
                    if ((showDataProviders & 2) != 0) {
                        // display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
                        if (dp != null)
                            return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
                        dp = valuelistPersist.getDataProviderID2();
                    }
                    if ((showDataProviders & 4) != 0) {
                        // display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
                        if (dp != null)
                            return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
                        dp = valuelistPersist.getDataProviderID3();
                    }
                    if (dp != null) {
                        dataProvider = application.getFlattenedSolution().getDataProviderForTable(table, dp);
                    }
                    isValuelistFormatSet = true;
                    return ComponentFormat.getComponentFormat(formatValue, dataProvider, application, true);
                } else if (valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
                    IValueList realValuelist = null;
                    ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(propertyDependencies.valueListPropertyName));
                    if (valuelistSabloValue != null) {
                        // take it from property, may not be the shared instance in case setvaluelistitems on component was used
                        realValuelist = valuelistSabloValue.getValueList();
                    }
                    if (realValuelist == null) {
                        realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, ComponentFormat.getComponentFormat(formatValue, dataproviderId, null, application, true).parsedFormat, null, true);
                    }
                    if (realValuelist.hasRealValues()) {
                        // if custom vl has both real and display values, the display values are TEXT (format is for those)
                        // of if it has displayValueType set, use that
                        isValuelistFormatSet = true;
                        int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
                        return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
                    }
                } else if (valuelistPersist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
                    PropertyDescription vlPD = webObjectCntxt.getPropertyDescription(propertyDependencies.valueListPropertyName);
                    Object vlPDConfig = null;
                    if (vlPD != null) {
                        vlPDConfig = vlPD.getConfig();
                        if (vlPDConfig instanceof FoundsetLinkedConfig)
                            vlPDConfig = ((FoundsetLinkedConfig) vlPDConfig).getWrappedConfig();
                    }
                    boolean lazyLoad = valuelistPersist.getLazyLoading() && vlPDConfig instanceof ValueListConfig && ((ValueListConfig) vlPDConfig).getLazyLoading();
                    if (!lazyLoad) {
                        IValueList realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, null, null, true);
                        if (realValuelist instanceof GlobalMethodValueList) {
                            ((GlobalMethodValueList) realValuelist).fill(null, "", null);
                            if (realValuelist.hasRealValues() || realValuelist.getSize() == 0 || (realValuelist.getSize() == 1 && valuelistPersist.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS)) {
                                // if global method vl has both real and display values, the display values are TEXT (format is for those)
                                // of if it has displayValueType set, use that
                                isValuelistFormatSet = true;
                                int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
                                return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    // here - we want to fall back to the dataprovider if available in for: [ ..., dataprovider] if valuelist didn't force a certain display type on the format
    }
    if (dataproviderId != null && foundsetId != null) {
        ITable table = null;
        Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
        // always assume now that the the properties has the foundset property name.
        FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectCntxt.getUnderlyingWebObject().getProperty(this.propertyDependencies.foundsetPropertyName);
        if (runtimeValOfFoundset != null && runtimeValOfFoundset.getFoundset() != null && runtimeValOfFoundset.getFoundset().getDataSource().equals(foundsetId)) {
            table = runtimeValOfFoundset.getFoundset().getTable();
        }
        if (table == null)
            table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetId, application, form);
        if (table != null) {
            dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
        }
    // else it will be searched for in form's context and table as below
    }
    if (dataProviderLookup == null) {
        WebObjectSpecification spec = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getSpecification();
        if (spec != null) {
            Collection<PropertyDescription> formComponentProperties = spec.getProperties(FormComponentPropertyType.INSTANCE);
            if (formComponentProperties != null) {
                for (PropertyDescription property : formComponentProperties) {
                    if (property.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) property.getConfig()).forFoundset != null) {
                        FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getProperty(((ComponentTypeConfig) property.getConfig()).forFoundset);
                        ITable table = null;
                        Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
                        if (runtimeValOfFoundset.getFoundset() != null)
                            table = runtimeValOfFoundset.getFoundset().getTable();
                        if (table == null)
                            table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(runtimeValOfFoundset.getFoundsetSelector(), application, form);
                        if (table != null) {
                            dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
                        }
                        break;
                    }
                }
            }
        }
    }
    if (dataProviderLookup == null && application != null)
        dataProviderLookup = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
    ComponentFormat format = ComponentFormat.getComponentFormat(formatValue, dataproviderId, dataProviderLookup, application, true);
    return format;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ValueList(com.servoy.j2db.persistence.ValueList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IDataProvider(com.servoy.j2db.persistence.IDataProvider) Relation(com.servoy.j2db.persistence.Relation) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ITable(com.servoy.j2db.persistence.ITable) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) IValueList(com.servoy.j2db.dataprocessing.IValueList) ComponentFormat(com.servoy.j2db.component.ComponentFormat) ValueListConfig(com.servoy.j2db.server.ngclient.property.ValueListConfig) PropertyDescription(org.sablo.specification.PropertyDescription) FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Aggregations

Form (com.servoy.j2db.persistence.Form)4 ComponentTypeConfig (com.servoy.j2db.server.ngclient.property.ComponentTypeConfig)4 IFormElement (com.servoy.j2db.persistence.IFormElement)2 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)2 FormElement (com.servoy.j2db.server.ngclient.FormElement)2 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)2 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 JSONObject (org.json.JSONObject)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)1 IForm (com.servoy.j2db.IForm)1 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)1 ITable (com.servoy.j2db.persistence.ITable)1 Relation (com.servoy.j2db.persistence.Relation)1