Search in sources :

Example 11 with FlattenedSolution

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

the class FormPropertyType method toRhinoValue.

@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext webObjectContext, Scriptable startScriptable) {
    if (webComponentValue instanceof Form) {
        return ((Form) webComponentValue).getName();
    } else {
        if (webComponentValue != null && webObjectContext != null && webObjectContext.getUnderlyingWebObject() instanceof IContextProvider) {
            // form is stored as uuid on disk
            FlattenedSolution solution = ((IContextProvider) webObjectContext.getUnderlyingWebObject()).getDataConverterContext().getSolution();
            Form form = solution.getForm(webComponentValue.toString());
            if (form == null) {
                form = (Form) solution.searchPersist(webComponentValue.toString());
            }
            if (form != null) {
                return form.getName();
            }
        }
    }
    return webComponentValue;
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 12 with FlattenedSolution

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

the class FormTemplateGenerator method isSingleValueComponent.

/**
 * @return false if the persist has no valuelist or at most one value in the valuelist, true otherwise
 */
public static boolean isSingleValueComponent(IFormElement persist) {
    Field field = (Field) persist;
    if (field.getValuelistID() > 0) {
        try {
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            FlattenedSolution fs = new FlattenedSolution((SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(((Solution) persist.getRootObject()).getName(), IRepository.SOLUTIONS), new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
            ValueList valuelist = fs.getValueList(field.getValuelistID());
            return isSingleValue(valuelist);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : Field(com.servoy.j2db.persistence.Field) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) ValueList(com.servoy.j2db.persistence.ValueList) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IRepository(com.servoy.j2db.persistence.IRepository) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 13 with FlattenedSolution

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

the class FindState method getRelatedFoundSet.

/*
	 * _____________________________________________________________ Related states implementation
	 */
/**
 * Get related foundset, relationName may be multiple-levels deep
 */
public IFoundSetInternal getRelatedFoundSet(String relationName, List<SortColumn> defaultSortColumns) {
    if (relationName == null || parent == null)
        return null;
    String partName = relationName;
    String restName = null;
    int index = relationName.indexOf('.');
    if (index > 0) {
        partName = relationName.substring(0, index);
        restName = relationName.substring(index + 1);
    }
    IFoundSetInternal rfs = relatedStates.get(partName);
    if (rfs == null) {
        FlattenedSolution fs = parent.getFoundSetManager().getApplication().getFlattenedSolution();
        Relation r = fs.getRelation(partName);
        // safety
        if (r == null)
            return null;
        try {
            if (r.isGlobal() || r.isParentRef()) {
                rfs = parent.getRelatedFoundSet(this, partName, defaultSortColumns);
            // do not store in relatedStates because it is not a relatedfindfoundset
            } else {
                if (!getValidSearchRelations().contains(r)) {
                    if (relatedFoundsetErrorReported == null)
                        relatedFoundsetErrorReported = new ArrayList<>();
                    if (!relatedFoundsetErrorReported.contains(partName)) {
                        relatedFoundsetErrorReported.add(partName);
                        String reason = "";
                        if (r.isGlobal())
                            reason = "global relation";
                        else if (r.isMultiServer())
                            reason = "multi server";
                        else if (!Relation.isValid(r, fs))
                            reason = "server/table not valid/loaded";
                        else {
                            reason = "relation primary datasource: " + r.getPrimaryDataSource() + " != findstate primary datasource: " + parent.getDataSource();
                        }
                        Debug.warn("Find: skip related search for '" + partName + "', relation cannot be used in search, because: " + reason);
                        parent.getFoundSetManager().getApplication().reportJSWarning(Messages.getString("servoy.relation.find.unusable", new Object[] { partName }) + " (" + reason + ')', // $NON-NLS-2$
                        null);
                    }
                    return null;
                }
                SQLSheet sheet = parent.getSQLSheet().getRelatedSheet(((FoundSetManager) parent.getFoundSetManager()).getApplication().getFlattenedSolution().getRelation(partName), ((FoundSetManager) parent.getFoundSetManager()).getSQLGenerator());
                rfs = ((FoundSetManager) parent.getFoundSetManager()).createRelatedFindFoundSet(this, partName, sheet);
                ((FoundSet) rfs).addParent(this);
                ((FoundSet) rfs).setFindMode();
                relatedStates.put(partName, rfs);
            }
        } catch (ServoyException ex) {
            // $NON-NLS-1$
            Debug.error("Error making related findstate", ex);
            return null;
        }
    }
    if (restName != null) {
        IRecordInternal record = rfs.getRecord(rfs.getSelectedIndex());
        if (record == null)
            return null;
        return record.getRelatedFoundSet(restName);
    }
    return rfs;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) IRelation(com.servoy.j2db.persistence.IRelation) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) ServoyException(com.servoy.j2db.util.ServoyException)

Example 14 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution 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)

Example 15 with FlattenedSolution

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

the class FormElementHelper method reload.

public void reload() {
    persistWrappers.clear();
    formTabSequences.clear();
    formComponentElements.clear();
    formComponentElementsForDesign.clear();
    FormComponentCache.templateCache.clear();
    for (FlattenedSolution fs : globalFlattendSolutions.values()) {
        fs.close(null);
    }
    globalFlattendSolutions.clear();
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Aggregations

FlattenedSolution (com.servoy.j2db.FlattenedSolution)79 JSFunction (org.mozilla.javascript.annotations.JSFunction)27 Form (com.servoy.j2db.persistence.Form)20 RepositoryException (com.servoy.j2db.persistence.RepositoryException)17 ArrayList (java.util.ArrayList)17 Relation (com.servoy.j2db.persistence.Relation)15 Media (com.servoy.j2db.persistence.Media)10 Solution (com.servoy.j2db.persistence.Solution)10 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)9 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)7 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)7 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)7 FormController (com.servoy.j2db.FormController)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ValueList (com.servoy.j2db.persistence.ValueList)6 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)6 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)6 ITable (com.servoy.j2db.persistence.ITable)5 QueryTable (com.servoy.j2db.query.QueryTable)5 SafeArrayList (com.servoy.j2db.util.SafeArrayList)5