/*
 * Copyright (c) 2011, Patrik Dufresne. All rights reserved.
 * Patrik Dufresne PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.ui;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.widgets.Shell;

import com.patrikdufresne.ui.MainWindow;
import com.patrikdufresne.util.Localized;
import com.planimod.core.PlanimodManagers;
import com.planimod.ui.views.admin.AdminViewPart;
import com.planimod.ui.views.employees.EmployeeViewPart;
import com.planimod.ui.views.nonavailabilities.NonAvailabilitiesViewPart;
import com.planimod.ui.views.planif.PlanifViewPart;
import com.planimod.ui.views.production.ProductionViewPart;
import com.planimod.ui.views.qualifs.QualificationViewPart;
import com.planimod.ui.views.shifts.ShiftViewPart;

/**
 * This implementation of the {@link MainWindow} create default vies for
 * Planimod and provide a {@link PlanimodManagers} service.
 * 
 * @author Patrik Dufresne
 * 
 */
public class PlanimodMainWindow extends MainWindow {

	/**
	 * Managers used by this window.
	 */
	private PlanimodManagers managers;

	/**
	 * Default constructor.
	 * 
	 * @param parentShell
	 * @see ApplicationWindow
	 */
	public PlanimodMainWindow(Shell parentShell) {
		super(parentShell);
	}

	/**
	 * This implementation add all the view required for Planimod.
	 */
	@Override
	protected void addViews() {
		addView(new EmployeeViewPart());
		addView(new NonAvailabilitiesViewPart());
		addView(new QualificationViewPart());
		addView(new ShiftViewPart());
		addView(new ProductionViewPart());
		addView(new PlanifViewPart());
		addView(new AdminViewPart());
	}

	/**
	 * This implementation add a shell title and icon.
	 */
	@Override
	protected void configureShell(final Shell shell) {
		super.configureShell(shell);
		shell.setText(Localized
				.get(PlanimodMainWindow.class, "applicationName")); //$NON-NLS-1$
	}

	/**
	 * Return the planimod managers.
	 * 
	 * @return
	 */
	public PlanimodManagers getManagers() {
		return this.managers;
	}

	/**
	 * Sets the managers used by this windows.
	 * 
	 * @param managers
	 */
	public void setManagers(PlanimodManagers managers) {
		this.managers = managers;
	}

	@Override
	public <T> T locateService(Class<T> serviceClass) {

		if (serviceClass.equals(PlanimodManagers.class)) {
			return (T) getManagers();
		}

		return null;

	}
}
