Пример #1
0
    /// <summary>
    /// Make sure a <see cref="Link"/> exists for the link relationship between the given
    /// pair of node data, added to the <see cref="LinkLayer"/>
    /// specified by its <see cref="Part.LayerName"/>.
    /// </summary>
    /// <param name="fromnodedata">the data from which the link relationship comes</param>
    /// <param name="tonodedata">the data to which the link relationship goes</param>
    /// <param name="model">the model that the node data are in, not an <see cref="Northwoods.GoXam.Model.ILinksModel"/></param>
    /// <returns>
    /// the <see cref="Link"/> for the connecting the two node data,
    /// either an existing one or a newly created one,
    /// or null if <see cref="FilterLinkForData(Object, Object, IDiagramModel)"/> returns false or if the diagram is uninitialized
    /// </returns>
    /// <remarks>
    /// <para>
    /// If the diagram already has a <see cref="Link"/> for the pair of node data,
    /// as determined by <see cref="FindLinkForData(Object, Object, IDiagramModel)"/>,
    /// or if <see cref="FilterLinkForData(Object, Object, IDiagramModel)"/> is false,
    /// this method will do nothing.
    /// </para>
    /// <para>
    /// The implementation of this method should not modify the model.
    /// </para>
    /// </remarks>
    public Link AddLinkForData(Object fromnodedata, Object tonodedata, IDiagramModel model) {
      if (fromnodedata == null || tonodedata == null) return null;
      VerifyAccess();
      Diagram diagram = this.Diagram;
      if (diagram == null) return null;
      DiagramPanel panel = diagram.Panel;
      if (panel == null) return null;
      if (model is ILinksModel) Diagram.Error("Diagram.AddLinkForData(Object, Object) cannot be used with an ILinksModel");
      Link oldlink = FindLinkForData(fromnodedata, tonodedata, model);
      if (oldlink != null) {
        UpdateCachedMembership(model, oldlink);
        return oldlink;
      }
      if (!FilterLinkForData(fromnodedata, tonodedata, model)) return null;

      // the "data" for this link is artificial, a VirtualLinkData
      Object linkdata = new VirtualLinkData(fromnodedata, tonodedata);
      String category = FindCategoryForLink(linkdata, model);
      DataTemplate template = FindTemplateForLink(linkdata, model, category);
      Link newlink = MakeLinkForData(linkdata, model, template, category);
      VerifyTransaction(linkdata, model);
      if (newlink != null) {
        newlink.Model = model;
        // add to collection of Links
        _LinksDictionary[linkdata] = newlink;
        _Links.Add(newlink);
        // add to a temporary layer so that ApplyTemplate will be successful
        // so that any attached properties become available on the Part's VisualElement
        LinkLayer templayer = panel.GetLayer<LinkLayer>(DiagramPanel.ToolLayerName);
        if (templayer != null) {
          templayer.IsAddingLink = true;
          templayer.Add(newlink);
        }
        newlink.ApplyTemplate();  //?? virtualization
        //?? LayerName might not be correct value until after ApplyTemplate
        if (templayer != null) templayer.IsAddingLink = false;
        String layername = newlink.LayerName;
        LinkLayer layer = (this.TemporaryParts ? templayer : panel.GetLayer<LinkLayer>(layername));
        if (layer != null) {
          layer.Add(newlink);
          UpdateCachedMembership(model, newlink);
          UpdatePortKnots(newlink);
          //?? AddLogicalChild
          OnLinkAdded(newlink);
        }
      }
      return newlink;
    }
Пример #2
0
    // links for IConnectedModel and ITreeModel -- no link data exists, so we use the VirtualLinkData class

    /// <summary>
    /// Given a pair of node data for which there is a link relationship,
    /// find the corresponding <see cref="Link"/> in this diagram.
    /// </summary>
    /// <param name="fromnodedata">the data from which the link relationship comes</param>
    /// <param name="tonodedata">the data to which the link relationship goes</param>
    /// <param name="model">the model that the node data are in, not an <see cref="Northwoods.GoXam.Model.ILinksModel"/></param>
    /// <returns>a <see cref="Link"/>, or null if such a link has not been created for that pair of node data</returns>
    /// <remarks>
    /// <para>
    /// The implementation of this method should not modify the model.
    /// </para>
    /// </remarks>
    public Link FindLinkForData(Object fromnodedata, Object tonodedata, IDiagramModel model) {
      if (fromnodedata == null && tonodedata == null) return null;
      VerifyAccess();
      ILinksModel lmodel = model as ILinksModel;
      if (lmodel != null) {
        foreach (Object linkdata in lmodel.GetFromLinksForNode(tonodedata)) {
          if (lmodel.GetFromNodeForLink(linkdata) == fromnodedata) return FindLinkForData(linkdata, model);
        }
        return null;
      } else {
        Object linkdata = new VirtualLinkData(fromnodedata, tonodedata);
        return FindLinkForData(linkdata, model);
      }
    }