Tomas Jelinek has uploaded a new change for review. Change subject: webadmin: Time zones contained couple of empty lines (#850696) ......................................................................
webadmin: Time zones contained couple of empty lines (#850696) https://bugzilla.redhat.com/850696 The probelm was that the selected item was set up like this: ... new KeyValuePairCompat<String, String>(...gettime_zone(), "") UpdateTimeZone() Where the UpdateTimeZone was an asynchronous request to get the time zones and set them up and select the correct one. Changed in a way, that the UpdateTimeZone now gets as an argument the time zone to set the selected item to, and after it fetches the values, it sets the selected time zone in this way: - if the argument is provided, set the selected time zone to it - if the argument is not provided, checks if something has already been selected, and if yes, selects it again - if none of the above is true, then selects the first of the time zones Change-Id: Iad95c26566a0e846f6f7712ce122210e7fc758b9 Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: Tomas Jelinek <tjeli...@redhat.com> --- 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/NewTemplateVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java 6 files changed, 35 insertions(+), 32 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/85/8285/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 28f487c..dbbf1ab 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 @@ -150,8 +150,7 @@ .add("Time Zone cannot be change since the Virtual Machine was booted at the first time."); //$NON-NLS-1$ } - getModel().getTimeZone().setSelectedItem(new KeyValuePairCompat<String, String>(vm.gettime_zone(), "")); //$NON-NLS-1$ - UpdateTimeZone(); + UpdateTimeZone(vm.gettime_zone()); // Update domain list UpdateDomain(); diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java index e770fb8..33da87c 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java @@ -202,9 +202,7 @@ if (!StringHelper.isNullOrEmpty(this.vm.gettime_zone())) { - getModel().getTimeZone() - .setSelectedItem(new KeyValuePairCompat<String, String>(this.vm.gettime_zone(), "")); //$NON-NLS-1$ - UpdateTimeZone(); + UpdateTimeZone(this.vm.gettime_zone()); } else { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java index 2d9b329..d7c04b2 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java @@ -113,11 +113,7 @@ if (!StringHelper.isNullOrEmpty(template.gettime_zone())) { - // Patch! Create key-value pair with a right key. - getModel().getTimeZone() - .setSelectedItem(new KeyValuePairCompat<String, String>(template.gettime_zone(), "")); //$NON-NLS-1$ - - UpdateTimeZone(); + UpdateTimeZone(template.gettime_zone()); } else { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java index 7888756..0cfb25c 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java @@ -130,10 +130,7 @@ if (!StringHelper.isNullOrEmpty(vmBase.gettime_zone())) { // Patch! Create key-value pair with a right key. - getModel().getTimeZone() - .setSelectedItem(new KeyValuePairCompat<String, String>(vmBase.gettime_zone(), "")); //$NON-NLS-1$ - - UpdateTimeZone(); + UpdateTimeZone(vmBase.gettime_zone()); } else { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java index 6961103..d2836ff 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java @@ -155,11 +155,7 @@ if (!StringHelper.isNullOrEmpty(template.gettime_zone())) { - // Patch! Create key-value pair with a right key. - getModel().getTimeZone() - .setSelectedItem(new KeyValuePairCompat<String, String>(template.gettime_zone(), "")); //$NON-NLS-1$ - - UpdateTimeZone(); + UpdateTimeZone(template.gettime_zone()); } else { 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 1b73ed1..968516e 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 @@ -148,7 +148,11 @@ final int windowsTimezones = 0; final int generalTimezones = 1; - protected void UpdateTimeZone() + protected void UpdateTimeZone() { + UpdateTimeZone(null); + } + + protected void UpdateTimeZone(final String selectedTimeZone) { final int index = getModel().getIsWindowsOS() ? windowsTimezones : generalTimezones; @@ -161,26 +165,28 @@ VmModelBehaviorBase behavior = (VmModelBehaviorBase) target; cachedTimeZones.set(index, ((HashMap<String, String>) returnValue).entrySet()); - behavior.PostUpdateTimeZone(); + behavior.PostUpdateTimeZone(selectedTimeZone); } }, getModel().getHash())); } else { - PostUpdateTimeZone(); + PostUpdateTimeZone(selectedTimeZone); } } - public void PostUpdateTimeZone() + public void PostUpdateTimeZone(String selectedTimeZone) { - // If there was some time zone selected before, try select it again. - Object selectedItem = getModel().getTimeZone().getSelectedItem(); - String oldTimeZoneKey = selectedItem == null ? null : ((Map.Entry<String, String>) selectedItem).getKey(); - final int index = getModel().getIsWindowsOS() ? windowsTimezones : generalTimezones; - getModel().getTimeZone().setItems(cachedTimeZones.get(index)); + + // If there was some time zone selected before, try select it again. + Entry<String, String> selectedTimeZoneEntry = + getTimezoneEntryByKey(selectedTimeZone, cachedTimeZones.get(index)); + Object selectedItem = + selectedTimeZoneEntry != null ? selectedTimeZoneEntry : getModel().getTimeZone().getSelectedItem(); + String oldTimeZoneKey = selectedItem == null ? null : ((Map.Entry<String, String>) selectedItem).getKey(); if (oldTimeZoneKey != null) { @@ -192,6 +198,20 @@ { getModel().getTimeZone().setSelectedItem(Linq.FirstOrDefault(cachedTimeZones.get(index))); } + } + + 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())) { + return entry; + } + } + + return null; } private String cachedDefaultTimeZoneKey; @@ -220,10 +240,7 @@ public void PostUpdateDefaultTimeZone() { - // Patch! Create key-value pair with a right key. - getModel().getTimeZone().setSelectedItem(new KeyValuePairCompat<String, String>(cachedDefaultTimeZoneKey, "")); //$NON-NLS-1$ - - UpdateTimeZone(); + UpdateTimeZone(cachedDefaultTimeZoneKey); } protected void UpdateDomain() -- To view, visit http://gerrit.ovirt.org/8285 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad95c26566a0e846f6f7712ce122210e7fc758b9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tomas Jelinek <tjeli...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches