Frank Kobzik has uploaded a new change for review. Change subject: webadmin: Console connect button availability fix ......................................................................
webadmin: Console connect button availability fix This patch fixes the behavior of console button availability broken by I00158bbd. For the availability check, the ConsoleUtils is used. For this to work, additional event had to be added into VmListModel. Change-Id: If102303d6b5c5ac45959b87a540c8ea278c227c3 Signed-off-by: Frantisek Kobzik <fkob...@redhat.com> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ConsoleUtils.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ConsoleModelsCache.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/MainTabVirtualMachinePresenter.java 4 files changed, 35 insertions(+), 18 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/13343/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ConsoleUtils.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ConsoleUtils.java index fb6f302..0feb677 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ConsoleUtils.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ConsoleUtils.java @@ -20,17 +20,13 @@ private Boolean spiceAvailable; private Boolean rdpAvailable; - private final String VNC_NOT_SUPPORTED_MESSAGE; - private final String BROWSER_NOT_SUPPORTED_MESSAGE; - private final ClientAgentType clientAgentType; + private final CommonApplicationConstants constants; @Inject public ConsoleUtils(ClientAgentType clientAgentType, CommonApplicationConstants constants) { this.clientAgentType = clientAgentType; - - VNC_NOT_SUPPORTED_MESSAGE = constants.vncNotSupportedMsg(); - BROWSER_NOT_SUPPORTED_MESSAGE = constants.browserNotSupportedMsg(); + this.constants = constants; } public boolean isSpiceAvailable() { @@ -96,30 +92,30 @@ } if (!(isRDPAvailable() || isSpiceAvailable())) { - return BROWSER_NOT_SUPPORTED_MESSAGE; + return constants.browserNotSupportedMsg(); } boolean isSpice = item.getDefaultConsoleModel() instanceof SpiceConsoleModel && isSpiceAvailable(); boolean isRdp = item.getAdditionalConsoleModel() != null && isRDPAvailable(); if (!isSpice && !isRdp) { - return VNC_NOT_SUPPORTED_MESSAGE; + return constants.vncNotSupportedMsg(); } return ""; //$NON-NLS-1$ } public ConsoleProtocol determineConnectionProtocol(HasConsoleModel item) { - if (item.isPool()) { + if (item == null || item.isPool()) { return null; } ConsoleProtocol selectedProtocol = item.getSelectedProtocol(); - if (item.getAdditionalConsoleModel() != null && isRDPAvailable() && selectedProtocol.equals(ConsoleProtocol.RDP)) { + if (item.getAdditionalConsoleModel() != null && isRDPAvailable() && ConsoleProtocol.RDP.equals(selectedProtocol)) { return ConsoleProtocol.RDP; } else if (item.getDefaultConsoleModel() instanceof SpiceConsoleModel && isSpiceAvailable() && - selectedProtocol.equals(ConsoleProtocol.SPICE)) { + ConsoleProtocol.SPICE.equals(selectedProtocol)) { return ConsoleProtocol.SPICE; } else if (item.getDefaultConsoleModel() instanceof VncConsoleModel) { return ConsoleProtocol.VNC; @@ -128,8 +124,9 @@ return null; } + //TODO consider refactoring it to use one parameter only if possible public boolean canShowConsole(ConsoleProtocol selectedProtocol, HasConsoleModel item) { - if (selectedProtocol == null) { + if (selectedProtocol == null || item == null) { return false; } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ConsoleModelsCache.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ConsoleModelsCache.java index 6676a6d..2d8059a 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ConsoleModelsCache.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ConsoleModelsCache.java @@ -141,10 +141,8 @@ : ConsoleProtocol.getProtocolByModel(selectedConsoleModel.getClass()); } - public ArrayList<ConsoleModel> GetConsoleModelsByVmGuid(Guid vmGuid) - { - if (cachedConsoleModels != null && cachedConsoleModels.containsKey(vmGuid)) - { + public ArrayList<ConsoleModel> getConsoleModelsByVmGuid(Guid vmGuid) { + if (cachedConsoleModels != null) { return cachedConsoleModels.get(vmGuid); } @@ -152,6 +150,10 @@ } private ConsoleModel resolveSelectedConsoleModel(Guid vmId) { + if (!cachedConsoleModels.containsKey(vmId)) { + return null; + } + for (ConsoleModel model : cachedConsoleModels.get(vmId)) { if (model.isUserSelected()) { return model; diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java index 257b9a4..e8aabd2 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java @@ -342,6 +342,12 @@ return consoleConnectEvent; } + private final Event checkConsoleAvailabilityEvent = new Event(new EventDefinition("CheckConsoleAvailabilityEvent", VmListModel.class)); //$NON-NLS-1$ + + public Event getCheckConsoleAvailabilityEvent() { + return checkConsoleAvailabilityEvent; + } + public UICommand fireConsoleConnectEventCommand; public UICommand getFireConsoleConnectEventCommand() { @@ -412,7 +418,7 @@ private final ConsoleModelsCache consoleModelsCache; - public ConsoleModelsCache getUberConsoleModel() { + public ConsoleModelsCache getConsoleModelsCache() { return consoleModelsCache; } @@ -2776,7 +2782,6 @@ && VdcActionUtils.CanExecute(items, VM.class, VdcActionType.StopVm)); getMigrateCommand().setIsExecutionAllowed(items.size() > 0 && VdcActionUtils.CanExecute(items, VM.class, VdcActionType.MigrateVm)); - getEditConsoleCommand().setIsExecutionAllowed(items.size() == 1); getFireConsoleConnectEventCommand().setIsExecutionAllowed(items.size() == 1); getCancelMigrateCommand().setIsExecutionAllowed(items.size() > 0 && VdcActionUtils.CanExecute(items, VM.class, VdcActionType.CancelMigrateVm)); @@ -2798,6 +2803,8 @@ getGuideCommand().setIsExecutionAllowed(getGuideContext() != null || (getSelectedItem() != null && getSelectedItems() != null && getSelectedItems().size() == 1)); + + this.checkConsoleAvailabilityEvent.raise(this, EventArgs.Empty); } /** diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/MainTabVirtualMachinePresenter.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/MainTabVirtualMachinePresenter.java index e24543e..2f762f0 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/MainTabVirtualMachinePresenter.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/MainTabVirtualMachinePresenter.java @@ -9,6 +9,7 @@ import org.ovirt.engine.ui.common.utils.ConsoleManager; import org.ovirt.engine.ui.common.utils.ConsoleUtils; import org.ovirt.engine.ui.common.widget.tab.ModelBoundTabData; +import org.ovirt.engine.ui.uicommonweb.models.ConsoleProtocol; import org.ovirt.engine.ui.uicommonweb.models.vms.VmListModel; import org.ovirt.engine.ui.uicompat.Event; import org.ovirt.engine.ui.uicompat.EventArgs; @@ -33,6 +34,7 @@ public class MainTabVirtualMachinePresenter extends AbstractMainTabWithDetailsPresenter<VM, VmListModel, MainTabVirtualMachinePresenter.ViewDef, MainTabVirtualMachinePresenter.ProxyDef> { private final ConsoleManager consoleManager; + private final ConsoleUtils consoleUtils; private final ErrorPopupManager errorPopupManager; @GenEvent @@ -58,6 +60,14 @@ } } }); + + getModel().getCheckConsoleAvailabilityEvent().addListener(new IEventListener() { + @Override + public void eventRaised(Event ev, Object sender, EventArgs args) { + ConsoleProtocol protocol = consoleUtils.determineConnectionProtocol(getModel()); + getModel().getFireConsoleConnectEventCommand().setIsExecutionAllowed(consoleUtils.canShowConsole(protocol, getModel())); + } + }); } public interface ViewDef extends AbstractMainTabWithDetailsPresenter.ViewDef<VM> { @@ -76,6 +86,7 @@ super(eventBus, view, proxy, placeManager, modelProvider); this.consoleManager = consoleManager; this.errorPopupManager = errorPopupManager; + this.consoleUtils = consoleUtils; } -- To view, visit http://gerrit.ovirt.org/13343 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If102303d6b5c5ac45959b87a540c8ea278c227c3 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Frank Kobzik <fkob...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches