Search in sources :

Example 1 with ScriptVariable

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

the class FlattenedSolution method getGlobalDataProviderEx.

private IDataProvider getGlobalDataProviderEx(String id, boolean quiet) throws RepositoryException {
    if (id == null)
        return null;
    Pair<String, String> scope = ScopesUtils.getVariableScope(id);
    if (scope.getLeft() != null) /* global scope */
    {
        // search all objects,will return globals
        ScriptVariable global = AbstractBase.selectByName(getScriptVariables(scope.getLeft(), false), scope.getRight());
        if (global != null) {
            return global;
        }
        // try @enum global variables
        return getEnumDataProvider(id);
    }
    // in case of multi-level relations we have more that 1 dot
    int indx = id.lastIndexOf('.');
    if (indx > 0) {
        String rel_name = id.substring(0, indx);
        String col = id.substring(indx + 1);
        Relation[] relations = getRelationSequence(rel_name);
        if (relations == null) {
            return null;
        }
        Relation r = relations[relations.length - 1];
        if (quiet) {
            boolean missingSrv = true;
            String ds = r.getForeignDataSource();
            if (ds != null) {
                String[] st = DataSourceUtilsBase.getDBServernameTablename(ds);
                if (st != null && st.length == 2) {
                    try {
                        missingSrv = (r.getRootObject().getServer(st[0]) == null);
                    } catch (RemoteException e) {
                    // we are in developer here - shouldn't happen
                    }
                }
            }
            if (missingSrv)
                return null;
        }
        // TODO if this is refactord out to be resolved outside the relation also look at the DataProviderConverter
        // the call from that class to flattenedSolution.getGlobalDataProvider(value);
        Column[] cols = r.getForeignColumns(this);
        if (cols == null || cols.length == 0)
            return null;
        IDataProvider c = getDataProviderForTable(getTable(r.getForeignDataSource()), col);
        if (r != null && c instanceof IColumn) {
            return new ColumnWrapper((IColumn) c, relations);
        }
        return c;
    }
    return null;
}
Also used : ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) IDataProvider(com.servoy.j2db.persistence.IDataProvider) Relation(com.servoy.j2db.persistence.Relation) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IColumn(com.servoy.j2db.persistence.IColumn) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) RemoteException(java.rmi.RemoteException)

Example 2 with ScriptVariable

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

the class FormScope method remove.

@Override
public void remove(ScriptVariable var) {
    ScriptVariable newVar = null;
    for (ScriptVariable loopVar : Utils.iterate(getScriptLookup().getScriptVariables(false))) {
        if (loopVar.getName().equals(var.getName())) {
            newVar = loopVar;
            break;
        }
    }
    if (newVar == null) {
        super.remove(var);
    } else {
        Form form = getFormController().getForm();
        Form deletedVarForm = (Form) var.getParent();
        Form newVarForm = (Form) newVar.getParent();
        while (form != null) {
            // when the deleted form var is found first in the hiearchy
            if (form.getName().equals(deletedVarForm.getName())) {
                // then remove this var, and put the new one in.
                super.remove(var);
                put(newVar);
                break;
            } else if (form.getName().equals(newVarForm.getName())) {
                // else if the newVarForm is still found first (then it is already the current one)
                return;
            }
            form = form.getExtendsForm();
        }
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable)

Example 3 with ScriptVariable

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

the class DataRenderer method createDataAdapter.

void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
    // IScriptExecutor can be null for a design component
    FormController formController = el == null ? null : el.getFormController();
    dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, formController, null, undoManager);
    // make it really fields only
    HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
    Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<IPersist, IDisplay> element = it.next();
        if (element.getValue() instanceof IDisplayData) {
            String id = ((IDisplayData) element.getValue()).getDataProviderID();
            if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable) {
                globalFields.add(element.getValue());
            }
            f.put(element.getKey(), element.getValue());
        }
    }
    fieldComponents = f;
}
Also used : FormController(com.servoy.j2db.FormController) HashMap(java.util.HashMap) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IPersist(com.servoy.j2db.persistence.IPersist) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ScriptVariable

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

the class FoundSet method getPrototype.

public Scriptable getPrototype() {
    if (prototypeScope == null) {
        LazyCompilationScope scope = new LazyCompilationScope(this, fsm.getApplication().getScriptEngine(), new ISupportScriptProviders() {

            public Iterator<? extends IScriptProvider> getScriptMethods(boolean sort) {
                List<ScriptMethod> methods = null;
                Iterator<TableNode> tableNodes = fsm.getApplication().getFlattenedSolution().getTableNodes(getTable());
                while (tableNodes.hasNext()) {
                    TableNode tn = tableNodes.next();
                    Iterator<ScriptMethod> fsMethods = tn.getFoundsetMethods(sort);
                    if (methods == null) {
                        if (!tableNodes.hasNext()) {
                            // just 1
                            return fsMethods;
                        }
                        methods = new ArrayList<ScriptMethod>();
                    }
                    while (fsMethods.hasNext()) {
                        methods.add(fsMethods.next());
                    }
                }
                return methods == null ? Collections.<ScriptMethod>emptyList().iterator() : methods.iterator();
            }

            public Iterator<ScriptVariable> getScriptVariables(boolean b) {
                return Collections.<ScriptVariable>emptyList().iterator();
            }

            public ScriptMethod getScriptMethod(int methodId) {
                // not called by LCS
                return null;
            }
        }) {

            @Override
            public String getClassName() {
                // $NON-NLS-1$
                return "FoundSetScope";
            }

            @Override
            public String getScopeName() {
                return getDataSource();
            }
        };
        // make sure functions like getSize cannot be overridden
        scope.setFunctionParentScriptable(this);
        prototypeScope = scope;
    }
    return prototypeScope;
}
Also used : ISupportScriptProviders(com.servoy.j2db.persistence.ISupportScriptProviders) IScriptProvider(com.servoy.j2db.persistence.IScriptProvider) Iterator(java.util.Iterator) TableNode(com.servoy.j2db.persistence.TableNode) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) LazyCompilationScope(com.servoy.j2db.scripting.LazyCompilationScope) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) SafeArrayList(com.servoy.j2db.util.SafeArrayList) Collectors.toList(java.util.stream.Collectors.toList) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 5 with ScriptVariable

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

the class JSForm method getVariables.

/**
 * An array consisting of all form variables for this form.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var variables = frm.getVariables();
 * for (var i in variables)
 * 	application.output(variables[i].name);
 *
 * @param returnInheritedElements boolean true to also return the elements from the parent form
 * @return an array of all variables on this form
 */
@JSFunction
public JSVariable[] getVariables(boolean returnInheritedElements) {
    List<JSVariable> variables = new ArrayList<JSVariable>();
    Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
    Iterator<ScriptVariable> scriptVariables = form2use.getScriptVariables(true);
    while (scriptVariables.hasNext()) {
        variables.add(new JSVariable(application, this, scriptVariables.next(), false));
    }
    return variables.toArray(new JSVariable[variables.size()]);
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) ArrayList(java.util.ArrayList) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)16 JSFunction (org.mozilla.javascript.annotations.JSFunction)6 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3 Form (com.servoy.j2db.persistence.Form)3 ArrayList (java.util.ArrayList)3 Column (com.servoy.j2db.persistence.Column)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 IColumn (com.servoy.j2db.persistence.IColumn)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 IPersist (com.servoy.j2db.persistence.IPersist)2 IScriptProvider (com.servoy.j2db.persistence.IScriptProvider)2 ISupportScriptProviders (com.servoy.j2db.persistence.ISupportScriptProviders)2 Relation (com.servoy.j2db.persistence.Relation)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)2 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)2 TableNode (com.servoy.j2db.persistence.TableNode)2 LazyCompilationScope (com.servoy.j2db.scripting.LazyCompilationScope)2 IBaseColumn (com.servoy.base.persistence.IBaseColumn)1 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)1