Search in sources :

Example 6 with IDataProvider

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

the class FormAndTableDataProviderLookup method getDataProvider.

public IDataProvider getDataProvider(String id) throws RepositoryException {
    if (id == null)
        return null;
    // this getGlobalDataProvider handles related DPs as well like a.b.c
    IDataProvider retval = this.flattenedSolution.getGlobalDataProvider(id);
    if (retval == null) {
        retval = formProviders.get(id);
        if (retval != null) {
            return retval;
        }
        retval = this.flattenedSolution.getDataProviderForTable(getTable(), id);
        if (retval != null) {
            formProviders.put(id, retval);
        } else {
            retval = form.getScriptVariable(id);
            if (retval != null) {
                formProviders.put(id, retval);
            }
        }
    }
    return retval;
}
Also used : IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 7 with IDataProvider

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

the class NGUtils method getDataProviderPropertyDescription.

public static PropertyDescription getDataProviderPropertyDescription(String dataProviderName, IApplication app, Form form, ITable table, boolean parseHTMLIfString, boolean useLocalDateTime) {
    FormAndTableDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(app.getFlattenedSolution(), form, table);
    IDataProvider dp = null;
    try {
        dp = dpLookup.getDataProvider(dataProviderName);
    } catch (RepositoryException e) {
        Debug.error(e);
    }
    if (dp != null) {
        int dpType;
        if (dp instanceof IColumn || dp instanceof ColumnWrapper) {
            IColumn column = (dp instanceof IColumn) ? (IColumn) dp : ((ColumnWrapper) dp).getColumn();
            ColumnInfo ci = column.getColumnInfo();
            if (ci != null && ci.hasFlag(IBaseColumn.UUID_COLUMN)) {
                return UUID_DATAPROVIDER_CACHED_PD;
            }
            dpType = app.getFoundSetManager().getConvertedTypeForColumn(column, true);
        } else
            dpType = dp.getDataProviderType();
        return getDataProviderPropertyDescription(dpType, parseHTMLIfString, useLocalDateTime);
    }
    return null;
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 8 with IDataProvider

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

the class DataAdapterList method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationListner
	 */
/**
 * listen for global var changes via own listener and state vars(mainly columns) via state listener if via javascript any var is changed it will be noted
 * here,and dispatched to refresh the displays
 */
public void valueChanged(ModificationEvent e) {
    if (destroyed) {
        Debug.error("Destroyed DataAdapterList " + formController + " was still attached to the record: " + e.getRecord() + ", removing it if possible, currentRecord: " + currentRecord, new RuntimeException());
        if (e.getRecord() != null)
            e.getRecord().removeModificationListener(this);
        else if (currentRecord != null)
            currentRecord.removeModificationListener(this);
        return;
    }
    if (formController != null && formController.isDestroyed()) {
        Debug.error("Destroying DataAdapterList of a destroyed " + formController, new RuntimeException());
        destroy();
        return;
    }
    FormScope formScope = getFormScope();
    if (visible && (currentRecord != null || (formScope != null && formScope.has(e.getName(), formScope)))) {
        for (IDataAdapter da : dataAdapters.values()) {
            // dataAdapter should call state.getValue if name from event is same as its dataProviderID
            da.valueChanged(e);
        }
        // check if a related adapter depends on he global
        if (e != null && e.getName() != null) {
            for (IDisplayRelatedData drd : relatedDataAdapters) {
                boolean depends = false;
                String[] allRelationNames = drd.getAllRelationNames();
                for (int a = 0; !depends && allRelationNames != null && a < allRelationNames.length; a++) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(allRelationNames[a]);
                    for (int r = 0; !depends && relations != null && r < relations.length; r++) {
                        try {
                            IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(application.getFlattenedSolution());
                            for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
                                depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
                            }
                        } catch (RepositoryException ex) {
                            Debug.log(ex);
                        }
                    }
                }
                if (depends) {
                    // related adapter depends on the modified global
                    if (drd instanceof IDisplayDependencyData)
                        ((IDisplayDependencyData) drd).dependencyChanged(currentRecord);
                    else
                        drd.setRecord(currentRecord, true);
                }
            }
        }
        // inform servoy aware beans
        for (IServoyAwareBean drd : servoyAwareBeans) {
            if (drd instanceof IModificationListener) {
                try {
                    ((IModificationListener) drd).valueChanged(e);
                } catch (RuntimeException ex) {
                    // never make the app break on faulty beans
                    Debug.error(ex);
                }
            }
        }
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) FormScope(com.servoy.j2db.scripting.FormScope) Relation(com.servoy.j2db.persistence.Relation) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean)

Example 9 with IDataProvider

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

the class PartNode method getAggregatesFromRenderer.

private void getAggregatesFromRenderer(final List<AggregateVariable> aggregates, final Form f, DataRenderer a_renderer) throws RepositoryException {
    Map<IPersist, IDisplay> allFields = a_renderer.getFieldComponents();
    Iterator<IDisplay> it = allFields.values().iterator();
    while (it.hasNext()) {
        IDisplay display = it.next();
        if (display instanceof IDisplayData) {
            String dataProviderID = ((IDisplayData) display).getDataProviderID();
            if (dataProviderID != null) {
                IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(dataProviderID);
                if (dp instanceof AggregateVariable) {
                    if (!aggregates.contains(dp))
                        aggregates.add((AggregateVariable) dp);
                }
            } else if (display instanceof IDisplayTagText) {
                String tagText = ((IDisplayTagText) display).getTagText();
                Text.processTags(tagText, new ITagResolver() {

                    public String getStringValue(String name) {
                        try {
                            IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(name);
                            if (dp instanceof AggregateVariable) {
                                if (!aggregates.contains(dp))
                                    aggregates.add((AggregateVariable) dp);
                            }
                        } catch (Exception e) {
                            Debug.error(e);
                        }
                        return null;
                    }
                });
            }
        }
    }
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) ITagResolver(com.servoy.base.util.ITagResolver) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IDataProvider(com.servoy.j2db.persistence.IDataProvider) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) IDisplayTagText(com.servoy.j2db.ui.IDisplayTagText) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 10 with IDataProvider

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

the class DataProviderEditor method fillDataProviderList.

protected void fillDataProviderList() {
    try {
        ITable table = null;
        if (definedTable == null) {
            FormManager fm = (FormManager) application.getFormManager();
            FormController fc = fm.getCurrentMainShowingFormController();
            if (fc != null) {
                Form form = fc.getForm();
                table = application.getFlattenedSolution().getTable(form.getDataSource());
            }
        } else {
            if (!showRelatedOptionsOnly)
                table = definedTable;
        }
        DefaultListModel model = (DefaultListModel) list.getModel();
        model.removeAllElements();
        if (showNoneOption)
            model.addElement("-none-");
        if (!showColumnsOnly)
            model.addElement("*columns");
        Object o = relationsComboBox.getSelectedItem();
        if (o != null) {
            if (o instanceof String) {
            // table = form.getTable();
            } else {
                table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
            }
            if (table != null) {
                Iterator<Column> it = table.getColumnsSortedByName();
                while (it.hasNext()) {
                    IColumn c = it.next();
                    ColumnInfo ci = c.getColumnInfo();
                    if (ci != null && ci.isExcluded()) {
                        continue;
                    }
                    if (hideMediaColumns) {
                        // use dataprovider type as defined by column converter
                        ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
                        if (componentFormat.dpType == IColumnTypes.MEDIA) {
                            continue;
                        }
                    }
                    model.addElement(c);
                }
            }
        }
        FlattenedSolution s = application.getFlattenedSolution();
        if (table != null && !showColumnsOnly) {
            Iterator it = s.getScriptCalculations(table, true);
            if (it.hasNext()) {
                model.addElement("*calculations");
            }
            while (it.hasNext()) {
                ScriptCalculation sc = (ScriptCalculation) it.next();
                for (int i = 0; i < model.size(); i++) {
                    Object obj = model.elementAt(i);
                    if (obj instanceof IDataProvider) {
                        IDataProvider dp = (IDataProvider) obj;
                        if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
                            // remove the column from the list if use by
                            model.remove(i);
                            // stored calc
                            break;
                        }
                    }
                }
                model.addElement(sc);
            }
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
            Iterator it3 = s.getAggregateVariables(table, true);
            if (it3.hasNext()) {
                model.addElement("*aggregates");
            }
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (table != null && showColumnsOnly && showSortableOnly) {
            Iterator it3 = s.getAggregateVariables(table, true);
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (showGlobalsOption && showColumnsOnly) {
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) DefaultListModel(javax.swing.DefaultListModel) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IDataProvider(com.servoy.j2db.persistence.IDataProvider) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Aggregations

IDataProvider (com.servoy.j2db.persistence.IDataProvider)25 RepositoryException (com.servoy.j2db.persistence.RepositoryException)13 Column (com.servoy.j2db.persistence.Column)11 IColumn (com.servoy.j2db.persistence.IColumn)11 Relation (com.servoy.j2db.persistence.Relation)8 QueryColumn (com.servoy.j2db.query.QueryColumn)6 FormController (com.servoy.j2db.FormController)5 LiteralDataprovider (com.servoy.j2db.persistence.LiteralDataprovider)5 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)4 ColumnWrapper (com.servoy.j2db.persistence.ColumnWrapper)4 Form (com.servoy.j2db.persistence.Form)4 ITable (com.servoy.j2db.persistence.ITable)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)3 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 IPersist (com.servoy.j2db.persistence.IPersist)3 Table (com.servoy.j2db.persistence.Table)3 IBaseColumn (com.servoy.base.persistence.IBaseColumn)2 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)2