private void NetworkComboBox_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; XenAPI.Network network = (XenAPI.Network)(e.Index == -1 ? NetworkComboBox.SelectedItem : NetworkComboBox.Items[e.Index]); if (network == null) { return; } string purpose = FindOtherPurpose(network); string label = purpose == null || purpose == Purpose? network.ToString() : string.Format(Messages.NETWORK_IN_USE_BY, network.ToString(), purpose); Brush text_brush = (e.State & DrawItemState.Selected) > 0 ? SystemBrushes.HighlightText : SystemBrushes.ControlText; e.DrawBackground(); g.DrawString(label, Program.DefaultFont, text_brush, new PointF(e.Bounds.X + 1, e.Bounds.Y + 1)); e.DrawFocusRectangle(); }
public void RefreshButtons() { XenAPI.Network network = (XenAPI.Network)NetworkComboBox.SelectedItem; string purpose = network == null ? null : FindOtherPurpose(network); InUseWarning = purpose == null || purpose == Purpose ? null : type == Type.SECONDARY && network == ManagementNetwork? string.Format(Messages.NETWORKING_PROPERTIES_IN_USE_WARNING_MANAGEMENT, network.ToString()) : string.Format(Messages.NETWORKING_PROPERTIES_IN_USE_WARNING, network.ToString(), purpose); PurposeLabel.Visible = PurposeTextBox.Visible = DeleteButton.Visible = (type == Type.SECONDARY); panelHAEnabledWarning.Visible = (type == Type.PRIMARY_WITH_HA); SetDNSControlsVisible(type != Type.SECONDARY); panelInUseWarning.Visible = InUseWarning != null; InUseWarningText.Text = InUseWarning; IpAddressSettingsLabel.Text = type == Type.SECONDARY ? Messages.NETWORKING_PROPERTIES_IP_SETTINGS : Messages.NETWORKING_PROPERTIES_IP_AND_DNS_SETTINGS; IPAddressLabel.Text = Pool ? Messages.IP_ADDRESS_RANGE_LABEL : Messages.IP_ADDRESS_LABEL; tableLayoutPanelStaticSettings.Enabled = FixedIPRadioButton.Checked; RangeEndLabel.Visible = Pool; Valid = InUseWarning == null && NetworkComboBox.SelectedIndex != -1 && (DHCPIPRadioButton.Checked || ((StringUtility.IsIPAddress(IPAddressTextBox.Text)) && StringUtility.IsValidNetmask(SubnetTextBox.Text) && IsOptionalIPAddress(GatewayTextBox.Text))) && (type == Type.SECONDARY || ((IsOptionalIPAddress(PreferredDNSTextBox.Text) && IsOptionalIPAddress(AlternateDNS1TextBox.Text) && IsOptionalIPAddress(AlternateDNS2TextBox.Text)))); // Grey out everything if HA is enabled: CA-24714 if (type == Type.PRIMARY_WITH_HA) { foreach (Control c in Controls) { c.Enabled = false; } haEnabledWarningIcon.Enabled = haEnabledRubric.Enabled = true; } var pif = Tag as PIF; var existingCluster = network != null?network.Connection.Cache.Clusters.FirstOrDefault() : null; if (pif != null && existingCluster != null) { Host host = network.Connection.Resolve(pif.host); ClusteringEnabled = network.Connection.Cache.Cluster_hosts.Any(cluster => cluster.host.opaque_ref == pif.host.opaque_ref && cluster.enabled); if (ClusteringEnabled) { if (host != null && host.enabled) { DisableControls(string.Format(Messages.CANNOT_CHANGE_IP_CLUSTERING_ENABLED, network.Name())); } else { DeleteButton.Enabled = false; tableLayoutInfo.Visible = true; labelWarning.Text = string.Format(Messages.CANNOT_REMOVE_IP_WHEN_CLUSTERING_ON_NETWORK, network.Name()); } } } }