

// this means, ContentActionProcessor extends PageComponentProcessor
ContentActionProcessor.prototype = new PageComponentProcessor;

/*
	This class is to cooperatively use builder obj and content obj together.
*/
function ContentActionProcessor()
{


	var mainPageDiv = document.getElementById("middlecontent");

	this.contentOperator = null;

	this.activeContent = null;

	this.popupManager = new PopupListManager();

	this.setContentOperator = function(op)
	{
		this.contentOperator = op;
	}

	
	this.displayEditor = function()
	{
		if (this.activeContent != null)
		{
			var caller = this.instantiateCaller(mainPageDiv);
		 	caller.callableObj.build_content_editor(this.activeContent, caller);		
		}
	}

	this.displayContentPanel = function(contentObj)
	{
		// first, close the popup menu (if it exists)
		var popupName = this.popupManager.generateInfoPopupName(contentObj);
		HoverMenu.removeMenus(popupName);
		
		var caller = this.instantiateCaller(mainPageDiv);
		
		this.builderObj.build_content_panel(contentObj, caller);
		
		this.activeContent = contentObj;
	}

	this.displayPopup = function(contentObj, sender, popup)
	{
		popup.setTop(getY(sender) + 15);
		popup.setLeft(getX(sender));
		popup.setName(this.popupManager.generateInfoPopupName(contentObj));
		popup.setCssClassName("contentInfoPopup");
	
		var processor = this;
		var callback = function(retrievedContext) 
		{
	
			if (processor.popupManager.getPopup(sender) == popup)
			{
				popup.setContext(retrievedContext);
				popup.display();
				
			}
		
		};		
		
		var retriever = new InfoContextRetriever(this.builderObj, contentObj, callback);
		retriever.retrieve();	
	}

	this.deleteActiveContent = function()
	{
		if (this.activeContent != null)
		{
			var caller = new RPCaller(new CallbackStandardization().getStandardGroup(function(mo, mr) { alert(mo); }),this.contentOperator );
		
			this.contentOperator.deleteContent(this.activeContent, caller);
		}
	}

    // retriever is an optional parameter.
	this.retrieveContentFromId = function(id, callback)
	{
		
		var caller = new RPCaller(new CallbackStandardization().getStandardGroup(function(mo, mr) {  callback(mr); }), this.contentOperator);
		caller.cachingMechanism = cacheMechanism;
		this.contentOperator.retrieveFromId(id, caller);
	}


	
	// deliberately specified again (inheritance causes that!)
	PageComponentProcessor.singleton = this;

	ContentActionProcessor.singleton = this;

	
}

ContentActionProcessor.getSingleton = function()
	{
		if (ContentActionProcessor.singleton == null)
		{
			return new ContentActionProcessor();
		}
		else
		{
			return ContentActionProcessor.singleton;
		}
	}

