private void RestoreGridHomeServerSelectionFromMapping() { foreach (DataGridViewRow row in m_dataGridView.Rows) { string sysId = (string)row.Cells[0].Tag; if (m_vmMappings.ContainsKey(sysId)) { var mapping = m_vmMappings[sysId]; DataGridViewEnableableComboBoxCell cbCell = row.Cells[m_colTarget.Index] as DataGridViewEnableableComboBoxCell; if (cbCell == null) { return; } List <IEnableableXenObjectComboBoxItem> list = cbCell.Items.OfType <IEnableableXenObjectComboBoxItem>().ToList(); IEnableableXenObjectComboBoxItem item = list.FirstOrDefault(cbi => MatchingWithXenRefObject(cbi, mapping.XenRef)); if (item != null) { cbCell.Value = item; } } } }
private void SetComboBoxPreSelection(DataGridViewEnableableComboBoxCell cb) { if (cb.Value == null) { var firstEnabled = cb.Items.OfType <IEnableableComboBoxItem>().FirstOrDefault(i => i.Enabled); if (firstEnabled != null) { cb.Value = firstEnabled; SetButtonNextEnabled(true); } else { SetButtonNextEnabled(false); } } else { SetButtonNextEnabled(true); } }
private void SetComboBoxPreSelection(DataGridViewEnableableComboBoxCell cb) { if (cb.Value == null) { if (cb.Items.Count > 0) { if (cb.Items.OfType <IEnableableComboBoxItem>().All(i => !i.Enabled)) { cb.Value = null; SetButtonNextEnabled(false); } else { cb.Value = cb.Items.OfType <IEnableableComboBoxItem>().First(i => i.Enabled); } } else { SetButtonNextEnabled(false); //do not allow to leave the page if a vm has no target } } }
private void PopulateDataGridView(IEnableableXenObjectComboBoxItem selectedItem) { Program.AssertOnEventThread(); updatingHomeServerList = true; try { var target = m_comboBoxConnection.SelectedItem as DelayLoadingOptionComboBoxItem; m_dataGridView.SuspendLayout(); ClearDataGridView(); var hasPoolSharedStorage = target != null && HasPoolSharedStorage(target.Item.Connection); foreach (var kvp in m_vmMappings) { var tb = new DataGridViewTextBoxCell { Value = kvp.Value.VmNameLabel, Tag = kvp.Key }; var cb = new DataGridViewEnableableComboBoxCell { FlatStyle = FlatStyle.Flat }; var homeserverFilters = CreateTargetServerFilterList(selectedItem, new List <string> { kvp.Key }); if (target != null) { if (hasPoolSharedStorage) { foreach (var pool in target.Item.Connection.Cache.Pools) { var item = new NoTargetServerPoolItem(pool); cb.Items.Add(item); if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) || (target.Item.opaque_ref == pool.opaque_ref)) { cb.Value = item; } break; //there exists one pool per connection } } var sortedHosts = new List <Host>(target.Item.Connection.Cache.Hosts); sortedHosts.Sort(); foreach (var host in sortedHosts) { var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters); item.LoadSync(); cb.Items.Add(item); if (item.Enabled && ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) || (target.Item.opaque_ref == host.opaque_ref))) { cb.Value = item; } } } SetComboBoxPreSelection(cb); var row = new DataGridViewRow(); row.Cells.AddRange(tb, cb); m_dataGridView.Rows.Add(row); } HelpersGUI.ResizeGridViewColumnToAllCells(m_colTarget); //set properly the width of the last column if (restoreGridHomeServerSelection) { RestoreGridHomeServerSelectionFromMapping(); restoreGridHomeServerSelection = false; } } finally { updatingHomeServerList = false; m_dataGridView.ResumeLayout(); } }
private void PopulateDataGridView(List <ReasoningFilter> homeserverFilters) { Program.AssertOnEventThread(); updatingHomeServerList = true; try { Connection = null; var target = m_comboBoxConnection.SelectedItem as DelayLoadingOptionComboBoxItem; if (target != null) { Connection = target.Item.Connection; } ClearDataGridView(); SetButtonNextEnabled(true); var hasPoolSharedStorage = HasPoolSharedStorage(); foreach (var kvp in m_vmMappings) { var tb = new DataGridViewTextBoxCell { Value = kvp.Value.VmNameLabel, Tag = kvp.Key }; var cb = new DataGridViewEnableableComboBoxCell { FlatStyle = FlatStyle.Flat }; if (Connection != null) { if (hasPoolSharedStorage) { foreach (var pool in Connection.Cache.Pools) { var item = new DoNotAssignHomeServerPoolItem(pool); cb.Items.Add(item); if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) || (target != null && target.Item.opaque_ref == pool.opaque_ref)) { cb.Value = item; } break; //there exists one pool per connection } } foreach (var host in Connection.Cache.Hosts) { HomeServerItem item = new HomeServerItem(host, homeserverFilters); cb.Items.Add(item); if ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) || (target != null && target.Item.opaque_ref == host.opaque_ref)) { cb.Value = item; } } } SetComboBoxPreSelection(cb); var row = new DataGridViewRow(); row.Cells.AddRange(tb, cb); m_dataGridView.Rows.Add(row); } HelpersGUI.ResizeLastGridViewColumn(m_colTarget); //set properly the width of the last column if (restoreGridHomeServerSelection) { RestoreGridHomeServerSelectionFromMapping(); restoreGridHomeServerSelection = false; } } finally { updatingHomeServerList = false; } }