use of com.servoy.base.solutionmodel.IBaseSMForm 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.base.solutionmodel.IBaseSMForm 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);
}
Aggregations