// Check if the category is shown for the current category editor type
        private bool IsCategoryShown(Type categoryEditorType)
        {
            bool           ret            = true;
            CategoryEditor editorToRemove = (CategoryEditor)ExtensibilityAccessor.SafeCreateInstance(categoryEditorType);

            if (editorToRemove != null)
            {
                ModelCategoryEntry affectedCategory = _categoryList.FindCategory(editorToRemove.TargetCategory) as ModelCategoryEntry;
                if (affectedCategory == null)
                {
                    ret = false;
                }
            }
            else
            {
                ret = false;
            }
            return(ret);
        }
        // Helper method that adjusts the visible set of CategoryEditors based on the specified selection
        private void UpdateCategoryEditors(View.Selection selection)
        {
            // Figure out which category editors to show
            Dictionary <Type, object> newCategoryEditorTypes = _propertyToolBar.CurrentViewManager.GetCategoryEditors(
                FindCommonType(selection == null ? null : selection.SelectedObjects),
                _categoryList);

            // Figure out which CategoryEditors are no longer needed and remove them
            List <Type> editorTypesToRemove = null;

            foreach (KeyValuePair <Type, string> item in _activeCategoryEditors)
            {
                if (!newCategoryEditorTypes.ContainsKey(item.Key) || !IsCategoryShown(item.Key))
                {
                    // New selection does not include this existing category editor
                    // or the category that contains this editor
                    // so remove the editor.
                    if (editorTypesToRemove == null)
                    {
                        editorTypesToRemove = new List <Type>();
                    }

                    editorTypesToRemove.Add(item.Key);
                }
                else
                {
                    // This category editor already exists, so don't re-add it
                    newCategoryEditorTypes.Remove(item.Key);
                }
            }

            if (editorTypesToRemove != null)
            {
                foreach (Type editorTypeToRemove in editorTypesToRemove)
                {
                    ModelCategoryEntry affectedCategory = _categoryList.FindCategory(_activeCategoryEditors[editorTypeToRemove]) as ModelCategoryEntry;
                    if (affectedCategory != null)
                    {
                        affectedCategory.RemoveCategoryEditor(editorTypeToRemove);
                    }

                    _activeCategoryEditors.Remove(editorTypeToRemove);
                }
            }

            // Figure out which CategoryEditors are now required and add them
            foreach (Type editorTypeToAdd in newCategoryEditorTypes.Keys)
            {
                CategoryEditor editor = (CategoryEditor)ExtensibilityAccessor.SafeCreateInstance(editorTypeToAdd);
                if (editor == null)
                {
                    continue;
                }

                ModelCategoryEntry affectedCategory = _categoryList.FindCategory(editor.TargetCategory) as ModelCategoryEntry;
                if (affectedCategory == null)
                {
                    continue;
                }

                affectedCategory.AddCategoryEditor(editor);
                _activeCategoryEditors[editorTypeToAdd] = editor.TargetCategory;
            }
        }