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

com.talk2object.plum.viewgeneration.viewbuilder.BeanFormViewBuilder Maven / Gradle / Ivy

package com.talk2object.plum.viewgeneration.viewbuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.talk2object.plum.interaction.model.Bean;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.interaction.rich.field.ValueType;
import com.talk2object.plum.interaction.view.component.containers.window.FormView;
import com.talk2object.plum.view.component.Component;
import com.talk2object.plum.view.event.AbstractEventListener;
import com.talk2object.plum.viewgeneration.ViewBuildContext;

public class BeanFormViewBuilder extends AbstractFormViewBuilder {

	@Override
	public Component build(Object model, ViewBuildContext context) {

		final Map map = (Map) model;

		// create fields
		List fields = new ArrayList();
		for (String key : map.keySet()) {

			Object val = map.get(key);

			Class cls = val.getClass();

			ValueType type = ValueType.valueOf(val.getClass());

			InteractiveField field = type.createRichField(key, cls, null);

			field.setInitValue(val);

			fields.add(field);
		}

		final FormView formView = build(fields, context);
		formView.setSubmitEventHandler(new AbstractEventListener() {

			@Override
			public void process(Component source, String eventName,
					Object... parameters) {

				for (InteractiveField field : formView.getAllInputs()) {
					String key = field.getName();
					Object val = field.getValue();

					map.put(key, val);
				}
			}
		});

		return formView;
	}

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy