package org.ovirt.engine.ui.userportal.section.main.presenter;

import org.ovirt.engine.ui.userportal.ApplicationDynamicMessages;
import org.ovirt.engine.ui.userportal.place.UserPortalPlaceManager;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ContentSlot;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.proxy.Proxy;
import com.gwtplatform.mvp.client.proxy.RevealContentHandler;

public class MainSectionPresenter extends Presenter<MainSectionPresenter.ViewDef, MainSectionPresenter.ProxyDef> {

    @ProxyCodeSplit
    public interface ProxyDef extends Proxy<MainSectionPresenter> {
    }

    public interface ViewDef extends View {
    }

    @ContentSlot
    public static final Type<RevealContentHandler<?>> TYPE_SetHeader = new Type<RevealContentHandler<?>>();

    @ContentSlot
    public static final Type<RevealContentHandler<?>> TYPE_SetMainContent = new Type<RevealContentHandler<?>>();

    private final HeaderPresenterWidget header;
    private final UserPortalPlaceManager placeManager;
    private final String basicGuideUrl;
    private final String extendedGuideUrl;

    @Inject
    public MainSectionPresenter(EventBus eventBus, ViewDef view, ProxyDef proxy, HeaderPresenterWidget header,
            UserPortalPlaceManager userPortalPlaceManager, ApplicationDynamicMessages dynamicMessages) {
        super(eventBus, view, proxy, RevealType.RootLayout);
        this.header = header;
        this.placeManager = userPortalPlaceManager;
        this.basicGuideUrl = dynamicMessages.guideUrl();
        this.extendedGuideUrl = dynamicMessages.extendedGuideUrl();
    }

    @Override
    protected void onReveal() {
        super.onReveal();

        setInSlot(TYPE_SetHeader, header);
    }

    @Override
    protected void onReset() {
        // This is called before the place is actually changed, so we need to reverse the logic, and set the
        // extended guide when switching away from the basic (but it is still visible), and vice versa.
        if (placeManager.isMainSectionBasicPlaceVisible()) {
            header.setGuideUrl(basicGuideUrl);
        } else {
            header.setGuideUrl(extendedGuideUrl);
        }
    }
}

@@ -57,16 +57,71 @@
 enter;%0A%0A
+import org.ovirt.engine.ui.common.widget.AlertManager;%0A
 import o
@@ -1394,16 +1394,61 @@
 uideUrl;
+%0A    private final AlertManager alertManager;
 %0A%0A    @I
@@ -1665,16 +1665,55 @@
 Messages
+,%0A            AlertManager alertManager
 ) %7B%0A    
@@ -1972,24 +1972,66 @@
 GuideUrl();%0A
+        this.alertManager = alertManager;%0A
     %7D%0A%0A    @
@@ -2094,24 +2094,24 @@
 nReveal();%0A%0A
-
         setI
@@ -2140,16 +2140,302 @@
 header);
+%0A%0A        // Enable alerts within the scope of main section%0A        alertManager.setCanShowAlerts(true);%0A    %7D%0A%0A    @Override%0A    protected void onHide() %7B%0A        super.onHide();%0A%0A        // Disable alerts outside the scope of main section%0A        alertManager.setCanShowAlerts(false);
 %0A    %7D%0A%0A

Enable contextual alerts in UserPortal