Example #1
0
        public RelDocNodeProxy(Main.IDocumentLeafNode docNode, Main.IDocumentNode parentNode)
        {
            if (null == docNode)
            {
                throw new ArgumentNullException(nameof(docNode));
            }
            if (null == parentNode)
            {
                throw new ArgumentNullException(nameof(parentNode));
            }
            var docNodeRoot    = Main.AbsoluteDocumentPath.GetRootNode(docNode);
            var parentNodeRoot = Main.AbsoluteDocumentPath.GetRootNode(parentNode);

            if (!object.ReferenceEquals(docNodeRoot, parentNodeRoot))
            {
                throw new ArgumentException(string.Format("parentNode (type: {0}) and docNode (type: {1}) have no common root. This suggests that one of the items is not rooted. Please report this error! The type of the parent node's root is {2}. The type of the docNode's root is {3}.", parentNode.GetType(), docNode.GetType(), parentNodeRoot.GetType(), docNodeRoot.GetType()));
            }

            InternalSetDocNode(docNode, parentNode);

            if (!(_docNodePath != null))
            {
                throw new InvalidProgramException(); // because we tested above that both nodes have a common root
            }
            _parent = parentNode;
        }
Example #2
0
        /// <summary>
        /// Sets the document node that is held by this proxy.
        /// </summary>
        /// <param name="value">The document node. If <c>docNode</c> implements <see cref="Main.IDocumentLeafNode" />,
        /// the document path is stored for this object in addition to the object itself.</param>
        /// <param name="parentNode">The start point of the document path. Should be equal to the member _parent, but this might be not set now.</param>
        protected void InternalSetDocNode(Main.IDocumentLeafNode value, IDocumentLeafNode parentNode)
        {
            if (!IsValidDocument(value))
            {
                throw new ArgumentException("This type of document is not allowed for the proxy of type " + GetType().ToString());
            }
            if (null == parentNode)
            {
                throw new InvalidOperationException("Parent of this node must be set in order to set the docnode.");
            }

            var oldValue = InternalDocNode;

            if (object.ReferenceEquals(oldValue, value))
            {
                return; // Nothing to do
            }
            if (null != _weakDocNodeChangedHandler)
            {
                _weakDocNodeChangedHandler.Remove();
                _weakDocNodeChangedHandler = null;
            }
            if (null != _weakDocNodeTunneledEventHandler)
            {
                _weakDocNodeTunneledEventHandler.Remove();
                _weakDocNodeTunneledEventHandler = null;
            }

            if (null != oldValue)
            {
                ClearDocNode();
            }

            var newPath = RelativeDocumentPath.GetRelativePathFromTo(parentNode, value);

            if (null != newPath)
            {
                InternalDocumentPath = newPath; // especially in dispose situations, the new path can be null. In this case we leave the path as it was
            }
            _docNodeRef = new WeakReference(value);

#if DEBUG_DOCNODEPROXYLOGGING
            Current.Console.WriteLine("RelDocNodeProxy.SetDocNode, path is <<{0}>>", _docNodePath);
#endif

            value.TunneledEvent += (_weakDocNodeTunneledEventHandler = new WeakActionHandler <object, object, TunnelingEventArgs>(EhDocNode_TunneledEvent, handler => value.TunneledEvent -= handler));

            if (null != _docNodePath && !_docNodePath.IsIdentity) // it does not make sense to watch the changed event of our target node is our parent because the parent can handle the Changed event itself
            {
                value.Changed += (_weakDocNodeChangedHandler = new WeakEventHandler(EhDocNode_Changed, handler => value.Changed -= handler));
            }

            OnAfterSetDocNode();

            EhSelfChanged(new Main.InstanceChangedEventArgs(oldValue, value));
        }
 public override string GetNameOfChildObject(Main.IDocumentLeafNode obj)
 {
     if (obj is TItem item)
     {
         if (_itemsByName.ContainsKey(item.Name))
         {
             return(item.Name);
         }
     }
     return(null);
 }
Example #4
0
 public override string GetNameOfChildObject(Main.IDocumentLeafNode o)
 {
     if (o is DataTable)
     {
         var gr = (DataTable)o;
         if (_itemsByName.ContainsKey(gr.Name))
         {
             return(gr.Name);
         }
     }
     return(null);
 }
        public override string GetNameOfChildObject(Main.IDocumentLeafNode o)
        {
            var layout = o as WorksheetLayout;

            if (layout == null)
            {
                return(null);
            }
            if (null == this[layout.Guid])
            {
                return(null); // is not contained in this collection
            }
            return(layout.Guid.ToString());
        }
Example #6
0
        protected virtual IDocumentLeafNode ResolveDocumentObject(Main.IDocumentLeafNode startnode)
        {
            if (IsDisposeInProgress)
            {
                return(null);
            }

            if (!(_docNodePath != null || IsDisposeInProgress))
            {
                throw new InvalidProgramException();
            }

            var docNode = InternalDocumentNode;

            if (docNode == null)
            {
#if DEBUG_DOCNODEPROXYLOGGING
                Current.Console.WriteLine("DocNodeProxy.ResolveDocumentObject, path is <<{0}>>", _docNodePath);
#endif

#if DOCNODEPROXY_CONCURRENTDEBUG
                _debug.Enqueue("START ResolveDocumentObject");
#endif

                var node = Main.AbsoluteDocumentPath.GetNodeOrLeastResolveableNode(_docNodePath, startnode, out var wasCompletelyResolved);
                if (null == node)
                {
                    throw new InvalidProgramException("node should always be != null, since we use absolute paths, and at least an AltaxoDocument should be resolved here.");
                }

                if (wasCompletelyResolved)
                {
                    SetDocNode(node);
                    docNode = InternalDocumentNode;
                }
                else // not completely resolved
                {
                    SetWatchOnNode(node);
                }

#if DOCNODEPROXY_CONCURRENTDEBUG
                _debug.Enqueue("STOP  ResolveDocumentObject");
#endif
            }
            return(docNode);
        }
Example #7
0
 /// <summary>
 /// Gets the parent GraphDocumentCollection of a child graph.
 /// </summary>
 /// <param name="child">A graph for which the parent collection is searched.</param>
 /// <returns>The parent GraphDocumentCollection, if it exists, or null otherwise.</returns>
 public static GraphDocumentCollection GetParentGraphDocumentCollectionOf(Main.IDocumentLeafNode child)
 {
     return((GraphDocumentCollection)Main.AbsoluteDocumentPath.GetRootNodeImplementing(child, typeof(GraphDocumentCollection)));
 }
Example #8
0
 /// <summary>
 /// Gets the parent DataTableCollection of a child table, a child ColumnCollection, or a child column.
 /// </summary>
 /// <param name="child">Can be a DataTable, a DataColumnCollection, or a DataColumn for which the parent table collection is searched.</param>
 /// <returns>The parent DataTableCollection, if it exists, or null otherwise.</returns>
 public static Altaxo.Data.DataTableCollection GetParentDataTableCollectionOf(Main.IDocumentLeafNode child)
 {
     return((DataTableCollection)Main.AbsoluteDocumentPath.GetRootNodeImplementing(child, typeof(DataTableCollection)));
 }
Example #9
0
 /// <summary>
 /// Gets the parent ProjectFolderPropertyBagCollection of a child graph.
 /// </summary>
 /// <param name="child">A graph for which the parent collection is searched.</param>
 /// <returns>The parent ProjectFolderPropertyBagCollection, if it exists, or null otherwise.</returns>
 public static ProjectFolderPropertyDocumentCollection GetParentProjectFolderPropertyBagCollectionOf(Main.IDocumentLeafNode child)
 {
     return((ProjectFolderPropertyDocumentCollection)Main.AbsoluteDocumentPath.GetRootNodeImplementing(child, typeof(ProjectFolderPropertyDocumentCollection)));
 }