use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElementHelper method generateFormComponentCacheObject.
private static FormComponentCache generateFormComponentCacheObject(INGFormElement parentElement, PropertyDescription pd, Form frm, FlattenedSolution fs, final List<FormElement> list) {
IFormElementCache cache = new IFormElementCache() {
@Override
public FormElement getFormElement(IFormElement component, FlattenedSolution flattendSol, PropertyPath path, boolean design) {
for (FormElement formElement : list) {
if (component.getID() == formElement.getPersistIfAvailable().getID()) {
return formElement;
}
}
return FormElementHelper.INSTANCE.getFormElement(component, flattendSol, path, design);
}
};
String template = FormLayoutGenerator.generateFormComponent(frm, fs, cache);
return new FormComponentCache(list, template, frm.getUUID().toString());
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class DataRendererFactory method completeRenderers.
/**
* Fills all the panels provided in emptyDataRenderers with the components from the form
*
* @param form the form to work with
* @param emptyDataRenderers the orderedHashmap with the Part -> DataRenderer
* @param insets for any border
* @param with of all parts
* @return usesSliding
*/
public Map completeRenderers(IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
int partHeight = 0;
boolean formHasBgImage = false;
Pair<IStyleSheet, IStyleRule> formStyle = ComponentFactory.getCSSPairStyleForForm(app, form);
if (formStyle != null && formStyle.getRight() != null && formStyle.getRight().hasAttribute(CSS.Attribute.BACKGROUND_IMAGE.toString())) {
formHasBgImage = true;
}
Iterator e2 = form.getParts();
while (e2.hasNext()) {
Part part = (Part) e2.next();
Color bg = ComponentFactory.getPartBackground(app, part, form);
if (bg == null && printing)
bg = Color.white;
DataRenderer panel = (DataRenderer) emptyDataRenderers.get(part);
if (panel != null) {
panel.setDoubleBuffered(!printing);
int total = Math.abs(part.getHeight() - partHeight);
setBasicSettings(panel, bg, new Dimension(width, total), new Point(0, partHeight), printing);
}
partHeight = part.getHeight();
// revert css3 features
Pair<IStyleSheet, IStyleRule> pair = ComponentFactory.getStyleForBasicComponent(app, part, form);
if (panel != null) {
// panel.setBgColor(part.getBackground());
if (pair != null && pair.getRight() != null && pair.getLeft() != null) {
// panel.setCssRule(pair.getRight());
Border border = pair.getLeft().getBorder(pair.getRight());
if (border != null) {
panel.setBorder(border);
}
}
// boolean partHasBgColor = (part.getBackground() != null) ||
// (pair != null && pair.getRight() != null && pair.getRight().hasAttribute(CSS.Attribute.BACKGROUND_COLOR.toString()));
// if (!form.getTransparent() && (formHasBgImage || (partHasBgColor && bg.getAlpha() < 255)))
// {
// panel.setPaintBackgroundOnTopOfFormImage(true);
// }
}
}
// place all the elements
Iterator<IFormElement> e1 = form.getFormElementsSortedByFormIndex();
return placeElements(e1, app, form, listner, emptyDataRenderers, width, 0, 0, printing, false, undoManager, false, tabSequence);
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class DataRendererFactory method createPortalRenderer.
public IDataRenderer createPortalRenderer(IApplication app, Portal objToRender, Form dataProviderLookup, IScriptExecuter listner, boolean printing, ControllerUndoManager undoManager) throws Exception {
List<IPersist> allObjectsAsList = objToRender.getAllObjectsAsList();
List<IFormElement> formElements = new ArrayList<IFormElement>(allObjectsAsList.size());
for (IPersist persist : allObjectsAsList) {
if (persist instanceof IFormElement) {
formElements.add((IFormElement) persist);
}
}
List<IFormElement> children = new SortedList<IFormElement>(new Comparator<IFormElement>() {
public int compare(IFormElement o1, IFormElement o2) {
// reverse order, right order for tab sequence
int result = -PositionComparator.XY_PERSIST_COMPARATOR.compare(o1, o2);
if (result == 0) {
return (o1.getFormIndex() - o2.getFormIndex());
}
return result;
}
}, formElements);
Iterator<IFormElement> e1 = children.iterator();
Map emptyDataRenderers = new LinkedHashMap();
DataRenderer dr = null;
int height = objToRender.getRowHeight();
boolean calculateHeight = (height == 0);
// for safety
if (height == 0)
height = 100;
// int leftBorder = 0;
// int bottomBorder = 0;
// if (objToRender.getShowHorizontalLines())
// {
// bottomBorder = 1;
// }
// if (objToRender.getShowVerticalLines())
// {
// leftBorder = 4;
// }
boolean showSelection = objToRender.getShowVerticalLines();
dr = (DataRenderer) getEmptyDataRenderer(ComponentFactory.getWebID(dataProviderLookup, objToRender), "portal_" + objToRender.getName(), app, showSelection);
setBasicSettings(dr, objToRender.getBackground(), new Dimension(objToRender.getSize().width, height), new Point(0, 0), printing);
// first is dummy saying is portal
emptyDataRenderers.put(new Boolean(true), dr);
dr.setLocation(objToRender.getLocation());
Border b = ComponentFactoryHelper.createBorder(objToRender.getBorderType());
Insets ins = new Insets(0, 0, 0, 0);
if (b != null) {
ins = ComponentFactoryHelper.getBorderInsetsForNoComponent(b);
}
// if (b instanceof EmptyBorder)
// {
// ins = ((EmptyBorder)b).getBorderInsets();
// }
placeElements(e1, app, dataProviderLookup, listner, emptyDataRenderers, objToRender.getSize().width, -(objToRender.getLocation().x + ins.right), -ins.top, printing, true, undoManager, true, null);
int biggest_width = 10;
int biggest_height = calculateHeight ? 0 : height;
Component[] comps = dr.getComponents();
boolean hasRowBGColorCalc = objToRender.getRowBGColorCalculation() != null;
for (Component element : comps) {
int w = element.getLocation().x + element.getSize().width;
if (w > biggest_width)
biggest_width = w;
if (hasRowBGColorCalc && element instanceof JComponent)
((JComponent) element).setOpaque(false);
if (calculateHeight) {
int h = element.getLocation().y + element.getSize().height;
if (h > biggest_height)
biggest_height = h;
}
}
dr.setSize(new Dimension(biggest_width, biggest_height));
dr.setPreferredSize(new Dimension(biggest_width, biggest_height));
if (printing) {
// sliding inside a multiline portal renderer is nor supported, be we have to attach the springs for resizes
addSpringsBetweenComponents(app, dr);
}
return dr;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class DesignFormLayoutStructureGenerator method generateLayoutContainer.
public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, int nested) {
WebLayoutSpecification spec = null;
if (container.getPackageName() != null) {
PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
if (pkg != null) {
spec = pkg.getSpecification(container.getSpecName());
}
}
writer.print("<");
writer.print(container.getTagType());
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("' ");
}
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());
}
}
}
for (Entry<String, String> entry : attributes.entrySet()) {
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(" svy-id='");
writer.print(container.getID());
writer.print("'");
writer.print(">\n");
Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
while (components.hasNext()) {
int count = 0;
while (count++ < nested) {
writer.print('\t');
}
IPersist component = components.next();
if (component instanceof LayoutContainer) {
generateLayoutContainer((LayoutContainer) component, form, fs, writer, nested + 1);
} else if (component instanceof IFormElement) {
generateFormElement(writer, (IFormElement) component, form, fs);
}
}
int count = 1;
while (count++ < nested) {
writer.print('\t');
}
writer.print("</");
writer.print(container.getTagType());
writer.print(">\n");
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class DesignFormLayoutStructureGenerator method generateFormElement.
public static void generateFormElement(PrintWriter writer, IFormElement formElement, Form form, FlattenedSolution fs) {
String tagName = FormTemplateGenerator.getComponentTypeName(formElement);
String name = formElement.getName();
writer.print("<");
writer.print(tagName);
writer.print(" name='");
writer.print(name);
writer.print("'");
FormElement fe = new FormElement(formElement, fs, new PropertyPath(), false);
JSONObject json = new JSONObject(fe.getPropertiesString());
for (String key : json.keySet()) {
// for now skip these 2, the size is weird that it has that "Dimension" in it
if (key.equals("size") || key.equals("visible"))
continue;
writer.write(' ');
writer.write(key);
writer.write("='");
writer.write(json.opt(key).toString());
writer.write("'");
}
writer.print(" svy-id='");
writer.print(formElement.getID());
writer.print("'");
writer.print("/>\n");
}
Aggregations