use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method getRelation.
/**
* Gets an existing relation by the specified name and returns a JSRelation Object.
*
* @sample
* var relation = solutionModel.getRelation('name');
* application.output("The primary server name is " + relation.primaryServerName);
* application.output("The primary table name is " + relation.primaryTableName);
* application.output("The foreign table name is " + relation.foreignTableName);
* application.output("The relation items are " + relation.getRelationItems());
*
* @param name the specified name of the relation
*
* @return a JSRelation
*/
@JSFunction
public JSRelation getRelation(String name) {
if (name == null)
return null;
FlattenedSolution fs = application.getFlattenedSolution();
Relation relation = fs.getRelation(name);
if (relation != null) {
return new JSRelation(relation, application, false);
}
return null;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method cloneForm.
/**
* Makes an exact copy of the given form and gives it the new name.
*
* @sample
* // get an existing form
* var form = solutionModel.getForm("existingForm")
* // make a clone/copy from it
* var clone = solutionModel.cloneForm("clonedForm", form)
* // add a new label to the clone
* clone.newLabel("added label",50,50,80,20);
* // show it
* forms["clonedForm"].controller.show();
*
* @param newName the new name for the form clone
*
* @param jsForm the form to be cloned
*
* @return a JSForm
*/
@JSFunction
public JSForm cloneForm(String newName, IBaseSMForm jsForm) {
FlattenedSolution fs = application.getFlattenedSolution();
Form clone = fs.clonePersist(((JSForm) jsForm).getSupportChild(), IdentDocumentValidator.checkName(newName), fs.getSolutionCopy());
application.getFormManager().addForm(clone, false);
return instantiateForm(clone, true);
}
use of com.servoy.j2db.FlattenedSolution 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.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method cloneComponent.
/**
* Makes an exact copy of the given component (JSComponent/JSField/JSLabel), gives it a new name and moves it to a new parent form, specified as a parameter.
*
* @sample
* // get an existing field to clone.
* var field = solutionModel.getForm("formWithField").getField("fieldName");
* // get the target form for the copied/cloned field
* var form = solutionModel.getForm("targetForm");
* // make a clone/copy of the field and re parent it to the target form.
* var clone = solutionModel.cloneComponent("clonedField",field,form);
* // show it
* forms["targetForm"].controller.show();
*
* @param newName the new name of the cloned component
*
* @param component the component to clone
*
* @param newParentForm the new parent form
*
* @return the exact copy of the given component
*/
@JSFunction
public JSComponent<?> cloneComponent(String newName, IBaseSMComponent component, IBaseSMForm newParentForm) {
if (component == null || !(((JSBase) component).getBaseComponent(false).getParent() instanceof Form)) {
throw new RuntimeException("only components of a form can be cloned");
}
JSForm parent = (JSForm) newParentForm;
if (parent == null) {
parent = (JSForm) ((JSBase) component).getJSParent();
}
parent.checkModification();
Form form = parent.getSupportChild();
FlattenedSolution fs = application.getFlattenedSolution();
fs.clonePersist(((JSBase) component).getBaseComponent(false), IdentDocumentValidator.checkName(newName), form);
return parent.getComponent(newName);
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method removeForm.
/**
* Removes the specified form during the persistent connected client session.
*
* NOTE: Make sure you call history.remove first in your Servoy method (script).
*
* @sample
* //first remove it from the current history, to destroy any active form instance
* var success = history.removeForm('myForm')
* //removes the named form from this session, please make sure you called history.remove() first
* if(success)
* {
* solutionModel.removeForm('myForm')
* }
*
* @param name the specified name of the form to remove
*
* @return true is form has been removed, false if form could not be removed
*/
@JSFunction
public boolean removeForm(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Form form = fs.getForm(name);
if (form != null) {
if (application.getFormManager().removeForm(form)) {
fs.deletePersistCopy(form, false);
return true;
}
}
return false;
}
Aggregations