/**
 *  RELOAD TOOLS
 *
 *  Copyright (c) 2004 Oleg Liber, Bill Olivier, Phillip Beauvoir
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  Project Management Contact:
 *
 *  Oleg Liber
 *  Bolton Institute of Higher Education
 *  Deane Road
 *  Bolton BL3 5AB
 *  UK
 *
 *  e-mail:   o.liber@bolton.ac.uk
 *
 *
 *  Technical Contact:
 *
 *  Phillip Beauvoir
 *  e-mail:   p.beauvoir@bolton.ac.uk
 *
 *  Web:      http://www.reload.ac.uk
 *
 */

package uk.ac.reload.editor.learningdesign.editor.activities;

import uk.ac.reload.dweezil.gui.layout.RelativeLayoutManager;
import uk.ac.reload.editor.datamodel.DataComponent;
import uk.ac.reload.editor.learningdesign.datamodel.components.activities.LearningActivity;
import uk.ac.reload.editor.learningdesign.editor.shared.ItemModelTypePanel;
import uk.ac.reload.editor.learningdesign.editor.shared.MetadataPanel;

/**
 * Learning Activity Editor Panel
 *
 * @author Phillip Beauvoir
 * @version $Id: LearningActivityEditorPanel.java,v 1.16 2004/11/26 18:22:42 phillipus Exp $
 */
public class LearningActivityEditorPanel
extends ActivityEditorPanel
{

	/**
	 * Learning Objectives panel
	 */
	private ItemModelTypePanel _objectivesPanel;
    
	/**
	 * Pre-requisites panel
	 */
	private ItemModelTypePanel _prereqPanel;
    
	/**
	 * Description panel
	 */
	private ItemModelTypePanel _descPanel;
	
	/**
	 * CompleteActivityPanel
	 */
	private ActivityCompletionPanel _completeActivityPanel;
	
    /**
     * Metadata Panel
     */
    private MetadataPanel _metadataPanel;

	
    /**
	 * Default Constructor
	 */
	public LearningActivityEditorPanel() {
	    super();
	}
	
	/** 
	 * Over-ride to set sub-panels
	 */
	public void setComponent(DataComponent dataComponent) {
	    super.setComponent(dataComponent);

	    LearningActivity la = (LearningActivity)dataComponent;
	    
	    // Description
	    _descPanel.setItemModelType(la.getDescriptionItemModelType());

	    // Completion Panel
	    _completeActivityPanel.setComponent(dataComponent);
	    
	    // Learning Objectives
	    _objectivesPanel.setItemModelType(la.getLearningObjectivesItemModelType());
	    
	    // Pre-requisites
	    _prereqPanel.setItemModelType(la.getPrerequisitesItemModelType());
	    
        // Metadata
        _metadataPanel.setMetadataType(la.getMetadataType());
	}
	
	/**
	 * Set up the view
	 */
	protected void setupView() {
		super.setupView();

		RelativeLayoutManager layoutManager = getRelativeLayoutManager();
		
		// Description
		_descPanel = new ItemModelTypePanel(false);
		layoutManager.addFromLeftToRightEdges(_descPanel, "_descPanel", "fieldPanel",
				RelativeLayoutManager.BOTTOM, 15, 10);

		// Complete Activity - Choice of "User Choice" or "Time Limit" & Completion Feedback Panel
		_completeActivityPanel = new ActivityCompletionPanel(false);
		layoutManager.addFromLeftToRightEdges(_completeActivityPanel, "_completeActivityPanel", "_descPanel",
				RelativeLayoutManager.BOTTOM, 15, 10);

		// Objectives
		_objectivesPanel = new ItemModelTypePanel(false);
		layoutManager.addFromLeftToRightEdges(_objectivesPanel, "_objectivesPanel", "_completeActivityPanel",
				RelativeLayoutManager.BOTTOM, 15, 10);
		
		// Prerequisites
		_prereqPanel = new ItemModelTypePanel(false);
		layoutManager.addFromLeftToRightEdges(_prereqPanel, "_prereqPanel", "_objectivesPanel",
				RelativeLayoutManager.BOTTOM, 15, 10);

		// Environment Refs
		_envListPanel = addEnvironmentListPanel("_prereqPanel");
		
		// Metadata
		_metadataPanel = new MetadataPanel();
		layoutManager.addFromLeftToRightEdges(_metadataPanel, "_metadataPanel", "envlistPanel",
				RelativeLayoutManager.BOTTOM, 20, 10);
	}

    /**
     * Clean up
     */
    public void cleanup() {
        super.cleanup();
        
        if(_objectivesPanel != null) {
            _objectivesPanel.cleanup();
        }
        
        if(_prereqPanel != null) {
            _prereqPanel.cleanup();
        }
        
        if(_descPanel != null) {
            _descPanel.cleanup();
        }
        
        if(_completeActivityPanel != null) {
            _completeActivityPanel.cleanup();
        }
        
        if(_metadataPanel != null) {
            _metadataPanel.cleanup();
        }
    }
}
