Relate+ uses the Club and Forum association property types to associate pages with Community entities. This is a great way to integrate community and editorial content. However, the edit control for the property uses a flat list of all available clubs/forums. As a community grows this list may grow out of bounds for efficient editing, which is why I saw the need to be able to browse say Clubs in a tree like with the Page property type.
I didn’t want to limit my property type to a certain structure or otherwise limit the source for the tree where the property value is selected. For that reason I created a generic control and an interface which should be implemented to feed the tree with data.
The class implementing the interface decides how the tree should be built. This way Clubs, Forums (or really anything) can be put in a tree sorted by Site, Category, first letter in name, or a combination of several of these, or anything else. The property edit control, inheriting an abstract class associated with the tree control, is still responsible for saving the value, so invalid selections (like selecting the “first letter in name” parent rather than a Club) can be disregarded.
The property types that can be used with the tree control are not limited, they can be based on PropertyNumber, PropertyString or anything else. The representation (as strings) is controlled by your implementation. Internally in the tree control the values are treated as strings (by calling the ToString method of your PropertyData.Value). This example uses a property type derived from PropertyNumber to represent a Category in EPiServer Community.
This is the code implementing the data feeding interface, IHierarchialdata, in the class CommunityCategoryData:
2:/// Represents the categories in the current EPiServer Community installation,
75:/// Helper method which gets the ICategory object corresponding to an ID as a string
77:/// <param name="key">The ID as a string</param>
79:protected ICategory GetCategory(string key)
81: ICategory cat = null;
83:if (int.TryParse(key, out id))
85: cat = CategoryHandler.GetCategory(id);
As you can see all it does is basically to feed data according to the category tree from the Community database, as well as implement some required settings for the dialog and user friendly names for the categories when displayed in edit mode.
Needed is also the property control (and of course the property, but that only overrides the CreatePropertyControl method), which is based on the abstract HierarchialSelectionControlBase class which is responsible for rendering the controls:
2:/// Implementation of the HierarchicalSelectionControlBase used by
11:// Return the type of the class responsible for returning the
12:// hierarchial data to the HierarchialBrowser control
18:/// Overridden method which sets the height and width of the
24:base.DialogWidth = 480;
25:base.DialogHeight = 640;
29:/// Overridden method which sets the value selected in the dialog,
30:/// taking into consideration that the dialog uses a string representation
31:/// and that the property used is based on PropertyNumber
35:// Parse the string value, default to 0
36:int id = 0;
37:int.TryParse(this.EditControl.Value, out id);
As you can see, this is were we provide information where the control should get it’s tree data from (the CommunityCategoryData class) and make sure the value is saved in correct form (remember it’s represented by a string by calling your PropertyData.Value.ToString() when loaded).
The community category property type looks like this:
And the dialog when launched looks like this:
The source code for the base classes and interfaces, the page used in the dialog as well as the Community category example implementation can be downloaded from http://www.mediafire.com/src (the file HierarchialBrowser-src-20090421.zip)