Class TreeModel<TNodeData, TNodeKey, TSharedData>
TreeModels support tree-structured graphs of nodes and links. Each node can have at most one "tree parent"; cycles are not permitted. The reference to the parent node's key is a property of the child node data.
Implements
Namespace: Northwoods.Go.Models
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
public class TreeModel<TNodeData, TNodeKey, TSharedData> : Model<TNodeData, TNodeKey, TSharedData>, IModel where TNodeData : class, new() where TNodeKey : IEquatable<TNodeKey>
Type Parameters
Name | Description |
---|---|
TNodeData | |
TNodeKey | |
TSharedData |
Remarks
TreeModels, unlike GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>s, do not support arbitrary link relationships between nodes, nor is there a separate link data object for each parent-child relationship. Furthermore there is no support for grouping or label nodes.
The NodeParentKeyProperty property names the property on the node data whose value is the key of the "tree parent" node. The default value for this property is "Parent".
For example, one can define a graph consisting of one parent node with two child nodes:
model.NodeDataSource = new List<MyNodeData> {
new MyNodeData { Key = "Alpha" },
new MyNodeData { Key = "Beta", Parent = "Alpha" },
new MyNodeData { Key = "Gamma", Parent = "Alpha" }
};
If you need to show a more complicated graph structure than a tree, use a GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>. If you want to have multiple links between the same pair of nodes, or if you want to associate more information with each link and cannot put the information on the child node, you will need to have a separate link data object for each link, and that would require the use of GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>.
Constructors
TreeModel(TreeModel<TNodeData, TNodeKey, TSharedData>)
Constructs a copy of a given TreeModel, without copying the data.
Declaration
protected TreeModel(TreeModel<TNodeData, TNodeKey, TSharedData> model)
Parameters
Type | Name | Description |
---|---|---|
TreeModel<TNodeData, TNodeKey, TSharedData> | model |
TreeModel(IEnumerable<TNodeData>)
This constructs an empty TreeModel unless one provides arguments as the initial data array values for the NodeDataSource property.
Declaration
public TreeModel(IEnumerable<TNodeData> nodedatasource = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TNodeData> | nodedatasource | an optional collection containing objects to be represented by Nodes. |
Properties
NodeParentKeyProperty
Gets or sets the name of the property on node data that specifies the key of the node data that acts as the "parent" for this "child" node data.
Declaration
public string NodeParentKeyProperty { get; set; }
Property Value
Type | Description |
---|---|
string |
Remarks
The default value is the name "Parent", meaning that it expects the data to have a property named "Parent" if the node wants to refer to the parent node by its key. The value must not be null nor an empty string.
If you want to set this property you must do so before using the model, and especially before you assign Model.
See Also
ParentLinkCategoryProperty
Gets or sets the name of the data property that returns a string describing that node data's parent link's category.
Declaration
public string ParentLinkCategoryProperty { get; set; }
Property Value
Type | Description |
---|---|
string |
Remarks
The default value is the name "ParentLinkCategory". This is used by the diagram to distinguish between different kinds of links. The name must not be null. If the value is an empty string, GetParentLinkCategoryForNodeData(TNodeData) will return an empty string for all node data objects.
If you want to set this property you must do so before using the model, and especially before you assign Model.
See Also
Methods
CopyNodeData(TNodeData)
This override also makes sure any copied node data does not have a reference to a parent node.
Declaration
public override TNodeData CopyNodeData(TNodeData nodedata)
Parameters
Type | Name | Description |
---|---|---|
TNodeData | nodedata | an object represented by a node, group, or non-link. |
Returns
Type | Description |
---|---|
TNodeData |
Overrides
See Also
GetParentKeyForNodeData(TNodeData)
If there is a parent node for the given node data, return the parent's key.
Declaration
public TNodeKey GetParentKeyForNodeData(TNodeData nodedata)
Parameters
Type | Name | Description |
---|---|---|
TNodeData | nodedata | an object represented by a node. |
Returns
Type | Description |
---|---|
TNodeKey | This returns the default |
See Also
GetParentLinkCategoryForNodeData(TNodeData)
Find the category for the parent link of a given child node data, a string naming the link template that the Diagram should use to represent the link.
Declaration
public string GetParentLinkCategoryForNodeData(TNodeData childdata)
Parameters
Type | Name | Description |
---|---|---|
TNodeData | childdata | an object represented by a node data. |
Returns
Type | Description |
---|---|
string |
See Also
Set(object, string, object)
This override changes the value of some property of a node data or an item data, given a string naming the property and the new value, in a manner that can be undone/redone and that automatically updates any bindings.
Declaration
public override void Set(object data, string propname, object val)
Parameters
Type | Name | Description |
---|---|---|
object | data | an object typically the value of a Data and represented by a Node, Link, Group, simple Part, or item in a ItemList; or this model's SharedData. |
string | propname | a string that is not null or the empty string. |
object | val | the new value for the property. |
Overrides
Remarks
This gets the old value of the property; if the value is the same as the new value, no side-effects occur.
See Also
SetParentKeyForNodeData(TNodeData, TNodeKey)
Change the parent node for the given node data, given a key for the new parent.
Declaration
public void SetParentKeyForNodeData(TNodeData nodedata, TNodeKey key)
Parameters
Type | Name | Description |
---|---|---|
TNodeData | nodedata | an object represented by a node. |
TNodeKey | key | This may be the default |
See Also
SetParentLinkCategoryForNodeData(TNodeData, string)
Change the category for the parent link of a given child node data, a string naming the link template that the Diagram should use to represent the link.
Declaration
public void SetParentLinkCategoryForNodeData(TNodeData childdata, string cat)
Parameters
Type | Name | Description |
---|---|---|
TNodeData | childdata | an object represented by a node data. |
string | cat | Must not be null. |
Remarks
Changing the link template will cause any existing Link to be removed from the Diagram and replaced with a new Link created by copying the new link template and applying any data-bindings. Note that the new template must be an instance of the same class as the original link. Thus one cannot change the category of a link from an instance of Link to an instance of a subclass of Link, nor vice-versa.