use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class TemplateGenerator method getFormHTMLAndCSS.
public static Pair<String, String> getFormHTMLAndCSS(Solution solution, Form form, IServiceProvider sp, String formInstanceName) throws RepositoryException, RemoteException {
if (form == null)
return null;
final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
boolean enableAnchoring = sp != null ? Utils.getAsBoolean(sp.getRuntimeProperties().get("enableAnchors")) : Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.webclient.enableAnchors", Boolean.TRUE.toString()));
String overriddenStyleName = null;
Pair<String, ArrayList<Pair<String, String>>> retval = formCache.getFormAndCssPair(form, formInstanceName, overriddenStyleName, repository);
Form f = form;
FlattenedSolution fsToClose = null;
try {
if (retval == null) {
if (f.getExtendsID() > 0) {
FlattenedSolution fs = sp == null ? null : sp.getFlattenedSolution();
if (fs == null) {
try {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
fsToClose = fs = new FlattenedSolution(solution.getSolutionMetaData(), new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return repository;
}
});
} catch (RepositoryException e) {
Debug.error("Couldn't create flattened form for the template generator", e);
}
}
f = fs.getFlattenedForm(f);
if (f == null) {
Debug.log("TemplateGenerator couldn't get a FlattenedForm for " + form + ", solution closed?");
f = form;
}
}
StringBuffer html = new StringBuffer();
TextualCSS css = new TextualCSS();
IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(sp, solution, f, formInstanceName);
int viewType = layoutProvider.getViewType();
layoutProvider.renderOpenFormHTML(html, css);
int startY = 0;
Iterator<Part> parts = f.getParts();
while (parts.hasNext()) {
Part part = parts.next();
int endY = part.getHeight();
if (Part.rendersOnlyInPrint(part.getPartType())) {
startY = part.getHeight();
// is never shown (=printing only)
continue;
}
Color bgColor = ComponentFactory.getPartBackground(sp, part, f);
if (part.getPartType() == Part.BODY && (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW)) {
layoutProvider.renderOpenTableViewHTML(html, css, part);
// tableview == bodypart
createCellBasedView(f, f, html, css, layoutProvider.needsHeaders(), startY, endY, bgColor, sp, viewType, enableAnchoring, startY, endY);
layoutProvider.renderCloseTableViewHTML(html);
} else {
layoutProvider.renderOpenPartHTML(html, css, part);
placePartElements(f, startY, endY, html, css, bgColor, enableAnchoring, sp);
layoutProvider.renderClosePartHTML(html, part);
}
startY = part.getHeight();
}
layoutProvider.renderCloseFormHTML(html);
retval = new Pair<String, ArrayList<Pair<String, String>>>(html.toString(), css.getAsSelectorValuePairs());
formCache.putFormAndCssPair(form, formInstanceName, overriddenStyleName, repository, retval);
}
Map<String, String> formIDToMarkupIDMap = null;
if (sp instanceof IApplication) {
Map runtimeProps = sp.getRuntimeProperties();
Map<WebForm, Map<String, String>> clientFormsIDToMarkupIDMap = (Map<WebForm, Map<String, String>>) runtimeProps.get("WebFormIDToMarkupIDCache");
if (clientFormsIDToMarkupIDMap == null) {
clientFormsIDToMarkupIDMap = new WeakHashMap<WebForm, Map<String, String>>();
runtimeProps.put("WebFormIDToMarkupIDCache", clientFormsIDToMarkupIDMap);
}
IForm wfc = ((IApplication) sp).getFormManager().getForm(formInstanceName);
if (wfc instanceof FormController) {
IFormUIInternal wf = ((FormController) wfc).getFormUI();
if (wf instanceof WebForm) {
if (!((WebForm) wf).isUIRecreated())
formIDToMarkupIDMap = clientFormsIDToMarkupIDMap.get(wf);
if (formIDToMarkupIDMap == null) {
ArrayList<Pair<String, String>> formCSS = retval.getRight();
ArrayList<String> selectors = new ArrayList<String>(formCSS.size());
for (Pair<String, String> formCSSEntry : formCSS) selectors.add(formCSSEntry.getLeft());
formIDToMarkupIDMap = getWebFormIDToMarkupIDMap((WebForm) wf, selectors);
clientFormsIDToMarkupIDMap.put((WebForm) wf, formIDToMarkupIDMap);
}
}
}
}
String webFormCSS = getWebFormCSS(retval.getRight(), formIDToMarkupIDMap);
// string the formcss/solutionname/ out of the url.
webFormCSS = StripHTMLTagsConverter.convertMediaReferences(webFormCSS, solution.getName(), new ResourceReference("media"), "", false).toString();
return new Pair<String, String>(retval.getLeft(), webFormCSS);
} finally {
if (fsToClose != null) {
fsToClose.close(null);
}
}
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class WebForm method getBounds.
public Rectangle getBounds(IComponent component) {
if (// $NON-NLS-1$
component instanceof Component && Utils.getAsBoolean(formController.getApplication().getRuntimeProperties().get("enableAnchors"))) {
IPersist persist = getPersist(((Component) component).getId());
if (persist instanceof ISupportAnchors && ((ISupportAnchors) persist).getAnchors() > 0 && ((ISupportAnchors) persist).getAnchors() != IAnchorConstants.DEFAULT) {
int anchors = ((ISupportAnchors) persist).getAnchors();
IDataRenderer renderer = ((Component) component).findParent(IDataRenderer.class);
int partHeight = 0;
if (renderer != null) {
partHeight = renderer.getSize().height;
}
int designWidth = formController.getForm().getWidth();
int designHeight = 0;
Part part = formController.getForm().getPartAt(((BaseComponent) persist).getLocation().y);
if (part != null) {
int top = formController.getForm().getPartStartYPos(part.getID());
designHeight = part.getHeight() - top;
}
if (partHeight > 0 && formWidth > 0 && designWidth > 0 && designHeight > 0) {
int navid = formController.getForm().getNavigatorID();
int navigatorWidth = 0;
if (navid == Form.NAVIGATOR_DEFAULT && formController.getForm().getView() != FormController.TABLE_VIEW && formController.getForm().getView() != FormController.LOCKED_TABLE_VIEW) {
navigatorWidth = WebDefaultRecordNavigator.DEFAULT_WIDTH;
} else if (navid != Form.NAVIGATOR_NONE) {
ISupportNavigator navigatorSupport = findParent(ISupportNavigator.class);
if (navigatorSupport != null) {
FormController currentNavFC = navigatorSupport.getNavigator();
if (currentNavFC != null) {
navigatorWidth = currentNavFC.getForm().getWidth();
}
}
}
Rectangle bounds = new Rectangle(component.getLocation(), component.getSize());
if ((anchors & IAnchorConstants.EAST) != 0 && (anchors & IAnchorConstants.WEST) == 0) {
bounds.x += formWidth - designWidth - navigatorWidth;
}
if ((anchors & IAnchorConstants.SOUTH) != 0 && (anchors & IAnchorConstants.NORTH) == 0) {
bounds.y += partHeight - designHeight;
}
if ((anchors & IAnchorConstants.EAST) != 0 && (anchors & IAnchorConstants.WEST) != 0 && (formWidth - designWidth - navigatorWidth > 0)) {
bounds.width += formWidth - designWidth - navigatorWidth;
}
if ((anchors & IAnchorConstants.SOUTH) != 0 && (anchors & IAnchorConstants.NORTH) != 0 && (partHeight - designHeight > 0)) {
bounds.height += partHeight - designHeight;
}
return bounds;
}
}
}
return null;
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class FormElement method adjustLocationRelativeToPart.
private void adjustLocationRelativeToPart(FlattenedSolution fs, Map<String, Object> map) {
if (map != null && form != null) {
Form flatForm = fs.getFlattenedForm(form);
Point location = getDesignLocation();
if (location != null) {
// if it is design client, it has no parts
boolean isInDesginer = getDesignId() != null;
if (isInDesginer) {
map.put(StaticContentSpecLoader.PROPERTY_LOCATION.getPropertyName(), location);
map.put("offsetY", 0);
} else {
Point newLocation = new Point(location);
Part part = flatForm.getPartAt(location.y);
if (part != null) {
int top = flatForm.getPartStartYPos(part.getID());
newLocation.y = newLocation.y - top;
map.put(StaticContentSpecLoader.PROPERTY_LOCATION.getPropertyName(), newLocation);
map.put("offsetY", top);
map.put("partHeight", part.getHeight());
}
}
}
}
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class AngularFormGenerator method writePosition.
/**
* @param writer
* @param o
*/
@SuppressWarnings("nls")
public static void writePosition(JSONWriter writer, IPersist o, Form form, WebFormComponent webComponent, boolean isDesigner) {
if (o instanceof BaseComponent && ((BaseComponent) o).getCssPosition() != null) {
CSSPosition position = ((BaseComponent) o).getCssPosition();
if (webComponent != null) {
Object runtimeValue = webComponent.getProperty(IContentSpecConstants.PROPERTY_CSS_POSITION);
if (runtimeValue instanceof CSSPosition) {
position = (CSSPosition) runtimeValue;
}
}
writer.key("position");
writer.object();
if (CSSPositionUtils.isSet(position.left)) {
writer.key("left").value(CSSPositionUtils.getCSSValue(position.left));
}
if (CSSPositionUtils.isSet(position.top)) {
String top = position.top;
if (!isDesigner) {
Point location = CSSPositionUtils.getLocation((BaseComponent) o);
Part prt = form.getPartAt(location.y);
if (prt != null) {
int topStart = form.getPartStartYPos(prt.getID());
if (topStart > 0) {
if (top.endsWith("px")) {
top = top.substring(0, top.length() - 2);
}
int topInteger = Utils.getAsInteger(top, -1);
if (topInteger != -1) {
top = String.valueOf(topInteger - topStart);
} else {
top = "calc(" + top + "-" + topStart + "px)";
}
}
}
}
writer.key("top").value(CSSPositionUtils.getCSSValue(top));
}
if (CSSPositionUtils.isSet(position.bottom)) {
writer.key("bottom").value(CSSPositionUtils.getCSSValue(position.bottom));
}
if (CSSPositionUtils.isSet(position.right)) {
writer.key("right").value(CSSPositionUtils.getCSSValue(position.right));
}
if (CSSPositionUtils.isSet(position.width)) {
if (CSSPositionUtils.isSet(position.left) && CSSPositionUtils.isSet(position.right)) {
writer.key("min-width").value(CSSPositionUtils.getCSSValue(position.width));
} else {
writer.key("width").value(CSSPositionUtils.getCSSValue(position.width));
}
}
if (CSSPositionUtils.isSet(position.height)) {
if (CSSPositionUtils.isSet(position.top) && CSSPositionUtils.isSet(position.bottom)) {
writer.key("min-height").value(CSSPositionUtils.getCSSValue(position.height));
} else {
writer.key("height").value(CSSPositionUtils.getCSSValue(position.height));
}
}
writer.endObject();
} else {
Point location = ((IFormElement) o).getLocation();
Dimension size = ((IFormElement) o).getSize();
if (webComponent != null) {
Object runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_LOCATION);
if (runtimeValue instanceof Point) {
location = (Point) runtimeValue;
}
runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_SIZE);
if (runtimeValue instanceof Dimension) {
size = (Dimension) runtimeValue;
}
}
if (location != null && size != null) {
int anchorFlags = ((BaseComponent) o).getAnchors();
boolean anchoredTop = (anchorFlags & IAnchorConstants.NORTH) != 0;
boolean anchoredRight = (anchorFlags & IAnchorConstants.EAST) != 0;
boolean anchoredBottom = (anchorFlags & IAnchorConstants.SOUTH) != 0;
boolean anchoredLeft = (anchorFlags & IAnchorConstants.WEST) != 0;
if (!anchoredLeft && !anchoredRight)
anchoredLeft = true;
if (!anchoredTop && !anchoredBottom)
anchoredTop = true;
writer.key("position");
writer.object();
if (anchoredTop) {
writer.key("top");
writer.value(location.y + "px");
}
if (anchoredBottom) {
writer.key("bottom");
int partHeight = form.getSize().height;
if (!isDesigner) {
// search for element's part using its design time location
Part prt = form.getPartAt(((IFormElement) o).getLocation().y);
if (prt != null) {
int prtEnd = form.getPartEndYPos(prt.getID());
if (prtEnd > form.getSize().height)
prtEnd = form.getSize().height;
partHeight = prtEnd - form.getPartStartYPos(prt.getID());
}
}
writer.value(partHeight - location.y - size.height + "px");
}
if (!anchoredTop || !anchoredBottom) {
writer.key("height");
writer.value(size.height + "px");
}
if (anchoredLeft) {
writer.key("left");
writer.value(location.x + "px");
}
if (anchoredRight) {
writer.key("right");
writer.value((form.getWidth() - location.x - size.width) + "px");
}
if (!anchoredLeft || !anchoredRight) {
writer.key("width");
writer.value(size.width + "px");
}
if (anchoredTop && anchoredBottom) {
writer.key("min-height");
writer.value(size.height + "px");
}
if (anchoredLeft && anchoredRight) {
writer.key("min-width");
writer.value(size.width + "px");
}
writer.endObject();
}
}
}
use of com.servoy.j2db.persistence.Part in project servoy-client by Servoy.
the class AngularFormGenerator method generateJS.
@SuppressWarnings("nls")
@Override
public String generateJS() throws IOException {
IWebFormController cachedFormController = client != null ? client.getFormManager().getCachedFormController(realFormName) : null;
FormTemplateObjectWrapper formTemplate = new FormTemplateObjectWrapper(getAContext(), true, false);
FormWrapper formWrapper = formTemplate.getFormWrapper(form);
// for this form it is really just some json.
StringWriter stringWriter = new StringWriter();
final JSONWriter writer = new JSONWriter(stringWriter);
writer.object();
writer.key(realFormName);
writer.object();
writer.key("responsive");
writer.value(form.isResponsiveLayout());
writer.key("size");
writer.object();
writer.key("width");
writer.value(form.getWidth());
writer.key("height");
writer.value(form.getSize().getHeight());
writer.endObject();
String styleClasses = form.getStyleClass();
if (styleClasses != null) {
writer.key("styleclass");
String[] classes = styleClasses.split(" ");
writer.array();
for (String cls : classes) {
writer.value(cls);
}
writer.endArray();
}
writer.key("children");
// write the default form value object.
writer.array();
writer.object();
writer.key("name");
writer.value("");
writer.key("model");
writer.object();
Map<String, Object> containerProperties = null;
if (cachedFormController != null && cachedFormController.getFormUI() instanceof Container) {
Container con = (Container) cachedFormController.getFormUI();
DataConversion dataConversion = new DataConversion();
TypedData<Map<String, Object>> typedProperties = con.getProperties();
con.writeProperties(FullValueToJSONConverter.INSTANCE, null, writer, typedProperties, dataConversion);
JSONUtils.writeClientConversions(writer, dataConversion);
containerProperties = typedProperties.content;
}
final Map<String, Object> finalContainerProperties = containerProperties;
if (formWrapper != null) {
Map<String, Object> properties = formWrapper.getProperties();
properties.forEach((key, value) -> {
if (finalContainerProperties == null || !finalContainerProperties.containsKey(key)) {
writer.key(key);
if (value instanceof Integer || value instanceof Long) {
writer.value(((Number) value).longValue());
} else if (value instanceof Float || value instanceof Double) {
writer.value(((Number) value).doubleValue());
} else if (value instanceof Boolean) {
writer.value(((Boolean) value).booleanValue());
} else if (value instanceof Dimension) {
writer.object();
writer.key("width");
writer.value(((Dimension) value).getWidth());
writer.key("height");
writer.value(((Dimension) value).getHeight());
writer.endObject();
} else {
writer.value(value);
}
}
});
}
writer.endObject();
writer.endObject();
if (form.isResponsiveLayout()) {
if (zoomedInContainer != null) {
zoomedInContainer.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, null, form, true, isDesigner), PositionComparator.XY_PERSIST_COMPARATOR);
} else {
form.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, null, form, true, isDesigner), PositionComparator.XY_PERSIST_COMPARATOR);
}
} else {
Iterator<Part> it = form.getParts();
while (it.hasNext()) {
Part part = it.next();
if (!Part.rendersOnlyInPrint(part.getPartType())) {
writer.object();
writer.key("part");
writer.value(true);
writer.key("classes");
writer.array();
writer.value("svy-" + PartWrapper.getName(part));
if (part.getStyleClass() != null) {
writer.value(part.getStyleClass());
}
writer.endArray();
writer.key("layout");
writer.object();
writer.key("position");
writer.value("absolute");
writer.key("left");
writer.value("0px");
writer.key("right");
writer.value("0px");
int top = form.getPartStartYPos(part.getID());
if (part.getPartType() <= Part.BODY) {
writer.key("top");
writer.value(top + "px");
}
if (part.getPartType() >= Part.BODY) {
writer.key("bottom");
writer.value(form.getSize().height - part.getHeight() + "px");
}
if (part.getPartType() != Part.BODY) {
writer.key("height");
writer.value((part.getHeight() - top) + "px");
}
if (part.getBackground() != null && !form.getTransparent()) {
writer.key("background-color");
writer.value(PersistHelper.createColorString(part.getBackground()));
}
if (part.getPartType() == Part.BODY) {
writer.key("overflow-x");
writer.value(AbstractFormLayoutProvider.getCSSScrolling(form.getScrollbars(), true));
writer.key("overflow-y");
writer.value(AbstractFormLayoutProvider.getCSSScrolling(form.getScrollbars(), false));
} else {
writer.key("overflow");
// $NON-NLS-1$
writer.value("hidden");
}
writer.endObject();
writer.key("children");
// write the default form value object.
writer.array();
form.acceptVisitor(new ChildrenJSONGenerator(writer, getAContext(), form, null, part, form, true, isDesigner), ChildrenJSONGenerator.FORM_INDEX_WITH_HIERARCHY_COMPARATOR);
writer.endArray();
writer.endObject();
}
}
}
writer.endArray();
writer.endObject();
writer.endObject();
return stringWriter.toString();
}
Aggregations