use of com.servoy.j2db.util.text.FixedMaskFormatter in project servoy-client by Servoy.
the class WebDataField method getTextConverter.
public static IConverter getTextConverter(final ParsedFormat fp, final Locale l, final String name, final String dataProviderID) {
if (fp.isAllUpperCase()) {
return new IConverter() {
public String convertToString(Object value, Locale locale) {
if (value == null)
return "";
return value.toString().toUpperCase(l);
}
public Object convertToObject(String value, Locale locale) {
if (value == null)
return null;
return value.toUpperCase(l);
}
};
}
if (fp.isAllLowerCase()) {
return new IConverter() {
public String convertToString(Object value, Locale locale) {
if (value == null)
return "";
return value.toString().toLowerCase(l);
}
public Object convertToObject(String value, Locale locale) {
if (value == null)
return null;
return value.toLowerCase(l);
}
};
}
if (fp.getDisplayFormat() != null) {
try {
final FixedMaskFormatter displayFormatter = new FixedMaskFormatter(fp.getDisplayFormat());
displayFormatter.setValueContainsLiteralCharacters(!fp.isRaw());
if (fp.getPlaceHolderString() != null)
displayFormatter.setPlaceholder(fp.getPlaceHolderString());
else if (fp.getPlaceHolderCharacter() != 0)
displayFormatter.setPlaceholderCharacter(fp.getPlaceHolderCharacter());
return new IConverter() {
public String convertToString(Object value, Locale locale) {
// $NON-NLS-1$
if (value == null)
return "";
try {
return displayFormatter.valueToString(value);
} catch (ParseException e) {
Debug.log(e);
return value.toString();
}
}
public Object convertToObject(String value, Locale locale) {
// $NON-NLS-1$
if (value == null || "".equals(value.trim()))
return null;
try {
return displayFormatter.parse(value);
} catch (Exception e) {
// $NON-NLS-1$
String extraMsg = "";
if (name != null) {
// $NON-NLS-1$
extraMsg = " on component " + name;
}
// $NON-NLS-1$
extraMsg += " with dataprovider: " + dataProviderID;
throw new // $NON-NLS-1$//$NON-NLS-2$
ConversionException(// $NON-NLS-1$//$NON-NLS-2$
"Can't convert from string '" + value + "' to object with format: " + fp.getEditFormat() + extraMsg, e).setConverter(this);
}
}
};
} catch (ParseException e) {
// $NON-NLS-1$
Debug.error("format problem: " + fp.getDisplayFormat(), e);
return null;
}
}
return null;
}
use of com.servoy.j2db.util.text.FixedMaskFormatter in project servoy-client by Servoy.
the class DataLookupField method fillValueListImpl.
/**
* @param firstTime
*/
private void fillValueListImpl(final boolean firstTime) {
try {
if (list != null && changeListener != null)
list.removeListDataListener(changeListener);
String txt = getText();
// if this Typeahead is using a masked formatter remove the mask characters before looking up the string
if (getFormatter() != null && (getFormatter() instanceof FixedMaskFormatter)) {
FixedMaskFormatter formatter = (FixedMaskFormatter) getFormatter();
int invalidOffset = formatter.getInvalidOffset(txt, true);
invalidOffset = (invalidOffset == -1 ? 0 : invalidOffset);
txt = txt.substring(0, invalidOffset);
}
if (txt.length() > 0 || Boolean.TRUE.equals(UIUtils.getUIProperty(this, IApplication.TYPE_AHEAD_SHOW_POPUP_WHEN_EMPTY, Boolean.TRUE))) {
dlm.fill(parentState, dataProviderID, txt, firstTime);
if (dlm.getSize() == 0 && firstTime && dlm.getValueList() != null && dlm.getValueList().hasRealValues()) {
dlm.fill(parentState, dataProviderID, null, firstTime);
}
if (jlist != null) {
jlist.setModel(dlm);
jlist.setSelectedValue(txt, true);
jlist.setFont(getFont());
// use bgcolor only for opaque popup
if (isOpaque())
jlist.setBackground(getListBackgroundColor());
jlist.setForeground(getListForegroundColor());
}
showPopup();
} else if (popup != null) {
popup.setVisible(false);
}
} catch (Exception e) {
Debug.error(e);
} finally {
if (list != null && changeListener != null)
list.addListDataListener(changeListener);
}
}
Aggregations