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

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

package com.talk2object.plum.interaction.rich.field.component;

import java.util.List;

import com.talk2object.plum.input.value.image.Image;
import com.talk2object.plum.interaction.controller.AbstractController;
import com.talk2object.plum.interaction.controller.Controller;
import com.talk2object.plum.interaction.rich.field.AbstractComponentBridge;
import com.talk2object.plum.interaction.rich.field.ComponentBridge;
import com.talk2object.plum.interaction.rich.field.ImageField;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.view._abstract.components.ImageView;
import com.talk2object.plum.view._abstract.components.listbox.DropdownList;
import com.talk2object.plum.view._abstract.components.listbox.RadioField;
import com.talk2object.plum.view._abstract.components.listbox.option.ObjectOptions;
import com.talk2object.plum.view._abstract.components.listbox.option.Options;
import com.talk2object.plum.view._abstract.components.listbox.option.converter.DefaultOptionConverter;
import com.talk2object.plum.view._abstract.components.listbox.option.converter.OptionConverter;
import com.talk2object.plum.view._abstract.window.UIComponent;

public class ImageFieldViewBuilder extends AbstractFieldViewBuilder {

	@Override
	protected UIComponent createComponent(InteractiveField input) {
		ImageView imageView = new ImageView();
		ImageField imageInput = (ImageField) input;
		UIComponent component = imageView;

		imageView.setWidth(imageInput.getWidth());
		imageView.setHeight(imageInput.getHeight());

		new AbstractController(
				input, imageView) {

			@Override
			public void updateViewState() {

				getView().setImage((Image) getModel().getValue());
			}

			@Override
			public void updateModelState() {

				getModel().setValue(getView().getImage());
			}
		};

		return component;
	}

	@Override
	protected UIComponent createListComponent(InteractiveField input) {
		RadioField box = new RadioField();
		UIComponent component = box;

		List list = input.getOptions();
		if (input.isNullable())
			list.add(0, null);

		Options options = new ObjectOptions(list);

		box.setOptions(options);

		final Controller controller = new AbstractController(
				input, box) {

			@Override
			public void updateViewState() {

				getView().setSelectedValue(getModel().getValue());
			}

			@Override
			public void updateModelState() {

				getModel().setValue(getView().getSelectedValue());
			}
		};

		return component;
	}

	@Override
	public Class getModelClass() {

		return ImageField.class;
	}
}