use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormLayoutGenerator method generateFormElement.
// private static boolean canContainComponents(WebComponentSpecification spec)
// {
// Map<String, PropertyDescription> properties = spec.getProperties();
// for (PropertyDescription propertyDescription : properties.values())
// {
// String simpleTypeName = propertyDescription.getType().getName().replaceFirst(spec.getName() + ".", "");
// if (simpleTypeName.equals(ComponentPropertyType.TYPE_NAME)) return true;
// Object configObject = propertyDescription.getConfig();
// if (configObject != null)
// {
// try
// {
// if (configObject instanceof JSONObject && ((JSONObject)configObject).has(DesignerFilter.DROPPABLE))
// {
// Object droppable = ((JSONObject)configObject).get(DesignerFilter.DROPPABLE);
// if (droppable instanceof Boolean && (Boolean)droppable)
// {
// if (simpleTypeName.equals("tab")) return true;
// }
// }
// }
// catch (JSONException e)
// {
// Debug.log(e);
// }
// }
// }
// return false;
// }
public static void generateFormElement(PrintWriter writer, FormElement fe, Form form) {
IPersist fePersist = fe.getPersistIfAvailable();
String name = fe.getName();
boolean selectable = fe.isFormComponentChild() ? name.indexOf('$' + FormElement.SVY_NAME_PREFIX) == -1 : true;
writer.print("<");
writer.print(fe.getTagname());
writer.print(" name='");
writer.print(name);
writer.print("'");
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
String elementName = name;
if (elementName.startsWith("svy_") && fePersist != null) {
elementName = "svy_" + fePersist.getUUID().toString();
}
writer.print(" data-svy-name='");
writer.print(form.getName() + "." + elementName);
writer.print("'");
}
String designId = getDesignId(fe);
if (designId != null) {
if (form.isResponsiveLayout()) {
writer.print(" svy-id='");
writer.print(designId);
writer.print("'");
if (fePersist instanceof ISupportBounds) {
writer.print(" svy-location='");
writer.print(((ISupportBounds) fePersist).getLocation().x);
writer.print("'");
}
if (!selectable) {
writer.print(" svy-non-selectable='noname'");
}
writer.print(" svy-formelement-type='");
writer.print(fe.getTypeName());
writer.print("'");
JSONObject ngClass = new JSONObject();
List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
if (typeAndPropertyNames[0].size() > 0) {
writer.print(" svy-types='");
writer.print("[" + String.join(",", typeAndPropertyNames[0]) + "]");
writer.print("'");
writer.print(" svy-types-properties='");
writer.print("[" + String.join(",", typeAndPropertyNames[1]) + "]");
writer.print("'");
ngClass.put("drop_highlight", "<canContainDraggedElement('" + fe.getTypeName() + "',['" + String.join("','", typeAndPropertyNames[0]) + "'])<");
}
List<String> forbiddenComponentNames = fe.getForbiddenComponentNames();
if (forbiddenComponentNames.size() > 0) {
writer.print(" svy-forbidden-components='");
writer.print("[" + String.join(",", forbiddenComponentNames) + "]");
writer.print("'");
}
String directEditPropertyName = getDirectEditProperty(fe);
if (directEditPropertyName != null) {
writer.print(" directEditPropertyName='");
writer.print(directEditPropertyName);
writer.print("'");
}
if (// is this inherited or override element?
!fe.getForm().equals(form) || fePersist instanceof ISupportExtendsID && PersistHelper.getSuperPersist((ISupportExtendsID) fePersist) != null) {
ngClass.put("inheritedElement", true);
}
if (fe.isFormComponentChild()) {
ngClass.put("formComponentChild", true);
}
ngClass.put("invisible_element", "<getDesignFormControllerScope().model('" + designId + "').svyVisible == false<".toString());
// added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
ngClass.put("highlight_child_element", "<design_highlight=='highlight_element'<".toString());
writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
}
writer.print(" svy-model=\"model('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-api=\"api('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-handlers=\"handlers('");
writer.print(designId);
writer.print("')\"");
writer.print(" svy-servoyApi=\"servoyApi('");
writer.print(designId);
writer.print("')\"");
if (fePersist instanceof IFormElement) {
writer.print(" form-index=" + ((IFormElement) fePersist).getFormIndex() + "");
}
} else {
writer.print(" svy-model='model.");
writer.print(name);
writer.print("'");
writer.print(" svy-api='api.");
writer.print(name);
writer.print("'");
writer.print(" svy-handlers='handlers.");
writer.print(name);
writer.print("'");
writer.print(" svy-servoyApi='handlers.");
writer.print(name);
writer.print(".svy_servoyApi'");
}
writer.print(">");
writer.print("</");
writer.print(fe.getTagname());
writer.print(">");
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormLayoutGenerator method generateRecordViewForm.
public static void generateRecordViewForm(PrintWriter writer, Form form, String realFormName, IServoyDataConverterContext context, boolean design) {
generateFormStartTag(writer, form, realFormName, false, design);
Iterator<Part> it = form.getParts();
if (design) {
while (it.hasNext()) {
Part part = it.next();
if (!Part.rendersOnlyInPrint(part.getPartType())) {
writer.print("<div ng-style=\"");
writer.print(PartWrapper.getName(part));
writer.print("Style\"");
String partClass = "svy-" + PartWrapper.getName(part);
if (part.getStyleClass() != null) {
partClass += " " + part.getStyleClass();
}
writer.print(" class=\"");
writer.print(partClass);
writer.print("\">");
generateEndDiv(writer);
}
}
}
Map<IPersist, FormElement> cachedElementsMap = new HashMap<IPersist, FormElement>();
if (context != null && context.getApplication() != null) {
IFormController controller = ((BasicFormManager) context.getApplication().getFormManager()).getCachedFormController(realFormName);
if (controller != null && controller.getFormUI() instanceof WebFormUI) {
List<FormElement> cachedFormElements = ((WebFormUI) controller.getFormUI()).getFormElements();
for (FormElement fe : cachedFormElements) {
if (fe.getPersistIfAvailable() != null) {
cachedElementsMap.put(fe.getPersistIfAvailable(), fe);
}
}
}
}
it = form.getParts();
while (it.hasNext()) {
Part part = it.next();
if (!Part.rendersOnlyInPrint(part.getPartType())) {
if (!design) {
writer.print("<div svy-ng-style=\"");
writer.print(PartWrapper.getName(part));
writer.print("Style\"");
String partClass = "svy-" + PartWrapper.getName(part);
if (part.getStyleClass() != null) {
partClass += " " + part.getStyleClass();
}
writer.print(" class=\"");
writer.print(partClass);
writer.print("\">");
}
for (IFormElement bc : PartWrapper.getBaseComponents(part, form, context, design, false)) {
FormElement fe = null;
if (cachedElementsMap.containsKey(bc)) {
fe = cachedElementsMap.get(bc);
}
if (fe == null) {
fe = FormElementHelper.INSTANCE.getFormElement(bc, context.getSolution(), null, design);
}
generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
generateFormElement(writer, fe, form);
generateEndDiv(writer);
}
if (!design)
generateEndDiv(writer);
}
}
generateFormEndTag(writer, design);
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormLayoutStructureGenerator method generateLayout.
public static void generateLayout(Form form, String realFormName, FlattenedSolution fs, PrintWriter writer, DesignProperties design) {
try {
FormLayoutGenerator.generateFormStartTag(writer, form, realFormName, false, design != null);
Iterator<IPersist> components = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, FormElementHelper.INSTANCE);
} else if (component instanceof IFormElement) {
FormLayoutGenerator.generateFormElement(writer, FormElementHelper.INSTANCE.getFormElement((IFormElement) component, fs, null, false), form);
}
}
FormLayoutGenerator.generateFormEndTag(writer, design != null);
} catch (Exception e) {
Debug.error(e);
}
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class PartWrapper method getBaseComponents.
public static Collection<BaseComponent> getBaseComponents(Part part, Form context, IServoyDataConverterContext converterContext, boolean isDesign, boolean flatten) {
if (!isDesign && part.getPartType() == Part.BODY) {
switch(context.getView()) {
case FormController.TABLE_VIEW:
case FormController.LOCKED_TABLE_VIEW:
case IForm.LIST_VIEW:
case FormController.LOCKED_LIST_VIEW:
return Arrays.asList(new BaseComponent[] { new BodyPortal(context) });
}
}
List<BaseComponent> baseComponents = new ArrayList<>();
int startPos = context.getPartStartYPos(part.getID());
int endPos = part.getHeight();
Comparator<? super IFormElement> comparator = null;
if (context.isResponsiveLayout()) {
comparator = PositionComparator.XY_PERSIST_COMPARATOR;
} else {
comparator = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR;
}
List<IFormElement> persists = null;
if (flatten) {
persists = context.getFlattenedObjects(comparator);
} else {
persists = new ArrayList(context.getAllObjectsAsList());
Iterator<IFormElement> it = persists.iterator();
while (it.hasNext()) {
IPersist persist = it.next();
if (!(persist instanceof BaseComponent)) {
it.remove();
}
}
Collections.sort(persists, comparator);
}
for (IFormElement persist : persists) {
Point location = CSSPositionUtils.getLocation(persist);
if (startPos <= location.y && endPos > location.y && persist instanceof BaseComponent) {
if (isSecurityVisible(persist, converterContext.getSolution(), context))
baseComponents.add((BaseComponent) persist);
}
}
return baseComponents;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FlattenedSolution method updatePersistInSolutionCopy.
public void updatePersistInSolutionCopy(final IPersist persist) {
if (mainSolution == null && loginFlattenedSolution != null) {
loginFlattenedSolution.updatePersistInSolutionCopy(persist);
return;
}
if (copySolution == null)
return;
IPersist copyPersist = (IPersist) copySolution.acceptVisitor(new IPersistVisitor() {
public Object visit(IPersist o) {
if (o.getUUID().equals(persist.getUUID())) {
return o;
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
});
if (copyPersist != null) {
((AbstractBase) copyPersist).copyPropertiesMap(((AbstractBase) persist).getPropertiesMap(), false);
ISupportChilds parent = copyPersist.getParent();
flush(persist);
if (parent instanceof Form) {
((Form) parent).setLastModified(System.currentTimeMillis());
} else if (copyPersist instanceof Form) {
((Form) copyPersist).setLastModified(System.currentTimeMillis());
}
} else if (persist.getParent() != null && !(persist.getParent() instanceof Solution)) {
ISupportChilds copyParent = (ISupportChilds) copySolution.acceptVisitor(new IPersistVisitor() {
public Object visit(IPersist o) {
if (o.getUUID().equals(persist.getParent().getUUID())) {
return o;
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
});
if (copyParent != null) {
if (persist instanceof ICloneable) {
((ICloneable) persist).clonePersist((AbstractBase) copyParent);
} else {
copyParent.addChild(persist);
}
flush(persist);
if (copyParent instanceof Form) {
((Form) copyParent).setLastModified(System.currentTimeMillis());
}
}
}
}
Aggregations