Hi, I’m trying to create a GraphLinksModel without using base classes GLMNodeData and GLMLinkData. Here are my node, link and port data.
And here is the kind of diagram I’m trying to do:
Here is the implementation of the model:
Public Class CustomModel
Inherits Northwoods.GoXam.Model.GraphLinksModel(Of INode, Guid, Connector, Stream)
Public Sub New()
MyBase.Modifiable = True
MyBase.NodeKeyPath = “Id”
MyBase.LinkFromParameterPath = “From”
MyBase.LinkToParameterPath = “To”
MyBase.NodesSource = New List(Of INode)
MyBase.LinksSource = New List(Of Stream)
End Sub
Protected Overrides Function InsertLink(fromdata As INode, fromparam As Connector, todata As INode, toparam As Connector) As Stream
If fromdata Is Nothing Then Return Nothing
If todata Is Nothing Then Return Nothing
Dim newStream As Stream = New Stream()
newStream.From = fromparam
newStream.To = toparam
Dim links As List(Of Stream) = TryCast(LinksSource, List(Of Stream))
links.Add(newStream)
The problem is that there is a mismatch between the capabilities of GraphLinksModel, which supports a parameterized type for the PortKey, and Diagram/PartManager, which does not – ports are always identified by strings only. So as a practical matter the PortKey must be String.
I suppose we could extend this mechanism by allowing you to provide conversion functions.
Ok, I changed the PortKey to String but now, I have another problem. When I create a link between 2 ports, it passes through the overrides InsertLink method, but the link doesn’t appear in the diagram.
CustomModel:
Public Class CustomModel
Inherits Northwoods.GoXam.Model.GraphLinksModel(Of INode, Guid, String, Stream)
Public Sub New()
MyBase.Modifiable = True
MyBase.NodeKeyPath = “Id” MyBase.LinkFromParameterPath = “FromToString” MyBase.LinkToParameterPath = “ToToString”
MyBase.LinkFromPath = “”
MyBase.LinkToPath = “”
MyBase.NodesSource = New List(Of INode)
MyBase.LinksSource = New List(Of Stream)
End Sub
Protected Overrides Function InsertLink(fromdata As INode, fromparam As String, todata As INode, toparam As String) As Stream
If fromdata Is Nothing Then Return Nothing
If todata Is Nothing Then Return Nothing
Dim newStream As Stream = New Stream()
newStream.From = New Guid(fromparam)
newStream.To = New Guid(toparam)
Dim links As List(Of Stream) = TryCast(LinksSource, List(Of Stream))
links.Add(newStream)
You appear to be using a List as the LinksSource and NodesSource collections. Because they do not implement INotifyCollectionChanged, you need to explicitly call model.DoLinkAdded or .DoNodeAdded when you add a link data or a node data to the respective collections. Otherwise GoXam cannot know that the collections have been modified.
That’s why most (all?) of the samples use ObservableCollection – to avoid having to call those model methods. Using collections that implement INotifyCollectionChanged is expected for normal binding and model usage in WPF and Silverlight.
FromToString and ToToString are the From and To property of the class Stream but in String format. I call it this way just for a test purpose. In other words, FromToString corresponds to the FromPort identifier and ToToString correspond to the ToPort identifier.
And for your information, Stream class doesn’t inherit from GLMLinkData.
To tell you the truth, it’s the first time that I work with Ports and I’m a little bit confused. I set model.LinkFromParameterPath = “FromToString” because Stream.FromToString corresponds to the FromPort. And I set model.LinkFromPath = “” because I thought that because Stream already knew from where it comes (FromToString), LinkFromPath was not necessary…
Should I add a new property referring to the From and ToNode in the class Stream?