package org.ovirt.engine.ui.webadmin.section.main.presenter.popup.guide;

import org.ovirt.engine.ui.common.presenter.AbstractModelBoundPopupPresenterWidget;
import org.ovirt.engine.ui.uicommonweb.UICommand;
import org.ovirt.engine.ui.uicommonweb.models.GuideModel;
import org.ovirt.engine.ui.uicommonweb.models.Model;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.cluster.ClusterPopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.datacenter.FindMultiStoragePopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.datacenter.FindSingleStoragePopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.host.HostPopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.storage.StoragePopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.vm.VmDiskPopupPresenterWidget;
import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.vm.VmInterfacePopupPresenterWidget;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class GuidePopupPresenterWidget extends AbstractModelBoundPopupPresenterWidget<GuideModel, GuidePopupPresenterWidget.ViewDef> {
    public interface ViewDef extends AbstractModelBoundPopupPresenterWidget.ViewDef<GuideModel> {
    }

    private final Provider<ClusterPopupPresenterWidget> clusterPopupProvider;
    private final Provider<HostPopupPresenterWidget> hostPopupProvider;
    private final Provider<StoragePopupPresenterWidget> storagePopupProvider;
    private final Provider<VmInterfacePopupPresenterWidget> vmInterfacePopupProvider;
    private final Provider<VmDiskPopupPresenterWidget> vmDiskPopupPopupProvider;
    private final Provider<MoveHostPopupPresenterWidget> moveHostPopupProvider;
    private final Provider<FindSingleStoragePopupPresenterWidget> singleStoragePopupProvider;
    private final Provider<FindMultiStoragePopupPresenterWidget> multiStoragePopupProvider;

    @Inject
    public GuidePopupPresenterWidget(EventBus eventBus, ViewDef view,
            Provider<ClusterPopupPresenterWidget> clusterPopupProvider,
            Provider<HostPopupPresenterWidget> hostPopupProvider,
            Provider<StoragePopupPresenterWidget> storagePopupProvider,
            Provider<VmInterfacePopupPresenterWidget> vmInterfacePopupProvider,
            Provider<VmDiskPopupPresenterWidget> vmDiskPopupPopupProvider,
            Provider<MoveHostPopupPresenterWidget> moveHostPopupProvider,
            Provider<FindSingleStoragePopupPresenterWidget> singleStoragePopupProvider,
            Provider<FindMultiStoragePopupPresenterWidget> multiStoragePopupProvider) {
        super(eventBus, view);

        this.clusterPopupProvider = clusterPopupProvider;
        this.hostPopupProvider = hostPopupProvider;
        this.storagePopupProvider = storagePopupProvider;
        this.vmInterfacePopupProvider = vmInterfacePopupProvider;
        this.vmDiskPopupPopupProvider = vmDiskPopupPopupProvider;
        this.moveHostPopupProvider = moveHostPopupProvider;
        this.singleStoragePopupProvider = singleStoragePopupProvider;
        this.multiStoragePopupProvider = multiStoragePopupProvider;
    }

    @Override
    public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(GuideModel source,
            UICommand lastExecutedCommand, Model windowModel) {
        String lastExecutedCommandName = lastExecutedCommand.getName();

        if (lastExecutedCommandName.equals("AddCluster")) { //$NON-NLS-1$
            return clusterPopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddHost")) { //$NON-NLS-1$
            return hostPopupProvider.get();
        } else if (lastExecutedCommandName.equals("SelectHost")) { //$NON-NLS-1$
            return moveHostPopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddDataStorage")) { //$NON-NLS-1$
            return storagePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddIsoStorage")) { //$NON-NLS-1$
            return storagePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddLocalStorage")) { //$NON-NLS-1$
            return storagePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AttachDataStorage")) { //$NON-NLS-1$
            return multiStoragePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AttachIsoStorage")) { //$NON-NLS-1$
            return singleStoragePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddNetwork")) { //$NON-NLS-1$
            return vmInterfacePopupProvider.get();
        } else if (lastExecutedCommandName.equals("AddDisk")) { //$NON-NLS-1$
            return vmDiskPopupPopupProvider.get();
        } else {
            return super.getModelPopup(source, lastExecutedCommand, windowModel);
        }
    }
}

@@ -182,29 +182,185 @@
 .ui.
-uicommonweb.UICommand
+common.presenter.popup.DefaultConfirmationPopupPresenterWidget;%0Aimport org.ovirt.engine.ui.uicommonweb.UICommand;%0Aimport org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel
 ;%0Aim
@@ -1440,24 +1440,25 @@
 .ViewDef%3E %7B%0A
+%0A
     public i
@@ -2210,16 +2210,113 @@
 rovider;
+%0A    private final Provider%3CDefaultConfirmationPopupPresenterWidget%3E defaultConfirmPopupProvider;
 %0A%0A    @I
@@ -3002,16 +3002,107 @@
 Provider
+,%0A            Provider%3CDefaultConfirmationPopupPresenterWidget%3E defaultConfirmPopupProvider
 ) %7B%0A    
@@ -3623,24 +3623,96 @@
 upProvider;%0A
+        this.defaultConfirmPopupProvider = defaultConfirmPopupProvider;%0A
     %7D%0A%0A    @
@@ -5378,16 +5378,255 @@
       %7D%0A
-
     %7D%0A
+%0A    @Override%0A    public AbstractModelBoundPopupPresenterWidget%3C? extends ConfirmationModel, ?%3E getConfirmModelPopup(GuideModel source,%0A            UICommand lastExecutedCommand) %7B%0A        return defaultConfirmPopupProvider.get();%0A    %7D%0A%0A
 %7D%0A

Add host via Guide-Me doesn't work (#818182)