com.talk2object.plum.interaction.rich.field.viewBuilder.LongFieldViewBuilder Maven / Gradle / Ivy
package com.talk2object.plum.interaction.rich.field.viewBuilder;
import com.talk2object.plum.interaction.controller.AbstractController;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.interaction.rich.field.LongField;
import com.talk2object.plum.view.component.Component;
import com.talk2object.plum.view.component.TextBox;
public class LongFieldViewBuilder extends AbstractFieldViewBuilder {
@Override
protected Component createInputComponent(InteractiveField input) {
TextBox textBox = new TextBox();
Component component = textBox;
new AbstractController(input, textBox) {
@Override
public void updateViewState() {
String numberStr = "";
if (getModel().getValue() != null)
numberStr = getModel().getValue().toString();
getView().setText(numberStr);
}
@Override
public void updateModelState() {
if (getView().getText().isEmpty())
return;
try {
Long number = Long.parseLong(getView().getText());
getModel().setValue(number);
} catch (NumberFormatException e) {
// wrong format
}
}
};
return component;
}
@Override
public Class getModelClass() {
return LongField.class;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy