internal static void NavigateTo(EFObject efobject)
        {
            if (efobject.RuntimeModelRoot() == null)
            {
                // nothing to navigate to, so just return;
                return;
            }

            if (efobject.RuntimeModelRoot() is StorageEntityModel)
            {
                // s-space object, so just return;
                return;
            }

            var selectionService = Services.DslMonitorSelectionService;
            Debug.Assert(selectionService != null, "Could not retrieve IMonitorSelectionService from Escher package.");
            var foundDSLElementMatchInDiagram = false;
            if (selectionService != null)
            {
                var singleDiagramDocView = selectionService.CurrentDocumentView as SingleDiagramDocView;

                if (singleDiagramDocView != null)
                {
                    foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                        singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                    if (foundDSLElementMatchInDiagram)
                    {
                        // The code below is added to ensure that the right doc-view is shown and activated.
                        singleDiagramDocView.Frame.Show();
                        return;
                    }
                }
            }

            // Retrieves the doc data for the efobject.
            var docdata = VSHelpers.GetDocData(Services.ServiceProvider, efobject.Uri.LocalPath) as ModelingDocData;
            Debug.Assert(docdata != null, "Could not find get doc data for artifact with URI:" + efobject.Uri.LocalPath);
            if (docdata != null)
            {
                foreach (var docView in docdata.DocViews)
                {
                    var singleDiagramDocView = docView as SingleDiagramDocView;
                    Debug.Assert(
                        singleDiagramDocView != null,
                        "Why the doc view is not type of SingleDiagramDocView? Actual type:" + docView.GetType().Name);
                    if (docView != null)
                    {
                        foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                            singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                        if (foundDSLElementMatchInDiagram)
                        {
                            // The code below is added to ensure that the right doc-view is shown and activated.
                            singleDiagramDocView.Frame.Show();
                            return;
                        }
                    }
                }
            }
        }
Пример #2
0
        public static void NavigateTo(EFObject efobject)
        {
            if (efobject == null)
            {
                return;
            }

            // if this is a mapping element, just return, since we can't navigate to a mapping element in the explorer
            if (efobject.RuntimeModelRoot() != null && efobject.RuntimeModelRoot() is MappingModel ||
                efobject is MappingModel)
            {
                return;
            }

            // now set the focus on this node
            var editingContext =
                PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(
                    efobject.Artifact.ArtifactSet.GetEntityDesignArtifact().Uri);

            Debug.Assert(editingContext != null, "Unable get EditingContext");
            if (editingContext != null)
            {
                // make sure that ExplorerWindow has the right context (this is necessary when navigating to efObject in file that's not currently opened)
                var explorerWindow = PackageManager.Package.ExplorerWindow;
                if (explorerWindow.Context != editingContext)
                {
                    explorerWindow.Context = editingContext;
                }

                var explorerInfo = editingContext.Items.GetValue <ExplorerWindow.ExplorerInfo>();
                Debug.Assert(explorerInfo != null, "Unable get ExplorerInfo from EditingContext");
                if (explorerInfo != null)
                {
                    var explorerFrame = explorerInfo._explorerFrame;
                    Debug.Assert(explorerFrame != null, "Unable to get ExplorerFrame from ExplorerInfo");
                    if (explorerFrame != null)
                    {
                        // note - if we don't show the frame before calling GetTreeViewItem, then
                        // we don't find the correct tree view item the first time GetTreeViewItem is called.
                        // we find a parent. Rather, we find a parent close to the root.
                        var frame = PackageManager.Package.ExplorerWindow.Frame as IVsWindowFrame;
                        if (frame != null)
                        {
                            frame.Show();
                        }

                        // Ensure that the root node is expanded so the selected node is shown.
                        // Only need to expand the root node, the rest of the nodes will be expanded when the code traverse to the selected node.
                        explorerFrame.ExplorerTreeRoot.IsExpanded = true;

                        var treeViewItem = GetTreeViewItemForEFObject(efobject, explorerFrame);
                        Debug.Assert(treeViewItem != null, "Unable to get TreeViewItem from explorerFrame");

                        if (treeViewItem != null)
                        {
                            treeViewItem.IsSelected = true;
                            treeViewItem.Focus();
                        }
                    }
                }
            }
        }
        private static void RetrieveDiagramItemCollectionForEFObject(
            EntityDesignerDiagram diagram, EFObject efobject, DiagramItemCollection diagramItemCollection)
        {
            if (efobject == null)
            {
                return;
            }

            var cModel = efobject.RuntimeModelRoot() as ConceptualEntityModel;

            if (cModel == null)
            {
                // this either isn't a c-space object, or it is the ConceptualEntityModel node, so just return null
                return;
            }

            // if this is a child element of the association, return the diagram item for the association
            if (!(efobject is Association))
            {
                var association = efobject.GetParentOfType(typeof(Association)) as Association;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }

            if (efobject is Association)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is NavigationProperty)
            {
                var np              = efobject as NavigationProperty;
                var shapeElement    = GetDesignerShapeElementForEFObject(diagram, np.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;

                if (entityTypeShape != null)
                {
                    // get the view model navigation property
                    var vmNavProp = diagram.ModelElement.ModelXRef.GetExisting(np) as ViewModel.NavigationProperty;

                    // try to create the DiagramItem from this
                    if (vmNavProp != null)
                    {
                        var index = entityTypeShape.NavigationCompartment.Items.IndexOf(vmNavProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.NavigationCompartment, entityTypeShape.NavigationCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is Property)
            {
                var prop = efobject as Property;
                if (prop.IsComplexTypeProperty)
                {
                    // complex type properties are not supported in the designer
                    return;
                }
                var shapeElement    = GetDesignerShapeElementForEFObject(diagram, prop.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;
                if (entityTypeShape != null)
                {
                    // get the view model  property
                    var vmProp = diagram.ModelElement.ModelXRef.GetExisting(prop) as ViewModel.Property;

                    if (vmProp != null)
                    {
                        var index = entityTypeShape.PropertiesCompartment.Items.IndexOf(vmProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.PropertiesCompartment, entityTypeShape.PropertiesCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is EntityType)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is EntitySet)
            {
                var es = efobject as EntitySet;
                foreach (var entityType in es.GetEntityTypesInTheSet())
                {
                    if (entityType != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, entityType, diagramItemCollection);
                    }
                }
                return;
            }
            else if (efobject is AssociationSet)
            {
                // return a diagram item for the association
                var associationSet = efobject as AssociationSet;
                var association    = associationSet.Association.Target;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is AssociationSetEnd)
            {
                var associationSetEnd = efobject as AssociationSetEnd;
                var end = associationSetEnd.Role.Target;
                if (end != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, end, diagramItemCollection);
                    return;
                }
                else
                {
                    var es = associationSetEnd.EntitySet.Target;
                    if (es != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, es, diagramItemCollection);
                        return;
                    }
                }
            }
            else if (efobject is PropertyRef)
            {
                var pref = efobject as PropertyRef;
                if (pref.Name.Target != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref.Name.Target, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is PropertyRefContainer)
            {
                var prefContainer = efobject as PropertyRefContainer;

                // just use the first entry in the list.
                foreach (var pref in prefContainer.PropertyRefs)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is EFAttribute)
            {
                // this is an EFAttribute node, so get the DiagramItem for the parent
                RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                return;
            }
            else if (efobject is ConceptualEntityModel)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is ConceptualEntityContainer)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is FunctionImport)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else
            {
                Debug.Fail("unexpected type of efobject.  type = " + efobject.GetType());
                if (efobject.Parent != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                }
            }
        }
        internal static void NavigateTo(EFObject efobject)
        {
            if (efobject.RuntimeModelRoot() == null)
            {
                // nothing to navigate to, so just return;
                return;
            }

            if (efobject.RuntimeModelRoot() is StorageEntityModel)
            {
                // s-space object, so just return;
                return;
            }

            var selectionService = Services.DslMonitorSelectionService;

            Debug.Assert(selectionService != null, "Could not retrieve IMonitorSelectionService from Escher package.");
            var foundDSLElementMatchInDiagram = false;

            if (selectionService != null)
            {
                var singleDiagramDocView = selectionService.CurrentDocumentView as SingleDiagramDocView;

                if (singleDiagramDocView != null)
                {
                    foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                        singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                    if (foundDSLElementMatchInDiagram)
                    {
                        // The code below is added to ensure that the right doc-view is shown and activated.
                        singleDiagramDocView.Frame.Show();
                        return;
                    }
                }
            }

            // Retrieves the doc data for the efobject.
            var docdata = VSHelpers.GetDocData(Services.ServiceProvider, efobject.Uri.LocalPath) as ModelingDocData;

            Debug.Assert(docdata != null, "Could not find get doc data for artifact with URI:" + efobject.Uri.LocalPath);
            if (docdata != null)
            {
                foreach (var docView in docdata.DocViews)
                {
                    var singleDiagramDocView = docView as SingleDiagramDocView;
                    Debug.Assert(
                        singleDiagramDocView != null,
                        "Why the doc view is not type of SingleDiagramDocView? Actual type:" + docView.GetType().Name);
                    if (docView != null)
                    {
                        foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                            singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                        if (foundDSLElementMatchInDiagram)
                        {
                            // The code below is added to ensure that the right doc-view is shown and activated.
                            singleDiagramDocView.Frame.Show();
                            return;
                        }
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 ///     Gets a value indicating whether the EFObject should be visited.
 /// </summary>
 protected override bool ShouldVisit(EFObject efObject)
 {
     return(!(efObject.RuntimeModelRoot() is StorageEntityModel));
 }
 /// <summary>
 ///     Gets a value indicating whether the EFObject should be visited.
 /// </summary>
 protected override bool ShouldVisit(EFObject efObject)
 {
     return !(efObject.RuntimeModelRoot() is StorageEntityModel);
 }
        private static void RetrieveDiagramItemCollectionForEFObject(
            EntityDesignerDiagram diagram, EFObject efobject, DiagramItemCollection diagramItemCollection)
        {
            if (efobject == null)
            {
                return;
            }

            var cModel = efobject.RuntimeModelRoot() as ConceptualEntityModel;

            if (cModel == null)
            {
                // this either isn't a c-space object, or it is the ConceptualEntityModel node, so just return null
                return;
            }

            // if this is a child element of the association, return the diagram item for the association
            if (!(efobject is Association))
            {
                var association = efobject.GetParentOfType(typeof(Association)) as Association;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }

            if (efobject is Association)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is NavigationProperty)
            {
                var np = efobject as NavigationProperty;
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, np.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;

                if (entityTypeShape != null)
                {
                    // get the view model navigation property
                    var vmNavProp = diagram.ModelElement.ModelXRef.GetExisting(np) as ViewModel.NavigationProperty;

                    // try to create the DiagramItem from this
                    if (vmNavProp != null)
                    {
                        var index = entityTypeShape.NavigationCompartment.Items.IndexOf(vmNavProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.NavigationCompartment, entityTypeShape.NavigationCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is Property)
            {
                var prop = efobject as Property;
                if (prop.IsComplexTypeProperty)
                {
                    // complex type properties are not supported in the designer
                    return;
                }
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, prop.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;
                if (entityTypeShape != null)
                {
                    // get the view model  property
                    var vmProp = diagram.ModelElement.ModelXRef.GetExisting(prop) as ViewModel.Property;

                    if (vmProp != null)
                    {
                        var index = entityTypeShape.PropertiesCompartment.Items.IndexOf(vmProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.PropertiesCompartment, entityTypeShape.PropertiesCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is EntityType)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is EntitySet)
            {
                var es = efobject as EntitySet;
                foreach (var entityType in es.GetEntityTypesInTheSet())
                {
                    if (entityType != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, entityType, diagramItemCollection);
                    }
                }
                return;
            }
            else if (efobject is AssociationSet)
            {
                // return a diagram item for the association
                var associationSet = efobject as AssociationSet;
                var association = associationSet.Association.Target;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is AssociationSetEnd)
            {
                var associationSetEnd = efobject as AssociationSetEnd;
                var end = associationSetEnd.Role.Target;
                if (end != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, end, diagramItemCollection);
                    return;
                }
                else
                {
                    var es = associationSetEnd.EntitySet.Target;
                    if (es != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, es, diagramItemCollection);
                        return;
                    }
                }
            }
            else if (efobject is PropertyRef)
            {
                var pref = efobject as PropertyRef;
                if (pref.Name.Target != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref.Name.Target, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is PropertyRefContainer)
            {
                var prefContainer = efobject as PropertyRefContainer;

                // just use the first entry in the list.
                foreach (var pref in prefContainer.PropertyRefs)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is EFAttribute)
            {
                // this is an EFAttribute node, so get the DiagramItem for the parent
                RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                return;
            }
            else if (efobject is ConceptualEntityModel)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is ConceptualEntityContainer)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is FunctionImport)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else
            {
                Debug.Fail("unexpected type of efobject.  type = " + efobject.GetType());
                if (efobject.Parent != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                }
            }
        }
        public static void NavigateTo(EFObject efobject)
        {
            if (efobject == null)
            {
                return;
            }

            // if this is a mapping element, just return, since we can't navigate to a mapping element in the explorer
            if (efobject.RuntimeModelRoot() != null && efobject.RuntimeModelRoot() is MappingModel
                || efobject is MappingModel)
            {
                return;
            }

            // now set the focus on this node
            var editingContext =
                PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(
                    efobject.Artifact.ArtifactSet.GetEntityDesignArtifact().Uri);
            Debug.Assert(editingContext != null, "Unable get EditingContext");
            if (editingContext != null)
            {
                // make sure that ExplorerWindow has the right context (this is necessary when navigating to efObject in file that's not currently opened)
                var explorerWindow = PackageManager.Package.ExplorerWindow;
                if (explorerWindow.Context != editingContext)
                {
                    explorerWindow.Context = editingContext;
                }

                var explorerInfo = editingContext.Items.GetValue<ExplorerWindow.ExplorerInfo>();
                Debug.Assert(explorerInfo != null, "Unable get ExplorerInfo from EditingContext");
                if (explorerInfo != null)
                {
                    var explorerFrame = explorerInfo._explorerFrame;
                    Debug.Assert(explorerFrame != null, "Unable to get ExplorerFrame from ExplorerInfo");
                    if (explorerFrame != null)
                    {
                        // note - if we don't show the frame before calling GetTreeViewItem, then 
                        // we don't find the correct tree view item the first time GetTreeViewItem is called.
                        // we find a parent. Rather, we find a parent close to the root. 
                        var frame = PackageManager.Package.ExplorerWindow.Frame as IVsWindowFrame;
                        if (frame != null)
                        {
                            frame.Show();
                        }

                        // Ensure that the root node is expanded so the selected node is shown.
                        // Only need to expand the root node, the rest of the nodes will be expanded when the code traverse to the selected node.
                        explorerFrame.ExplorerTreeRoot.IsExpanded = true;

                        var treeViewItem = GetTreeViewItemForEFObject(efobject, explorerFrame);
                        Debug.Assert(treeViewItem != null, "Unable to get TreeViewItem from explorerFrame");

                        if (treeViewItem != null)
                        {
                            treeViewItem.IsSelected = true;
                            treeViewItem.Focus();
                        }
                    }
                }
            }
        }