Fixes issue where the Finish page of the NewVM wizard was not showing the selected home server correctly.

This commit is contained in:
Konstantina Chremmou 2022-09-30 14:18:03 +01:00
parent 0d70266173
commit 940b1580b9
5 changed files with 31 additions and 67 deletions

View File

@ -109,6 +109,7 @@ namespace XenAdmin.Controls
this.ReasonColumn});
resources.ApplyResources(this.ServersGridView, "ServersGridView");
this.ServersGridView.Name = "ServersGridView";
this.ServersGridView.SelectionChanged += new System.EventHandler(this.ServersGridView_SelectionChanged);
this.ServersGridView.VisibleChanged += new System.EventHandler(this.ServersGridView_VisibleChanged);
//
// ImageColumn

View File

@ -48,6 +48,7 @@ namespace XenAdmin.Controls
private IXenConnection Connection;
private Host SrHost;
private Host Affinity;
private bool selectedOnVisibleChanged;
/// <summary>
/// Should always be true if the AffinityPicker is used to create a VM.
@ -56,9 +57,7 @@ namespace XenAdmin.Controls
/// </summary>
internal bool AutoSelectAffinity = true;
public event EventHandler SelectedAffinityChanged = new EventHandler(OnSelectedAffinityChanged);
private static void OnSelectedAffinityChanged(object obj, EventArgs e) { }
public event Action SelectedAffinityChanged;
public AffinityPicker()
{
@ -72,9 +71,9 @@ namespace XenAdmin.Controls
SrHost = srhost;
tableLayoutPanelWlbWarning.Visible = Helpers.WlbEnabledAndConfigured(connection);
LoadServers();
_UpdateControl();
UpdateControl();
SelectRadioButtons();
SelectedAffinityChanged(SelectedAffinity, new EventArgs());
SelectedAffinityChanged?.Invoke();
}
private void LoadServers()
@ -88,16 +87,6 @@ namespace XenAdmin.Controls
}
private void UpdateControl()
{
_UpdateControl();
SelectedAffinityChanged(SelectedAffinity, new EventArgs());
}
/// <summary>
/// does not fire selected affinity changed event
/// </summary>
private void _UpdateControl()
{
if (Connection == null)
return;
@ -126,25 +115,15 @@ namespace XenAdmin.Controls
}
}
public Host SelectedAffinity
{
get
{
return DynamicRadioButton.Checked ? null : SelectedServer();
}
}
public Host SelectedAffinity => DynamicRadioButton.Checked ? null : SelectedServer();
private Host SelectedServer()
{
if (ServersGridView.SelectedRows.Count == 0)
return null;
if (ServersGridView.SelectedRows.Count > 0)
return ((ServerGridRow)ServersGridView.SelectedRows[0]).Server;
Host h = ((ServerGridRow)ServersGridView.SelectedRows[0]).Server;
if (h == null)
return null;
return h;
return null;
}
private bool SelectServer(Host host)
@ -173,7 +152,6 @@ namespace XenAdmin.Controls
private bool SelectSomething()
{
//Now decide if we want to select anything.
bool selected = false;
if (Affinity != null)
@ -182,9 +160,6 @@ namespace XenAdmin.Controls
if (!selected && SrHost != null)
selected = SelectServer(SrHost);
/* if (!selected)
selected = SelectAnyServer();*/
return selected;
}
@ -193,17 +168,14 @@ namespace XenAdmin.Controls
return SelectedAffinity != null || DynamicRadioButton.Checked;
}
private void affinityListBox_SelectedValueChanged(object sender, EventArgs e)
{
UpdateControl();
}
// we dont need to bother firing events if the other radio button gets checked or unchecked
private void StaticRadioButton_CheckedChanged(object sender, EventArgs e)
{
if (StaticRadioButton.Checked && SelectedServer() == null)
SelectSomething();
UpdateControl();
SelectedAffinityChanged?.Invoke();
if (StaticRadioButton.Checked)
ServersGridView.Select();
@ -217,8 +189,6 @@ namespace XenAdmin.Controls
ServersGridView.Select();
}
bool selectedOnVisibleChanged = false;
private void ServersGridView_VisibleChanged(object sender, EventArgs e)
{
if (!selectedOnVisibleChanged)
@ -227,6 +197,12 @@ namespace XenAdmin.Controls
SelectSomething();//CA-213728
}
}
private void ServersGridView_SelectionChanged(object sender, EventArgs e)
{
UpdateControl();
SelectedAffinityChanged?.Invoke();
}
}
internal class ServerGridRow : DataGridViewExRow

View File

@ -269,7 +269,7 @@ namespace XenAdmin.Wizards.NewVMWizard
{
if (!page_4_HomeServer.DisableStep)
{
m_affinity = page_4_HomeServer.SelectedHomeServer;
m_affinity = page_4_HomeServer.Affinity;
page_6_Storage.Affinity = m_affinity;
page_CloudConfigParameters.Affinity = m_affinity;
}

View File

@ -36,7 +36,7 @@ namespace XenAdmin.Wizards.NewVMWizard
//
resources.ApplyResources(this.affinityPicker1, "affinityPicker1");
this.affinityPicker1.Name = "affinityPicker1";
this.affinityPicker1.SelectedAffinityChanged += new System.EventHandler(this.affinityPicker1_SelectedAffinityChanged);
this.affinityPicker1.SelectedAffinityChanged += new System.Action(this.affinityPicker1_SelectedAffinityChanged);
//
// Page_HomeServer
//

View File

@ -29,6 +29,7 @@
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using XenAdmin.Actions.VMActions;
using XenAPI;
@ -49,31 +50,18 @@ namespace XenAdmin.Wizards.NewVMWizard
#region XenTabPage overrides
public override string Text
{
get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME; }
}
public override string Text => Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME;
public override string PageTitle
{
get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE; }
}
public override string PageTitle => Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE;
public override string HelpID
{
get { return "HomeServer"; }
}
public override string HelpID => "HomeServer";
public override List<KeyValuePair<string, string>> PageSummary
{
get
public override List<KeyValuePair<string, string>> PageSummary =>
new List<KeyValuePair<string, string>>
{
List<KeyValuePair<string, string>> sum = new List<KeyValuePair<string, string>>();
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER,
Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE));
return sum;
}
}
new KeyValuePair<string, string>(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER,
Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE)
};
public override bool EnableNext()
{
@ -122,17 +110,16 @@ namespace XenAdmin.Wizards.NewVMWizard
#region Accessors
public Host SelectedHomeServer { get { return affinityPicker1.SelectedAffinity; } }
public Host Affinity { private get; set; }
public Host Affinity { get; set; }
public VM SelectedTemplate { private get; set; }
public InstallMethod SelectedInstallMethod { private get; set; }
public VDI SelectedCD { private get; set; }
#endregion
private void affinityPicker1_SelectedAffinityChanged(object sender, System.EventArgs e)
private void affinityPicker1_SelectedAffinityChanged()
{
Affinity = affinityPicker1.SelectedAffinity;
OnPageUpdated();
}
}