/**
 * Copyright (C) 2015 Born Informatik AG (www.born.ch)
 *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */
package org.wte4j.examples.showcase.client.main;

import org.gwtbootstrap3.client.ui.Button;
import org.gwtbootstrap3.client.ui.gwt.FlowPanel;
import org.wte4j.examples.showcase.client.generation.GenerateDocumentDisplay;
import org.wte4j.examples.showcase.client.generation.GenerateDocumentPanel;
import org.wte4j.examples.showcase.client.generation.GenerateDocumentPresenter;
import org.wte4j.examples.showcase.client.management.TemplateManagerDisplay;
import org.wte4j.examples.showcase.client.management.TemplateManagerPanel;
import org.wte4j.examples.showcase.client.management.TemplateManagerPresenter;
import org.wte4j.ui.client.templates.TemplateListPanel;
import org.wte4j.ui.client.templates.TemplateListPresenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Label;

public class MainPresenter {
	private MainDisplay mainDisplay;

	public void bind(MainDisplay aDisplay) {
		if (mainDisplay != null) {
			throw new IllegalStateException("Presenter allready bound");
		}
		mainDisplay = aDisplay;

		bindGenerateDocumentAction();
		bindManageTemplateAction();

	}

	private void bindManageTemplateAction() {
		mainDisplay.addManageTemplateClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				displayTemplatesContent();

			}
		});
	}

	private void bindGenerateDocumentAction() {
		mainDisplay.addGenerateDocumentClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				displayGenerateDocumentContent();
			}
		});
	}

	public void displayTemplatesContent() {
		TemplateManagerDisplay contentDisplay = new TemplateManagerPanel();
		TemplateManagerPresenter contentPresenter = new TemplateManagerPresenter();
		contentPresenter.bind(contentDisplay);
		
		mainDisplay.setMainContent(contentDisplay);
		mainDisplay.setRightContent(new Label("Helptext manage templates"));
		mainDisplay.setGenerateDocumentActive(false);
		mainDisplay.setManageTemplatesActive(true);
	}

	public void displayGenerateDocumentContent() {
		GenerateDocumentDisplay contentDisplay = new GenerateDocumentPanel();
		GenerateDocumentPresenter contentPresenter = new GenerateDocumentPresenter();
		contentPresenter.bind(contentDisplay);

		mainDisplay.setMainContent(contentDisplay);
		mainDisplay.setRightContent(new Label("Helptext generate documents"));
		mainDisplay.setGenerateDocumentActive(true);
		mainDisplay.setManageTemplatesActive(false);

	}
}

@@ -1554,16 +1554,130 @@
 Display;
+%0A%09private TemplateManagerDisplay templateManagerDisplay;%0A%09private GenerateDocumentDisplay generateDocumentDisplay;
 %0A%0A%09publi
@@ -1836,16 +1836,66 @@
 splay;%0A%0A
+%09%09initGenerateDocument();%0A%09%09initManageTemplate();%0A
 %09%09bindGe
@@ -1949,24 +1949,477 @@
 ion();%0A%0A%09%7D%0A%0A
+%09private void initGenerateDocument() %7B%0A%09%09generateDocumentDisplay = new GenerateDocumentPanel();%0A%09%09GenerateDocumentPresenter contentPresenter = new GenerateDocumentPresenter();%0A%09%09contentPresenter.bind(generateDocumentDisplay);%0A%09%7D%0A%0A%09private void initManageTemplate() %7B%0A%09%09templateManagerDisplay = new TemplateManagerPanel();%0A%09%09TemplateManagerPresenter contentPresenter = new TemplateManagerPresenter();%0A%09%09contentPresenter.bind(templateManagerDisplay);%0A%09%7D%0A%0A
 %09private voi
@@ -2886,234 +2886,53 @@
 %7B%0A%09%09
-TemplateManagerDisplay contentDisplay = new TemplateManagerPanel();%0A%09%09TemplateManagerPresenter contentPresenter = new TemplateManagerPresenter();%0A%09%09contentPresenter.bind(contentDisplay);%0A%09%09%0A%09%09mainDisplay.setMainContent(content
+%0A%09%09mainDisplay.setMainContent(templateManager
 Disp
@@ -3160,233 +3160,51 @@
 %7B%0A%09%09
-GenerateDocumentDisplay contentDisplay = new GenerateDocumentPanel();%0A%09%09GenerateDocumentPresenter contentPresenter = new GenerateDocumentPresenter();%0A%09%09contentPresenter.bind(contentDisplay);%0A%0A%09%09mainDisplay.setMainContent(cont
+%0A%09%09mainDisplay.setMainContent(generateDocum
 entD

Store main display panels in showcase instead of creating them every tab press