/*-----------------------------------------------------------------------------
	Copyright the original author or authors.
	 
	Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	 
		http://www.mozilla.org/MPL/MPL-1.1.html
	 
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/
 
import org.aswing.plaf.asw.ASWingLookAndFeel;
import org.aswing.UIManager;
 
import com.bourre.mvc.AbstractView;
import com.bourre.mvc.IController;
import com.bourre.mvc.IModel;
 
import net.customactions.asdk.core.ApplicationInterface;
import net.customactions.asdk.core.factory.StudioFactory;
import net.customactions.asdk.core.ICoreObject;
import net.customactions.asdk.util.ClassUtil;
import net.customactions.aslicensor.mvc.LicensorController;
import net.customactions.aslicensor.mvc.LicensorModel;
import net.customactions.aslicensor.mvc.view.MainView;
 
/**
 * {@code LicensorView } class.
 * 
 * <p>Use PixLib MVC Implementation
 * <p>Extends {@link com.bourre.mvc.AbstractView} class
 *
 * @author Romain Ecarnot
 * @version 1.0
 */
class net.customactions.aslicensor.mvc.LicensorView extends AbstractView implements ICoreObject {
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructs a new {@code LicensorView} instance.
	 * 
	 * <p>Creates a new {@code MainView} with AsWing/JWindow framework component.
	 * {@code MainView} is registring as Model's listener, so Model's events are directly
	 * broadcasted in JWindow instance.
	 * 
	 * @param p_oModel Model instance in MVC Design
	 * @param p_oController Controller in MVC Design
	 * @param p_mcContainer {@code MovieClip} visual container for view
	 */
	public function LicensorView(p_oModel : IModel, p_oController : IController, p_mcContainer : MovieClip) {
		super(p_oModel, p_oController, p_mcContainer);
		
		__sClassName = ClassUtil.getClassName(this);
		
		__buildView();
		
		LicensorModel( LicensorController( getController() ).getModel() ).addModelListener(__mainView);
	}
	
	/**
	 * Calls {@code LicensorController} to select license file.
	 */
	public function handleLicenseClick(Void) : Void {
		LicensorController( getController() ).browseLicense();
	}
	
	/**
	 * Calls {@code LicensorController} to select source folder.
	 */
	public function handleSourceClick(Void) : Void {
		LicensorController( getController() ).browseSource();
	}
	
	/**
	 * Calls {@code LicensorController} to check files listing.
	 */
	public function handleCheckClick(Void) : Void {
		LicensorController( getController() ).check();
	}
	
	/**
	 * Calls {@code LicensorController} to process license insertion.
	 */
	public function handleProcessClick(Void) : Void {
		LicensorController( getController() ).process();
	}
	
	/**
	 * Returns full namespace + classname for this instance.
	 * 
	 * <p>ASDK core implementation
	 * 
	 * @return String
	 */
	public function getClassName(Void) : String {
		return __sClassName;
	}
	
	
	/*------------------------------------------------------------------------------------------*/
	
	
	//-------------------------------------------------------------------------
	// Internal properties
	//-------------------------------------------------------------------------
	 
	private var __sClassName : String;
	private var __mainView : MainView;
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Builds UI.
	 * 
	 * <p>Use {@code ApplicationInterface.getInstance( StudioFactory.getInstance() );} to
	 * define OS strategy. (using SWF Studio strategy in this example)
	 * 
	 * <p>Creates a {@code MainView} instance (sub view)
	 */
	private function __buildView(Void) : Void {
		ApplicationInterface.getInstance( StudioFactory.getInstance() );
		
		Stage.align = "TL";
		Stage.scaleMode = "NoScale";
		
		UIManager.setLookAndFeel( new ASWingLookAndFeel() );
		
		__mainView = new MainView(this);
		__mainView.setSize(Stage.width, Stage.height);
		__mainView.show();
	}
	
}