package org.ovirt.engine.ui.userportal.uicommon.model.vm;

import org.ovirt.engine.core.common.businessentities.storage.Disk;
import org.ovirt.engine.ui.common.auth.CurrentUser;
import org.ovirt.engine.ui.common.presenter.AbstractModelBoundPopupPresenterWidget;
import org.ovirt.engine.ui.common.presenter.popup.DefaultConfirmationPopupPresenterWidget;
import org.ovirt.engine.ui.uicommonweb.UICommand;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
import org.ovirt.engine.ui.uicommonweb.models.Model;
import org.ovirt.engine.ui.uicommonweb.models.userportal.UserPortalListModel;
import org.ovirt.engine.ui.uicommonweb.models.vms.VmDiskListModel;
import org.ovirt.engine.ui.userportal.section.main.presenter.popup.vm.VmDiskPopupPresenterWidget;
import org.ovirt.engine.ui.userportal.section.main.presenter.popup.vm.VmDiskRemovePopupPresenterWidget;
import org.ovirt.engine.ui.userportal.uicommon.model.UserPortalSearchableDetailModelProvider;
import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class VmDiskListModelProvider extends UserPortalSearchableDetailModelProvider<Disk, UserPortalListModel, VmDiskListModel> {

    private final Provider<VmDiskPopupPresenterWidget> diskPopupProvider;
    private final Provider<VmDiskRemovePopupPresenterWidget> removeConfirmPopupProvider;

    @Inject
    public VmDiskListModelProvider(EventBus eventBus,
            Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider,
            CurrentUser user,
            Provider<VmDiskPopupPresenterWidget> diskPopupProvider,
            Provider<VmDiskRemovePopupPresenterWidget> removeConfirmPopupProvider) {
        super(eventBus, defaultConfirmPopupProvider, user);
        this.diskPopupProvider = diskPopupProvider;
        this.removeConfirmPopupProvider = removeConfirmPopupProvider;
    }

    @Override
    public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(VmDiskListModel source,
            UICommand lastExecutedCommand, Model windowModel) {
        if (lastExecutedCommand == getModel().getNewCommand() || lastExecutedCommand == getModel().getEditCommand()) {
            return diskPopupProvider.get();
        } else {
            return super.getModelPopup(source, lastExecutedCommand, windowModel);
        }
    }

    @Override
    public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(VmDiskListModel source,
            UICommand lastExecutedCommand) {
        if (lastExecutedCommand == getModel().getRemoveCommand()) {
            return removeConfirmPopupProvider.get();
        } else {
            return super.getConfirmModelPopup(source, lastExecutedCommand);
        }
    }

}

@@ -651,32 +651,136 @@
 mDiskListModel;%0A
+import org.ovirt.engine.ui.userportal.section.main.presenter.popup.vm.VmDiskAttachPopupPresenterWidget;%0A
 import org.ovirt
@@ -853,32 +853,32 @@
 resenterWidget;%0A
-
 import org.ovirt
@@ -1467,16 +1467,92 @@
 rovider;
+%0A    private Provider%3CVmDiskAttachPopupPresenterWidget%3E attachPopupProvider;
 %0A%0A    @I
@@ -1881,16 +1881,92 @@
 Provider
+,%0A            Provider%3CVmDiskAttachPopupPresenterWidget%3E attachPopupProvider
 ) %7B%0A    
@@ -2139,24 +2139,80 @@
 upProvider;%0A
+        this.attachPopupProvider = attachPopupProvider;%0A
     %7D%0A%0A    @
@@ -2547,32 +2547,32 @@
 Provider.get();%0A
-
         %7D else %7B
@@ -2556,32 +2556,161 @@
 get();%0A        %7D
+ else if (lastExecutedCommand == getModel().getAttachCommand()) %7B%0A            return attachPopupProvider.get();%0A        %7D%0A       
  else %7B%0A        

Attach disk to VM window does not open