use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class TemplateGenerator method createFieldHTML.
private static void createFieldHTML(Field field, Form form, StringBuffer html, TextualCSS css, int startY, int endY, boolean enableAnchoring, IServiceProvider sp) {
boolean addWrapperDiv = enableAnchoring && WebAnchoringHelper.needsWrapperDivForAnchoring(field);
TextualStyle styleObj = css.addStyle('#' + ComponentFactory.getWebID(form, field));
boolean[] userCssClassAdded = new boolean[] { false };
Properties minSizeStyle = styleObj;
if (addWrapperDiv) {
// Anchoring fields (<input>s, <textarea>s) with { left: 0px; right: 0px; } pair
// or { top: 0px; bottom: 0px; } does not work. Thus we add a dummy wrapper <div>
// which accepts this kind of anchoring, and we place the field inside the <div>
// with { width: 100%; height: 100%; }, which works fine.
String wrapperId = ComponentFactory.getWebID(form, field) + WRAPPER_SUFFIX;
TextualStyle wrapperStyle = css.addStyle('#' + wrapperId);
wrapperStyle.setProperty("overflow", "visible");
minSizeStyle = wrapperStyle;
html.append("<div ");
html.append(getWicketIDParameter(form, field, "", WRAPPER_SUFFIX));
html.append(getJavaScriptIDParameter(form, field, "", WRAPPER_SUFFIX));
if (field.getDisplayType() == Field.COMBOBOX) {
html.append(getCssClassForElement(field, userCssClassAdded, COMBOBOX_CLASS));
}
html.append(getCssClassForElement(field, userCssClassAdded, ""));
html.append(">");
}
Insets padding = (Insets) DEFAULT_FIELD_PADDING.clone();
Insets border = (Insets) DEFAULT_FIELD_BORDER_SIZE.clone();
if (field.getDisplayType() == Field.COMBOBOX || field.getDisplayType() == Field.LIST_BOX || field.getDisplayType() == Field.MULTISELECT_LISTBOX) {
padding = DEFAULT_LABEL_PADDING;
}
BorderAndPadding ins = applyBaseComponentProperties(field, form, styleObj, padding, border, sp);
Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(sp, form);
IStyleSheet ss = pairStyle != null ? pairStyle.getLeft() : null;
// By default no css class applied.
String cssClass = "";
switch(field.getDisplayType()) {
case Field.PASSWORD:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
html.append("<input ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append("type='password' ");
if (field.getSelectOnEnter()) {
// $NON-NLS-1$
html.append("onfocus='Servoy.Utils.doSelect(this)'");
}
html.append("/>");
}
break;
case Field.RTF_AREA:
{
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(">RTF field not supported in webclient</div>");
}
break;
case Field.HTML_AREA:
if (!field.getEditable()) {
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(">non editable HTML field</div>");
boolean hasFontFamily = styleObj.containsKey("font-family");
boolean hasFontSize = styleObj.containsKey("font-size");
if (hasFontFamily || hasFontSize) {
for (String dfe : DEFAULT_FONT_ELEMENTS) {
TextualStyle htmlAreaFont = css.addStyle('#' + ComponentFactory.getWebID(form, field) + " " + dfe);
if (hasFontFamily)
htmlAreaFont.setProperty("font-family", styleObj.getProperty("font-family"));
if (hasFontSize)
htmlAreaFont.setProperty("font-size", styleObj.getProperty("font-size"));
}
}
break;
} else {
String editorId = "editor_" + ComponentFactory.getWebID(form, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
html.append("><textarea id='");
html.append(editorId);
html.append("' name='");
html.append(editorId);
html.append("' ");
html.append(getWicketIDParameter(form, field, "editor_", ""));
html.append(" rows=\"20\" cols=\"75\"></textarea></div>");
styleObj.setProperty("padding", "0px");
styleObj.setProperty("overflow", "hidden");
}
break;
case Field.TEXT_AREA:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
applyScrolling(styleObj, field);
html.append("<textarea ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append("></textarea>");
}
break;
case Field.CHECKS:
case Field.RADIOS:
boolean isRadio = (field.getDisplayType() == Field.RADIOS);
String selector = (isRadio ? "radio" : "check");
cssClass = (isRadio ? "radio" : "check");
IValueList val = null;
ValueList valuelist = null;
if (field.getValuelistID() > 0 && sp != null) {
valuelist = sp.getFlattenedSolution().getValueList(field.getValuelistID());
}
boolean addSingle = ComponentFactory.isSingleValue(valuelist);
// If we have multiple checkboxes, then the default is "field".
if (field.getValuelistID() > 0 && !addSingle && !isRadio)
cssClass = "radioCheckField";
// If we have a style for the form, apply "check" class if present, default to "field" if "check" class is not present.
if (ss != null) {
cssClass = "radioCheckField";
String lookUpValue = selector;
IStyleRule s = ss.getCSSRule(lookUpValue);
if (s.getAttributeCount() == 0) {
if ((field.getStyleClass() != null) && (field.getStyleClass().trim().length() > 0)) {
lookUpValue += '.' + field.getStyleClass().trim();
s = ss.getCSSRule(lookUpValue);
if (s.getAttributeCount() > 0)
cssClass = selector;
}
} else {
cssClass = selector;
}
}
if ((field.getValuelistID() > 0 || isRadio) && !addSingle) {
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, cssClass));
html.append(">Multi checkboxes</div>");
} else {
html.append("<div ");
html.append(getCssClassForElement(field, userCssClassAdded, cssClass));
html.append(getWicketIDParameter(form, field));
html.append(" tabIndex=\"-1\" ");
//
html.append(">");
html.append("<table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'><tr><td id='check_td' style='vertical-align: middle;'><input onmousedown='radioCheckInputMouseDown=true' onmouseup='radioCheckInputMousedDown=false' onmouseout='radioCheckInputMouseDown=false' class='radioCheckInput' style='border-width: 0px; padding: " + (isRadio ? "0px" : "3px") + //
"; margin: 0px; vertical-align: middle;' ");
html.append(getWicketIDParameter(form, field, "check_", ""));
html.append(getDataProviderIDParameter(field));
if (isRadio) {
html.append("type='radio' ");
} else {
html.append("type='checkbox' ");
}
html.append("/>");
html.append("<label style='border-width: 0px; padding-top: " + (isRadio ? "0px" : "2px") + "; padding-left: 3px; margin: 0px; vertical-align: middle;");
html.append("' ");
html.append(getWicketIDParameter(form, field, "text_", ""));
html.append(">");
html.append("</label>");
html.append("</td></tr></table></div>");
}
break;
case Field.COMBOBOX:
{
ins = null;
// if (ins == null)
// {
// ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE,DEFAULT_FIELD_PADDING);
// }
html.append("<select ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(">Combobox</select>");
}
break;
case Field.MULTISELECT_LISTBOX:
case Field.LIST_BOX:
{
ins = null;
html.append("<select ");
if (field.getDisplayType() == Field.MULTISELECT_LISTBOX) {
html.append("multiple=\"multiple\"");
}
html.append(getWicketIDParameter(form, field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "listbox"));
html.append(">Listbox</select>");
}
break;
case Field.CALENDAR:
case Field.SPINNER:
createCompositeFieldHTML(html, form, field, styleObj, userCssClassAdded);
break;
case Field.IMAGE_MEDIA:
{
applyScrolling(styleObj, field);
// in tableview position is not set
styleObj.setProperty("position", "relative");
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append('>');
TextualStyle inline2 = new TextualStyle();
// inline2.setProperty("top", "1px");
// inline2.setProperty("left", "1px");
// inline2.setProperty("position", "absolute");
// inline2.setProperty("cursor", "pointer");
// inline2.setProperty("background-color", "gray");
inline2.setProperty("z-index", "1");
html.append("<img ");
html.append(inline2.toString());
html.append(" border=0 servoy:id='save_icon' src='#' class='image-media-save' alt='Save' />");
html.append("<img ");
// inline2.setProperty("left", "17px");
html.append(inline2.toString());
html.append(" border=0 servoy:id='upload_icon' src='#' class='image-media-upload' alt='Upload' />");
html.append("<img ");
// inline2.setProperty("left", "33px");
html.append(inline2.toString());
html.append(" border=0 servoy:id='remove_icon' src='#' class='image-media-remove' alt='Remove' />");
// html.append("<a ");
// html.append(inline2.toString());
// html.append(" servoy:id='upload' href='#' border=0><img servoy:id='upload_icon' src='#' alt='' /></a>");
// html.append("<a ");
// inline2.setProperty("left","16px");
// html.append(inline2.toString());
// html.append(" servoy:id='save' href='#' border=0><img servoy:id='save_icon' src='#' alt='' /></a>");
TextualStyle inline = new TextualStyle();
inline.setProperty("top", "0px");
inline.setProperty("left", "0px");
inline.setProperty("position", "absolute");
if (field.getOnActionMethodID() < 1) {
inline.setProperty("cursor", "default");
}
html.append("<input ");
html.append(inline.toString());
html.append(getWicketIDParameter(form, field));
html.append(getJavaScriptIDParameter(form, field));
html.append("value='");
if (field.getName() != null)
html.append(field.getName());
html.append("' ");
html.append("type='image' ");
html.append(" src='#' alt='' ");
html.append(" onclick='return false;' ");
html.append("/>");
// html.append("<img ");
// html.append(inline.toString());
// html.append(" src='#' alt='' ");
// html.append(getWicketIDParameter(field));
// html.append(" />");
html.append("</div>");
}
break;
default:
case Field.TYPE_AHEAD:
case Field.TEXT_FIELD:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
html.append("<input ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, field.getValuelistID() > 0 ? "field typeahead" : "field"));
html.append("type='text' ");
if (field.getSelectOnEnter()) {
// $NON-NLS-1$
html.append("onfocus='Servoy.Utils.doSelect(this)'");
}
html.append("/>");
}
break;
}
if (field.getHorizontalAlignment() != -1) {
if (// all who's actual implementation is based on WebDataCompositeTextField
isCompositeTextField(field.getDisplayType())) {
TextualStyle childTextCSS = css.addStyle('#' + ComponentFactory.getWebID(form, field) + WebDataCompositeTextField.AUGMENTED_FIELD_ID);
applyTextProperties(field, childTextCSS);
} else {
applyTextProperties(field, styleObj);
}
}
Insets borderAndPadding = ins == null ? new Insets(0, 0, 0, 0) : ins.getSum();
WebAnchoringHelper.addMinSize(field.getAnchors(), sp, minSizeStyle, new Dimension(field.getSize().width - borderAndPadding.left - borderAndPadding.right, field.getSize().height - borderAndPadding.top - borderAndPadding.bottom), field);
if (addWrapperDiv) {
html.append("</div>");
styleObj.setProperty("width", "100%");
styleObj.setProperty("height", "100%");
styleObj.setProperty("position", "absolute");
} else {
applyLocationAndSize(field, styleObj, ins, startY, endY, form.getSize().width, enableAnchoring, isListViewBodyElement(form, field.getLocation()) ? new Point(-3, 0) : null);
}
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method initializeComponent.
@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
if (dal != null && dal.isDestroyed()) {
Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
return;
}
if (// Don't know any other place for this
view instanceof Portal && c instanceof IDisplayData) {
String id = ((IDisplayData) c).getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
}
}
if (!isListViewMode() && c instanceof WebDataCheckBox) {
// $NON-NLS-1$
((WebDataCheckBox) c).setText("");
}
if (element != null) {
// apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
// for listview this is the location to use.
Point loc = ((IComponent) c).getLocation();
int height = ((IComponent) c).getSize().height;
PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
if (!isListViewMode()) {
((IComponent) c).setLocation(loc);
// it shouldn't be possible to change the height
if (c instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) c).getScriptObject();
if (so instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) so;
if (ic.getHeight() != height) {
ic.setSize(ic.getWidth(), height);
}
}
}
}
} else {
// $NON-NLS-1$
Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
}
if (c instanceof IDisplayData) {
IDisplayData cdd = (IDisplayData) c;
if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
cdd.setValidationEnabled(validationEnabled);
}
} else if (c instanceof IDisplayRelatedData) {
((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
} else if (c instanceof IServoyAwareBean) {
((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
}
addClassToCellComponent(c);
if (// the check could be extended against IDelegate<?>
c instanceof WebDataCompositeTextField) {
Object delegate = ((WebDataCompositeTextField) c).getDelegate();
if (delegate instanceof Component) {
// make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
addClassToCellComponent((Component) delegate);
}
}
if (c instanceof ISupportValueList) {
ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
IValueList list;
if (idVl != null && (list = idVl.getValueList()) != null) {
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((ISupportValueList) c).setValueList(list);
}
}
}
applyClientProperties(c, element);
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class ValuelistPropTest method fillTestSolution.
@Override
protected void fillTestSolution() throws ServoyException {
try {
ValueList vl = solution.createNewValueList(validator, "myVl1");
vl.setCustomValues("1\n2\n3");
vl = solution.createNewValueList(validator, "myVl2");
vl.setCustomValues("11\n22\n33");
Form form = solution.createNewForm(validator, null, "test", "mem:test", false, new Dimension(600, 400));
form.setNavigatorID(-1);
form.createNewPart(IBaseSMPart.BODY, 5);
form.createNewWebComponent("myCustomComponent", "my-component");
} catch (JSONException e) {
e.printStackTrace();
throw new ServoyException();
}
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class PersistFieldInstanceTest method testFieldWithValueList.
@Test
public void testFieldWithValueList() throws RepositoryException {
Form form = solution.getForm("test");
Assert.assertNotNull(form);
ValueList vl = solution.getValueList("test");
Assert.assertNotNull(vl);
Field field = form.createNewField(new Point(0, 0));
field.setDataProviderID("mycolumn");
field.setFormat("#,###.00");
field.setDisplayType(Field.TYPE_AHEAD);
field.setValuelistID(vl.getID());
// needed for a valuelist property type that searches it's form's table via the webform ui
WebFormUI formUI = new WebFormUI(client.getFormManager().getForm(form.getName()));
IDataAdapterList dataAdapterList = formUI.getDataAdapterList();
List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
Assert.assertEquals(1, formElements.size());
WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), formUI, form);
Object property = wc.getProperty("valuelistID");
Assert.assertTrue(property != null ? property.getClass().getName() : "null", property instanceof ValueListTypeSabloValue && ((ValueListTypeSabloValue) property).getValueList() instanceof CustomValueList);
Assert.assertEquals("#,###.00", ((CustomValueList) ((ValueListTypeSabloValue) property).getValueList()).getFormat().getDisplayFormat());
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class PersistFieldInstanceTest method testSetValuelistItems.
@Test
public void testSetValuelistItems() {
client.setValueListItems("test_items", new String[] { "aaa" }, new String[] { "bbb" }, false);
ValueList vl = client.getFlattenedSolution().getValueList("test_items");
IValueList valuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(client, vl, true, Types.OTHER, null, null);
Assert.assertEquals(valuelist.getElementAt(0), "aaa");
Assert.assertEquals(valuelist.getRealElementAt(0), "bbb");
}
Aggregations