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

com.talk2object.plum.interaction.controller.AbstractController Maven / Gradle / Ivy

package com.talk2object.plum.interaction.controller;

import com.talk2object.plum.view._abstract.window.UIComponent;
import com.talk2object.plum.view.event.AbstractEventListener;
import com.talk2object.plum.view.event.StateChangeListener;
import com.talk2object.plum.view.event.ValueChangeListener;

public abstract class AbstractController implements
		Controller {

	private M model;

	private V view;

	/**
	 * the controller itself will be added as event listener to the view.
	 * 
	 * @param model
	 * @param view
	 */
	public AbstractController(M model, V view) {
		this.model = model;
		this.view = view;

		addEventListeners();
	}

	protected V getView() {
		return view;
	}

	protected M getModel() {
		return model;
	}

	protected void addEventListeners() {
		view.addEventListener(UIComponent.EVENT_STATE_CHANGE,
				new StateChangeListener() {

					@Override
					public void onStateChange() {
						updateModelState();

					}
				});

		// update view state from model state
		view.addEventListener(UIComponent.EVENT_BEFORE_UPDATE_VIEW,
				new AbstractEventListener() {

					@Override
					public void process(String eventName, Object... parameters) {
						updateViewState();
					}
				});
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy