use of com.servoy.j2db.persistence.ISupportBounds in project servoy-client by Servoy.
the class WebForm method getFormAnchorInfo.
@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
Iterator<IPersist> e1 = formController.getForm().getAllObjects();
while (e1.hasNext()) {
IPersist obj = e1.next();
if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
}
}
// In case we are in table view.
if (view instanceof WebCellBasedView) {
WebCellBasedView formPart = (WebCellBasedView) view;
formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
formAnchorInfo.isTableView = true;
formAnchorInfo.bodyContainerId = formPart.getMarkupId();
}
// Find the id of the form navigator, if any.
visitChildren(Component.class, new IVisitor() {
public Object component(Component component) {
if (component instanceof WebDefaultRecordNavigator) {
formAnchorInfo.navigatorWebId = component.getMarkupId();
return IVisitor.CONTINUE_TRAVERSAL;
} else if (component instanceof WebTabPanel) {
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
} else
return IVisitor.CONTINUE_TRAVERSAL;
}
});
visitChildren(WebDataRenderer.class, new IVisitor() {
public Object component(Component component) {
WebDataRenderer formPart = (WebDataRenderer) component;
final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
Component parent = formPart.getParent();
formAnchorInfo.bodyContainerId = parent.getMarkupId();
}
formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {
public Object component(Component comp) {
String id = comp.getId();
ISupportAnchors obj = elements.get(id);
if (obj != null) {
int anchors = obj.getAnchors();
if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
if (r != null) {
if (anchors == 0)
anchors = IAnchorConstants.DEFAULT;
int hAlign = -1;
int vAlign = -1;
if (obj instanceof ISupportTextSetup) {
ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
hAlign = alignedObj.getHorizontalAlignment();
vAlign = alignedObj.getVerticalAlignment();
}
String imageDisplayURL = null;
boolean isRandomParamRemoved = false;
if (comp instanceof IImageDisplay) {
Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
imageDisplayURL = (String) aImageDisplayURL[0];
isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
}
part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
}
}
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
return formAnchorInfo;
}
use of com.servoy.j2db.persistence.ISupportBounds 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();
}
}
Aggregations