package com.mindoo.ec09.example5.ca;

import org.eclipse.ui.part.ViewPart;

/**
 * Abstract superclass for viewparts that are doing Composite Application communication.
 * The class does the necessary registration of the viewpart and it's data exchange PCSBean.
 */
public abstract class ComponentViewPart extends ViewPart implements IDataProvider {
	public ComponentViewPart() {
		System.out.println("Instantiating "+getClass().getName());
	}

	public void setupNames() {
		ViewBean bean = (ViewBean)getData();
		if (bean.getPartName() != null)
			setPartName(bean.getPartName());
		if (bean.getContentDescription() != null)
			setContentDescription(bean.getContentDescription());
	}

	public void registerData() {
		String viewID = getViewSite().getId();
		String secondaryId = getViewSite().getSecondaryId();
		PCSBean bean = getData();
		System.out.println(getClass().getName()+" registering "+viewID+"/"+secondaryId+" to "+bean);
		ViewBeanRegistry.getInstance().registerViewBean(viewID, secondaryId, bean);
	}

	public void dispose() {
		String viewID = getViewSite().getId();
		String secondaryId = getViewSite().getSecondaryId();
		ViewBeanRegistry.getInstance().unregisterViewBean(viewID, secondaryId);
		super.dispose();
	}
}
