use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormLayoutGenerator method generateFormComponent.
public static String generateFormComponent(Form form, FlattenedSolution fs, IFormElementCache cache) {
StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);
Iterator<? extends IPersist> componentsIterator = null;
if (!form.isResponsiveLayout()) {
List<IPersist> components = fs.getFlattenedForm(form).getAllObjectsAsList();
List<IFormElement> formElements = new ArrayList<>();
for (IPersist persist : components) {
if (persist instanceof IFormElement) {
formElements.add((IFormElement) persist);
}
}
Collections.sort(formElements, new Comparator<IFormElement>() {
public int compare(IFormElement o1, IFormElement o2) {
int result = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR.compare(o1, o2);
if (result == 0) {
result = TabSeqComparator.compareTabSeq(getTabSeq(o1), o1, getTabSeq(o2), o2);
}
return result;
}
});
componentsIterator = formElements.iterator();
} else {
componentsIterator = fs.getFlattenedForm(form).getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
}
while (componentsIterator.hasNext()) {
IPersist component = componentsIterator.next();
// if (PartWrapper.isSecurityVisible(component, fs, form))
if (component instanceof LayoutContainer) {
FormLayoutStructureGenerator.generateLayoutContainer((LayoutContainer) component, form, fs, writer, null, cache);
} else if (component instanceof IFormElement) {
FormElement fe = cache.getFormElement((IFormElement) component, fs, null, false);
if (form != null && !form.isResponsiveLayout()) {
FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
}
FormLayoutGenerator.generateFormElement(writer, fe, form);
if (form != null && !form.isResponsiveLayout()) {
FormLayoutGenerator.generateEndDiv(writer);
}
}
}
return out.getBuffer().toString();
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormLayoutStructureGenerator method generateLayoutContainer.
public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, DesignProperties design, IFormElementCache cache) {
WebLayoutSpecification spec = null;
if (container.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(container.getSpecName());
}
}
boolean isCSSPositionContainer = CSSPositionUtils.isCSSPositionContainer(spec);
writer.print("<");
writer.print(container.getTagType());
Set<String> writtenAttributes = new HashSet<>();
if (design != null) {
writer.print(" svy-id='");
writer.print(container.getUUID().toString());
writer.print("'");
writer.print(" svy-location='");
writer.print(container.getLocation().x);
writer.print("'");
boolean highSet = false;
JSONObject ngClass = new JSONObject();
String layoutStyleClasses = "";
String solutionStyleClasses = "";
if (spec != null) {
writer.print(" svy-layoutname='");
writer.print(spec.getPackageName() + "." + spec.getName());
writer.print("'");
ngClass.put("svy-layoutcontainer", true);
if (// is this inherited?
!(container.getAncestor(IRepository.FORMS).getID() == form.getID())) {
ngClass.put("inheritedElement", true);
}
String designClass = spec.getDesignStyleClass() != null && spec.getDesignStyleClass().length() > 0 ? spec.getDesignStyleClass() : "customDivDesign";
if ("customDivDesign".equals(designClass) && hasSameDesignClassAsParent(container, spec)) {
designClass = isEvenLayoutContainer(container) ? "customDivDesignOdd" : "customDivDesignEven";
}
highSet = true;
if (design.mainContainer != container.getID()) {
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put(designClass, "<showWireframe<");
} else {
writer.print(" data-maincontainer='true'");
ngClass.put(designClass, "<false<");
}
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
List<String> containerStyleClasses = getStyleClassValues(spec, container.getCssClasses());
solutionStyleClasses = getSolutionSpecificClasses(spec, container);
if (!containerStyleClasses.isEmpty()) {
layoutStyleClasses = containerStyleClasses.stream().collect(Collectors.joining(" "));
writer.print(" class='" + layoutStyleClasses + "'");
}
if (container.getCssClasses() != null && container.getCssClasses().trim().length() > 0) {
writtenAttributes.add("class");
}
if (spec.getAllowedChildren().size() > 0 || spec.getExcludedChildren() != null) {
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("drop_highlight", "<canContainDraggedElement('" + spec.getPackageName() + "." + spec.getName() + "')<");
}
}
if (!highSet)
ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
if (ngClass.length() > 0) {
writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
}
if (writtenAttributes.contains("class")) {
writer.print(" svy-layout-class='" + layoutStyleClasses + "'");
writer.print(" svy-solution-layout-class='" + solutionStyleClasses + "'");
}
writer.print(" svy-title='" + getLayouContainerTitle(container) + "'");
}
if (container.getName() != null) {
writer.print(" svy-name='");
writer.print(container.getName());
writer.print("' ");
}
if (container.getElementId() != null) {
writer.print(" id='");
writer.print(container.getElementId());
writer.print("' ");
}
writer.print(" svy-autosave ");
if (isCSSPositionContainer) {
// we need to specify the height
writer.print(" style='height:");
writer.print(container.getSize().height);
writer.print("px;position: relative;' ");
}
Map<String, String> attributes = new HashMap<String, String>(container.getMergedAttributes());
if (spec != null) {
for (String propertyName : spec.getAllPropertiesNames()) {
PropertyDescription pd = spec.getProperty(propertyName);
if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
attributes.put(propertyName, pd.getDefaultValue().toString());
}
}
}
String classes = attributes.get("class");
if (classes == null)
classes = "svy-layoutcontainer";
else
classes += " svy-layoutcontainer";
attributes.put("class", classes);
for (Entry<String, String> entry : attributes.entrySet()) {
if (design != null && writtenAttributes.contains(entry.getKey()))
continue;
writer.print(" ");
try {
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
if (entry.getValue() != null && entry.getValue().length() > 0) {
writer.print("=\"");
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
writer.print("\"");
}
} catch (IOException e) {
Debug.error(e);
}
}
writer.print(">");
Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, cache);
} else if (component instanceof IFormElement) {
FormElement fe = cache.getFormElement((IFormElement) component, fs, null, design != null);
if (!isSecurityVisible(fs, fe.getPersistIfAvailable(), form)) {
continue;
}
if (isCSSPositionContainer) {
FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, false);
}
FormLayoutGenerator.generateFormElement(writer, fe, form);
if (isCSSPositionContainer) {
FormLayoutGenerator.generateEndDiv(writer);
}
}
}
writer.print("</");
writer.print(container.getTagType());
writer.print(">");
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FlattenedSolution method getAllObjectsAsList.
public List<IPersist> getAllObjectsAsList() {
if (mainSolution == null) {
if (loginFlattenedSolution != null) {
return loginFlattenedSolution.getAllObjectsAsList();
}
return Collections.emptyList();
}
if (allObjectscache == null) {
List<IPersist> retval = new ArrayList<IPersist>(allObjectsSize);
if (copySolution != null) {
fillList(retval, copySolution);
}
getAllModuleObjects(retval);
fillList(retval, mainSolution);
if (loginFlattenedSolution != null) {
List<IPersist> elements = loginFlattenedSolution.getAllObjectsAsList();
for (IPersist persist : elements) {
if (!retval.contains(persist))
retval.add(persist);
}
}
allObjectsSize = retval.size();
retval.removeAll(getIndex().getRemoved());
allObjectscache = retval;
}
return allObjectscache;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FlattenedSolution method getMaxID.
protected int getMaxID() {
final int[] maxId = new int[1];
IPersistVisitor visitor = new IPersistVisitor() {
public Object visit(IPersist o) {
if (maxId[0] < o.getID()) {
maxId[0] = o.getID();
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
};
mainSolution.acceptVisitor(visitor);
if (modules != null) {
for (Solution module : modules) {
module.acceptVisitor(visitor);
}
}
int max = maxId[0];
if (loginFlattenedSolution != null) {
int loginMax = loginFlattenedSolution.getMaxID();
if (loginMax > max) {
max = loginMax;
}
}
return max;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FlattenedSolution method getSolutionCopy.
public Solution getSolutionCopy(boolean create) {
if (mainSolution == null) {
if (loginFlattenedSolution != null) {
return loginFlattenedSolution.getSolutionCopy(create);
}
return null;
}
if (copySolution != null || !create)
return copySolution;
try {
SimplePersistFactory factory = getPersistFactory();
copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
copySolution.setChangeHandler(new ChangeHandler(factory) {
// overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
@Override
public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
return factory.createObject(parent, object_type_id, element_id, uuid);
}
});
copySolution.getChangeHandler().addIPersistListener(this);
getIndex().setSolutionModelSolution(copySolution);
} catch (Exception e) {
Debug.error(e);
}
return copySolution;
}
Aggregations