Search in sources :

Example 1 with TextFormatterAttribute

use of com.codename1.rad.models.TextFormatterAttribute in project CodeRAD by shannah.

the class HTMLComponentPropertyView method update.

@Override
public void update() {
    super.update();
    // String oldVal = getComponent().get
    String newVal = ContentType.convert(getProperty().getContentType(), getProperty().getValue(getEntity().getEntity()), ContentType.Text);
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        newVal = formatter.getValue().format(newVal);
    }
    if (!Objects.equals(oldVal, newVal)) {
        getComponent().setBodyText(newVal);
        oldVal = newVal;
    }
}
Also used : TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute)

Example 2 with TextFormatterAttribute

use of com.codename1.rad.models.TextFormatterAttribute in project CodeRAD by shannah.

the class LabelPropertyView method getText.

protected String getText() {
    String out = _getText();
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findInheritedAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        return formatter.getValue().format(out);
    }
    return out;
}
Also used : TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute)

Example 3 with TextFormatterAttribute

use of com.codename1.rad.models.TextFormatterAttribute in project CodeRAD by shannah.

the class TextAreaPropertyView method commit.

public void commit() {
    String text = getComponent().getText();
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        if (!formatter.getValue().supportsParse()) {
            throw new RuntimeException("Formatter does not support parse committing text '" + text + "'.");
        }
        try {
            text = formatter.getValue().parse(text);
        } catch (ParseException ex) {
            throw new RuntimeException("Failed to parse text '" + text + "' for property.");
        }
    }
    getProperty().setValue(getEntity().getEntity(), ContentType.convert(ContentType.Text, text, getProperty().getContentType()));
}
Also used : TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute) ParseException(com.codename1.l10n.ParseException)

Example 4 with TextFormatterAttribute

use of com.codename1.rad.models.TextFormatterAttribute in project CodeRAD by shannah.

the class TextAreaPropertyView method update.

@Override
public void update() {
    super.update();
    String oldVal = getComponent().getText();
    String newVal = ContentType.convert(getProperty().getContentType(), getProperty().getValue(getEntity().getEntity()), ContentType.Text);
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        newVal = formatter.getValue().format(newVal);
    }
    if (!Objects.equals(oldVal, newVal)) {
        getComponent().setText(newVal);
    }
    HintUIID hintUiid = (HintUIID) getField().findAttribute(HintUIID.class);
    if (hintUiid != null) {
        Label hintLabel = getComponent().getHintLabel();
        if (hintLabel != null) {
            String oldUiid = hintLabel.getUIID();
            String newUiidStr = hintUiid.getValue(getEntity());
            if (newUiidStr != null && !Objects.equals(oldUiid, newUiidStr)) {
                hintLabel.setUIID(newUiidStr);
            }
        }
    }
}
Also used : HintUIID(com.codename1.rad.attributes.HintUIID) Label(com.codename1.ui.Label) TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute)

Example 5 with TextFormatterAttribute

use of com.codename1.rad.models.TextFormatterAttribute in project CodeRAD by shannah.

the class SpanLabelPropertyView method update.

@Override
public void update() {
    super.update();
    String oldVal = getComponent().getText();
    String newVal = getPropertySelector().getText("");
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        newVal = formatter.getValue().format(newVal);
    }
    if (!Objects.equals(oldVal, newVal)) {
        getComponent().setText(newVal);
    }
}
Also used : TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute)

Aggregations

TextFormatterAttribute (com.codename1.rad.models.TextFormatterAttribute)7 ParseException (com.codename1.l10n.ParseException)2 HintUIID (com.codename1.rad.attributes.HintUIID)2 Label (com.codename1.ui.Label)2 Entity (com.codename1.rad.models.Entity)1 Property (com.codename1.rad.models.Property)1