All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.talk2object.plum.interaction.rich.field.component.IntegerFieldViewBuilder Maven / Gradle / Ivy

There is a newer version: 0.1.22
Show newest version
package com.talk2object.plum.interaction.rich.field.component;

import com.talk2object.plum.interaction.controller.AbstractController;
import com.talk2object.plum.interaction.controller.Controller;
import com.talk2object.plum.interaction.rich.field.IntegerField;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.view._abstract.components.TextBox;
import com.talk2object.plum.view._abstract.window.UIComponent;

public class IntegerFieldViewBuilder extends AbstractFieldViewBuilder {

	@Override
	protected UIComponent createComponent(InteractiveField input) {

		TextBox textBox = new TextBox();
		UIComponent 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 {
					Integer number = Integer.parseInt(getView().getText());
					getModel().setValue(number);
				} catch (NumberFormatException e) {
					// wrong format
				}

			}
		};
		

		return component;
	}

	@Override
	public Class getModelClass() {
		return IntegerField.class;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy