/* Copyright (c) Citrix Systems Inc. * All rights reserved. * * Redistribution and use in source and binary forms, * with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above * copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using XenAdmin.CustomFields; using XenAPI; using XenAdmin.XenSearch; namespace XenAdmin.Controls.XenSearch { public partial class GroupingControl : UserControl { private static readonly List potentialGroups; private static readonly FolderGroupingType folderGroupingType; private static readonly List customFields; private Searcher searcher; private NonReopeningContextMenuStrip contextMenuStrip; private Button lastButtonClicked; public static event Action CustomFieldRemoved; public event Action GroupingChanged; private const int MAX_GROUPS = 5; private const int innerGutter = 6; static GroupingControl() { potentialGroups = new List(); XenModelObjectPropertyGroupingType poolGroup = new XenModelObjectPropertyGroupingType(ObjectTypes.AllExcFolders & ~ObjectTypes.Pool, // i.e., all except Pool PropertyNames.pool, null); var applianceGroup = new XenModelObjectPropertyGroupingType(ObjectTypes.VM, PropertyNames.appliance, poolGroup); XenModelObjectPropertyGroupingType hostGroup = new XenModelObjectPropertyGroupingType(ObjectTypes.AllExcFolders & ~ObjectTypes.Pool & ~ObjectTypes.Server, PropertyNames.host, applianceGroup); potentialGroups.Add(poolGroup); potentialGroups.Add(hostGroup); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.VM, PropertyNames.os_name)); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.VM, PropertyNames.power_state)); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.VM, PropertyNames.virtualisation_status)); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.AllExcFolders, PropertyNames.type)); potentialGroups.Add(new XenModelObjectPropertyGroupingType(ObjectTypes.VM, PropertyNames.networks, poolGroup)); XenModelObjectPropertyGroupingType srGroup = new XenModelObjectPropertyGroupingType(ObjectTypes.VM | ObjectTypes.VDI, PropertyNames.storage, poolGroup); potentialGroups.Add(srGroup); potentialGroups.Add(new XenModelObjectPropertyGroupingType(ObjectTypes.VM, PropertyNames.disks, srGroup)); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.VM, PropertyNames.ha_restart_priority)); potentialGroups.Add(new BoolGroupingType(ObjectTypes.VM, PropertyNames.read_caching_enabled)); potentialGroups.Add(new BoolGroupingType(ObjectTypes.VM, PropertyNames.vendor_device_state)); potentialGroups.Add(applianceGroup); potentialGroups.Add(new PropertyGroupingType(ObjectTypes.AllExcFolders, PropertyNames.tags)); potentialGroups.Add(new XenModelObjectPropertyGroupingType( ObjectTypes.AllExcFolders & ~ObjectTypes.Pool & ~ObjectTypes.Server & ~ObjectTypes.VM, PropertyNames.vm, hostGroup)); potentialGroups.Add(new AllCustomFieldsGroupingType()); folderGroupingType = new FolderGroupingType(); customFields = new List(); OtherConfigAndTagsWatcher.OtherConfigChanged += OtherConfigWatcher_OtherConfigChanged; CustomFieldsManager.CustomFieldsChanged += OtherConfigWatcher_OtherConfigChanged; } private static void OtherConfigWatcher_OtherConfigChanged() { List customFieldDefinitions = CustomFieldsManager.GetCustomFields(); // Add new custom fields foreach (CustomFieldDefinition definition in customFieldDefinitions) if (!customFields.Exists(cf => cf.definition.Equals(definition))) customFields.Add(new CustomFieldGroupingType(ObjectTypes.AllExcFolders, definition)); // Remove old ones foreach (CustomFieldGroupingType customFieldGroupingType in customFields.ToArray()) if (!customFieldDefinitions.Exists(cfd => customFieldGroupingType.definition.Equals(cfd))) { customFields.Remove(customFieldGroupingType); OnCustomFieldRemoved(customFieldGroupingType); } } private static void OnCustomFieldRemoved(CustomFieldGroupingType groupingType) { if (CustomFieldRemoved != null) CustomFieldRemoved(groupingType); } private readonly List