Search in sources :

Example 1 with IDataProviderLookup

use of com.servoy.j2db.persistence.IDataProviderLookup in project servoy-client by Servoy.

the class WebDataRendererFactory method placeElements.

protected Map placeElements(IApplication app, Form form, IScriptExecuter listener, Map emptyDataRenderers, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
    // $NON-NLS-1$
    final boolean useAJAX = Utils.getAsBoolean(app.getRuntimeProperties().get("useAJAX"));
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    String orientation = OrientationApplier.getHTMLContainerOrientation(app.getLocale(), app.getSolution().getTextOrientation());
    // $NON-NLS-1$
    boolean leftToRight = !"rtl".equalsIgnoreCase(orientation);
    // $NON-NLS-1$
    boolean isAnchoringEnabled = Utils.getAsBoolean(app.getRuntimeProperties().get("enableAnchors"));
    // Insets insets = new Insets(0, 0, 0, 0);
    for (IFormElement obj : Utils.iterate(form.getFormElementsSortedByFormIndex())) {
        Point l = null;
        l = (obj).getLocation();
        // unknown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            WebDataRenderer panel = (WebDataRenderer) it.next();
            // Border border = panel.getBorder();
            // if (border instanceof EmptyBorder)
            // {
            // insets = ((EmptyBorder)border).getBorderInsets();
            // }
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                org.apache.wicket.Component comp = (org.apache.wicket.Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listener, printing);
                if (comp != null) {
                    if (obj instanceof Field) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && (comp instanceof WebBaseLabel || comp instanceof WebBaseSubmitLink)) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if ((obj instanceof ISupportTabSeq) && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    org.apache.wicket.Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    } else if (newComp instanceof WebImageBeanHolder) {
                        WebImageBeanHolder wiBeanHolder = (WebImageBeanHolder) newComp;
                        Object bean = wiBeanHolder.getDelegate();
                        if (bean instanceof IServoyAwareBean) {
                            IServoyAwareBean ourBean = (IServoyAwareBean) bean;
                            panel.addDisplayComponent(obj, ourBean);
                        }
                    }
                    ((IComponent) comp).setLocation(new Point((l.x), (l.y - start)));
                    if (form.getOnRecordEditStartMethodID() > 0 && comp instanceof IFieldComponent) {
                        if (useAJAX && comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null && !ScopesUtils.isVariableScope(((IDisplayData) comp).getDataProviderID())) {
                            StartEditOnFocusGainedEventBehavior.addNewBehaviour(comp);
                        }
                    }
                    // - beans
                    if (isAnchoringEnabled && (((obj instanceof Field) && WebAnchoringHelper.needsWrapperDivForAnchoring((Field) obj)) || (obj instanceof Bean) || ((obj instanceof GraphicalComponent) && ComponentFactory.isButton((GraphicalComponent) obj)))) {
                        panel.add(WebAnchoringHelper.getWrapperComponent(comp, obj, start, panel.getSize(), leftToRight, false));
                    } else {
                        panel.add(comp);
                    }
                }
            }
        }
    }
    Iterator it = labelForComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Entry) it.next();
        Object key = entry.getKey();
        if (key instanceof WebBaseLabel || key instanceof WebBaseSubmitLink) {
            IFieldComponent component = (IFieldComponent) labelForComponents.get(entry.getValue());
            if (component != null) {
                if (key instanceof WebBaseLabel) {
                    ((WebBaseLabel) entry.getKey()).setLabelFor(component);
                } else {
                    ((WebBaseSubmitLink) entry.getKey()).setLabelFor(component);
                }
                (component).addLabelFor((ILabel) entry.getKey());
                if (!component.isVisible()) {
                    component.setComponentVisible(component.isVisible());
                }
                if (!component.isEnabled()) {
                    component.setComponentEnabled(component.isEnabled());
                }
            }
        }
    }
    it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        WebDataRenderer panel = (WebDataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listener, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Bean(com.servoy.j2db.persistence.Bean) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Field(com.servoy.j2db.persistence.Field) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) Component(org.apache.wicket.Component) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) HashMap(java.util.HashMap) Map(java.util.Map) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 2 with IDataProviderLookup

use of com.servoy.j2db.persistence.IDataProviderLookup in project servoy-client by Servoy.

the class FlattenedSolution method getDataproviderLookup.

public IDataProviderLookup getDataproviderLookup(IFoundSetManagerInternal foundSetManager, final IPersist p) {
    IDataProviderLookup retval = null;
    synchronized (this) {
        if (dataProviderLookups == null)
            dataProviderLookups = new HashMap<IPersist, IDataProviderLookup>();
        retval = dataProviderLookups.get(p);
        if (retval != null)
            return retval;
    }
    if (p instanceof Form) {
        ITable t = null;
        try {
            if (foundSetManager == null) {
                t = getTable(((Form) p).getDataSource());
            } else {
                t = foundSetManager.getTable(((Form) p).getDataSource());
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
        retval = new FormAndTableDataProviderLookup(this, (Form) p, t);
    } else if (p instanceof Portal) {
        ITable t = null;
        Relation[] relations = getRelationSequence(((Portal) p).getRelationName());
        if (relations == null) {
            return null;
        }
        t = getTable(relations[relations.length - 1].getForeignDataSource());
        retval = new FormAndTableDataProviderLookup(this, (Form) p.getParent(), t);
    } else // solution
    {
        retval = new IDataProviderLookup() {

            public IDataProvider getDataProvider(String id) throws RepositoryException {
                return getGlobalDataProvider(id);
            }

            public Table getTable() throws RepositoryException {
                return null;
            }
        };
    }
    synchronized (this) {
        dataProviderLookups.put(p, retval);
    }
    return retval;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Portal(com.servoy.j2db.persistence.Portal) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 3 with IDataProviderLookup

use of com.servoy.j2db.persistence.IDataProviderLookup in project servoy-client by Servoy.

the class DataRendererFactory method placeElements.

// returns usesSliding
private Map placeElements(Iterator<IFormElement> e1, IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, int XCorrection, int YCorrection, boolean printing, boolean cutDataProviderNames, ControllerUndoManager undoManager, boolean isPortal, TabSequenceHelper<Component> tabSequence) throws Exception {
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    // Insets insets = new Insets(0, 0, 0, 0);
    while (e1.hasNext()) {
        Point l = null;
        IPersist obj = e1.next();
        l = ((IFormElement) obj).getLocation();
        // unkown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            DataRenderer panel = (DataRenderer) it.next();
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                Component comp = (Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listner, printing);
                // Test for a visible bean, then get the real component
                if (comp instanceof VisibleBean) {
                    comp = ((VisibleBean) comp).getDelegate();
                }
                if (comp != null) {
                    if (obj instanceof Field && comp instanceof JComponent) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && comp instanceof JLabel) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if (obj instanceof ISupportTabSeq && comp instanceof JComponent && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        // HACK:don;t no other way to do this.........
                        if (newComp instanceof IDisplayData && cutDataProviderNames) {
                            IDisplayData da = (IDisplayData) newComp;
                            String id = da.getDataProviderID();
                            if (id != null && !ScopesUtils.isVariableScope(id)) {
                                // only cut first relation (so you can have relation chain inside portal)
                                int index = id.indexOf('.');
                                // TODO:check if part before . is same as relation name (objToRender.getRelationID() )
                                if (index > 0) {
                                    id = id.substring(index + 1);
                                }
                                da.setDataProviderID(id);
                            }
                        }
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    }
                    comp.setLocation((l.x) + XCorrection, (l.y - start) + YCorrection);
                    int index = 0;
                    if (!printing && obj instanceof ISupportAnchors) {
                        panel.add(comp, new Integer(((ISupportAnchors) obj).getAnchors()), index);
                    } else if (printing) {
                        if (obj instanceof ISupportPrintSliding && !isPortal) {
                            int slide = ((ISupportPrintSliding) obj).getPrintSliding();
                            if (slide != ISupportPrintSliding.NO_SLIDING) {
                                listTocomplete.put(comp, new Integer(slide));
                                panel.setUsingSliding(true);
                            }
                        }
                        panel.add(comp, index);
                    } else {
                        panel.add(comp, index);
                    }
                }
            }
        }
    }
    if (!printing) {
        Iterator it = labelForComponents.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Entry) it.next();
            if (entry.getKey() instanceof JLabel) {
                JComponent component = (JComponent) labelForComponents.get(entry.getValue());
                if (component != null) {
                    ((JLabel) entry.getKey()).setLabelFor(component);
                    if (component instanceof IFieldComponent) {
                        ((IFieldComponent) component).addLabelFor((ILabel) entry.getKey());
                        if (!((IFieldComponent) component).isVisible()) {
                            ((IFieldComponent) component).setComponentVisible(((IFieldComponent) component).isVisible());
                        }
                        if (!((IFieldComponent) component).isEnabled()) {
                            ((IFieldComponent) component).setComponentEnabled(((IFieldComponent) component).isEnabled());
                        }
                    }
                }
            }
        }
    }
    Iterator it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        DataRenderer panel = (DataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listner, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Field(com.servoy.j2db.persistence.Field) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) ISupportPrintSliding(com.servoy.j2db.persistence.ISupportPrintSliding) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 4 with IDataProviderLookup

use of com.servoy.j2db.persistence.IDataProviderLookup in project servoy-client by Servoy.

the class DataproviderTypeSabloValue method dataProviderOrRecordChanged.

@Override
public void dataProviderOrRecordChanged(final IRecordInternal record, final String dataProvider, final boolean isFormDP, final boolean isGlobalDP, boolean fireChangeEvent) {
    // TODO can type or fieldFormat change, for example in scripting the format is reset (but type shouldn't really change)
    IDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null);
    Collection<PropertyDescription> properties = webObjectContext.getProperties(TypesRegistry.getType(FormatPropertyType.TYPE_NAME));
    FormatTypeSabloValue formatSabloValue = null;
    for (PropertyDescription formatPd : properties) {
        // see whether format if "for" this property (dataprovider)
        Object formatConfig = formatPd.getConfig();
        if (formatConfig instanceof String[] && Arrays.asList((String[]) formatConfig).indexOf(dpPD.getName()) != -1) {
            INGApplication application = servoyDataConverterContext.getApplication();
            formatSabloValue = (FormatTypeSabloValue) webObjectContext.getProperty(formatPd.getName());
            if (formatSabloValue != null) {
                if (formatSabloValue.getFormatDesignValue() != null) {
                    fieldFormat = ComponentFormat.getComponentFormat(formatSabloValue.getFormatDesignValue(), dataProviderID, dpLookup, application);
                }
                break;
            }
        }
    }
    if (fieldFormat != null) {
        typeOfDP = NGUtils.getDataProviderPropertyDescription(fieldFormat.uiType, getDataProviderConfig().hasParseHtml(), fieldFormat.parsedFormat.useLocalDateTime());
        if (record instanceof FindState) {
            ((FindState) record).setFormat(dataProviderID, fieldFormat.parsedFormat);
        }
    } else {
        // see type of dataprovider; this is done only once - first time we get a new record
        typeOfDP = NGUtils.getDataProviderPropertyDescription(dataProviderID, servoyDataConverterContext.getApplication(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null, getDataProviderConfig().hasParseHtml(), formatSabloValue != null ? formatSabloValue.getComponentFormat().parsedFormat.useLocalDateTime() : false);
    }
    if (dpPD.hasTag(TAG_TYPE_NAME)) {
        IPropertyType<?> specType = TypesRegistry.getType((String) dpPD.getTag(TAG_TYPE_NAME));
        if (specType != null && (typeOfDP == null || !specType.getClass().isAssignableFrom(typeOfDP.getClass()))) {
            typeOfDP = new PropertyDescriptionBuilder().withName("Spec type hint").withType(specType).build();
        }
    }
    String dpID = dataProviderID;
    IDataProvider dp = null;
    if (dpLookup != null) {
        try {
            dp = dpLookup.getDataProvider(dataProviderID);
            if (dp != null) {
                dpID = dp.getDataProviderID();
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    if (globalRelationName != null) {
        try {
            IFoundSetInternal newRelatedFoundset = servoyDataConverterContext.getApplication().getFoundSetManager().getGlobalRelatedFoundSet(globalRelationName);
            if (newRelatedFoundset != globalRelatedFoundset) {
                if (globalRelatedFoundsetListener == null) {
                    globalRelatedFoundsetListener = new IFoundSetEventListener() {

                        @Override
                        public void foundSetChanged(FoundSetEvent e) {
                            if (e.getType() == FoundSetEvent.CONTENTS_CHANGED) {
                                dataProviderOrRecordChanged(DataproviderTypeSabloValue.this.dataAdapterList.getRecord(), null, false, false, true);
                            }
                        }
                    };
                } else if (globalRelatedFoundset != null) {
                    globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
                }
                globalRelatedFoundset = newRelatedFoundset;
                globalRelatedFoundset.addFoundSetEventListener(globalRelatedFoundsetListener);
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedFoundsetSelectionListener != null) {
        try {
            ArrayList<IFoundSetInternal> newRelatedFoundsets = getRelatedFoundsets(record, relationName);
            boolean equals = testByReference(newRelatedFoundsets, this.relatedFoundsets);
            if (!equals) {
                IDataProvider column = dp;
                if (column instanceof ColumnWrapper) {
                    column = ((ColumnWrapper) column).getColumn();
                }
                boolean isAggregate = (column instanceof IColumn) ? ((IColumn) column).isAggregate() : false;
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
                }
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
                }
                relatedFoundsets = newRelatedFoundsets;
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().addListSelectionListener(relatedFoundsetSelectionListener);
                }
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).addAggregateModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedRecordModificationListener != null) {
        try {
            ArrayList<IRecordInternal> newRelatedRecords = getRelatedRecords(record, relationName);
            boolean equals = testByReference(newRelatedRecords, this.relatedRecords);
            if (!equals) {
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.removeModificationListener(relatedRecordModificationListener);
                }
                relatedRecords = newRelatedRecords;
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.addModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    Object v = com.servoy.j2db.dataprocessing.DataAdapterList.getValueObject(record, servoyDataConverterContext.getForm().getFormScope(), dpID);
    if (v == Scriptable.NOT_FOUND)
        v = null;
    if (fieldFormat != null && !findMode) {
        // if it has an UI converter, transform it from the record/scope value into the UI value
        v = ComponentFormat.applyUIConverterToObject(v, dataProviderID, servoyDataConverterContext.getApplication().getFoundSetManager(), fieldFormat);
    }
    v = replaceTagsIfNeeded(v);
    boolean changed = ((v != uiValue) && (v == null || !v.equals(uiValue)));
    uiValue = v;
    if (changed) {
        jsonValue = null;
    }
    if (// if it is a foundset related DAL then always call valuechanged (the value can be of a previous row)
    fireChangeEvent && (changed || dataAdapterList instanceof FoundsetDataAdapterList)) {
        changeMonitor.valueChanged();
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) IDataProvider(com.servoy.j2db.persistence.IDataProvider) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) FindState(com.servoy.j2db.dataprocessing.FindState) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) FoundsetDataAdapterList(com.servoy.j2db.server.ngclient.property.FoundsetDataAdapterList) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) RepositoryException(com.servoy.j2db.persistence.RepositoryException) FoundSetEvent(com.servoy.j2db.dataprocessing.FoundSetEvent) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) PropertyDescription(org.sablo.specification.PropertyDescription) IColumn(com.servoy.j2db.persistence.IColumn) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup) IFoundSetEventListener(com.servoy.j2db.dataprocessing.IFoundSetEventListener)

Example 5 with IDataProviderLookup

use of com.servoy.j2db.persistence.IDataProviderLookup 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

IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)5 HashMap (java.util.HashMap)3 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 Field (com.servoy.j2db.persistence.Field)2 Form (com.servoy.j2db.persistence.Form)2 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 ISupportPrinting (com.servoy.j2db.persistence.ISupportPrinting)2 ISupportTabSeq (com.servoy.j2db.persistence.ISupportTabSeq)2 ITable (com.servoy.j2db.persistence.ITable)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 Point (java.awt.Point)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 PropertyDescription (org.sablo.specification.PropertyDescription)2