use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSForm method getMethods.
/**
* Returns all existing form methods for this form.
*
* @sample
* var frm = solutionModel.getForm("myForm");
* var methods = frm.getMethods();
* for (var m in methods)
* application.output(methods[m].getName());
*
* @param returnInheritedElements boolean true to also return the elements from the parent form
* @return all form methods for the form
*/
@JSFunction
public JSMethod[] getMethods(boolean returnInheritedElements) {
List<JSMethod> methods = new ArrayList<JSMethod>();
Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
Iterator<ScriptMethod> scriptMethods = form2use.getScriptMethods(true);
while (scriptMethods.hasNext()) {
methods.add(new JSMethod(this, scriptMethods.next(), application, false));
}
return methods.toArray(new JSMethod[methods.size()]);
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSForm method setExtendsForm.
@JSSetter
public void setExtendsForm(Object superForm) {
checkModification();
Form f = null;
if (superForm instanceof JSForm) {
f = ((JSForm) superForm).getSupportChild();
} else if (superForm instanceof String) {
f = application.getFlattenedSolution().getForm((String) superForm);
}
if (f == null) {
if (superForm != null) {
// this kind of argument is not supported or wrong
throw new RuntimeException("extendsForm must receive either null, a JSForm object or a valid form name");
}
getForm().setExtendsID(AbstractBase.DEFAULT_INT);
} else {
// }
if (f.isResponsiveLayout() != getForm().isResponsiveLayout()) {
if (getForm().isResponsiveLayout()) {
if (// only if it is not an abstract form
f.getParts().hasNext()) {
throw new RuntimeException("Form '" + getForm().getName() + "' is a responsive layout form, it cannot extend form '" + f.getName() + "' which is an absolute layout form.");
}
} else {
throw new RuntimeException("Form '" + getForm().getName() + "' is an absolute layout form, it cannot extend form '" + f.getName() + "' which is a responsive layout form.");
}
}
getForm().setExtendsID(f.getID());
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSForm method getMethodId.
public static int getMethodId(IApplication application, AbstractBase base, ScriptMethod method) {
ISupportChilds parent = method.getParent();
Form f = getFormParent(base);
// quick check if it is solution or own form..
if (parent instanceof Solution || parent.getUUID().equals(f.getUUID())) {
return method.getID();
}
// it could be a extends form
while (f != null && f.getExtendsID() > 0) {
f = application.getFlattenedSolution().getForm(f.getExtendsID());
if (f != null && parent.getUUID().equals(f.getUUID())) {
return method.getID();
}
}
// or a foundset method
Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(f.getDataSource(), false);
while (foundsetMethods.hasNext()) {
if (foundsetMethods.next().getID() == method.getID()) {
return method.getID();
}
}
// $NON-NLS-1$ //$NON-NLS-2$
throw new RuntimeException("Method " + method.getName() + " must be a solution method, foundset method or a forms own method");
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSBaseContainer method newWebComponent.
/**
* Creates a new JSWebComponent (spec based component) object on the RESPONSIVE form.
*
* @sample
* var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
* var container = myForm.getLayoutContainer("row1")
* var bean = container.newWebComponent('bean','mypackage-testcomponent',1);
*
* @param name the specified name of the JSWebComponent object
* @param type the webcomponent name as it appears in the spec
* @param position the position of JSWebComponent object in its parent container
*
* @return a JSWebComponent object
*/
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSWebComponent newWebComponent(String name, String type, int position) {
checkModification();
try {
AbstractContainer container = getContainer();
Form form = (Form) container.getAncestor(IRepository.FORMS);
if (form.isResponsiveLayout()) {
if (name == null) {
String componentName = type;
int index = componentName.indexOf("-");
if (index != -1) {
componentName = componentName.substring(index + 1);
}
// $NON-NLS-1$//$NON-NLS-2$
componentName = componentName.replaceAll("-", "_");
// $NON-NLS-1$
name = componentName + "_" + id.incrementAndGet();
IJSParent<?> parent = this;
while (!(parent instanceof JSForm)) {
parent = parent.getJSParent();
}
if (parent instanceof JSForm) {
while (findComponent((JSForm) parent, name) != null) {
name = componentName + "_" + id.incrementAndGet();
}
}
}
WebComponent webComponent = container.createNewWebComponent(IdentDocumentValidator.checkName(name), type);
webComponent.setLocation(new Point(position, position));
return createWebComponent(this, webComponent, application, true);
} else {
throw new RuntimeException("Form " + form.getName() + " is not responsive. Cannot create component without specifying the location and size.");
}
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSBaseContainer method getCorrectIJSParent.
/**
* When creating a JSWebComponent from a who-knows-how-deeply-nested (in case of responsive forms) webComponent in a form and we only know the form,
* then we need to get step by step the solution model objects in order to use the correct direct parent for the child SM object creation.
*
* @param startingContainer
* @param possiblyNestedChild nested child component
* @return the direct parent (IJSParent) of the given webComponent.
*/
private IJSParent<?> getCorrectIJSParent(JSBaseContainer<?> startingContainer, IPersist possiblyNestedChild) {
ArrayList<ISupportChilds> parentHierarchy = new ArrayList<>();
ISupportChilds parent = possiblyNestedChild.getParent();
while (parent != (startingContainer.getContainer() instanceof IFlattenedPersistWrapper<?> ? ((IFlattenedPersistWrapper<?>) startingContainer.getContainer()).getWrappedPersist() : startingContainer.getContainer()) && !(parent instanceof Form)) {
parentHierarchy.add(parent);
parent = parent.getParent();
}
for (int i = parentHierarchy.size(); --i >= 0; ) {
ISupportChilds container = parentHierarchy.get(i);
if (container instanceof LayoutContainer) {
startingContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer((IJSParent<?>) startingContainer, (LayoutContainer) container);
} else {
// $NON-NLS-1$
throw new RuntimeException("unexpected parent: " + container);
}
}
return startingContainer;
}
Aggregations