src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/DSLDesignerNavigationHelper.cs
/// <summary>
///     This class will set the focus on the "most-appropriate" DSL node for the given EFObject and DSL Diagram.  It is assumed that the
///     EFObject is either a C-Space node, or an M-space node.
/// </summary>
This class will set the focus on the "most-appropriate" DSL node for the given EFObject and DSL Diagram.  It is assumed that the
EFObject is either a C-Space node, or an M-space node.
This class will set the focus on the " most - appropriate " DSL node for the given EFObject and DSL Diagram . It is assumed that the EFObject is either a C - Space node or an M - space node .
internal static bool NavigateToDSLNodeInDiagram(EntityDesignerDiagram diagram, EFObject efobject)
        {
            var foundDSLElementMatchInDiagram = false;
            var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(efobject.Artifact.Uri);
            var cModel = efobject.GetParentOfType(typeof(ConceptualEntityModel)) as ConceptualEntityModel;
            var cspaceEFObject = efobject;
            EFObject mspaceEFObject = null;
            if (cModel == null)
            {
                var mModel = efobject.GetParentOfType(typeof(MappingModel)) as MappingModel;
                Debug.Assert(mModel != null, "efobject is neither in c-space or s-space");
                cspaceEFObject = GetCSpaceEFObjectForMSpaceEFObject(efobject);
                mspaceEFObject = efobject;
            }
            var diagramItemCollection = new DiagramItemCollection();
            RetrieveDiagramItemCollectionForEFObject(diagram, cspaceEFObject, diagramItemCollection);
            if (diagram != null
                && diagramItemCollection.Count > 0)
            {
                diagram.Show();
                if (diagram.ActiveDiagramView != null)
                {
                    diagram.ActiveDiagramView.Focus();
                    diagram.ActiveDiagramView.Selection.Set(diagramItemCollection);
                    diagram.EnsureSelectionVisible();
                }
                else
                {
                    diagram.InitialDiagramItemSelection = diagramItemCollection;
                    if (diagram.ClientViews != null
                        && diagram.ClientViews.Count > 0)
                    {
                        foreach (DiagramClientView clientView in diagram.ClientViews)
                        {
                            clientView.Selection.Set(diagramItemCollection);
                            clientView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                            break;
                        }
                    }
                }
                foundDSLElementMatchInDiagram = true;
            }
            if (mspaceEFObject != null) 
            {
                var mappingDetailsInfo = context.Items.GetValue<MappingDetailsInfo>();
                if (mappingDetailsInfo.MappingDetailsWindow != null)
                {
                    mappingDetailsInfo.MappingDetailsWindow.NavigateTo(mspaceEFObject);
                }
            }
            return foundDSLElementMatchInDiagram;
        }
internal static bool NavigateToDSLNodeInDiagram ( EntityDesignerDiagram diagram , EFObject efobject ) { var foundDSLElementMatchInDiagram = false ; var context = PackageManager . Package . DocumentFrameMgr . EditingContextManager . GetNewOrExistingContext ( efobject . Artifact . Uri ) ; var cModel = efobject . GetParentOfType ( typeof ( ConceptualEntityModel ) ) as ConceptualEntityModel ; var cspaceEFObject = efobject ; EFObject mspaceEFObject = null ; if ( cModel == null ) { var mModel = efobject . GetParentOfType ( typeof ( MappingModel ) ) as MappingModel ; Debug . Assert ( mModel != null , " " ) ; cspaceEFObject = GetCSpaceEFObjectForMSpaceEFObject ( efobject ) ; mspaceEFObject = efobject ; } var diagramItemCollection = new DiagramItemCollection ( ) ; RetrieveDiagramItemCollectionForEFObject ( diagram , cspaceEFObject , diagramItemCollection ) ; if ( diagram != null && diagramItemCollection . Count > 0 ) { diagram . Show ( ) ; if ( diagram . ActiveDiagramView != null ) { diagram . ActiveDiagramView . Focus ( ) ; diagram . ActiveDiagramView . Selection . Set ( diagramItemCollection ) ; diagram . EnsureSelectionVisible ( ) ; } else { diagram . InitialDiagramItemSelection = diagramItemCollection ; if ( diagram . ClientViews != null && diagram . ClientViews . Count > 0 ) { foreach ( DiagramClientView clientView in diagram . ClientViews ) { clientView . Selection . Set ( diagramItemCollection ) ; clientView . Selection . EnsureVisible ( DiagramClientView . EnsureVisiblePreferences . ScrollIntoViewCenter ) ; break ; } } } foundDSLElementMatchInDiagram = true ; } if ( mspaceEFObject != null ) { var mappingDetailsInfo = context . Items . GetValue < MappingDetailsInfo > ( ) ; if ( mappingDetailsInfo . MappingDetailsWindow != null ) { mappingDetailsInfo . MappingDetailsWindow . NavigateTo ( mspaceEFObject ) ; } } return foundDSLElementMatchInDiagram ; }
This class will set the focus on the "most-appropriate" DSL node for the given EFObject and DSL Diagram.
This class will set the focus on the " most - appropriate " DSL node for the given EFObject and DSL Diagram .
// find the model parent (if this is a c-space object) // by default, we assume that this our c-space object // if this is a mapping node, then we want to find the closest corresponding c-space node // to which this mapping node is mapped, and set the focus on that. // navigate to the shape in the DSL designer // If no active view exists, do the following: // - Set the selection on the first associated views (if any). // - Set InitialSelectionDIagramItemSelectionProperty to prevent the first EntityTypeShape to be selected (default behavior) //   This case can happen when the diagram is not initialized or is not fully rendered. // navigate to the item in the mapping screen (if we are doing MSL items)
diagram
EntityDesignerDiagram
efobject
EFObject