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);
}
}
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);
}
}
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;
}
}
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);
}
}
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;
}
Aggregations