use of com.servoy.j2db.persistence.BaseComponent in project servoy-client by Servoy.
the class ChildrenJSONGenerator method writeFormElement.
public static void writeFormElement(JSONWriter writer, IPersist o, Form form, FormElement fe, WebFormUI formUI, ServoyDataConverterContext context, boolean designer) {
writer.key("name");
String name = designer ? fe.getDesignId() : fe.getName();
writer.value(name);
writer.key("type");
if (o instanceof TabPanel) {
// special support for TabPanel so that we have a specific tabpanel,tablesspanel,accordion and splitpane
String type = "servoydefault-tabpanel";
int orient = ((TabPanel) o).getTabOrientation();
if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
type = "servoydefault-splitpane";
else if (orient == TabPanel.ACCORDION_PANEL)
type = "servoydefault-accordion";
else if (orient == TabPanel.HIDE || (orient == TabPanel.DEFAULT_ORIENTATION && ((TabPanel) o).hasOneTab()))
type = "servoydefault-tablesspanel";
writer.value(ClientService.convertToJSName(type));
} else {
// hack for now to map it to the types that we know are there, so that we can test responsive without really already having to have bootstrap components.
writer.value(ClientService.convertToJSName(FormTemplateGenerator.getComponentTypeName((IFormElement) o)));
}
WebFormComponent webComponent = (formUI != null) ? formUI.getWebComponent(fe.getName()) : null;
AngularFormGenerator.writePosition(writer, o, form, webComponent, designer);
writer.key("model");
writer.object();
if (formUI != null) {
// there is a existing form, take the current properties from that.
if (webComponent != null) {
TypedData<Map<String, Object>> properties = webComponent.getProperties();
TypedData<Map<String, Object>> templateProperties = fe.propertiesForTemplateJSON();
// remove from the templates properties all the properties that are current "live" in the component
templateProperties.content.keySet().removeAll(properties.content.keySet());
DataConversion dataConversion = new DataConversion();
// write the template properties that are left
JSONUtils.writeData(FormElementToJSON.INSTANCE, writer, templateProperties.content, templateProperties.contentType, dataConversion, new FormElementContext(fe));
// write the actual values
webComponent.writeProperties(FullValueToJSONConverter.INSTANCE, null, writer, properties, dataConversion);
JSONUtils.writeClientConversions(writer, dataConversion);
} else {
System.err.println("null");
}
} else {
fe.propertiesAsTemplateJSON(writer, new FormElementContext(fe, context, null), false);
if (designer && Utils.isInheritedFormElement(o, form)) {
writer.key("svyInheritedElement");
writer.value(true);
}
}
if (designer) {
DataConversion dataConversion = new DataConversion();
fe.getWebComponentSpec().getProperties().values().forEach(pd -> {
if (pd.getType() instanceof IDesignerDefaultWriter)
((IDesignerDefaultWriter) pd.getType()).toDesignerDefaultJSONValue(writer, pd.getName(), dataConversion);
});
if (!dataConversion.getConversions().isEmpty()) {
JSONUtils.writeClientConversions(writer, dataConversion);
}
}
if (o instanceof BaseComponent) {
writer.key("servoyAttributes");
writer.object();
Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) fe.getPersistIfAvailable()).getMergedAttributes());
if (designer) {
attributes.put("svy-id", fe.getDesignId());
attributes.put("svy-formelement-type", fe.getTypeName());
attributes.put("svy-name", fe.getName());
attributes.put("svy-anchors", Integer.toString(((BaseComponent) o).getAnchors()));
List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
if (typeAndPropertyNames[0].size() > 0) {
attributes.put("svy-types", String.join(",", typeAndPropertyNames[0]));
attributes.put("svy-types-properties", String.join(",", typeAndPropertyNames[1]));
}
attributes.put("svy-priority", form.isResponsiveLayout() ? String.valueOf(((ISupportBounds) o).getLocation().x) : String.valueOf(((BaseComponent) o).getFormIndex()));
}
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
String elementName = name;
if (elementName.startsWith("svy_") && o.getUUID() != null) {
elementName = "svy_" + o.getUUID().toString();
}
attributes.put("data-cy", form.getName() + "." + elementName);
}
String directEditPropertyName = getDirectEditProperty(fe);
if (directEditPropertyName != null) {
attributes.put("directEditPropertyName", directEditPropertyName);
}
attributes.forEach((key, value) -> {
writer.key(StringEscapeUtils.escapeEcmaScript(key));
writer.value(value);
});
writer.endObject();
}
writer.endObject();
WebObjectSpecification spec = fe.getWebComponentSpec();
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
boolean isResponsive = false;
for (PropertyDescription pd : properties) {
Object propertyValue = fe.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
if (frm == null)
continue;
isResponsive = frm.isResponsiveLayout();
}
// responsive state can change, so send it with updates
writer.key("responsive");
writer.value(isResponsive);
}
}
Collection<String> handlers = fe.getHandlers();
if (handlers.size() > 0) {
writer.key("handlers");
writer.array();
for (String handler : handlers) {
writer.value(handler);
}
writer.endArray();
}
}
use of com.servoy.j2db.persistence.BaseComponent in project servoy-client by Servoy.
the class PersistBasedFormElementImpl method getFormElementPropertyValues.
public Map<String, Object> getFormElementPropertyValues(FlattenedSolution fs, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
Map<String, String> parsedAttributes = new HashMap<String, String>();
if (persist instanceof BaseComponent) {
Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) persist).getMergedAttributes());
if (attributes != null && attributes.size() > 0) {
attributes.forEach((key, value) -> {
if (value != null && key != null)
parsedAttributes.put(StringEscapeUtils.escapeEcmaScript(key), value);
});
}
}
if (persist instanceof IBasicWebComponent) {
if (FormTemplateGenerator.isWebcomponentBean(persist)) {
JSONObject jsonProperties = ((IBasicWebComponent) persist).getFlattenedJson();
if (jsonProperties == null)
jsonProperties = new ServoyJSONObject();
// convert from persist design-time value (which might be non-json) to the expected value
Map<String, Object> jsonMap = processPersistProperties(fs, specProperties, propertyPath);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstantsBase.PROPERTY_BEANXML);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstants.PROPERTY_JSON);
try {
// add beanXML (which is actually a JSON string here) defined properties to the map
formElement.convertFromJSONToFormElementValues(fs, specProperties, jsonMap, formElement.getWebComponentSpec().getHandlers(), jsonProperties, propertyPath);
} catch (Exception ex) {
Debug.error("Error while parsing bean design json", ex);
jsonMap.put("error", "Error while parsing bean design json(bean not supported in NGClient?): " + persist);
}
if (parsedAttributes.size() > 0) {
jsonMap.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return jsonMap;
} else {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
defaultProperties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), ((IBasicWebComponent) persist).getSize());
defaultProperties.put(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName(), ((IBasicWebComponent) persist).getName());
defaultProperties.put("error", "Bean not supported in NGClient: " + persist);
return defaultProperties;
}
} else if (persist instanceof AbstractBase) {
Map<String, Object> map = processPersistProperties(fs, specProperties, propertyPath);
if (persist instanceof Field && ((Field) persist).getDisplayType() == Field.MULTISELECT_LISTBOX) {
map.put("multiselectListbox", Boolean.TRUE);
} else if (persist instanceof TabPanel) {
convertFromTabPanelToNGProperties((IFormElement) persist, fs, map, specProperties, propertyPath);
} else if (persist instanceof Portal) {
convertFromPortalToNGProperties((Portal) persist, fs, map, specProperties, propertyPath);
}
if (parsedAttributes.size() > 0) {
map.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return map;
} else {
return Collections.emptyMap();
}
}
use of com.servoy.j2db.persistence.BaseComponent in project servoy-client by Servoy.
the class FormElementHelper method getRowHeight.
private int getRowHeight(Form form) {
int rowHeight = 0;
Part part = getBodyPart(form);
int startPos = form.getPartStartYPos(part.getID());
int endPos = part.getHeight();
Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (it.hasNext()) {
IPersist persist = it.next();
if (persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
continue;
if (persist instanceof BaseComponent) {
BaseComponent bc = (BaseComponent) persist;
Point location = bc.getLocation();
if (startPos <= location.y && endPos > location.y) {
if (rowHeight == 0) {
rowHeight = bc.getSize().height;
break;
}
}
}
}
return rowHeight == 0 ? 20 : rowHeight;
}
use of com.servoy.j2db.persistence.BaseComponent in project servoy-client by Servoy.
the class FormElementHelper method fillsWidth.
private boolean fillsWidth(Form form) {
if ((form.getScrollbars() & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) == ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) {
Part part = getBodyPart(form);
int startPos = form.getPartStartYPos(part.getID());
int endPos = part.getHeight();
Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (it.hasNext()) {
IPersist persist = it.next();
if (persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
continue;
if (persist instanceof BaseComponent) {
BaseComponent bc = (BaseComponent) persist;
if ((bc.getAnchors() & (IAnchorConstants.WEST + IAnchorConstants.EAST)) == (IAnchorConstants.WEST + IAnchorConstants.EAST)) {
return true;
}
}
}
}
return false;
}
use of com.servoy.j2db.persistence.BaseComponent in project servoy-client by Servoy.
the class ComponentFactory method getStyleForBasicComponentInternal.
private static Pair<IStyleSheet, IStyleRule> getStyleForBasicComponentInternal(IServiceProvider sp, AbstractBase bc, Form form, Set<Integer> visited) {
if (bc == null || sp == null)
return null;
// Protection agains cycle in form inheritance hierarchy.
if (!visited.add(new Integer(form.getID())))
return null;
Style repos_style = getStyleForForm(sp, form);
Pair<IStyleSheet, IStyleRule> pair = null;
if (repos_style != null) {
IStyleSheet ss = getCSSStyle(sp, repos_style);
String lookupName = getLookupName(bc);
if (lookupName != null) {
String formLookup = "";
ISupportChilds parent = bc.getParent();
if (parent instanceof Form) {
String styleClass = ((Form) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "form." + styleClass;
} else {
formLookup = "form";
}
} else if (parent instanceof Portal) {
String styleClass = ((Portal) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "portal." + styleClass;
} else {
formLookup = "portal";
}
parent = ((Portal) parent).getParent();
if (parent instanceof Form) {
styleClass = ((Form) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "form." + styleClass + ' ' + formLookup;
} else {
formLookup = "form " + formLookup;
}
}
}
IStyleRule s = null;
String styleClass = (bc instanceof BaseComponent) ? ((BaseComponent) bc).getStyleClass() : null;
if (bc instanceof Part) {
styleClass = ((Part) bc).getStyleClass();
}
if (lookupName.equals("check") || lookupName.equals("combobox") || "radio".equals(lookupName)) {
if (styleClass != null && styleClass.length() != 0) {
lookupName += '.' + styleClass;
}
lookupName = formLookup + ' ' + lookupName;
s = ss.getCSSRule(lookupName);
if (s.getAttributeCount() > 0)
return new Pair<IStyleSheet, IStyleRule>(ss, s);
else
lookupName = "field";
}
if (styleClass != null && styleClass.length() != 0) {
lookupName += '.' + styleClass;
}
lookupName = formLookup + ' ' + lookupName;
s = ss.getCSSRule(lookupName);
pair = new Pair<IStyleSheet, IStyleRule>(ss, s);
// see BoxPainter for getBorder/getInsets/getLength examples
}
}
if ((pair == null || pair.getRight() == null || (pair.getRight()).getAttributeCount() == 0)) {
if (sp.getFlattenedSolution() != null) {
List<Form> formHierarchy = sp.getFlattenedSolution().getFormHierarchy(form);
for (int i = 1; i < formHierarchy.size(); i++) {
pair = getStyleForBasicComponentInternal(sp, bc, formHierarchy.get(i), visited);
if (pair != null && pair.getRight() != null && (pair.getRight()).getAttributeCount() != 0) {
break;
}
}
}
}
return pair;
}
Aggregations