HierarchyNodeListEditor. Getting Started

This topic illustrates how to apply HierarchyNodeListEditors to tree-like hierarchical structure. For this purpose we will implement simply business class and implement IHierarchyNode interface. Then we will set HierarchyNodeListEditor and run the application.

Follow the steps described below.

  • Add XafariModule, XafariEditorsModule and XafariBCModule to the platform-agnostic Module Project.
  • Add platform-dependent modules XafariWinModule, Xafari.Editors.Win and Xafari.BC.Win for the Win app, and XafariWebModule, Xafari.Editors.Web, and XafariBCWeb for the Web app.
  • Add HierarchyNodeObject class with the following code:
  • c#
  • VB

[DefaultClassOptions]
public class HierarchyNodeObject : BaseObject, IHierarchyNode
{
  public HierarchyNodeObject(Session session)
    : base(session)
  {
  }
  public String Name
  {
    get
    {
      return GetPropertyValue<String>("Name");
    }
    set
    {
      SetPropertyValue("Name", value);
    }
  }
  private HierarchyNodeObject _parent;
  [Association("Parent - Children")]
  [ParentProperty]
  public HierarchyNodeObject Parent
  {
    get
    {
      return _parent;
    }
    set
    {
      SetPropertyValue("Parent1", ref _parent, value);
    }
  }
  [Association("Parent - Children")]
  [ChildrenProperty]
  public XPCollection<HierarchyNodeObject> Children
  {
    get
    {
      return GetCollection<HierarchyNodeObject>("Children");
    }
  }
  public string GetHierarchyNodeName(string hierarchyName = null)
  {
    return this.Name;
  }
  public string GetHierarchyNodeFullName(string hierarchyName = null, string separator = "/")
  {
    var typeInfo = XafTypesInfo.Instance.FindTypeInfo(this.GetType());
    var fullNameMember = typeInfo.Type.GetHierarchyMember<HierarchyFullNamePropertyAttribute>(hierarchyName);
    if (fullNameMember != null && fullNameMember.MemberType == typeof(string))
      return (string)fullNameMember.GetValue(this);
    return null;
  }
  public IHierarchyNode GetHierarchyParent(string hierarchyName = null)
  {
    return HierarchyNodePersistentHelper.GetParent(this, hierarchyName);
  }
  public IList GetHierarchyChildren(string hierarchyName = null)
  {
    return HierarchyNodePersistentHelper.GetChildren(this, hierarchyName);
  }
}

<DefaultClassOptions> _
Public Class HierarchyNodeObject
  Inherits BaseObject
  Implements IHierarchyNode
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Property Name As String
    Get
      Return GetPropertyValue(Of String)("Name")
    End Get
    Set
      SetPropertyValue("Name", value)
    End Set
  End Property
  Private __parent As HierarchyNodeObject
  <Association("Parent - Children")> _
<ParentProperty> _
Public Property Parent As HierarchyNodeObject
    Get
      Return __parent
    End Get
    Set
      SetPropertyValue("Parent1", __parent, value)
    End Set
  End Property
  <Association("Parent - Children")> _
<ChildrenProperty> _
Public ReadOnly Property Children As XPCollection(Of HierarchyNodeObject)
    Get
      Return GetCollection(Of HierarchyNodeObject)("Children")
    End Get
  End Property
  Public Function GetHierarchyNodeName(Optional ByVal hierarchyName As String = Nothing) As String
    Return Me.Name
  End Function
  Public Function GetHierarchyNodeFullName(Optional ByVal hierarchyName As String = Nothing, Optional ByVal separator As String = "/") As String
    Dim typeInfo = XafTypesInfo.Instance.FindTypeInfo(Me.[GetType]())
    Dim fullNameMember = typeInfo.Type.GetHierarchyMember(Of HierarchyFullNamePropertyAttribute)(hierarchyName)
    If fullNameMember IsNot Nothing AndAlso fullNameMember.MemberType = GetType(String) Then
      Return CType(fullNameMember.GetValue(Me), String)
    End If
    Return Nothing
  End Function
  Public Function GetHierarchyParent(Optional ByVal hierarchyName As String = Nothing) As IHierarchyNode
    Return HierarchyNodePersistentHelper.GetParent(Me, hierarchyName)
  End Function
  Public Function GetHierarchyChildren(Optional ByVal hierarchyName As String = Nothing) As IList
    Return HierarchyNodePersistentHelper.GetChildren(Me, hierarchyName)
  End Function
End Class

  • Add modules XafariEditorsModule and TreeListEditorsModuleBase to Module Project.
  • Add modules XafariEditorsWebModule and TreeListEditorsAspNetModule to the ASP.NET application project, add modules XafariEditorsWinModule and TreeListEditorsWindowsFormsModule to Windows Forms Application Project.
  • Invoke the Model Editor. Navigate to the Views|...|HierarchyNodeObject_ListView node as shown in the image below. Set the EditorType property to Xafari.Editors.Win.WinTreeListEditor for the Windows Forms application.
  • For the ASP.NET application project set the EditorType property to Xafari.Editors.Web.ASPxHierarchyNodeListEditor.

hierarchy_node_list_editor_3

  • Run the application (whether Windows Forms or ASP.NET). Create a number of hierarchical objects and see editor functionality in action.

Windows Forms:

hierarchy_node_list_editor_4

ASP.NET:

hierarchy_node_list_editor_5

When using Drag-and-Drop on tree list nodes, the confirmation popup window is shown to the user by default (see the image below):

hierarchy_node_list_editor_6

It is possible to disable this message if needed. To do it, invoke the Model Editor and navigate to the Options|Editors|HierarchyPropertyEditor node. Then, set the DragAndDropDialogConfirmationEnabled property to the False value (as shown in the figure below).

hierarchy_node_list_editor_7

You can download the solution used in this lesson for deeper examination.