use of com.servoy.j2db.persistence.LayoutContainer 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.LayoutContainer 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.LayoutContainer in project servoy-client by Servoy.
the class JSSolutionModel method getParentContainer.
private IJSParent<?> getParentContainer(IPersist persist) {
IJSParent<?> parent = null;
List<AbstractContainer> parentHierarchy = new ArrayList<AbstractContainer>();
IPersist currentParent = persist.getParent();
while (currentParent != null) {
if (currentParent instanceof AbstractContainer) {
parentHierarchy.add(0, (AbstractContainer) currentParent);
}
if (currentParent instanceof Form)
break;
currentParent = currentParent.getParent();
}
for (AbstractContainer container : parentHierarchy) {
if (container instanceof LayoutContainer) {
parent = new JSLayoutContainer(parent, application, (LayoutContainer) persist);
}
if (container instanceof Form) {
parent = instantiateForm((Form) container, false);
}
}
return parent;
}
use of com.servoy.j2db.persistence.LayoutContainer in project servoy-client by Servoy.
the class JSLayoutContainer method getLayoutContainer.
private LayoutContainer getLayoutContainer() {
if (!isCopy) {
// as long as the layoutcontainer is not already a copy, we have to get the real one
// so that changes to other instances of JSLayoutContainer that points to the same container are seen in this one.
LayoutContainer lc = (LayoutContainer) parent.getSupportChild().getChild(layoutContainer.getUUID());
layoutContainer = lc != null ? lc : layoutContainer;
}
return layoutContainer;
}
use of com.servoy.j2db.persistence.LayoutContainer 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