Пример #1
0
        internal void ClearChildren()
        {
            if (_children != null)
            {
                var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(_context);
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(_context);

                // remove children from xref recursively
                foreach (var child in _children)
                {
                    child.ClearChildren();
                    child.Parent = null;

                    // if in Search Results remove from them
                    explorerSearchResults.RemoveElementFromSearchResults(child);

                    if (child.ModelItem != null)
                    {
                        xref.Remove(child.ModelItem);
                    }
                }

                // clear the list
                _children.Clear();
            }
        }
Пример #2
0
        internal static ExplorerSearchResults GetExplorerSearchResults(EditingContext context)
        {
            var explorerSearchResults = context.Items.GetValue <ExplorerSearchResults>();

            if (null == explorerSearchResults)
            {
                explorerSearchResults = new ExplorerSearchResults();
                context.Items.SetValue(explorerSearchResults);
            }

            return(explorerSearchResults);
        }
Пример #3
0
        internal virtual void RemoveChildIfLoaded(EFElement efChildElementToRemove)
        {
            // only remove this child if we have already loaded from model
            // if we have not yet loaded then this child (or rather lack thereof)
            // will be picked up next time Children is called
            if (_hasLoadedFromModel)
            {
                var xref                  = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(_context);
                var explorerElement       = xref.GetExisting(efChildElementToRemove);
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(_context);

                if (explorerElement != null)
                {
                    if (RemoveChild(explorerElement))
                    {
                        if (_children.Contains(explorerElement))
                        {
                            explorerElement.ClearChildren();

                            // if in Search Results remove explorerElement from them
                            explorerSearchResults.RemoveElementFromSearchResults(explorerElement);

                            xref.Remove(efChildElementToRemove);
                            explorerElement.Parent = null;
                            _children.Remove(explorerElement);
                            return;
                        }
                    }

                    // this means efChildElementToRemove is a valid
                    // EFElement which we have mapped in our ViewModel
                    // but that we're trying to remove it when this
                    // ExplorerEFElement is not the child element's parent
                    Debug.Assert(
                        false, string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.BadRemoveChildNotParent, explorerElement.Name, Name));
                    return;
                    // TODO: we need to provide a general exception-handling mechanism and replace the above Assert()
                    // by e.g. the excepiton below
                    // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                    //     Resources.BadRemoveChildNotParent, explorerElement.Name, this.Name));
                }

                // otherwise the Model child element does not map to any
                // ViewModel element - this is valid as we do not display
                // all children
                return;
            }
        }
Пример #4
0
        internal ExplorerSearchResults ExpandViewModelToDisplaySearchResults(ModelSearchResults modelSearchResults)
        {
            // Loop through each Model item in the search results list and
            // use NavigationHelper to navigate to the search result - this
            // will automatically expand the tree view as necessary
            foreach (var result in modelSearchResults.Results)
            {
                GetExplorerEFElementForEFObject(ViewModel.EditingContext, result);
            }

            // must recalculate results _after_ navigation above, otherwise some ViewModel elements
            // may not have been loaded
            var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(ViewModel.EditingContext);

            explorerSearchResults.RecalculateResults(ViewModel.EditingContext, modelSearchResults);
            return(explorerSearchResults);
        }
Пример #5
0
        internal virtual void OnModelPropertyChanged(string modelPropName)
        {
            if (modelPropName == EFNameableItem.AttributeName
                ||
                modelPropName == IsKeyPropertyID)
            {
                // reset the name field if the EFNameableItem.AttributeName argument is passed
                Debug.Assert(ModelItem != null, "Name changed on a explorer node with no corresponding model item");
                if (ModelItem != null &&
                    modelPropName == EFNameableItem.AttributeName)
                {
                    _name = ModelItem.DisplayName;
                }

                // our "name" or "key-ness" changed, so we need to re-sort the
                // collection we are contained in
                var containingCollection = ContainingCollection;
                if (containingCollection != null)
                {
                    containingCollection.Sort();
                }

                // we need to reload the _children collection so that it reflects the correct sort-order
                if (Parent != null)
                {
                    Parent.LoadWpfChildrenCollection();
                }

                // update the Search Results - a rename may cause the elements to change or be re-ordered
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(_context);
                explorerSearchResults.OnRenameElement(this);

                OnPropertyChanged(modelPropName);
            }

            // assume any property change will change ToolTipText
            // since it displays the XElement contents
            OnPropertyChanged("ToolTipText");
        }
Пример #6
0
        protected override bool ProcessCreateOrDeleteChange(EditingContext ctx, ModelToExplorerModelXRef xref, EfiChange change)
        {
            var artifact = change.Changed as EFArtifact;

            var conceptualModel = change.Changed as ConceptualEntityModel;
            var storageModel    = change.Changed as StorageEntityModel;
            var mappingModel    = change.Changed as MappingModel;

            if (null != artifact
                ||
                null != conceptualModel
                ||
                null != storageModel
                ||
                null != mappingModel)
            {
                // reset the search results - they will no longer be valid
                // once the view model is recalculated below
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(ctx);
                explorerSearchResults.Reset();

                // reload the UI - the ExplorerViewModelChanged will be fired
                // allowing the frame to rebind
                CreateViewModel(ctx);

                // don't process any more
                return(false);
            }

            var efElement = change.Changed as EFElement;

            // ExplorerViewModelHelper only needs to process EFElement changes
            // (others are DefaultableValue and SingleItemBinding - but
            // ExplorerViewModel does not currently need to map these latter)
            if (null != efElement)
            {
                var parent = efElement.Parent as EFElement;
                Debug.Assert(
                    null != parent,
                    "received changed element of type " + change.Changed.GetType().FullName + " with non-EFElement parent of type "
                    + (efElement.Parent == null ? "NULL" : efElement.Parent.GetType().FullName));
                if (null != parent)
                {
                    // special case changing of an entity's key
                    // If we are creating/deleting a Key PropertyRef then we need
                    // to update the underlying ExplorerProperty
                    var propRef    = efElement as PropertyRef;
                    var keyElement = efElement as Key;
                    if (propRef != null)
                    {
                        keyElement = propRef.GetParentOfType(typeof(Key)) as Key;
                        if (keyElement != null &&
                            null != propRef.Name &&
                            null != propRef.Name.Target)
                        {
                            ExplorerEFElement explorerProp =
                                xref.GetExisting(propRef.Name.Target) as ExplorerProperty;
                            if (null != explorerProp)
                            {
                                explorerProp.OnModelPropertyChanged(ExplorerEFElement.IsKeyPropertyID);
                            }
                        }
                    }
                    else if (keyElement != null)
                    {
                        // key must be a child of an entity
                        var et = parent as EntityType;
                        if (et != null)
                        {
                            // the key is being created or completely removed, so sync up every property
                            foreach (var prop in et.Properties())
                            {
                                ExplorerEFElement explorerProp = xref.GetExisting(prop) as ExplorerProperty;
                                if (null != explorerProp)
                                {
                                    explorerProp.OnModelPropertyChanged(ExplorerEFElement.IsKeyPropertyID);
                                }
                            }
                        }
                    }
                    else
                    {
                        // find Explorer node which maps to the model's parent
                        // this can be null is the ViewModel does not map the
                        // parent object
                        if (typeof(FunctionImport) == efElement.GetType())
                        {
                            // the FunctionImport Explorer Parent node has been decided to be the ConceptualEntityModel ExplorerEFElement
                            // rather than the ConceptualEntityContainer one which we would more naturally use to match the model setup
                            parent = parent.Parent as EFElement;
                        }
                        var explorerParentItem = xref.GetExisting(parent);
                        if (null != explorerParentItem)
                        {
                            // now find the Explorer node which should be the new/deleted ViewModel element's parent
                            // (may not be the same as above due to Explorer ghost nodes)
                            explorerParentItem = explorerParentItem.GetParentNodeForElement(efElement);

                            if (EfiChange.EfiChangeType.Create == change.Type)
                            {
                                // It's possible that between the Create of a parent and its child
                                // the Children property is called on the parent which loads the
                                // child into the parent, even though the child is being added with
                                // change.Type = Create. For safety, we should remove the existing
                                // child (if it exists) so as to ensure any changes in the child change
                                // are reflected.
                                var explorerEFElement = xref.GetExisting(efElement);
                                if (explorerEFElement != null)
                                {
                                    explorerParentItem.RemoveChildIfLoaded(efElement);
                                }
                                explorerParentItem.InsertChildIfLoaded(efElement);
                            }
                            else
                            {
                                explorerParentItem.RemoveChildIfLoaded(efElement);
                            }
                        }
                    }
                }
            }

            return(true);
        }
        internal static ExplorerSearchResults GetExplorerSearchResults(EditingContext context)
        {
            var explorerSearchResults = context.Items.GetValue<ExplorerSearchResults>();
            if (null == explorerSearchResults)
            {
                explorerSearchResults = new ExplorerSearchResults();
                context.Items.SetValue(explorerSearchResults);
            }

            return explorerSearchResults;
        }