/// <summary>
        ///     Fired when the current document changes.
        /// </summary>
        /// <param name="oldView">Previous DocData</param>
        /// <param name="newView">Current DocData</param>
        protected override void OnDocumentWindowChanged(ModelingDocView oldView, ModelingDocView newView)
        {
            var newModelingData = newView != null ? newView.DocData : null;

            if (newModelingData != null &&
                IsDocumentSupported(newModelingData))
            {
                var store = newModelingData.Store;
                if (store != null)
                {
                    if (_currentDocData != null)
                    {
                        // if we're switching stores, make sure we clear the tree.  Prevents store disposed exceptions if
                        // the currentDocData.Store is disposed before we switch back to it.
                        if (newModelingData.Store != _currentDocData.Store)
                        {
                            // clear tree data, causes event handlers to be removed from our branches.
                            if (_treeProvider != null)
                            {
                                _treeProvider.Root = null;
                            }

                            // clear cached selection
                            _currentSelection    = null;
                            _currentBrowseObject = null;
                        }

                        // disable column event handlers
                        _treeControl.RemoveColumnEventHandlers();

                        // unsubscribe from document closing event
                        _currentDocData.DocumentClosing -= OnDocumentClosing;
                    }

                    // enable column event handlers
                    _treeControl.AddColumnEventHandlers();

                    // subscribe to document closing event
                    newModelingData.DocumentClosing += OnDocumentClosing;

                    // cache the doc data, so we can unsubscribe properly.  We cannot
                    // unsubscribe using oldView.DocData, because we may get an OnDocumentWindowChanged(oldModelingData, null)
                    // just prior to a document close.  In that case, we'd unsubscribe too early, and not clean up properly
                    // in OnDocumentClosed.  Instead we wait until either we get a new supported document, or the old one closes.
                    _currentDocData = newModelingData;
                }
            }
            else
            {
                // it's possible that the oldView is not some docData we support, in that case, don't do anything
                var oldModelingData = oldView != null ? oldView.DocData : null;
                if (oldModelingData != null &&
                    IsDocumentSupported(oldModelingData))
                {
                    // Null or unsupported view, clear our selection context.  Note that we leave the tree populated
                    // here so that in the common case of switching back and forth between designer and code, we
                    // don't lose selection/expansion state in the tree.  We also clear/save the selection context,
                    // because we don't want to push anything to the property browser while the watermark is showing.
                    _currentBrowseObject = PrimarySelection;
                    SetSelectedComponents(new object[] { });
                    if (_containerControl != null)
                    {
                        _containerControl.WatermarkVisible = true;
                    }
                }
            }
        }