Hierarchy Attributes

For declaring the properties that refer to the parent and the child node, use the ParentPropertyAttribute and the ChildrenPropertyAttribute respectively. The property that defines the hierarchy name should be decorated with the HierarchyNodeNamePropertyAttribute. The properties that define the full name and the full path should be decorated with the HierarchyFullNamePropertyAttribute and the HierarchyFullPathPropertyAttribute respectively.

Important:

IHierarchyNode interface supports multiple hierarchies. If the object implements two or more hierarchies, you should use attributes with the parameter that specifies the name of the hierarchy.

  • example

[ParentProperty(Hierarchy1)]
 [ChildrenProperty(Hierarchy1)]
 [HierarchyNodeNameProperty(Hierarchy1)]
 [HierarchyFullNameProperty(Hierarchy1)]
 [HierarchyFullPathProperty(Hierarchy1)]

To specify how the object should be removed, pass the chosen way of deletion to the ChildrenPropertyAttribute as a parameter:

  • example

[ChildrenProperty("Hierarchy1", DeletingMode = DeletingMode.Replacement)]

You will also need to override the OnDeleting() method. Call the DeleteObject() method of the HierarchyManager class:

  • c#
  • VB

protected override void OnDeleting()
{
  base.OnDeleting();
  HierarchyManager.Instance.GetHierarchyInfo<ExampleIHierarchyNode>().DeleteObject(this);
}

Protected Overrides Sub OnDeleting()
  MyBase.OnDeleting()
  HierarchyManager.Instance.GetHierarchyInfo(Of ExampleIHierarchyNode)().DeleteObject(Me)
End Sub

One of the following three methods can be used to check whether child elements exist:

  • DirectDatabaseCount – requests "Exists()" directly to the database.
  • CollectionCount – obtains the collection of all child elements and compares the number of elements in the collection to zero.
  • Default – DirectDatabaseCount is used if no objects are edited, otherwise CollectionCount is used.

To specify a particular method, use the GetChildrenCountMode parameter of the ChildrenPropertyAttribute.

  • example

[ChildrenProperty GetChildrenCountMode = GetChildrenCountMode.DirectDatabaseCount)]

To prevent possible looping, use the CheckCircularReference method of the HierarchyManager class.

  • example

HierarchyManager.Instance.GetHierarchyInfo<ExampleIHierarchyNode>().CheckCircularReference(hierarchyNodeObject);

The IModelClassXafari interface was extended to suit hierarchical objects. The Application Model now has two addition parameters: DefaultTreeListView and DefaultGridListView.

ihierarchynode_interface_2

The DefaultTreeListView parameter specifies the default List View with a tree-like editor.

The DefaultGridListView parameter specifies default List View with a list Editor (for example, GridListEditor).

HierarchyNode and HierarchicalClassifierItem

The Xafari framework provides the developer with two ready-made types implementing the IHierarchyNode interface: HierarchyNode and HierarchicalClassifierItem.

The use cases can be found in the demo applications:

  • Northwind DC: Employee.cs, Department.cs
  • Feature Center: DCIHierarchyNodeObject.cs

After removing the HierarchicalClassifierItem object, the removal modifier counts. The AfterConstruction and OnDeleting methods are virtual.