/*
 * Copyright 2011 Serbian Object Laboratories (SOL)
 * 
 * Licensed under the GPL licence
 * 
 * http://www.gnu.org/licenses/gpl.html
 */
package companyorganization;

import rs.sol.soloist.helpers.init.DefaultContextInit;
import rs.sol.soloist.helpers.init.Initializer;
import rs.sol.soloist.helpers.init.InitializerFailedException;
import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIDeckComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIHTMLComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIImageComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILinkComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIStatusBarComponent;
import rs.sol.soloist.server.guiconfiguration.layout.HorizontalAlignment;
import rs.sol.soloist.server.guiconfiguration.layout.VerticalAlignment;
import rs.sol.soloist.server.guiconfiguration.style.GUIContext;
import rs.sol.soloist.server.server.SoloistServiceServlet;

public class ApplicationInit implements Initializer {

	private static final String COPYRIGHT_TEXT = "Copyright &copy; 2011 - <a href='http://www.sol.rs/'>Serbian Object Laboratories (SOL)</a> - <a href='http://www.soloist4uml.com/pricing-and-licensing'>Licence</a>&nbsp;";
	private static final String TITLE = "SOLoist Demo - Company Organization";

	private GUIApplicationComponent application;
	private GUIContext context;
	private GUIPanelComponent mainPanel;

	private GUIPanelComponent titlePanel;
	private GUIDeckComponent centralPanel;

	public void init() throws InitializerFailedException {

		application = new GUIApplicationComponent();
		SoloistServiceServlet.registerApplication(application);
		application.setName("CompanyOrganization");
		application.setTitle("Company Organization");
		
		context = new GUIContext();
		DefaultContextInit.getRoot().addContext(context);
		application.setContext(context);

		mainPanel = GUIPanelComponent.createVertical(application);
		mainPanel.setStyle("main_panel");
		
		// Title
		titlePanel = GUIPanelComponent.createHorizontal(mainPanel);
		titlePanel.setStyle("titlePanel");
		titlePanel.setCellAlignment(null, VerticalAlignment.TOP);
		titlePanel.setCellSize("100%", "80");

		// Logo
		GUIImageComponent leftLogoComponent = GUIImageComponent.create(titlePanel, "res/img/logo-left.png");
		leftLogoComponent.setStyle("logo-image");
		leftLogoComponent.setCellSize("200", null);

		GUILabelComponent pageTitle = GUILabelComponent.create(titlePanel, TITLE, null);
		pageTitle.setStyle("page_title");

		GUILinkComponent poweredBy = GUILinkComponent.create(titlePanel, "Powered by SOLoist", "http://www.soloist4uml.com/");
		poweredBy.setStyle("poweredBy");
		
		poweredBy.setCellAlignment(null, VerticalAlignment.BOTTOM);

		// Central panel
		centralPanel = GUIDeckComponent.create(GUIPanelComponent.createFlow(mainPanel));
		centralPanel.setStyle("centralPanel");

		// Bottom panel
		GUIPanelComponent bottomPanel = GUIPanelComponent.createVertical(mainPanel);
		bottomPanel.setStyle("bottomPanel");		

		GUIPanelComponent statusBarPanel = GUIPanelComponent.createHorizontal(bottomPanel);
		statusBarPanel.setStyle("status_bar_panel");
		statusBarPanel.setCellSize("100%", null);
		
		GUILabelComponent statusBarLabel = GUILabelComponent.create(statusBarPanel, "Status bar: ", null);
		statusBarLabel.setCellSize("75px", null);
		statusBarLabel.setStyle("status_bar_label");

		GUIStatusBarComponent statusBar = GUIStatusBarComponent.create(statusBarPanel);
		statusBar.setStyle("status_bar");

		GUIHTMLComponent html = GUIHTMLComponent.create(statusBarPanel, COPYRIGHT_TEXT);
		html.setStyle("footer_panel");
		html.setCellAlignment(HorizontalAlignment.LEFT, null);
		html.setSize("400", null);
	}
}
