use of com.servoy.j2db.dataprocessing.GlobalMethodValueList in project servoy-client by Servoy.
the class WebDataField method getConverter.
/**
* @see wicket.Component#getConverter()
*/
@SuppressWarnings("nls")
@Override
public IConverter getConverter(Class<?> cls) {
if (converter != null)
return converter;
int mappedType = Column.mapToDefaultType(dataType);
String displayFormat = parsedFormat.getDisplayFormat();
if (list == null && mappedType == IColumnTypes.TEXT) {
converter = getTextConverter(parsedFormat, getLocale(), getName(), getDataProviderID());
if (converter == null) {
converter = super.getConverter(cls);
}
} else if (displayFormat == null && list == null) {
converter = super.getConverter(cls);
} else if (mappedType == IColumnTypes.DATETIME) {
boolean lenient = Boolean.TRUE.equals(UIUtils.getUIProperty(this.getScriptObject(), application, IApplication.DATE_FORMATTERS_LENIENT, Boolean.TRUE));
StateFullSimpleDateFormat displayFormatter = new StateFullSimpleDateFormat(displayFormat, null, application.getLocale(), lenient);
if (!parsedFormat.isMask() && parsedFormat.getEditFormat() != null) {
StateFullSimpleDateFormat editFormatter = new StateFullSimpleDateFormat(parsedFormat.getEditFormat(), null, application.getLocale(), lenient);
converter = new FormatConverter(this, eventExecutor, displayFormatter, editFormatter, parsedFormat);
} else {
converter = new FormatConverter(this, eventExecutor, displayFormatter, parsedFormat);
}
} else if ((mappedType == IColumnTypes.INTEGER || mappedType == IColumnTypes.NUMBER) && (list == null || !list.hasRealValues())) {
int maxLength = parsedFormat.getMaxLength() == null ? -1 : parsedFormat.getMaxLength().intValue();
// if there is no display format, but the max length is set, then generate a display format.
if (maxLength != -1 && (displayFormat == null || displayFormat.length() == 0)) {
char[] chars = new char[maxLength];
for (int i = 0; i < chars.length; i++) chars[i] = '#';
displayFormat = new String(chars);
}
if (displayFormat != null) {
RoundHalfUpDecimalFormat displayFormatter = new RoundHalfUpDecimalFormat(displayFormat, application.getLocale());
if (parsedFormat.getEditFormat() != null) {
RoundHalfUpDecimalFormat editFormatter = new RoundHalfUpDecimalFormat(parsedFormat.getEditFormat(), application.getLocale());
converter = new FormatConverter(this, eventExecutor, displayFormatter, editFormatter, parsedFormat);
} else {
converter = new FormatConverter(this, eventExecutor, displayFormatter, parsedFormat);
}
}
}
if (list != null) {
if (converter == null && mappedType == IColumnTypes.TEXT && list instanceof GlobalMethodValueList) {
converter = getTextConverter(parsedFormat, getLocale(), getName(), getDataProviderID());
}
converter = new ValuelistValueConverter(list, this, converter);
}
if (converter == null)
converter = super.getConverter(cls);
return converter;
}
use of com.servoy.j2db.dataprocessing.GlobalMethodValueList in project servoy-client by Servoy.
the class DataField method installFormat.
public void installFormat(ComponentFormat componentFormat) {
fp = componentFormat.parsedFormat;
this.dataType = componentFormat.uiType;
this.displayFormat = null;
this.editFormat = null;
editorDocument.clearValidators();
boolean emptyCustom = (list instanceof CustomValueList) && !(list instanceof GlobalMethodValueList) && list.getSize() == 0;
if (!fp.isEmpty() && (list == null || (!list.hasRealValues() && !emptyCustom))) {
displayFormat = fp.getDisplayFormat();
editFormat = fp.getEditFormat();
if (fp.getMaxLength() != null && fp.getMaxLength().intValue() > 0) {
editorDocument.setValidator(MAX_LENGTH_VALIDATOR, new LengthDocumentValidator(fp.getMaxLength().intValue()));
}
if (fp.isAllLowerCase()) {
// $NON-NLS-1$
editorDocument.setValidator("LowerCaseDocumentValidator", new LowerCaseDocumentValidator());
TextFormatter display = new TextFormatter();
TextFormatter edit = new TextFormatter();
setFormatterFactory(new EditingFixedDefaultFormatterFactory(display, display, edit, edit));
} else if (fp.isAllUpperCase()) {
// $NON-NLS-1$
editorDocument.setValidator("UpperCaseDocumentValidator", new UpperCaseDocumentValidator());
TextFormatter display = new TextFormatter();
TextFormatter edit = new TextFormatter();
setFormatterFactory(new EditingFixedDefaultFormatterFactory(display, display, edit, edit));
} else if (fp.isNumberValidator()) {
// $NON-NLS-1$
editorDocument.setValidator("NumberDocumentValidator", new NumberDocumentValidator());
TextFormatter display = new TextFormatter();
TextFormatter edit = new TextFormatter();
setFormatterFactory(new EditingFixedDefaultFormatterFactory(display, display, edit, edit));
} else {
int maxLength = fp.getMaxLength() == null ? -1 : fp.getMaxLength().intValue();
// if there is no display format, but the max length is set, then generate a display format.
if (maxLength != -1 && (displayFormat == null || displayFormat.length() == 0)) {
// if this is just a text type textfield then just set those formatters (the max length is already set)
if (Column.mapToDefaultType(dataType) == IColumnTypes.TEXT) {
TextFormatter display = new TextFormatter();
TextFormatter edit = new TextFormatter();
setFormatterFactory(new EditingFixedDefaultFormatterFactory(display, display, edit, edit));
} else {
char[] chars = new char[maxLength];
for (int i = 0; i < chars.length; i++) chars[i] = '#';
displayFormat = new String(chars);
}
}
if (displayFormat != null) {
if (editFormat == null)
editFormat = displayFormat;
try {
JFormattedTextField.AbstractFormatter displayFormatter = null;
JFormattedTextField.AbstractFormatter editFormatter = null;
switch(Column.mapToDefaultType(dataType)) {
case IColumnTypes.NUMBER:
// example: $#,###.##
displayFormatter = new NullNumberFormatter(new RoundHalfUpDecimalFormat(displayFormat, application.getLocale()));
editFormatter = new NullNumberFormatter(new RoundHalfUpDecimalFormat(editFormat, application.getLocale()), maxLength);
setFormatterFactory(new EditingFixedDefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter, editFormatter));
break;
case IColumnTypes.INTEGER:
// example: $#,###.##
displayFormatter = new NullNumberFormatter(new RoundHalfUpDecimalFormat(displayFormat, application.getLocale()));
editFormatter = new NullNumberFormatter(new RoundHalfUpDecimalFormat(editFormat, application.getLocale()), maxLength);
setFormatterFactory(new EditingFixedDefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter, editFormatter));
break;
case IColumnTypes.DATETIME:
boolean mask = fp.isMask();
char placeHolder = fp.getPlaceHolderCharacter();
if (mask)
editFormat = displayFormat;
displayFormatter = new NullDateFormatter(new StateFullSimpleDateFormat(displayFormat, false));
editFormatter = new NullDateFormatter(new StateFullSimpleDateFormat(editFormat, Boolean.TRUE.equals(UIUtils.getUIProperty(this, IApplication.DATE_FORMATTERS_LENIENT, Boolean.TRUE))), !mask);
if (mask) {
editFormatter = ((NullDateFormatter) editFormatter).getMaskFormatter(placeHolder);
} else {
// date formats are default in override mode
setCaret(getOvertypeCaret());
}
// example: MM/dd/yyyy
setFormatterFactory(new EditingFixedDefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter));
break;
default:
displayFormatter = new ValueListMaskFormatter(displayFormat, true);
editFormatter = new ValueListMaskFormatter(displayFormat, false);
if (fp.isRaw()) {
((ServoyMaskFormatter) editFormatter).setValueContainsLiteralCharacters(false);
((ServoyMaskFormatter) displayFormatter).setValueContainsLiteralCharacters(false);
}
if (fp.getAllowedCharacters() != null) {
((ServoyMaskFormatter) editFormatter).setValidCharacters(fp.getAllowedCharacters());
((ServoyMaskFormatter) displayFormatter).setValidCharacters(fp.getAllowedCharacters());
}
if (editFormat != null) {
if (editFormat.length() == 1) {
((ServoyMaskFormatter) editFormatter).setPlaceholderCharacter(editFormat.charAt(0));
} else {
((ServoyMaskFormatter) editFormatter).setPlaceholder(editFormat);
}
}
setFormatterFactory(new EditingFixedDefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter));
// format overrules max length check
editorDocument.setValidator(MAX_LENGTH_VALIDATOR, new LengthDocumentValidator(0));
break;
}
} catch (Exception ex) {
Debug.error(ex);
}
}
}
} else // for text fields
{
TextFormatter display = new TextFormatter();
TextFormatter edit = new TextFormatter();
setFormatterFactory(new EditingFixedDefaultFormatterFactory(display, display, edit, edit));
}
if (maxLength >= 0 && editorDocument.getValidator(MAX_LENGTH_VALIDATOR) == null) {
editorDocument.setValidator(MAX_LENGTH_VALIDATOR, new LengthDocumentValidator(maxLength));
}
}
use of com.servoy.j2db.dataprocessing.GlobalMethodValueList in project servoy-client by Servoy.
the class FormatTypeSabloValue method getSabloValue.
protected ComponentFormat getSabloValue(String formatValue, String dataproviderId, Object valuelistId, String foundsetId, IWebObjectContext webObjectCntxt) {
INGApplication application = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getApplication();
IDataProviderLookup dataProviderLookup = null;
// IMPORTANT: here we use the for: configs in .spec file
//
// if you have for: [valuelist, dataprovider] then 2 things can happen:
// - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
// - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
// defines both "for" valuelist and dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
//
// if you have just for: dataprovider the the dataprovider property determines the type
// if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
isValuelistFormatSet = false;
if (valuelistId != null) {
// if we have a "for" valuelist, see if this valuelist forces the format type due to display values (when they are separate from real values)
// otherwise it will do nothing and loop/fallback to the other if clause below which checks the "for" dataprovider
ValueList valuelistPersist = ValueListTypeSabloValue.getValuelistPersist(valuelistId, application);
if (valuelistPersist != null) {
IDataProvider dataProvider = null;
ITable table;
try {
if (valuelistPersist.getRelationName() != null) {
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valuelistPersist.getRelationName());
table = application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource());
} else {
table = application.getFlattenedSolution().getTable(valuelistPersist.getDataSource());
}
if (table != null) {
// if the format is for a table valuelist - the type to be used is the one of the dp chosen as 'display' in the valuelist
String dp = null;
// if show == real then we can use show anyway cause there is only one value for both real and display; if show != real we care about show
int showDataProviders = valuelistPersist.getShowDataProviders();
if ((showDataProviders & 1) != 0) {
dp = valuelistPersist.getDataProviderID1();
}
if ((showDataProviders & 2) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID2();
}
if ((showDataProviders & 4) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID3();
}
if (dp != null) {
dataProvider = application.getFlattenedSolution().getDataProviderForTable(table, dp);
}
isValuelistFormatSet = true;
return ComponentFormat.getComponentFormat(formatValue, dataProvider, application, true);
} else if (valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
IValueList realValuelist = null;
ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(propertyDependencies.valueListPropertyName));
if (valuelistSabloValue != null) {
// take it from property, may not be the shared instance in case setvaluelistitems on component was used
realValuelist = valuelistSabloValue.getValueList();
}
if (realValuelist == null) {
realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, ComponentFormat.getComponentFormat(formatValue, dataproviderId, null, application, true).parsedFormat, null, true);
}
if (realValuelist.hasRealValues()) {
// if custom vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
} else if (valuelistPersist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
PropertyDescription vlPD = webObjectCntxt.getPropertyDescription(propertyDependencies.valueListPropertyName);
Object vlPDConfig = null;
if (vlPD != null) {
vlPDConfig = vlPD.getConfig();
if (vlPDConfig instanceof FoundsetLinkedConfig)
vlPDConfig = ((FoundsetLinkedConfig) vlPDConfig).getWrappedConfig();
}
boolean lazyLoad = valuelistPersist.getLazyLoading() && vlPDConfig instanceof ValueListConfig && ((ValueListConfig) vlPDConfig).getLazyLoading();
if (!lazyLoad) {
IValueList realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, null, null, true);
if (realValuelist instanceof GlobalMethodValueList) {
((GlobalMethodValueList) realValuelist).fill(null, "", null);
if (realValuelist.hasRealValues() || realValuelist.getSize() == 0 || (realValuelist.getSize() == 1 && valuelistPersist.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS)) {
// if global method vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
}
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
// here - we want to fall back to the dataprovider if available in for: [ ..., dataprovider] if valuelist didn't force a certain display type on the format
}
if (dataproviderId != null && foundsetId != null) {
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
// always assume now that the the properties has the foundset property name.
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectCntxt.getUnderlyingWebObject().getProperty(this.propertyDependencies.foundsetPropertyName);
if (runtimeValOfFoundset != null && runtimeValOfFoundset.getFoundset() != null && runtimeValOfFoundset.getFoundset().getDataSource().equals(foundsetId)) {
table = runtimeValOfFoundset.getFoundset().getTable();
}
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetId, application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
// else it will be searched for in form's context and table as below
}
if (dataProviderLookup == null) {
WebObjectSpecification spec = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getSpecification();
if (spec != null) {
Collection<PropertyDescription> formComponentProperties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (formComponentProperties != null) {
for (PropertyDescription property : formComponentProperties) {
if (property.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) property.getConfig()).forFoundset != null) {
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getProperty(((ComponentTypeConfig) property.getConfig()).forFoundset);
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
if (runtimeValOfFoundset.getFoundset() != null)
table = runtimeValOfFoundset.getFoundset().getTable();
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(runtimeValOfFoundset.getFoundsetSelector(), application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
break;
}
}
}
}
}
if (dataProviderLookup == null && application != null)
dataProviderLookup = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
ComponentFormat format = ComponentFormat.getComponentFormat(formatValue, dataproviderId, dataProviderLookup, application, true);
return format;
}
Aggregations