/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
package com.pragprog.dhnako.carserv.wicket.ui;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.nakedobjects.metamodel.services.ServicesInjector;
import org.nakedobjects.plugins.headless.embedded.NakedObjectsMetaModel;
import org.nakedobjects.plugins.headless.viewer.DomainObjectContainerHeadlessViewer;

public abstract class NakedObjectsPanel extends Panel {

	private static final long serialVersionUID = 1L;

	private transient DomainObjectContainerHeadlessViewer container;

	public NakedObjectsPanel(String id) {
		super(id, null);
		init();
	}

	public NakedObjectsPanel(String id, IModel model) {
		super(id, model);
		init();
	}

	private void init() {
		injectServices();
	}

	@Override
	protected void onBeforeRender() {
		init();
		super.onBeforeRender();
	}
	

	protected void injectServices() {
		getServicesInjector().injectDependencies(this);
	}
	
	private ServicesInjector getServicesInjector() {
		return getMetaModel().getServicesInjector();
	}
	/**
	 * Make available to subclasses.
	 */
	protected NakedObjectsMetaModel getMetaModel() {
		NakedObjectsApplication application = (NakedObjectsApplication) getSession().getApplication();
    	return application.getNakedObjectsMetaModel();
	}

	public DomainObjectContainerHeadlessViewer getContainer() {
		return container;
	}
	public void setContainer(DomainObjectContainerHeadlessViewer container) {
		this.container = container;
	}

}
