use of com.servoy.j2db.dataprocessing.IValueList 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.dataprocessing.IValueList 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.dataprocessing.IValueList 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");
}
use of com.servoy.j2db.dataprocessing.IValueList in project servoy-client by Servoy.
the class ComponentFactory method createTypeAheadWithValueList.
/**
* @param application
* @param field
* @param dataProviderLookup
* @param fl
* @return
*/
private static IFieldComponent createTypeAheadWithValueList(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, int type, ParsedFormat format, IStylePropertyChangesRecorder jsChangeRecorder) {
RuntimeDataField scriptable;
IFieldComponent fl;
ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
if (valuelist == null) {
scriptable = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(scriptable, getWebID(form, field));
} else {
scriptable = new RuntimeDataLookupField(jsChangeRecorder, application);
if (valuelist.getValueListType() == IValueListConstants.DATABASE_VALUES) {
try {
IValueList secondLookup = getFallbackValueList(application, field.getDataProviderID(), type, format, valuelist);
LookupValueList lookupValueList = new LookupValueList(valuelist, application, secondLookup, format != null ? format.getDisplayFormat() : null);
fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), lookupValueList);
} catch (Exception e1) {
Debug.error(e1);
return null;
}
} else if (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES || valuelist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
fl = application.getItemFactory().createDataLookupField((RuntimeDataLookupField) scriptable, getWebID(form, field), (CustomValueList) getRealValueList(application, valuelist, true, type, format, field.getDataProviderID()));
} else {
return null;
}
}
scriptable.setComponent(fl, field);
return fl;
}
use of com.servoy.j2db.dataprocessing.IValueList in project servoy-client by Servoy.
the class ComponentFactory method getRealValueList.
@SuppressWarnings("unchecked")
public static IValueList getRealValueList(IServiceProvider application, ValueList valuelist, boolean useSoftCacheForCustom, int type, ParsedFormat format, String dataprovider, boolean readOnlyCache) {
if (application == null) {
application = J2DBGlobals.getServiceProvider();
}
IValueList list = null;
if (valuelist != null && (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES || // reuse,those are static,OTHERS not!
(valuelist.getValueListType() == IValueListConstants.DATABASE_VALUES && valuelist.getDatabaseValuesType() == IValueListConstants.TABLE_VALUES))) {
WeakHashMap<UUID, Object> hmValueLists = null;
if (application != null) {
hmValueLists = (WeakHashMap<UUID, Object>) application.getRuntimeProperties().get(IServiceProvider.RT_VALUELIST_CACHE);
if (hmValueLists == null) {
hmValueLists = new WeakHashMap<UUID, Object>();
application.getRuntimeProperties().put(IServiceProvider.RT_VALUELIST_CACHE, hmValueLists);
}
Object object = hmValueLists.get(valuelist.getUUID());
if (object instanceof SoftReference<?>) {
SoftReference<IValueList> sr = (SoftReference<IValueList>) object;
list = sr.get();
// if it was inserted by a soft reference but now it can't be softly referenced, put it back in hard.
if (list != null && !useSoftCacheForCustom && !readOnlyCache) {
hmValueLists.put(valuelist.getUUID(), list);
}
} else if (object instanceof IValueList) {
list = (IValueList) object;
}
}
// as it may have been changed via solution model (that creates a new persist copy ), and then we need to replace the cached value
if (list != null && list.getValueList() != valuelist) {
list = null;
}
if (list == null) {
list = ValueListFactory.createRealValueList(application, valuelist, type, format);
if (valuelist.getFallbackValueListID() > 0 && valuelist.getFallbackValueListID() != valuelist.getID()) {
list.setFallbackValueList(getFallbackValueList(application, dataprovider, type, format, valuelist));
}
if (!useSoftCacheForCustom && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
if (hmValueLists != null && !readOnlyCache)
hmValueLists.put(valuelist.getUUID(), list);
if (dataprovider != null) {
((CustomValueList) list).addDataProvider(dataprovider);
}
} else {
if (hmValueLists != null && !readOnlyCache)
hmValueLists.put(valuelist.getUUID(), new SoftReference<IValueList>(list));
if (dataprovider != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((CustomValueList) list).addDataProvider(dataprovider);
}
}
} else if (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
if (application instanceof IApplication && ((IApplication) application).isInDeveloper()) {
int currentType = ((CustomValueList) list).getValueType();
if (currentType == Types.OTHER) {
((CustomValueList) list).setValueType(type);
if (dataprovider != null) {
((CustomValueList) list).addDataProvider(dataprovider);
}
} else if (type != Types.OTHER && type != currentType && !((Column.mapToDefaultType(type) == IColumnTypes.INTEGER && Column.mapToDefaultType(currentType) == IColumnTypes.NUMBER) || (Column.mapToDefaultType(type) == IColumnTypes.NUMBER && Column.mapToDefaultType(currentType) == IColumnTypes.INTEGER))) {
List<String> lst = ((CustomValueList) list).getDataProviders();
StringBuffer message = new StringBuffer("The valuelist was already created for type: " + Column.getDisplayTypeString(((CustomValueList) list).getValueType()));
message.append("\n for the dataproviders: ");
for (String previousProviders : lst) {
message.append(previousProviders);
message.append(",");
}
message.setLength(message.length() - 1);
message.append("\nSo it can't be used also for type: " + Column.getDisplayTypeString(type) + " for the dataprovider: " + dataprovider);
message.append("\nPlease edit these dataprovider(s) (using table editor for database column or Edit variable context menu action for variables) of this valuelist: " + valuelist.getName() + " so that they have the same type.");
application.reportError("Valuelist: " + list.getName() + " used with different types", message);
}
}
}
} else {
list = ValueListFactory.createRealValueList(application, valuelist, type, format);
if (valuelist != null && valuelist.getFallbackValueListID() > 0 && valuelist.getFallbackValueListID() != valuelist.getID()) {
list.setFallbackValueList(getFallbackValueList(application, dataprovider, type, format, valuelist));
}
}
return list;
}
Aggregations