Search in sources :

Example 6 with ScriptVariable

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

the class JSForm method newVariable.

/**
 * Creates a new form JSVariable - based on the name of the variable object , the  type  and it's default value , uses the SolutionModel JSVariable constants.
 *
 * This method does not require the form to be destroyed and recreated. Use this method if you want to change the form's model without destroying the runtime form</b>
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
 * var variable = form.newVariable('myVar', JSVariable.TEXT , "'This is a default value (with triple quotes)!'");
 * //or variable = form.newVariable('myVar', JSVariable.TEXT)
 * //variable.defaultValue = "'This is a default value (with triple quotes)!'" // setting the default value after the variable is created requires form recreation
 * //variable.defaultValue = "{a:'First letter',b:'Second letter'}"
 * var field = form.newField(variable, JSField.TEXT_FIELD, 100, 100, 200, 200);
 * forms['newForm1'].controller.show();
 *
 * @param name the specified name of the variable
 *
 * @param type the specified type of the variable (see Solution Model -> JSVariable node constants)
 *
 * @param defaultValue the default value as a javascript expression string
 *
 * @return a JSVariable object
 */
@JSFunction
public JSVariable newVariable(String name, int type, String defaultValue) {
    checkModification();
    try {
        ScriptVariable variable = getForm().createNewScriptVariable(new ScriptNameValidator(application.getFlattenedSolution()), name, type);
        variable.setDefaultValue(defaultValue);
        addVariableToScopes(variable);
        return new JSVariable(application, this, variable, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 7 with ScriptVariable

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

the class JSSolutionModel method newGlobalVariable.

/**
 * Creates a new global variable with the specified name and number type.
 *
 * NOTE: The global variable number type is based on the value assigned from the SolutionModel-JSVariable node; for example: JSVariable.INTEGER.
 *
 * @sample
 * var myGlobalVariable = solutionModel.newGlobalVariable('globals', 'newGlobalVariable', JSVariable.INTEGER);
 * myGlobalVariable.defaultValue = 12;
 * //myGlobalVariable.defaultValue = "{a:'First letter',b:'Second letter'}" // an js object, type must be media.
 * //myGlobalVariable.defaultValue = '"some text"'; // Use two pairs of quotes if you want to assign a String as default value.
 * @param scopeName the scope in which the variable is created
 * @param name the specified name for the global variable
 *
 * @param type the specified number type for the global variable
 *
 * @return a JSVariable object
 */
@JSFunction
public JSVariable newGlobalVariable(String scopeName, String name, int type) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        String scope = scopeName == null ? ScriptVariable.GLOBAL_SCOPE : scopeName;
        ScriptVariable variable = fs.getSolutionCopy().createNewScriptVariable(new ScriptNameValidator(application.getFlattenedSolution()), scope, name, type);
        application.getScriptEngine().getScopesScope().getGlobalScope(scope).put(variable);
        return new JSVariable(application, variable, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 8 with ScriptVariable

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

the class JSVariable method checkModification.

void checkModification() {
    if (form != null) {
        form.checkModification();
        // make copy if needed
        if (!isCopy) {
            // then get the replace the item with the item of the copied relation.
            ScriptVariable tempVariable = (ScriptVariable) form.getSupportChild().getChild(variable.getUUID());
            if (tempVariable == null) {
                throw new RuntimeException("Cannot find variable '" + getName() + "' to modify. Modifying inherited variables is not allowed.");
            }
            variable = tempVariable;
            isCopy = true;
        }
    } else if (!isCopy) {
        // then get the replace the item with the item of the copied relation.
        variable = application.getFlattenedSolution().createPersistCopy(variable);
        isCopy = true;
    }
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable)

Example 9 with ScriptVariable

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

the class FormScope method createVars.

public void createVars() {
    // put all vars in scope if getForm is flattenform, it will return overridden scriptvars in correct order, sub wins
    Iterator<ScriptVariable> it = _fp.getForm().getScriptVariables(false);
    while (it.hasNext()) {
        ScriptVariable var = it.next();
        put(var);
    }
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable)

Example 10 with ScriptVariable

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

the class JSSolutionModel method getGlobalVariable.

/**
 * Gets an existing global variable by the specified name.
 *
 * @sample
 * var globalVariable = solutionModel.getGlobalVariable('globals', 'globalVariableName');
 * application.output(globalVariable.name + " has the default value of " + globalVariable.defaultValue);
 *
 * @param scopeName the scope in which the variable is searched
 * @param name the specified name of the global variable
 *
 * @return a JSVariable
 */
@JSFunction
public JSVariable getGlobalVariable(String scopeName, String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ScriptVariable variable = fs.getScriptVariable(scopeName, name);
    if (variable != null) {
        return new JSVariable(application, variable, false);
    }
    return null;
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) FlattenedSolution(com.servoy.j2db.FlattenedSolution) 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