コード例 #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
        public override void CreateViewModel(EditingContext ctx)
        {
            var service = ctx.GetEFArtifactService();

            Debug.Assert(service != null, "Null service in ExplorerViewModelHelper.CreateViewModel()");
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Null artifact in ExplorerViewModelHelper.CreateViewModel()");

            var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(ctx);

            xref.Clear();

            var edmRootNode = new ExplorerRootNode(ctx, null, artifact.Uri);

            var designerInfo = artifact.DesignerInfo();

            if (designerInfo != null &&
                designerInfo.Diagrams != null)
            {
                var explorerDiagrams = (ExplorerDiagrams)
                                       ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, designerInfo.Diagrams, edmRootNode, typeof(ExplorerDiagrams));
                edmRootNode.Diagrams = explorerDiagrams;
            }

            if (artifact.ConceptualModel() != null)
            {
                var browserCsdlEntityModel = (ExplorerConceptualEntityModel)
                                             ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, artifact.ConceptualModel(), edmRootNode, typeof(ExplorerConceptualEntityModel));
                edmRootNode.ConceptualModel = browserCsdlEntityModel;
            }

            if (artifact.StorageModel() != null)
            {
                var browserSsdlEntityModel = (ExplorerStorageEntityModel)
                                             ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, artifact.StorageModel(), edmRootNode, typeof(ExplorerStorageEntityModel));
                edmRootNode.StorageModel = browserSsdlEntityModel;
            }

            // expand the tree view so that the Conceptual, Storage Models, and Diagram nodes are visible
            if (edmRootNode.Diagrams != null)
            {
                edmRootNode.Diagrams.Types.ExpandTreeViewToMe();
            }

            if (edmRootNode.ConceptualModel != null)
            {
                edmRootNode.ConceptualModel.Types.ExpandTreeViewToMe();
            }

            if (edmRootNode.StorageModel != null)
            {
                edmRootNode.StorageModel.Types.ExpandTreeViewToMe();
            }

            base.ViewModel = new ExplorerViewModel(ctx, edmRootNode);
        }
コード例 #3
0
        internal void RecalculateResults(EditingContext context, ModelSearchResults modelSearchResults)
        {
            // reset all old IsInSearchResults values
            foreach (var oldSearchResult in Results)
            {
                oldSearchResult.IsInSearchResults = false;
            }

            // now recalculate the results based on the new ModelSearchResults
            Reset();
            _targetString        = modelSearchResults.TargetString;
            _elementTextToSearch = modelSearchResults.ElementTextToSearch;
            var modelToExplorerModelXRef = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(context);

            if (null != modelToExplorerModelXRef)
            {
                // add all the ExplorerEFElements to _results
                foreach (var result in modelSearchResults.Results)
                {
                    var resultsExplorerElement = modelToExplorerModelXRef.GetExisting(result);
                    if (resultsExplorerElement != null)
                    {
                        resultsExplorerElement.IsInSearchResults = true;
                        _results.Add(resultsExplorerElement);
                    }
                }

                // now sort _results according to the order they appear in the Explorer
                SortResults();
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
0
        internal override void OnModelPropertyChanged(string modelPropName)
        {
            base.OnModelPropertyChanged(modelPropName);

            var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(_context);

            if (modelPropName == EFNameableItem.AttributeName)
            {
                // This code below makes sure that if ExplorerConceptualEntityType's name is changed we need to ensure the corresponding ExplorerEntityTypeShape's name is also updated.
                // TODO: review the code below see if we can create a more generic code in ExplorerViewModelHelper's ProcessModelChangesCommitted.
                var entityType = ModelItem as EntityType;
                foreach (var ets in entityType.GetAntiDependenciesOfType <EntityTypeShape>())
                {
                    var exploreEFElement = xref.GetExisting(ets);
                    if (exploreEFElement != null)
                    {
                        exploreEFElement.OnModelPropertyChanged(modelPropName);
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        ///     this is called by the handler in ExplorerFrame so that we can catch
        ///     exceptions and reload the UI if needed - don't call this from anywhere else
        /// </summary>
        internal void ProcessModelChangesCommitted(EditingContext ctx, EfiChangedEventArgs e)
        {
            if (ctx == null)
            {
                // some other view has caused the context and/or artifact to close & reload
                // and we are still in the middle of firing the ModelChangesCommitted event
                // so just exit
                return;
            }

            var xref      = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(ctx);
            var artifacts = GetCurrentArtifactsInView(ctx);

            foreach (var change in e.ChangeGroup.Changes)
            {
                // only process changes for the artifact this view model is associated with
                if (artifacts.Contains(change.Changed.Artifact) == false)
                {
                    continue;
                }

                switch (change.Type)
                {
                // Create and Delete have the same action at the moment
                case EfiChange.EfiChangeType.Create:
                case EfiChange.EfiChangeType.Delete:
                    if (!ProcessCreateOrDeleteChange(ctx, xref, change))
                    {
                        // don't process any more
                        return;
                    }
                    break;

                case EfiChange.EfiChangeType.Update:
                    var updatedElement = change.Changed as EFElement;
                    if (updatedElement != null)
                    {
                        var explorerItem = xref.GetExisting(updatedElement);
                        if (explorerItem != null)
                        {
                            foreach (var propName in change.Properties.Keys)
                            {
                                explorerItem.OnModelPropertyChanged(propName);
                            }
                        }
                    }
                    else
                    {
                        var defaultableValue = change.Changed as DefaultableValue;
                        if (defaultableValue != null)
                        {
                            updatedElement = defaultableValue.Parent as EFElement;
                            if (updatedElement != null)
                            {
                                var explorerItem = xref.GetExisting(updatedElement);
                                if (explorerItem != null)
                                {
                                    explorerItem.OnModelPropertyChanged(defaultableValue.PropertyName);
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }