Arik Hadas has uploaded a new change for review. Change subject: frontend: keep timezone as null on edit VM ......................................................................
frontend: keep timezone as null on edit VM This patch fix the following problem: you open the edit dialog of VM that has null value in the timezone field, and then you press OK without doing any change to the timezone (it's not possible from that dialog anyway) - the UI selects in such case the first timezone in the timezones list and send it to the backend, and the backend tried to change the timezone to this value. If the VM is in UP state, it cause to the following bug: the backend tries to update the timezone field although it's not editable in case the VM is not DOWN, thus prevents the user from changing any value of running VM. The solution is to fix the UI in such a way that it will return null if it got null value in the timezone, when we edit VM. Change-Id: I7f8c80ae783e88740ee907d9ff52c0bd6c40734c Bug-Url: https://bugzilla.redhat.com/922609 Signed-off-by: Arik Hadas <[email protected]> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java 2 files changed, 22 insertions(+), 21 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/13197/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java index 5214def..21f45fd 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import org.ovirt.engine.core.common.businessentities.DisplayType; import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; @@ -77,6 +78,15 @@ } @Override + protected HashMap<String, String> getTimezones(String selectedTimeZone, HashMap timezones) { + HashMap<String, String> result = super.getTimezones(selectedTimeZone, timezones); + if (selectedTimeZone == null) { + result.put(null, ""); //$NON-NLS-1$ + } + return result; + } + + @Override public void DataCenter_SelectedItemChanged() { storage_pool dataCenter = (storage_pool) getModel().getDataCenter().getSelectedItem(); diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java index 2159917..f83242d 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java @@ -27,6 +27,7 @@ import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.NGuid; +import org.ovirt.engine.core.compat.StringHelper; import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.frontend.INewAsyncCallback; @@ -170,12 +171,11 @@ new INewAsyncCallback() { @Override public void OnSuccess(Object target, Object returnValue) { - VmModelBehaviorBase behavior = (VmModelBehaviorBase) target; - HashMap<String, String> timeZones = (HashMap<String, String>) returnValue; + HashMap<String, String> timeZones = behavior.getTimezones(selectedTimeZone, + (HashMap<String, String>) returnValue); cachedTimeZones.put(timezoneType, timeZones.entrySet()); behavior.PostUpdateTimeZone(selectedTimeZone); - } }, getModel().getHash())); } @@ -183,6 +183,10 @@ { PostUpdateTimeZone(selectedTimeZone); } + } + + protected HashMap<String, String> getTimezones(String selectedTimeZone, HashMap<String, String> timezones) { + return timezones; } private void PostUpdateTimeZone(String selectedTimeZone) @@ -212,29 +216,16 @@ // If there was some time zone selected before, try select it again. Entry<String, String> selectedTimeZoneEntry = getTimezoneEntryByKey(selectedTimeZone, cachedTimeZones.get(timezoneType)); - Object selectedItem = - selectedTimeZoneEntry != null ? selectedTimeZoneEntry : getModel().getTimeZone().getSelectedItem(); - String oldTimeZoneKey = selectedItem == null ? null : ((Map.Entry<String, String>) selectedItem).getKey(); + Map.Entry<String, String> selectedItem = selectedTimeZoneEntry != null ? + selectedTimeZoneEntry : (Map.Entry<String, String>) getModel().getTimeZone().getSelectedItem(); - if (oldTimeZoneKey != null) - { - getModel().getTimeZone() - .setSelectedItem(Linq.FirstOrDefault(cachedTimeZones.get(timezoneType), - new Linq.TimeZonePredicate(oldTimeZoneKey))); - } - else - { - getModel().getTimeZone().setSelectedItem(Linq.FirstOrDefault(cachedTimeZones.get(timezoneType))); - } + getModel().getTimeZone().setSelectedItem(Linq.FirstOrDefault(cachedTimeZones.get(timezoneType), + new Linq.TimeZonePredicate(selectedItem.getKey()))); } private Entry<String, String> getTimezoneEntryByKey(String key, Iterable<Entry<String, String>> timeZones) { - if (key == null) { - return null; - } - for (Entry<String, String> entry : timeZones) { - if (key.equals(entry.getKey())) { + if (StringHelper.stringsEqual(key, entry.getKey())) { return entry; } } -- To view, visit http://gerrit.ovirt.org/13197 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7f8c80ae783e88740ee907d9ff52c0bd6c40734c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
