Table of Contents

Class TreeModel<TNodeData, TNodeKey, TSharedData>

Namespace
Northwoods.Go.Models
Assembly
Northwoods.GoDiagram.WinForms.dll

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.

public class TreeModel<TNodeData, TNodeKey, TSharedData> : Model<TNodeData, TNodeKey, TSharedData>, IModel where TNodeData : class, new() where TNodeKey : IEquatable<TNodeKey>

Type Parameters

TNodeData
TNodeKey
TSharedData
Inheritance
Model<TNodeData, TNodeKey, TSharedData>
TreeModel<TNodeData, TNodeKey, TSharedData>
Implements
Inherited Members

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.

protected TreeModel(TreeModel<TNodeData, TNodeKey, TSharedData> model)

Parameters

model TreeModel<TNodeData, TNodeKey, TSharedData>

TreeModel(IEnumerable<TNodeData>)

This constructs an empty TreeModel unless one provides arguments as the initial data array values for the NodeDataSource property.

public TreeModel(IEnumerable<TNodeData> nodedatasource = null)

Parameters

nodedatasource IEnumerable<TNodeData>

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.

public string NodeParentKeyProperty { get; set; }

Property Value

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.

public string ParentLinkCategoryProperty { get; set; }

Property Value

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.

public override TNodeData CopyNodeData(TNodeData nodedata)

Parameters

nodedata TNodeData

an object represented by a node, group, or non-link.

Returns

TNodeData
See Also
CopyNodeData(TNodeData)

GetParentKeyForNodeData(TNodeData)

If there is a parent node for the given node data, return the parent's key.

public TNodeKey GetParentKeyForNodeData(TNodeData nodedata)

Parameters

nodedata TNodeData

an object represented by a node.

Returns

TNodeKey

This returns the default TNodeKey if there is no parent node data object.

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.

public string GetParentLinkCategoryForNodeData(TNodeData childdata)

Parameters

childdata TNodeData

an object represented by a node data.

Returns

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.

public override void Set(object data, string propname, object val)

Parameters

data object

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.

propname string

a string that is not null or the empty string.

val object

the new value for the property.

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.

public void SetParentKeyForNodeData(TNodeData nodedata, TNodeKey key)

Parameters

nodedata TNodeData

an object represented by a node.

key TNodeKey

This may be the default TNodeKey if there should be no parent node data.

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.

public void SetParentLinkCategoryForNodeData(TNodeData childdata, string cat)

Parameters

childdata TNodeData

an object represented by a node data.

cat string

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.

See Also