use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSSolutionModel method newForm.
protected JSForm newForm(String name, String dataSource, String styleName, boolean show_in_menu, int width, int height, boolean isResponsive) {
FlattenedSolution fs = application.getFlattenedSolution();
try {
Style style = null;
if (styleName != null) {
style = fs.getStyle(styleName);
}
Form form = createNewForm(style, IdentDocumentValidator.checkName(name), dataSource, show_in_menu, new Dimension(width, height));
if (!isResponsive) {
form.createNewPart(Part.BODY, height);
} else {
form.setResponsiveLayout(true);
}
if (fs.getSolution().getSolutionType() == SolutionMetaData.MOBILE) {
// mobile solution, make the form mobile
form.putCustomMobileProperty(IMobileProperties.MOBILE_FORM.propertyName, Boolean.TRUE);
// set internal style name
form.setStyleName("_servoy_mobile");
}
application.getFormManager().addForm(form, false);
return instantiateForm(form, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSBase method getOverridePersistIfNeeded.
public static AbstractBase getOverridePersistIfNeeded(AbstractBase persist, AbstractBase finalPersist, IJSParent parent) {
AbstractBase baseComponent = finalPersist;
if (persist != null && persist.getAncestor(IRepository.FORMS) != null) {
IJSParent<?> jsparent = parent;
while (jsparent != null) {
if (jsparent.getSupportChild() instanceof Form)
break;
jsparent = jsparent.getJSParent();
}
if (jsparent != null && jsparent.getSupportChild() instanceof Form && !jsparent.getSupportChild().getUUID().equals(persist.getAncestor(IRepository.FORMS).getUUID())) {
// inherited persist
try {
IPersist parentPersist = persist;
while (PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist) != null) {
parentPersist = PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist);
}
// first check if the override persist already exists, and return it in that case
List<IPersist> children = PersistHelper.getHierarchyChildren((AbstractBase) parent.getSupportChild());
IPersist form = parent.getSupportChild() instanceof Form ? parent.getSupportChild() : parent.getSupportChild().getAncestor(IRepository.FORMS);
if (form != null) {
for (IPersist p : children) {
if (parentPersist.getID() == ((ISupportExtendsID) p).getExtendsID() && form.equals(p.getAncestor(IRepository.FORMS))) {
return (AbstractBase) p;
}
}
} else {
// should not happen
Debug.error("Cannot find form of persist " + parent.getSupportChild());
}
baseComponent = (AbstractBase) persist.cloneObj(parent.getSupportChild(), false, null, false, false, false);
baseComponent.copyPropertiesMap(null, true);
((ISupportExtendsID) baseComponent).setExtendsID(parentPersist.getID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
return baseComponent;
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class JSBaseContainer method createLayoutContainer.
protected JSLayoutContainer createLayoutContainer(int x, int y, String spec, JSONObject config) {
checkModification();
try {
AbstractContainer container = getContainer();
Form form = (Form) container.getAncestor(IRepository.FORMS);
if (form.isResponsiveLayout()) {
String packageName = null;
String specName = null;
if (spec != null) {
String[] split = spec.split("-");
if (split.length == 1) {
specName = spec.trim();
} else if (split.length == 2) {
specName = split[1].trim();
packageName = split[0].trim();
} else {
Debug.warn("Illegal spec given: " + spec);
}
}
if (specName == null || packageName == null) {
if (container instanceof LayoutContainer) {
LayoutContainer parent = (LayoutContainer) (getContainer());
packageName = parent.getPackageName();
if (specName == null && parent.getAllowedChildren() != null && !parent.getAllowedChildren().isEmpty()) {
specName = parent.getAllowedChildren().get(0);
if (specName.contains("."))
specName = specName.split("\\.")[1];
}
}
}
if (specName == null) {
// the parent container could be a layout container or the form
// check if we have a sibling of the container we want to create
LayoutContainer sibling = container.getLayoutContainers().hasNext() ? container.getLayoutContainers().next() : null;
if (sibling != null) {
packageName = sibling.getPackageName();
specName = sibling.getSpecName();
}
}
LayoutContainer layoutContainer = getContainer().createNewLayoutContainer();
layoutContainer.setLocation(new Point(x, y));
layoutContainer.setPackageName(packageName);
layoutContainer.setSpecName(specName);
JSLayoutContainer jsLayoutContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer(this, layoutContainer);
JSONObject conf = config;
if (config == null) {
Map<String, PackageSpecification<WebLayoutSpecification>> layoutSpecifications = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications();
if (packageName != null && specName != null && layoutSpecifications != null && layoutSpecifications.get(packageName) != null) {
WebLayoutSpecification layoutSpec = layoutSpecifications.get(packageName).getSpecification(specName);
if (layoutSpec != null && (layoutSpec.getConfig() instanceof JSONObject || layoutSpec.getConfig() instanceof String)) {
conf = layoutSpec.getConfig() instanceof String ? new JSONObject((String) layoutSpec.getConfig()) : ((JSONObject) layoutSpec.getConfig());
}
}
}
return configLayoutContainer(jsLayoutContainer, layoutContainer, conf);
} else {
// check if form was just created with the solution model and suggest correct method to use
if (application.getFlattenedSolution().getSolutionCopy().getAllObjectsAsList().contains(form) && !application.getSolution().getAllObjectsAsList().contains(form)) {
throw new RuntimeException("Form " + form.getName() + " is not a responsive form, cannot add a layout container on it. Please use solutionModel.newForm('" + form.getName() + "',true) to create a responsive form.");
}
throw new RuntimeException("Form " + form.getName() + " is not responsive, cannot add a layout container on it. Please use a responsive form or create a responsive form with solutionModel.newForm(formName, true);");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class PersistHelper method getFlattenedPersist.
public static ISupportChilds getFlattenedPersist(FlattenedSolution flattenedSolution, Form parent, ISupportChilds persist) {
ISupportChilds flattenedPersist = persist;
if (flattenedPersist instanceof Form) {
flattenedPersist = flattenedSolution.getFlattenedForm(flattenedPersist);
}
if (flattenedPersist instanceof LayoutContainer && !(flattenedPersist instanceof FlattenedLayoutContainer)) {
FlattenedForm ff = flattenedSolution.getFlattenedForm(parent) instanceof FlattenedForm ? (FlattenedForm) flattenedSolution.getFlattenedForm(parent) : flattenedSolution.createFlattenedForm(parent);
flattenedPersist = new FlattenedLayoutContainer(ff, (LayoutContainer) flattenedPersist);
}
return flattenedPersist;
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class PersistHelper method getSuperPersist.
public static IPersist getSuperPersist(final ISupportExtendsID persist) {
if (persist instanceof IFlattenedPersistWrapper && ((IFlattenedPersistWrapper) persist).getWrappedPersist() instanceof Form) {
return ((IFlattenedPersistWrapper<Form>) persist).getWrappedPersist().getExtendsForm();
}
if (persist instanceof Form) {
return ((Form) persist).getExtendsForm();
}
final int extendsID = persist.getExtendsID();
if (extendsID > 0) {
try {
Form form = (Form) ((AbstractBase) persist).getAncestor(IRepository.FORMS);
if (form != null) {
form = form.getExtendsForm();
while (form != null) {
IPersist superPersist = form.getSuperPersist(extendsID);
// });
if (superPersist != null) {
return superPersist;
}
form = form.getExtendsForm();
}
}
} finally {
// System.err.println("getting super persist for " + persist.getID() + " extends: " + extendsID + " time " + (System.currentTimeMillis() - time));
}
}
return null;
}
Aggregations